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;
             }
         }
     }
 }