Esempio n. 1
0
        private void MainLoop()
        {
            bool exit          = false;
            int  oldmouse_x    = -1;
            int  oldmouse_y    = -1;
            bool?lastmousepoll = null;
            bool?thismousepoll = null;
            int  lastkey       = -1;

            do
            {
                AllegroAPI.poll_mouse(); //get mouse data

                if ((AllegroAPI.mouse_b & 1) > 0)
                {
                    thismousepoll = true;
                }
                else if (lastmousepoll.HasValue && lastmousepoll.Value == true)
                {
                    thismousepoll = false;
                }
                else
                {
                    thismousepoll = null;
                }



                if (AllegroAPI.mouse_x != oldmouse_x | Allegro.mouse_y != oldmouse_y)
                {
                    RatCow.Controls.GraphicContext.Instance.Render(AllegroAPI.mouse_x, AllegroAPI.mouse_y, thismousepoll);

                    oldmouse_x = AllegroAPI.mouse_x;
                    oldmouse_y = AllegroAPI.mouse_y;
                }
                else if (thismousepoll.HasValue)
                {
                    RatCow.Controls.GraphicContext.Instance.Render(AllegroAPI.mouse_x, AllegroAPI.mouse_y, thismousepoll);
                }

                lastmousepoll = thismousepoll;

                AllegroAPI.poll_keyboard();

                //read keyboard
                if (AllegroAPI.keypressed() != 0)
                {
                    var mapping = TranslateKey();

                    var k = AllegroAPI.readkey();
                    if (k != -1)
                    {
                        char c = (char)(k & 0xFF);

                        if (mapping == Key.Unmapped)
                        {
                            RatCow.Controls.GraphicContext.Instance.RenderText(c);
                        }
                        else
                        {
                            RatCow.Controls.GraphicContext.Instance.RenderKey(mapping, false, false, false);
                        }
                    }

                    lastkey = k;
                }

                AllegroAPI.vsync();
            }while (!exit);
        }