Esempio n. 1
0
        protected override bool OnStart()
        {
            try
            {
                GL.LoadBindings(new OpenGLBindingsContext());
            }
            catch (Exception ex)
            {
                XPlane.Trace.WriteLine(ex.ToString());
                return(false);
            }

            var desktopBounds = Screen.BoundsGlobal;

            _window = new Window(
                new Rect(desktopBounds.Left + 50, desktopBounds.Bottom + 450, desktopBounds.Left + 350, desktopBounds.Bottom + 150),
                decoration: WindowDecoration.RoundRectangle);
            _window.SetPositioningMode(WindowPositioningMode.PositionFree);
            _window.SetGravity(0, 1, 0, 1);
            _window.SetResizingLimits(200, 200, 500, 500);
            _window.Title                 = "Sample Window";
            _window.DrawWindow           += OnDrawWindow;
            _window.MouseLeftButtonEvent += OnMouseLeftButtonEvent;

            return(true);
        }
Esempio n. 2
0
 private void OnMouseLeftButtonEvent(Window window, ref MouseButtonEventArgs args)
 {
     if (args.MouseStatus == MouseStatus.Down)
     {
         bool isPoppedOut = window.IsPoppedOut;
         if (!_window.IsInFront)
         {
             _window.BringToFront();
         }
         else if (CoordInRect(args.X, args.Y, _popButtonRect)) // user clicked the pop-in/pop-out button
         {
             _window.SetPositioningMode(isPoppedOut ? WindowPositioningMode.PositionFree : WindowPositioningMode.PopOut, 0);
         }
         else if (CoordInRect(args.X, args.Y, _positionButtonRect)) // user clicked the "move to lower left" button
         {
             // If we're popped out, and the user hits the "move to lower left" button,
             // we need to move them to the lower left of their OS's desktop space (units are pixels).
             // On the other hand, if we're a floating window inside of X-Plane, we need
             // to move to the lower left of the X-Plane global desktop (units are boxels).
             var geometry = isPoppedOut ? _window.GeometryOS : _window.Geometry;
             // Remember, the main monitor's origin is *not* guaranteed to be (0, 0), so we need to query for it in order to move the window to its lower left
             var bounds      = isPoppedOut ? Screen.BoundsGlobal : Screen.AllMonitorBoundsOS[0];
             var newGeometry = new Rect(
                 bounds.Left,
                 bounds.Bottom + geometry.Height,
                 bounds.Left + geometry.Width,
                 bounds.Bottom);
             if (isPoppedOut)
             {
                 _window.GeometryOS = newGeometry;
             }
             else
             {
                 _window.Geometry = newGeometry;
             }
         }
     }
 }
Esempio n. 3
0
        private void OnDrawWindow(Window window, EventArgs args)
        {
            var white = new RGBColor(1, 1, 1);

            Graphics.SetGraphicsState();

            // We draw our rudimentary button boxes based on the height of the button text
            var(_, charHeight, _) = Graphics.GetFontDimensions(FontID.Proportional);


            bool isPoppedOut = window.IsPoppedOut;
            var  popLabel    = isPoppedOut ? "Pop In" : "Pop Out";

            // We'll change the text of the pop-in/pop-out button based on our current state
            var(l, t, r, b) = window.Geometry;

            // Position the pop-in/pop-out button in the upper left of the window (sized to fit the text)
            _popButtonRect = new RectF(
                l + 10,
                t - 15,
                l + 10 + Graphics.MeasureString(FontID.Proportional, popLabel), // *just* wide enough to fit the button text
                t - 15 - (float)(1.25 * charHeight));                           // a bit taller than the button text

            // Position the "move to lower left" button just to the right of the pop-in/pop-out button
            const string positionButtonText = "Move to Lower Left";

            _positionButtonRect = new RectF(
                _popButtonRect.Right + 30,
                _popButtonRect.Top,
                _popButtonRect.Right + 30 + Graphics.MeasureString(FontID.Proportional, positionButtonText),
                _popButtonRect.Bottom);

            // Draw our buttons
            {
                GL.Color4(0f, 1f, 0f, 1f);
                GL.Begin(PrimitiveType.LineLoop);
                {
                    GL.Vertex2(_popButtonRect.Left, _popButtonRect.Top);
                    GL.Vertex2(_popButtonRect.Right, _popButtonRect.Top);
                    GL.Vertex2(_popButtonRect.Right, _popButtonRect.Bottom);
                    GL.Vertex2(_popButtonRect.Left, _popButtonRect.Bottom);
                }
                GL.End();
                GL.Begin(PrimitiveType.LineLoop);
                {
                    GL.Vertex2(_positionButtonRect.Left, _positionButtonRect.Top);
                    GL.Vertex2(_positionButtonRect.Right, _positionButtonRect.Top);
                    GL.Vertex2(_positionButtonRect.Right, _positionButtonRect.Bottom);
                    GL.Vertex2(_positionButtonRect.Left, _positionButtonRect.Bottom);
                }
                GL.End();

                // Draw the button text (pop in/pop out)
                Graphics.DrawString(white, (int)_popButtonRect.Left, (int)_popButtonRect.Bottom + 4, popLabel, FontID.Proportional);

                // Draw the button text (reposition)
                Graphics.DrawString(white, (int)_positionButtonRect.Left, (int)_positionButtonRect.Bottom + 4, positionButtonText, FontID.Proportional);
            }

            // Draw a bunch of informative text
            {
                // Set the y position for the first bunch of text we'll draw to a little below the buttons
                int y = (int)_popButtonRect.Bottom - 2 * charHeight;

                // Display the total global desktop bounds
                var desktopBounds = Screen.BoundsGlobal;
                Graphics.DrawString(white, l, y,
                                    $"Global desktop bounds: ({desktopBounds.Left}, {desktopBounds.Bottom}) to ({desktopBounds.Right}, {desktopBounds.Top})",
                                    FontID.Proportional);

                y -= (int)(1.5 * charHeight);

                // Display our bounds

                if (_window.IsPoppedOut)
                {
                    var windowBounds = _window.GeometryOS;
                    Graphics.DrawString(white, l, y,
                                        $"OS Bounds: ({windowBounds.Left}, {windowBounds.Bottom}) to ({windowBounds.Right}, {windowBounds.Top})",
                                        FontID.Proportional);
                    y -= (int)(1.5 * charHeight);
                }
                else
                {
                    var windowBounds = _window.Geometry;
                    Graphics.DrawString(white, l, y,
                                        $"Window Bounds: ({windowBounds.Left}, {windowBounds.Bottom}) to ({windowBounds.Right}, {windowBounds.Top})",
                                        FontID.Proportional);
                    y -= (int)(1.5 * charHeight);
                }

                // Display whether we're in front of our our layer
                {
                    Graphics.DrawString(white, l, y,
                                        $"In front? {_window.IsInFront}",
                                        FontID.Proportional);
                    y -= (int)(1.5 * charHeight);
                }

                // Display the mouse's position info text
                {
                    var(mouseX, mouseY) = Screen.MouseLocationGlobal;
                    Graphics.DrawString(white, l, y,
                                        $"Draw mouse (global): {mouseX} {mouseY}\n",
                                        FontID.Proportional);
                    y -= (int)(1.5 * charHeight);
                }
            }
        }