MSGUITypable is an MSGUIClickable component that can handle keyboard input. MSGUITypable requires a facade that manages which instance is the one currently given keyboard focus.
Inheritance: MSGUIClickable
コード例 #1
0
ファイル: MSTextField.cs プロジェクト: verngutz/MoodSwing
        /// <summary>
        /// Constructs and MSTextField from the given parameters
        /// </summary>
        /// <param name="text">the initial text this MSTextField contains</param>
        /// <param name="boundingRectangle">the bounding Rectangle of this MSTextField</param>
        /// <param name="onEnter">the MSAction to perform when this MSTextField is focused and the Enter key has been pressed</param>
        /// <param name="onTab">the MSGUITypable that will be given the keyboard focus when this MSTextField is focused and the Tab key has been pressed</param>
        /// <param name="maxTextLength">the maximum length of the text that this MSTextField can contain</param>
        /// <param name="spriteFont">the SpriteFont that will be used to draw the text on this MSTextField</param>
        /// <param name="color">the text color of this MSTextField</param>
        /// <param name="spriteBatch">the SpriteBatch that will draw this MSTextField</param>
        /// <param name="game">the Game where this MSTextField will be used</param>
        public MSTextField(String text, Rectangle boundingRectangle, MSAction onEnter, MSGUITypable onTab, int maxTextLength, SpriteFont spriteFont, Color color, SpriteBatch spriteBatch, Game game)
            : base(boundingRectangle, null, Shape.RECTANGULAR, spriteBatch, game)
        {
            this.spriteFont = spriteFont;
            fontScale = boundingRectangle.Height / spriteFont.MeasureString(CURSOR).Y;
            cursorIndex = 0;
            cursorBlinkCounter = 0;
            cursorPosition = new Vector2(boundingRectangle.X - spriteFont.MeasureString(CURSOR).X * 5 * fontScale / 12, boundingRectangle.Y);
            Editable = false;
            text = "";
            this.maxTextLength = maxTextLength;
            Text = text;
            this.color = color;

            this.onEnter = onEnter;
            this.onTab = onTab;
            TabIsFired = false;
        }
コード例 #2
0
ファイル: MSFacadePanel.cs プロジェクト: verngutz/MoodSwing
        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;
        }
コード例 #3
0
ファイル: MSTextField.cs プロジェクト: verngutz/MoodSwing
 public MSTextField(String text, Rectangle boundingRectangle, MSAction onEnter, MSGUITypable onTab, int maxTextLength, SpriteFont spriteFont, SpriteBatch spriteBatch, Game game)
     : this(text, boundingRectangle, onEnter, onTab, maxTextLength, spriteFont, Color.Black, spriteBatch, game)
 {
 }
コード例 #4
0
ファイル: MSFacadePanel.cs プロジェクト: verngutz/MoodSwing
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     if (currentKeyboardFocused != null && currentKeyboardFocused.TabIsFired)
     {
         currentKeyboardFocused.HasKeyboardFocus = false;
         currentKeyboardFocused.TabIsFired = false;
         currentKeyboardFocused = currentKeyboardFocused.OnTab;
         currentKeyboardFocused.HasKeyboardFocus = true;
     }
 }