Exemple #1
0
        public void Dispose()
        {
            Dispose(true);

            window.Dispose();
            platform.Dispose();
            AgateApp.Dispose();
        }
        private void ChangeDisplayWindow(IResolution resolution)
        {
            currentResolution = resolution;

            wind?.Dispose();

            wind = DisplayWindow.CreateFullScreen(Name, resolution);
            Display.RenderTarget = wind.FrameBuffer;
        }
        public override void Dispose()
        {
            if (mFakeWindow != null)
            {
                mFakeDisplayWindow.Dispose();
                mFakeWindow.Dispose();
            }

            mDevice.Dispose();
        }
Exemple #4
0
        void Keyboard_KeyDown(InputEventArgs e)
        {
            if (e.KeyCode == KeyCode.Space)
            {
                ortho++;
                if (ortho > 2)
                {
                    ortho = 0;
                }

                Keyboard.ReleaseKey(KeyCode.Space);
            }
            else if (e.KeyCode == KeyCode.Escape)
            {
                wind.Dispose();
            }
        }
Exemple #5
0
        void Run(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed
                                         ("Pong Example", displayWidth, displayHeight);

                font = new FontSurface("Sans Serif", 14);

                paddle[0]    = new Vector2(50, displayHeight / 2);
                paddle[1]    = new Vector2(playAreaWidth - 50 - paddleWidth, displayHeight / 2);
                ball         = new Vector2(playAreaWidth / 2, displayHeight / 2);
                ballvelocity = new Vector2(-70, 70);

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.DarkGray);

                    DrawBorder();
                    DrawPaddles();
                    DrawBall();
                    DrawScore();

                    Display.EndFrame();
                    Core.KeepAlive();

                    if (Keyboard.Keys[KeyCode.Escape])
                    {
                        wind.Dispose();
                    }

                    float time_s = (float)Display.DeltaTime / 1000.0f;

                    UpdatePaddles(time_s);
                    UpdateBall(time_s);
                }
            }
        }
        public void SetRenderTarget(object render, object zoomRender)
        {
            mRenderTarget     = render;
            mZoomRenderTarget = zoomRender;

            if (wind != null)
            {
                wind.Dispose();
                zoomWind.Dispose();
                bgDark.Dispose();
                bgLight.Dispose();
            }

            zoomWind = DisplayWindow.CreateFromControl(zoomRender);
            wind     = DisplayWindow.CreateFromControl(render);

            bgDark  = new Surface("bgdark.png");
            bgLight = new Surface("bglight.png");

            DisplayColor = Color.White;
        }
        public void Run(string[] args)
        {
            ChangeDisplayWindow(3);

            Surface mySurface = new Surface("Images/pointer.png");

            Input.Unhandled.KeyDown   += Keyboard_KeyDown;
            Input.Unhandled.MouseMove += (sender, e) => mousePosition = e.MousePosition;

            IFont font = Font.AgateSans;

            Size bottomSize = font.MeasureString(bottomText);
            Size topSize    = font.MeasureString(topText + "z\nz");

            // Run the program while the window is open.
            while (AgateApp.IsAlive)
            {
                var mouseText = topText +
                                $"Resolution: {currentResolution}\nMouse: {mousePosition}";

                Display.BeginFrame();
                Display.Clear(Color.DarkGreen);

                font.DrawText(0, Display.CurrentWindow.Height - bottomSize.Height, bottomText);

                Display.Primitives.FillRect(Color.Maroon,
                                            new Rectangle(0, 0, Display.CurrentWindow.Width, topSize.Height));

                font.DrawText(mouseText);

                mySurface.Draw(mousePosition.X, mousePosition.Y);

                Display.EndFrame();
                AgateApp.KeepAlive();
            }

            mySurface.Dispose();
            wind.Dispose();
        }
