Exemplo n.º 1
0
        public bool isButtonClicked(MouseButton button, bool repeat = false)
        {
            MouseButtonState mb = buttons[(int)button];

            if (mb.pressed)             //this is a pressed event
            {
                return(true);
            }

            //look for repeat "pressed" events
            double t = buttons[(int)button].downDuration;

            if (repeat && t > buttonRepeatDelay)
            {
                double delay    = buttonRepeatDelay;
                double rate     = buttonRepeatRate;
                double halfRate = rate * 0.5;
                if (((t - delay % rate) > halfRate) != (((t - delay - UI.dt) % rate) > halfRate))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 public MouseState()
 {
     pos   = new Vector2();
     prev  = new Vector2();
     delta = new Vector2();
     for (int i = 0; i < MAX_BUTTONS; i++)
     {
         buttons[i] = new MouseButtonState();
     }
 }
Exemplo n.º 3
0
        internal void newFrame()
        {
            delta = pos - prev;
            prev  = pos;

            wheelDelta = wheel - wheelPrev;
            wheelPrev  = wheel;

            for (int i = 0; i < MAX_BUTTONS; i++)
            {
                MouseButtonState mb = buttons[i];
                mb.pressed          = mb.down && mb.downDuration < 0;
                mb.released         = !mb.down && mb.downDuration >= 0;
                mb.downDurationPrev = mb.downDuration;
                mb.downDuration     = mb.down ? (mb.downDuration < 0 ? 0.0 : mb.downDuration + UI.dt) : -1.0;
                mb.doubleClicked    = false;

                if (mb.pressed)
                {
                    if (UI.time - mb.pressedTime < doubleClickTime)
                    {
                        if ((pos - mb.pressedPos).LengthSquared < doubleClickDistance * doubleClickDistance)
                        {
                            mb.doubleClicked = true;
                            mb.pressedTime   = -1.0f;
                        }
                    }
                    else
                    {
                        mb.pressedTime = UI.time;
                    }

                    mb.pressedPos         = pos;
                    mb.dragMaxDistanceSqr = 0;
                }
                else if (mb.down)
                {
                    mb.dragMaxDistanceSqr = Math.Max(mb.dragMaxDistanceSqr, (pos - mb.pressedPos).LengthSquared);
                }
            }
        }