Exemplo n.º 1
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                // FIXME: MonoGame cannot read backbuffer
                //if (Screen != null)
                //    graphicsDevice.ResolveBackBuffer(Screen);
                PopupWindowMaterial.SetState(graphicsDevice, Screen);
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);
                SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
Exemplo n.º 2
0
 private void MouseReleasedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers)
 {
     if (userCommandArgs is PointerCommandArgs pointerCommandArgs)
     {
         mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(pointerCommandArgs.Position));
         mouseActiveWindow?.MouseReleased(pointerCommandArgs.Position, keyModifiers);
     }
     mouseActiveWindow = null;
 }
Exemplo n.º 3
0
 internal void WriteWindowZOrder()
 {
     Console.WriteLine();
     Console.WriteLine();
     Console.WriteLine("Windows: (bottom-to-top order, [V] = visible, [NI] = non-interactive)");
     Console.WriteLine("  Visible: {0}", String.Join(", ", VisibleWindows.Select(w => w.GetType().Name).ToArray()));
     Console.WriteLine("  All:     {0}", String.Join(", ", WindowsZOrder.Select(w => String.Format("{0}{1}{2}", w.GetType().Name, w.Interactive ? "" : "[NI]", w.Visible ? "[V]" : "")).ToArray()));
     Console.WriteLine();
 }
Exemplo n.º 4
0
 private void WindowScrollEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers)
 {
     if (userCommandArgs is ScrollCommandArgs scrollCommandArgs)
     {
         mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(scrollCommandArgs.Position));
         if (mouseActiveWindow != null)
         {
             mouseActiveWindow.MouseScroll(scrollCommandArgs.Position, scrollCommandArgs.Delta, keyModifiers);
         }
     }
 }
Exemplo n.º 5
0
 private void MouseDraggingEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers)
 {
     if (userCommandArgs is PointerMoveCommandArgs moveCommandArgs)
     {
         if (null == mouseActiveWindow)
         {
             mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(moveCommandArgs.Position));
         }
         mouseActiveWindow?.MouseDrag(moveCommandArgs.Position, moveCommandArgs.Delta, keyModifiers);
     }
 }
Exemplo n.º 6
0
        private void MouseClickedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers)
        {
            if (userCommandArgs is PointerCommandArgs pointerCommandArgs)
            {
                mouseDownPosition = pointerCommandArgs.Position;
                mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(pointerCommandArgs.Position));
                if ((mouseActiveWindow != null) && (mouseActiveWindow != WindowsZOrder.Last()))
                {
                    BringWindowToTop(mouseActiveWindow);
                }

                mouseActiveWindow?.MousePressed(pointerCommandArgs.Position, keyModifiers);
            }
        }
Exemplo n.º 7
0
        public void HandleUserInput(ElapsedTime elapsedTime)
        {
            if (UserInput.IsMouseLeftButtonPressed)
            {
                mouseDownPosition = new Point(UserInput.MouseX, UserInput.MouseY);
                mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(mouseDownPosition));
                if ((mouseActiveWindow != null) && (mouseActiveWindow != WindowsZOrder.Last()))
                {
                    BringWindowToTop(mouseActiveWindow);
                }
            }

            if (UserInput.IsMouseWheelChanged)
            {
                mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(mouseDownPosition));

                if (mouseActiveWindow != null)
                {
                    mouseActiveWindow.HandleUserInput();
                }
            }

            if (mouseActiveWindow != null)
            {
                if (UserInput.IsMouseLeftButtonPressed)
                {
                    mouseActiveWindow.MouseDown();
                }
                else if (UserInput.IsMouseLeftButtonReleased)
                {
                    mouseActiveWindow.MouseUp();
                }

                if (UserInput.IsMouseMoved)
                {
                    mouseActiveWindow.MouseMove();
                }

                if (Viewer.RealTime - LastUpdateRealTime >= 0.1)
                {
                    LastUpdateRealTime = Viewer.RealTime;
                    mouseActiveWindow.HandleUserInput();
                }

                if (UserInput.IsMouseLeftButtonReleased)
                {
                    mouseActiveWindow = null;
                }
            }
        }
Exemplo n.º 8
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                var oldTargets = graphicsDevice.GetRenderTargets();
                if (Viewer.Settings.WindowGlass)
                {
                    graphicsDevice.SetRenderTarget(Screen);
                    graphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.Transparent, 1, 0);
                    PopupWindowMaterial.SetState(graphicsDevice, oldTargets[0].RenderTarget as RenderTarget2D);
                }
                else
                {
                    PopupWindowMaterial.SetState(graphicsDevice, null);
                }
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);
                SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
                if (Viewer.Settings.WindowGlass)
                {
                    graphicsDevice.SetRenderTargets(oldTargets);
                    SpriteBatchMaterial.SetState(graphicsDevice, null);
                    SpriteBatchMaterial.SpriteBatch.Draw(Screen, Vector2.Zero, Color.White);
                    SpriteBatchMaterial.ResetState(graphicsDevice);
                }
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
Exemplo n.º 9
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            var rs = graphicsDevice.RenderState;

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                if (Screen != null)
                {
                    graphicsDevice.ResolveBackBuffer(Screen);
                }
                PopupWindowMaterial.SetState(graphicsDevice, Screen);
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);

                SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            rs.AlphaBlendEnable  = false;
            rs.AlphaFunction     = CompareFunction.Always;
            rs.AlphaTestEnable   = false;
            rs.DepthBufferEnable = true;
            rs.DestinationBlend  = Blend.Zero;
            rs.SourceBlend       = Blend.One;
        }