コード例 #1
0
ファイル: Button.cs プロジェクト: hakuliu/Schematogy
        public Button()
        {
            imgState = MyButtonState.Idle;

            GameEventManager.Instance.addHandler<MouseMotionEvent>(new GameEventHandler<MouseMotionEvent>(handleButtonMouseMotionAction));
            GameEventManager.Instance.addHandler<MouseEvent>(new GameEventHandler<MouseEvent>(handleButtonMouseAction));
        }
コード例 #2
0
ファイル: MyButton.cs プロジェクト: a1264393659/book
 protected override void OnMouseLeave(EventArgs e)
 {
     base.OnMouseLeave(e);
     //////////////////////////////////////
     State = MyButtonState.Leave;
     //////////////////////////////////////
     this.Invalidate(false);
 }
コード例 #3
0
ファイル: MyButton.cs プロジェクト: a1264393659/book
 protected override void OnMouseUp(MouseEventArgs mevent)
 {
     base.OnMouseUp(mevent);
     //////////////////////////////////////
     State = MyButtonState.Up;
     //////////////////////////////////////
     this.Invalidate(false);
 }
コード例 #4
0
ファイル: MyButton.cs プロジェクト: a1264393659/book
 protected override void OnMouseEnter(EventArgs e)
 {
     base.OnMouseEnter(e);
     //////////////////////////////////////
     State = MyButtonState.Enter;
     //////////////////////////////////////
     this.Invalidate(false);
 }
コード例 #5
0
ファイル: Button.cs プロジェクト: hakuliu/Schematogy
 private void handleButtonMouseMotionAction(MouseMotionEvent e)
 {
     if (this.HoverEnabled)
     {
         if (isInBounds(e.X, e.Y))
         {
             imgState = MyButtonState.Hover;
         }
         else
         {
             imgState = MyButtonState.Idle;
         }
     }
 }
コード例 #6
0
ファイル: Button.cs プロジェクト: hakuliu/Schematogy
 private void handleButtonMouseAction(MouseEvent e)
 {
     if (this.PressDownEnabled && e.Pressed == Microsoft.Xna.Framework.Input.ButtonState.Pressed && isInBounds(e.X, e.Y))
     {
         imgState = MyButtonState.Pressed;
     }
     else if(this.HoverEnabled && isInBounds(e.X, e.Y))
     {
         imgState = MyButtonState.Hover;
     }
     else if (!this.HoverEnabled)
     {
         imgState = MyButtonState.Idle;
     }
 }
コード例 #7
0
ファイル: BasicButton.cs プロジェクト: powernick/CodeLib
 /// <summary>
 ///   Get a flag.
 /// </summary>
 /// <param name="flag">
 ///   A <b>MyButtonState</b> value.
 /// </param>
 /// <returns>
 ///   A <b>bool</b> value indicates the flag.
 /// </returns>
 private bool GetFlag(MyButtonState flag)
 {
     return ((this._state & flag) == flag);
 }
コード例 #8
0
ファイル: BasicButton.cs プロジェクト: powernick/CodeLib
 /// <summary>
 ///   SetFlag.
 /// </summary>
 /// <param name="flag">
 ///   A <b>MyButtonState</b> value.
 /// </param>
 /// <param name="value">
 ///   A <b>bool</b> value.
 /// </param>
 private void SetFlag(MyButtonState flag, bool value)
 {
     if (value)
     {
         this._state |= flag;
     }
     else
     {
         this._state &= ~flag;
     }
     base.AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
 }
コード例 #9
0
 public bool Update(GameTime gameTime)
 {
     MouseState ms = Mouse.GetState();
     if (!(TextureTool.checkHoverTexure(_tex[Convert.ToInt32(_state)], _position, new Vector2(ms.X, ms.Y)))) // Normal
         _state = MyButtonState.Normal;
     else // Hovering
         if (ms.LeftButton != ButtonState.Pressed)
             _state = MyButtonState.Hover;
         else
         {
             _state = MyButtonState.Clicked;
             return false;
         }
     return true;
 }
コード例 #10
0
ファイル: Boxes_with_Beh.cs プロジェクト: brezza92/PixelFarm
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;


            //mouse behavior for LayoutFarm.CustomWidgets.Box,
            //with special attachment state => MyButtonState


            var mouseBeh = new UIMouseBehaviour <LayoutFarm.CustomWidgets.Box, MyButtonState>();

            mouseBeh.MouseEnter += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _mouseEnterState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            mouseBeh.MouseLeave += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _normalState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };
            mouseBeh.MouseHover += (s, e) =>
            {
                //b is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _hoverState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_hover:" + box.dbugId);
#endif
            };
            mouseBeh.MousePress += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                Color back_color = box.BackColor;
                box.BackColor = new Color((byte)System.Math.Min(back_color.A + 10, 255), back_color.R, back_color.G, back_color.B);
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_press:" + box.dbugId);
#endif
            };
            mouseBeh.MouseDown += (s, e) =>
            {
                MyButtonState buttonState = s.State;
                if (buttonState != null)
                {
                    if (buttonState.ClickCount > 3)
                    {
                        s.Source.BackColor = Color.Magenta;
                    }
                    buttonState.ClickCount++;
                }
            };


            for (int i = 0; i < 10; ++i)
            {
                var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);
                sampleButton.BackColor = _normalState;
                sampleButton.SetLocation(x_pos, 10);

                MyButtonState state = new MyButtonState();
                mouseBeh.AttachUniqueBehaviorTo(sampleButton, state);

                host.AddChild(sampleButton);

                x_pos += 30 + 5;
            }
        }