Esempio n. 1
0
        public static void Mouse_Driver(Body body)
        {
            cal_ave(ref lnx, ref lny, ref lbx, ref lby, false);
            cal_ave(ref rnx, ref rny, ref rbx, ref rby, true);

            if (nowHand != null)
            {
                beforeHands = nowHand;
                if (HandsStateList.Count >= STATE_RECORD_NUM)
                {
                    HandsStateList.RemoveAt(0);
                }
                HandsStateList.Add(new HandsState(body));
                nowHand = findState();
            }
            else
            {
                beforeHands = new HandsState();
                nowHand     = new HandsState(body);
                HandsStateList.Add(nowHand);
            }

            //operation start
            if (nowHand.operation == Operation.no_operation)
            {
                StateClear();
                MouseControl.SetCursorPos(screenWidth / 2, screenHeight / 2);
                lx = rx = screenWidth / 2;
                ly = ry = screenHeight / 2;
            }
            else if (nowHand.operation == Operation.left_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    //return;
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    MouseMiddleUp();
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    MouseRightUp();
                }
                MouseLeftDown();
            }
            else if (nowHand.operation == Operation.middle_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    MouseLeftUp();
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    return;
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    MouseRightUp();
                }
                MouseMiddleDown();
            }
            else if (nowHand.operation == Operation.right_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    MouseLeftUp();
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    MouseMiddleUp();
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    return;
                }
                MouseRightDown();
            }
            else if (nowHand.operation == Operation.move)
            {
                StateClear();
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
            }
            else if (nowHand.operation == Operation.wheel)
            {
                StateClear();
                //wheel
                if (beforeHands.operation != Operation.wheel)
                {
                    wheeldy = beforeHands.primeHandy;
                }
                int dy = nowHand.primeHandy - wheeldy;
                MouseRoll(dy);
            }
            cursor.UpdateHandCursor(nowHand.input);
        }
Esempio n. 2
0
        private static void move(float nx, float ny, float bx, float by, bool mouse, bool leftHand)
        {
            float dx = nx - bx;
            float dy = ny - by;
            // get current cursor position
            Point curPos = MouseControl.GetCursorPosition();
            // smoothing for using should be 0 - 0.95f. The way we smooth the cusor is: oldPos + (newPos - oldPos) * smoothValue
            float smoothing = 1 - cursor_smoothing;

            // set cursor position

            if (leftHand)
            {
                lx = (int)(lx + (dx * mouse_sensity * screenWidth) * smoothing);
                ly = (int)(ly - (dy * mouse_sensity * screenHeight) * smoothing);
                if (lx < 0)
                {
                    lx = 0;
                }
                if (lx > screenWidth)
                {
                    lx = screenWidth;
                }
                if (ly < 0)
                {
                    ly = 0;
                }
                if (ly > screenHeight)
                {
                    ly = screenHeight;
                }
                nowHand.input._dx = lx;
                nowHand.input._dy = ly;
                if (!mouse)
                {
                    MouseControl.SetCursorPos(lx, ly);
                }
            }
            else
            {
                rx = (int)(rx + (dx * mouse_sensity * screenWidth) * smoothing);
                ry = (int)(ry - (dy * mouse_sensity * screenHeight) * smoothing);
                if (rx < 0)
                {
                    rx = 0;
                }
                if (rx > screenWidth)
                {
                    rx = screenWidth;
                }
                if (ry < 0)
                {
                    ry = 0;
                }
                if (ry > screenHeight)
                {
                    ry = screenHeight;
                }
                nowHand.input._dx1 = rx;
                nowHand.input._dy1 = ry;
                if (mouse)
                {
                    MouseControl.SetCursorPos(rx, ry);
                }
            }
        }