Exemple #8
0
        public void Run(string[] args)
        {
            using (var wind = new DisplayWindowBuilder(args)
                              .BackbufferSize(800, 600)
                              .QuitOnClose()
                              .Build())
            {
                DisplayWindow fullWind = null;

                FontSurface bitmapFontSurface = FontSurface.BitmapMonospace("lotafont.png", new Size(16, 16));
                Font        bitmapFont        = new FontBuilder("lotafont").AddFontSurface(
                    new FontSettings(16, FontStyles.None), bitmapFontSurface).Build();

                int frame = 0;

                while (AgateApp.IsAlive)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.DarkGray);

                    IFont font = Font.AgateSans;
                    font.Size = 12;

                    // test the color changing
                    font.Color = Color.LightGreen;
                    font.DrawText(20, 150, "This is regular green text.");
                    font.Color = Color.White;

                    // test display alignment property
                    Point  textPoint = new Point(100, 50);
                    string text      = string.Format("This text is centered on {0},{1}.", textPoint.X, textPoint.Y);
                    Size   textSize  = font.MeasureString(text);

                    // draw a box around where the text should be displayed.
                    Display.Primitives.DrawRect(Color.Gray,
                                                new Rectangle(textPoint.X - textSize.Width / 2, textPoint.Y - textSize.Height / 2,
                                                              textSize.Width, textSize.Height));

                    font.DisplayAlignment = OriginAlignment.Center;
                    font.DrawText(textPoint, text);
                    font.DisplayAlignment = OriginAlignment.TopLeft;

                    // test text scaling
                    font.Size = 24;
                    text      = "This text is twice as big.";
                    textPoint = new Point(50, 75);
                    textSize  = font.MeasureString(text);

                    // draw a box with the same size the text should appear as
                    Display.Primitives.DrawRect(Color.White, new Rectangle(textPoint, textSize));

                    font.DrawText(textPoint, text);
                    font.Size = 12;

                    // this draws a white background behind the text we want to Display.
                    text  = "F2: Toggle VSync   F5:  Toggle Windowed / Fullscreen      ";
                    text += "FPS: " + Display.FramesPerSecond.ToString("0.00") + "    ";

                    if (AgateApp.IsActive)
                    {
                        text += "Active";
                    }
                    else
                    {
                        text += "Not Active";
                    }

                    // figure out how big the displayed text will be
                    textSize = font.MeasureString(text);

                    // draw the white background
                    Display.Primitives.FillRect(Color.White, new Rectangle(new Point(0, 0), textSize));

                    // draw the text on top of the background
                    font.Color = Color.Black;
                    font.DrawText(text);                     // supplying no position arguments defaults to (0, 0)

                    // draw something which moves to let us know the program is running
                    Display.Primitives.FillRect(Color.Red, new Rectangle(
                                                    10, 200, 70 + (int)(50 * Math.Cos(frame / 10.0)), 50));

                    // do some bitmap font stuff
                    bitmapFont.DrawText(10, 350, "THIS IS BITMAP FONT TEXT.");

                    bitmapFont.Color = Color.Red;
                    bitmapFont.DrawText(10, 366, "THIS IS RED TEXT.");
                    bitmapFont.Color = Color.White;

                    bitmapFont.Size = 32;
                    bitmapFont.DrawText(10, 382, "THIS IS BIGG.");

                    Display.Primitives.FillRect(Color.Blue, new Rectangle(95, 425, 10, 10));
                    bitmapFont.TextAlignment = OriginAlignment.Center;
                    bitmapFont.DrawText(100, 430, "CHECK");
                    bitmapFont.TextAlignment = OriginAlignment.TopLeft;

                    Display.Primitives.FillRect(Color.Green, new Rectangle(-10, -10, 20, 20));

                    // and we're done.
                    Display.EndFrame();
                    AgateApp.KeepAlive();

                    frame++;

                    // toggle full screen if the user pressed F5;
                    if (Input.Unhandled.Keys[KeyCode.F5])
                    {
                        System.Diagnostics.Debug.Print("IsFullscreen: {0}", Display.CurrentWindow.IsFullScreen);

                        if (Display.CurrentWindow.IsFullScreen == false)
                        {
                            fullWind = DisplayWindow.CreateFullScreen("Font Tester", 800, 600);
                        }
                        else
                        {
                            fullWind.Dispose();
                            Display.RenderTarget = wind.FrameBuffer;
                        }

                        Input.Unhandled.Keys.ReleaseAll();
                        System.Diagnostics.Debug.Print("IsFullscreen: {0}", Display.CurrentWindow.IsFullScreen);
                    }
                    else if (Input.Unhandled.Keys[KeyCode.F2])
                    {
                        Display.RenderState.WaitForVerticalBlank = !Display.RenderState.WaitForVerticalBlank;
                        Input.Unhandled.Keys.Release(KeyCode.F2);
                    }
                    else if (Input.Unhandled.Keys[KeyCode.Escape])
                    {
                        Display.Dispose();
                        return;
                    }
                }
            }
        }