예제 #1
0
        public void SaveToFile(string s)
        {
            mMutex.WaitOne();

            try
            {
                Bitmap b = new Bitmap(Width, Height, CreateGraphics());
                WindowGDI.Initialize(Graphics.FromImage(b));
                foreach (GraphicCommand c in mCmds)
                {
                    WindowGDI.Draw(c);
                }
                b.Save(s);
            }
            finally
            {
                mMutex.ReleaseMutex();
            }
        }
예제 #2
0
 private void GraphWindow_Paint(object sender, PaintEventArgs e)
 {
     mMutex.WaitOne();
     try
     {
         Bitmap b = new Bitmap(Width, Height, CreateGraphics());
         WindowGDI.Initialize(Graphics.FromImage(b));
         foreach (GraphicCommand c in mCmds)
         {
             WindowGDI.Draw(c);
         }
         if (Config.gbShowTurtle)
         {
             WindowGDI.DrawTurtle();
         }
         // TODO: replace this call with a bit block transfer API call
         e.Graphics.DrawImageUnscaled(b, 0, 0);
     }
     finally
     {
         mMutex.ReleaseMutex();
     }
 }
예제 #3
0
        // TODO: LOWPRI: reintroduce sessions
        //static string gsSessionFile = gsDataFolder + "\\session.cat";

        static void Main(string[] a)
        {
            if (Config.gbShowWelcome)
            {
                WriteLine("Welcome to the Cat programming language =^,,^=");
                WriteLine("version " + Config.gsVersion);
                WriteLine("by Christopher Diggins");
                WriteLine("licensed under the MIT License 1.0");
                WriteLine("http://www.cat-language.com");
                WriteLine("");
                WriteLine("for help, type in #help followed by the enter key");
                WriteLine("to exit, type in #exit followed by the enter key");
                WriteLine("");
            }

            if (!Directory.Exists(gsDataFolder))
            {
                try
                {
                    DirectoryInfo di = Directory.CreateDirectory(gsDataFolder);
                    if (di == null)
                    {
                        throw new Exception("Failed to create directory");
                    }
                }
                catch (Exception e)
                {
                    WriteLine("Failed to create application folder: " + e.Message);
                    WriteLine("I will be unable to save session data or compiled output");
                }
            }

            try
            {
                exec.LoadModule("everything.cat");

                foreach (string s in a)
                {
                    exec.LoadModule(s);
                }

                // main execution loop
                while (true)
                {
                    Prompt();
                    string s = Console.ReadLine();
                    if (s.Trim().Equals("#exit") || s.Trim().Equals("#x"))
                    {
                        break;
                    }
                    Output.LogLine(s);
                    if (s.Length > 0)
                    {
                        DateTime begin = DateTime.Now;

                        try
                        {
                            exec.Execute(s + '\n');
                            TimeSpan elapsed = DateTime.Now - begin;
                            if (Config.gbOutputTimeElapsed)
                            {
                                WriteLine("Time elapsed in msec " + elapsed.TotalMilliseconds.ToString("F"));
                            }
                            // Politely ask graphics window to redraw if needed
                        }
                        catch (Exception e)
                        {
                            WriteLine("exception occurred: " + e.Message);
                        }
                        if (Config.gbOutputStack)
                        {
                            exec.OutputStack();
                        }

#if (!NOGRAPHICS)
                        WindowGDI.Invalidate();
#endif
                    }
                }
            }
            catch (Exception e)
            {
                WriteLine("exception: " + e.Message);
            }

            SaveTranscript(Path.GetTempFileName());

            WriteLine("Press any key to exit ...");
            Console.ReadKey();
        }
예제 #4
0
 private void GraphWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     WindowGDI.NullifyWindow();
 }