Example #1
0
        public void MoveToTop(Widget c)
        {
            if (!children.Remove(c))
            {
                throw new Exception("No such child exists");
            }

            children.Add(c);
        }
Example #2
0
        public void Remove(Widget c)
        {
            if (!children.Remove(c))
            {
                throw new Exception("No such child exists");
            }

            c.parent = null;
            c.guiManager = null;
        }
Example #3
0
        private void DispatchMouseInput(MouseState mouseState)
        {
            Widget newWidgetWithMouse = GetWidgetAt(mouseState.X, mouseState.Y);
            if (newWidgetWithMouse != WidgetWithMouse)
            {
                if (WidgetWithMouse != null)
                {
                    WidgetWithMouse.OnMouseLeft();
                }

                WidgetWithMouse = newWidgetWithMouse;

                if (newWidgetWithMouse != null)
                {
                    newWidgetWithMouse.OnMouseEntered();
                }
            }

            if (mouseFocus == null)
            {
                mouseFocus = WidgetWithMouse;
            }

            if (mouseFocus == null)
            {
                return;
            }

            Point absPos = mouseFocus.AbsolutePosition;
            int x = mouseState.X - absPos.X;
            int y = mouseState.Y - absPos.Y;

            if (mouseState.X != lastMouseState.X || mouseState.Y != lastMouseState.Y)
            {
                mouseFocus.OnMouseMoved(x, y);
            }

            if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
            {
                mouseFocus.OnMousePressed(x, y, MouseButton.Left);
            }

            if (mouseState.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released)
            {
                mouseFocus.OnMousePressed(x, y, MouseButton.Right);
            }

            if (mouseState.MiddleButton == ButtonState.Pressed && lastMouseState.MiddleButton == ButtonState.Released)
            {
                mouseFocus.OnMousePressed(x, y, MouseButton.Middle);
            }

            if (mouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed)
            {
                mouseFocus.OnMouseReleased(x, y, MouseButton.Left);
            }

            if (mouseState.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
            {
                mouseFocus.OnMouseReleased(x, y, MouseButton.Right);
            }

            if (mouseState.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed)
            {
                mouseFocus.OnMouseReleased(x, y, MouseButton.Middle);
            }

            if (mouseState.LeftButton == ButtonState.Released && mouseState.RightButton == ButtonState.Released && mouseState.MiddleButton == ButtonState.Released)
            {
                mouseFocus = null;
            }
        }
Example #4
0
        public void Add(Widget c)
        {
            if (c.parent != null)
            {
                c.parent.Remove(c);
            }

            children.Add(c);
            c.parent = this;
            c.guiManager = guiManager;
        }
Example #5
0
        private void UpdateWidgets(GameTime gameTime, Widget w)
        {
            w.Update(gameTime);

            foreach (Widget c in w.Children)
            {
                UpdateWidgets(gameTime, c);
            }
        }
Example #6
0
        private Widget GetWidgetAt(Point p, Widget w)
        {
            if (!w.IsVisible)
            {
                return null;
            }

            p = new Point(p.X - w.Dimension.X, p.Y - w.Dimension.Y);
            Widget found = w.IsOpaque ? w : null;

            foreach (Widget c in w.Children)
            {
                if (c.IsVisible && c.Dimension.Contains(p))
                {
                    Widget g = GetWidgetAt(p, c);
                    if (g != null)
                    {
                        found = g;
                    }
                }
            }
            return found;
        }
Example #7
0
        private void DrawWidgets(Graphics g, GameTime gameTime, Widget w)
        {
            if (!w.IsVisible)
            {
                return;
            }

            g.PushClipRectangle(w.Dimension);

            if (w.IsOpaque)
            {
                g.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
                w.Draw(g, gameTime);
                g.End();
            }

            foreach (Widget c in w.Children)
            {
                DrawWidgets(g, gameTime, c);
            }

            g.PopClipRectangle();
        }
Example #8
0
        void Button_MouseReleased(Widget sender, int x, int y, MouseButton button)
        {
            if (button != MouseButton.Left)
            {
                return;
            }

            if (IsPressed && Clicked != null)
            {
                Clicked(this, x, y, button);
            }

            isMouseDown = false;
        }
Example #9
0
 void Button_MousePressed(Widget sender, int x, int y, MouseButton button)
 {
     isMouseDown = (button == MouseButton.Left);
 }