MSGUIClickable is a GUI component that is both drawable and clickable
Inheritance: MoodSwingCoreComponents.MS2DClickable, MSGUIObject
Exemplo n.º 1
0
 public void RemoveComponent(MSGUIClickable component)
 {
     clickableComponents.Remove(component);
     components.Remove(component);
 }
Exemplo n.º 2
0
        public void AddComponent(MSGUIClickable component, Alignment alignment)
        {
            switch (alignment)
            {
                case Alignment.TOP_LEFT:
                    component.Position = boundedPosition;
                    break;
                case Alignment.TOP_CENTER:
                    component.Position = boundedPosition + new Vector2((boundedSize.X - component.Size.X) / 2, 0);

                    break;
                case Alignment.TOP_RIGHT:
                    component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, 0);
                    break;
                case Alignment.MIDDLE_LEFT:
                    component.Position = boundedPosition + new Vector2(0, (boundedSize.Y - component.Size.Y) / 2);
                    break;
                case Alignment.MIDDLE_CENTER:
                    component.Position = boundedPosition + (boundedSize - component.Size) / 2;
                    break;
                case Alignment.MIDDLE_RIGHT:
                    component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, (boundedSize.Y - component.Size.Y) / 2);
                    break;
                case Alignment.BOTTOM_LEFT:
                    component.Position = boundedPosition + new Vector2(0, boundedSize.Y - component.Size.Y);
                    break;
                case Alignment.BOTTOM_CENTER:
                    component.Position = boundedPosition + new Vector2((boundedSize.X - component.Size.X) / 2, boundedSize.Y - component.Size.Y);
                    break;
                case Alignment.BOTTOM_RIGHT:
                    component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, boundedSize.Y - component.Size.Y);
                    break;
            }
            clickableComponents.Add(component);
            components.Add(component);
        }
Exemplo n.º 3
0
        public virtual bool HandleMouseInput(bool careIfMouseHasMoved)
        {
            bool hasEvent = false;
            MouseState currentMouseState = MSMouse.GetState();
            if (hasMouseFocus)
            {
                if (currentMouseState != oldMouseState || !careIfMouseHasMoved)
                {
                    bool hasHovered = false;
                    foreach (MSGUIClickable component in ClickableComponents.Reverse<MSGUIClickable>())
                    {
                        if (component.Visible)
                        {
                            if (component.CollidesWithMouse())
                            {
                                if (currentHovered != component)
                                {
                                    if (currentHovered != null) currentHovered.UnHover();
                                    currentHovered = component;
                                    currentHovered.Hover();
                                }
                                hasHovered = true;
                                break;
                            }
                        }
                    }
                    if (!hasHovered)
                    {
                        if (currentHovered != null)
                        {
                            currentHovered.UnHover();
                            currentHovered = null;
                        }
                    }
                    if (currentHovered != null)
                    {
                        if (currentMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)
                        {
                            currentHovered.LeftClick();
                        }
                        else if (currentMouseState.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed)
                        {
                            if (currentHovered is MSGUITypable)
                            {
                                if (currentKeyboardFocused != null) currentKeyboardFocused.HasKeyboardFocus = false;
                                currentKeyboardFocused = (MSGUITypable)currentHovered;
                                currentKeyboardFocused.HasKeyboardFocus = true;
                            }
                            currentHovered.UnLeftClick();
                            currentHovered = null;
                            hasEvent = true;
                        }

                        if (currentMouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released)
                        {
                            currentHovered.RightClick();
                        }
                        else if (currentMouseState.RightButton == ButtonState.Released && oldMouseState.RightButton == ButtonState.Pressed)
                        {
                            currentHovered.UnRightClick();
                            hasEvent = true;
                        }

                        if (currentMouseState.MiddleButton == ButtonState.Pressed && oldMouseState.MiddleButton == ButtonState.Released)
                        {
                            currentHovered.MiddleClick();
                        }
                        else if (currentMouseState.MiddleButton == ButtonState.Released && oldMouseState.MiddleButton == ButtonState.Pressed)
                        {
                            currentHovered.UnMiddleClick();
                            hasEvent = true;
                        }
                    }
                }
            }
            oldMouseState = currentMouseState;
            return hasEvent;
        }
Exemplo n.º 4
0
 public void AddComponent(MSGUIClickable component)
 {
     AddComponent(component, Alignment.MANUAL);
 }
Exemplo n.º 5
0
 public void ResetHovers()
 {
     if (currentHovered != null)
     {
         currentHovered.UnHover();
         currentHovered = null;
     }
 }