コード例 #1
0
ファイル: GUIUtils.cs プロジェクト: stpkforce/SanAndreasUnity
        public static Rect GetCornerRect(ScreenCorner corner, float width, float height, Vector2?padding = null)
        {
            float padX = 0,
                  padY = 0;

            if (padding != null)
            {
                padX = padding.Value.x;
                padY = padding.Value.y;
            }

            switch (corner)
            {
            case ScreenCorner.TopLeft:
                return(new Rect(padX, padY, width, height));

            case ScreenCorner.TopRight:
                return(new Rect(Screen.width - (width + padX), padY, width, height));

            case ScreenCorner.BottomLeft:
                return(new Rect(padX, Screen.height - (height + padY), width, height));

            case ScreenCorner.BottomRight:
                return(new Rect(Screen.width - (width + padX), Screen.height - (height + padY), width, height));
            }

            return(default(Rect));
        }
コード例 #2
0
        //FIXME: MUST REFACTOR
        void PathTracker_HotCornerTriggered(ScreenCorner corner)
        {
            if (!EnableHotCorners)
            {
                return;
            }
            Debug.WriteLine("HotCorner: " + corner);
            switch (corner)
            {
            case ScreenCorner.RightBottom:
                Sim.KeyDown(VirtualKeyCode.LWIN);
                Sim.KeyDown(VirtualKeyCode.VK_D);
                Sim.KeyUp(VirtualKeyCode.VK_D);
                Sim.KeyUp(VirtualKeyCode.LWIN);
                break;

            case ScreenCorner.RightTop:
                Sim.KeyDown(VirtualKeyCode.LMENU);
                Sim.KeyDown(VirtualKeyCode.TAB);
                Thread.Sleep(100);
                Sim.KeyUp(VirtualKeyCode.TAB);
                Sim.KeyUp(VirtualKeyCode.LMENU);
                break;

            case ScreenCorner.LeftTop:
                Sim.KeyPress(VirtualKeyCode.CANCEL);
                break;

            case ScreenCorner.LeftBottom:
                Sim.KeyPress(VirtualKeyCode.LWIN);
                break;
            }
        }
コード例 #3
0
        private void HotCornerHitTest()
        {
            const int TRIGGER_DIST = 2;
            const int REST_DIST    = 40;

            var scr = Common.OsSpecific.Windows.Screen.ScreenBoundsFromPoint(_curPos);

            if (scr == null)
            {
                return;
            }

            var corner = 0;

            for (corner = 0; corner < 4; corner++)
            {
                var p    = GetBoundsCornerPoint(scr.Value, (ScreenCorner)corner);
                var dist = GetPointDistance(ref p, ref _curPos);

                if (!_isHotCornerReset && _lastTriggeredCorner == (ScreenCorner)corner && dist > REST_DIST)
                {
                    _isHotCornerReset = true;
                }
                else if (dist <= TRIGGER_DIST && _isHotCornerReset)
                {
                    _isHotCornerReset    = false;
                    _lastTriggeredCorner = (ScreenCorner)corner;
                    Post(WM.HOT_CORNER, (int)corner);
                }
            }
        }
コード例 #4
0
        public void AttachToScreenCorner(ScreenCorner c = ScreenCorner.BottomRight)
        {
            Size r = SystemParameters.WorkArea.Size;

            if (c == ScreenCorner.TopLeft)
            {
                this.Left = Config.ScreenEdgePadding;
                this.Top  = Config.ScreenEdgePadding;
            }
            else if (c == ScreenCorner.TopRight)
            {
                this.Left = r.Width - this.Width - Config.ScreenEdgePadding;
                this.Top  = Config.ScreenEdgePadding;
            }
            else if (c == ScreenCorner.BottomLeft)
            {
                this.Left = Config.ScreenEdgePadding;
                this.Top  = r.Height - this.Height - Config.ScreenEdgePadding;
            }
            else if (c == ScreenCorner.BottomRight)
            {
                this.Left = r.Width - this.Width - Config.ScreenEdgePadding;
                this.Top  = r.Height - this.Height - Config.ScreenEdgePadding;
            }
        }
コード例 #5
0
    public static Vector3 CornerPosition(ScreenCorner corner)
    {
        var   worldRect = WorldRect();
        float xPosition, yPosition;

        if (corner == ScreenCorner.BottomLeft || corner == ScreenCorner.TopLeft)
        {
            xPosition = worldRect.xMin;
        }
        else
        {
            xPosition = worldRect.xMax;
        }


        if (corner == ScreenCorner.TopLeft || corner == ScreenCorner.TopRight)
        {
            yPosition = worldRect.yMax;
        }
        else
        {
            yPosition = worldRect.yMin;
        }

        return(new Vector3(xPosition, yPosition));
    }
コード例 #6
0
        private void SetPanningCursor(ScreenCorner corner)
        {
            Cursor.visible = false;
            DisableAllPanningArrows();
            switch (corner)
            {
            case ScreenCorner.TopLeft:
                _cornerArrowTopLeft.transform.position = Input.mousePosition;
                _cornerArrowTopLeft.enabled            = true;
                break;

            case ScreenCorner.TopRight:
                _cornerArrowTopRight.transform.position = Input.mousePosition;
                _cornerArrowTopRight.enabled            = true;
                break;

            case ScreenCorner.BottomLeft:
                _cornerArrowBottomLeft.transform.position = Input.mousePosition;
                _cornerArrowBottomLeft.enabled            = true;
                break;

            case ScreenCorner.BottomRight:
                _cornerArrowBottomRight.transform.position = Input.mousePosition;
                _cornerArrowBottomRight.enabled            = true;
                break;

            case ScreenCorner.Top:
                _sideArrowTop.transform.position = Input.mousePosition;
                _sideArrowTop.enabled            = true;
                break;

            case ScreenCorner.Bottom:
                _sideArrowBottom.transform.position = Input.mousePosition;
                _sideArrowBottom.enabled            = true;
                break;

            case ScreenCorner.Left:
                _sideArrowLeft.transform.position = Input.mousePosition;
                _sideArrowLeft.enabled            = true;
                break;

            case ScreenCorner.Right:
                _sideArrowRight.transform.position = Input.mousePosition;
                _sideArrowRight.enabled            = true;
                break;

            case ScreenCorner.None:
                Cursor.visible = true;
                break;

            default:
                break;
            }
        }
コード例 #7
0
        private void PanFromScreenBorder()
        {
            ScreenCorner mouseScreenCorner = GetScreenCornerForMousePosition(_borderPanningOffset, _borderPanningCornerSize);

            SetPanningCursor(mouseScreenCorner);

            switch (mouseScreenCorner)
            {
            case ScreenCorner.BottomLeft:
                _translateX += -1 * GetScaledPanSpeed();
                _translateZ += -1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.BottomRight:
                _translateX += 1 * GetScaledPanSpeed();
                _translateZ += -1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.TopLeft:
                _translateX += -1 * GetScaledPanSpeed();
                _translateZ += 1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.TopRight:
                _translateX += 1 * GetScaledPanSpeed();
                _translateZ += 1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.Left:
                _translateX += -1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.Right:
                _translateX += 1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.Bottom:
                _translateZ += -1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.Top:
                _translateZ += 1 * GetScaledPanSpeed();
                break;

            case ScreenCorner.None:
                break;
            }
        }
コード例 #8
0
        private void OnHotCorner(ScreenCorner corner)
        {
            if (DisableInFullscreen && IsInFullScreenMode())
            {
                return;
            }

            var mousePressed = Native.GetAsyncKeyState(Keys.LButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.RButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.MButton) < 0;

            if (!mousePressed && HotCornerTriggered != null)
            {
                HotCornerTriggered(corner);
            }
        }
コード例 #9
0
        /// <summary>
        /// Gets the location of a corner to draw the time in
        /// </summary>
        /// <param name="corner">The corner of the screen to draw the time in</param>
        /// <returns>The calculated destination the time will be drawn at</returns>
        public static Vector2 GetCornerDestination(ScreenCorner corner)
        {
            // Corner to draw
            Vector2 destination = new Vector2();

            // User configured about to indent
            float indentation = TimeOfThePrairieKing.Config.Indentation;

            // Resolution zoom value from user's options menu
            float zoomAdjustment = 1f / Game1.options.zoomLevel;

            // Actual size of the game window itself
            int viewportWidth  = Game1.graphics.GraphicsDevice.Viewport.Width;
            int viewportHeight = Game1.graphics.GraphicsDevice.Viewport.Height;

            // Dimensions of string, adjusted to hit the actual pixel size b/c it doesn't measure the string properly
            float stringWidth  = Game1.dialogueFont.MeasureString(Game1.getTimeOfDayString(Game1.timeOfDay)).X;
            float stringHeight = Game1.dialogueFont.MeasureString(Game1.getTimeOfDayString(Game1.timeOfDay)).Y;

            // The string measurements only align with the rectangle, and not the pixels inside
            //     This means we have to adjust the target coordinates with the adjusted offsets
            //     The string itself starts 5 pixels below, and 1 pixel to the right of where the rectangle starts
            float topOffset  = indentation - FontConstants.TopOffset;
            float leftOffset = indentation - FontConstants.LeftOffset;

            // We have to perform subtraction from the viewport endings to get back on screen
            float rightOffset  = viewportWidth - indentation - (stringWidth - FontConstants.RightOffset);
            float bottomOffset = viewportHeight - indentation - (stringHeight - FontConstants.BottomOffset);

            // Based on the corner specified, we will need to draw accordingly
            switch (corner)
            {
            case ScreenCorner.TopLeft:
                return(new Vector2(leftOffset, topOffset));

            case ScreenCorner.TopRight:
                return(new Vector2(rightOffset, topOffset));

            case ScreenCorner.BottomLeft:
                return(new Vector2(leftOffset, bottomOffset));

            case ScreenCorner.BottomRight:
                return(new Vector2(rightOffset, bottomOffset));
            }

            return(destination);
        }
コード例 #10
0
ファイル: GestureParser.cs プロジェクト: xuhe/WGestures
        void PathTracker_HotCornerTriggered(ScreenCorner corner)
        {
            if (!EnableHotCorners)
            {
                return;
            }
            Debug.WriteLine("HotCorner: " + corner);

            var cmd = IntentFinder.IntentStore.HotCornerCommands[(int)corner];

            if (cmd != null)
            {
                var shouldInit = cmd as INeedInit;
                if (shouldInit != null && !shouldInit.IsInitialized)
                {
                    shouldInit.Init();
                }
                cmd.Execute();
            }

            //previous hard-coded impl

            /*switch (corner)
             * {
             *  case ScreenCorner.RightBottom:
             *      Sim.KeyDown(VirtualKeyCode.LWIN);
             *      Sim.KeyDown(VirtualKeyCode.VK_D);
             *      Sim.KeyUp(VirtualKeyCode.VK_D);
             *      Sim.KeyUp(VirtualKeyCode.LWIN);
             *      break;
             *  case ScreenCorner.RightTop:
             *      Sim.KeyDown(VirtualKeyCode.LMENU);
             *      Sim.KeyDown(VirtualKeyCode.TAB);
             *      Thread.Sleep(100);
             *      Sim.KeyUp(VirtualKeyCode.TAB);
             *      Sim.KeyUp(VirtualKeyCode.LMENU);
             *      break;
             *  case ScreenCorner.LeftTop:
             *      Sim.KeyPress(VirtualKeyCode.CANCEL);
             *      break;
             *  case ScreenCorner.LeftBottom:
             *      Sim.KeyPress(VirtualKeyCode.LWIN);
             *      break;
             * }*/
        }
コード例 #11
0
        private void OnHotCorner(ScreenCorner corner)
        {
            if (DisableInFullscreen && IsInFullScreenMode())
            {
                return;
            }

            var mousePressed = Native.GetAsyncKeyState(Keys.LButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.RButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.MButton) < 0;

            if (!mousePressed && HotCornerTriggered != null)
            {
                HotCornerTriggered(corner);
            }
            //Console.WriteLine("+++++HotCorner:" + corner);
            //throw new NotImplementedException();
        }
コード例 #12
0
        public static void DrawHud(ScreenCorner screenCorner, Vector2 size, Vector2 padding, Color healthColor,
                                   Color healthBackgroundColor)
        {
            var rect = GUIUtils.GetCornerRect(screenCorner, size, padding);

            // draw icon for current weapon

            Rect texRect = rect;

            texRect.width  *= 0.4f;
            texRect.height *= 0.5f;

            Texture2D tex;

            if (Player.Instance.CurrentWeapon != null)
            {
                tex = Player.Instance.CurrentWeapon.HudTexture;
            }
            else
            {
                tex = Weapon.FistTexture;
            }

            if (tex != null)
            {
                var savedMatrix = GUI.matrix;
                // we have to flip texture around Y axis
                GUIUtility.ScaleAroundPivot(new Vector2(1.0f, -1.0f), texRect.center);

                //	GUI.DrawTexture( texRect, tex, ScaleMode.StretchToFill, true, 0.0f, Color.black, 3f, 5f );
                GUI.DrawTexture(texRect, tex);

                GUI.matrix = savedMatrix;
            }

            // health bar

            float barHeight     = 8f;         //rect.height / 10f;
            float barWidth      = rect.width * 0.5f;
            Rect  healthBarRect = new Rect(rect.width * 0.5f, texRect.yMax - barHeight, barWidth, barHeight);

            DrawBar(healthBarRect, 1.0f, healthColor, healthBackgroundColor);
        }
コード例 #13
0
        private static Point GetPointFromScreenCorner(Screen screen, ScreenCorner corner)
        {
            switch (corner)
            {
            case ScreenCorner.TopLeft:
                return(new Point(screen.Bounds.X, screen.Bounds.Y));

            case ScreenCorner.TopRight:
                return(new Point(screen.Bounds.Right, screen.Bounds.Y));

            case ScreenCorner.BottomLeft:
                return(new Point(screen.Bounds.X, screen.Bounds.Bottom));

            case ScreenCorner.BottomRight:
                return(new Point(screen.Bounds.Right, screen.Bounds.Bottom));
            }

            return(Point.Empty);
        }
コード例 #14
0
 /// <summary>
 /// This method tries to set the position of the window so that it's fully visible but one of it's corners is attached to given parameter.
 /// </summary>
 public void AttachToCorner(ScreenCorner corner)
 {
     if (corner == ScreenCorner.UpperLeft)
     {
         SetPosition(new Point(0, 0));
     }
     if (corner == ScreenCorner.UpperRight)
     {
         SetPosition(new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Rect.Width, 0));
     }
     if (corner == ScreenCorner.LowerRight)
     {
         SetPosition(new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Rect.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Rect.Height));
     }
     if (corner == ScreenCorner.LowerLeft)
     {
         SetPosition(new Point(0, Screen.PrimaryScreen.WorkingArea.Height - this.Rect.Height));
     }
 }
コード例 #15
0
        private Point GetBoundsCornerPoint(Rectangle bounds, ScreenCorner corner)
        {
            switch (corner)
            {
            case ScreenCorner.LeftBottom:
                return(new Point(bounds.Left, bounds.Bottom));

            case ScreenCorner.LeftTop:
                return(new Point(bounds.Left, bounds.Top));

            case ScreenCorner.RightBottom:
                return(new Point(bounds.Right, bounds.Bottom));

            case ScreenCorner.RightTop:
                return(new Point(bounds.Right, bounds.Top));

            default:
                throw new NotSupportedException(corner.ToString());
            }
        }
コード例 #16
0
        void PathTracker_HotCornerTriggered(ScreenCorner corner)
        {
            if (!EnableHotCorners)
            {
                return;
            }
            Debug.WriteLine("HotCorner: " + corner);

            var cmd = IntentFinder.IntentStore.HotCornerCommands[(int)corner];

            if (cmd != null)
            {
                var shouldInit = cmd as INeedInit;
                if (shouldInit != null && !shouldInit.IsInitialized)
                {
                    shouldInit.Init();
                }
                cmd.Execute();
            }
        }
コード例 #17
0
ファイル: GUIUtils.cs プロジェクト: stpkforce/SanAndreasUnity
 public static Rect GetCornerRect(ScreenCorner corner, Vector2 size, Vector2?padding = null)
 {
     return(GetCornerRect(corner, size.x, size.y, padding));
 }
コード例 #18
0
        public static void DrawHud(ScreenCorner screenCorner, Vector2 size, Vector2 padding, Color healthColor,
                                   Color healthBackgroundColor)
        {
            var rect = GUIUtils.GetCornerRect(screenCorner, size, padding);

            Ped ped = Ped.Instance;

            // draw icon for current weapon

            Weapon weapon = Ped.Instance.CurrentWeapon;

            Rect texRect = rect;

            texRect.width  *= 0.4f;
            texRect.height *= 0.5f;

            Texture2D tex;

            if (weapon != null)
            {
                tex = weapon.HudTexture;
            }
            else
            {
                tex = Weapon.FistTexture;
            }

            if (tex != null)
            {
                var savedMatrix = GUI.matrix;
                // we have to flip texture around Y axis
                GUIUtility.ScaleAroundPivot(new Vector2(1.0f, -1.0f), texRect.center);

                //	GUI.DrawTexture( texRect, tex, ScaleMode.StretchToFill, true, 0.0f, Color.black, 3f, 5f );
                GUI.DrawTexture(texRect, tex);

                GUI.matrix = savedMatrix;
            }

            // ammo

            if (weapon != null && weapon.IsGun)
            {
                string str = string.Format("<b>{0}-{1}</b>", weapon.AmmoOutsideOfClip, weapon.AmmoInClip);

                // draw it at the bottom of weapon icon
                Vector2 desiredSize = GUIUtils.CalcScreenSizeForText(str, GUIUtils.CenteredLabelStyle);
                Rect    ammoRect    = new Rect(new Vector2(texRect.position.x, texRect.yMax - desiredSize.y / 2.0f), new Vector2(texRect.width, desiredSize.y));

                GUI.Label(ammoRect, str, GUIUtils.CenteredLabelStyle);
            }


            // health bar

            float barHeight     = 8f;         //rect.height / 10f;
            float barWidth      = rect.width * 0.5f;
            Rect  healthBarRect = new Rect(rect.width * 0.5f, texRect.yMax - barHeight, barWidth, barHeight);

            DrawBar(healthBarRect, ped.Health / ped.MaxHealth, healthColor, healthBackgroundColor);
        }
コード例 #19
0
        private void HotCornerHitTest()
        {
            //FIXME: multi screen
            var scr = Native.GetScreenBounds();
            const int TRIGGER_DIST = 2;
            const int REST_DIST = 40;

            //reset when dist > Rest_Dist
            float dist;

            var leftBottom = new Point(scr.Left, scr.Bottom);
            dist = GetPointDistance(ref leftBottom, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.LeftBottom && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset = false;
                _lastTriggeredCorner = ScreenCorner.LeftBottom;
                Post(WM.HOT_CORNER, (int) ScreenCorner.LeftBottom);
                return;
            }

            var leftTop = new Point(scr.Left, scr.Top);
            dist = GetPointDistance(ref leftTop, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.LeftTop && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset = false;
                _lastTriggeredCorner = ScreenCorner.LeftTop;
                Post(WM.HOT_CORNER, (int) ScreenCorner.LeftTop);
                return;
            }

            var rightTop = new Point(scr.Right, scr.Top);
            dist = GetPointDistance(ref rightTop, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.RightTop && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset = false;
                _lastTriggeredCorner = ScreenCorner.RightTop;
                Post(WM.HOT_CORNER, (int) ScreenCorner.RightTop);
                return;
            }

            var rightBottom = new Point(scr.Right, scr.Bottom);
            dist = GetPointDistance(ref rightBottom, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.RightBottom && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset = false;
                _lastTriggeredCorner = ScreenCorner.RightBottom;
                Post(WM.HOT_CORNER, (int) ScreenCorner.RightBottom);
                return;
            }
        }
コード例 #20
0
 private Point GetBoundsCornerPoint(Rectangle bounds, ScreenCorner corner)
 {
     switch (corner)
     {
         case ScreenCorner.LeftBottom:
             return new Point(bounds.Left, bounds.Bottom);
         case ScreenCorner.LeftTop:
             return new Point(bounds.Left, bounds.Top);
         case ScreenCorner.RightBottom:
             return new Point(bounds.Right, bounds.Bottom);
         case ScreenCorner.RightTop:
             return new Point(bounds.Right, bounds.Top);
         default:
             throw new NotSupportedException(corner.ToString());
     }
 }
コード例 #21
0
        private void OnHotCorner(ScreenCorner corner)
        {
            if (DisableInFullscreen && IsInFullScreenMode()) return;

            var mousePressed = Native.GetAsyncKeyState(Keys.LButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.RButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.MButton) < 0;
            if (!mousePressed && HotCornerTriggered != null) HotCornerTriggered(corner);
        }
コード例 #22
0
        private void HotCornerHitTest()
        {
            const int TRIGGER_DIST = 2;
            const int REST_DIST = 40;

            var scr = Common.OsSpecific.Windows.Screen.ScreenBoundsFromPoint(_curPos);
            if (scr == null) return;
            
            var corner = 0;
            for(corner=0; corner<4; corner++)
            {
                var p = GetBoundsCornerPoint( scr.Value, (ScreenCorner)corner );
                var dist = GetPointDistance(ref p, ref _curPos);

                if (!_isHotCornerReset && _lastTriggeredCorner == (ScreenCorner) corner && dist > REST_DIST)
                {
                    _isHotCornerReset = true;
                }
                else if (dist <= TRIGGER_DIST && _isHotCornerReset)
                {
                    _isHotCornerReset = false;
                    _lastTriggeredCorner = (ScreenCorner) corner;
                    Post(WM.HOT_CORNER, (int)corner);
                }
            }
        }
コード例 #23
0
ファイル: Window.cs プロジェクト: alexhanh/Botting-Library
 /// <summary>
 /// This method tries to set the position of the window so that it's fully visible but one of it's corners is attached to given parameter.
 /// </summary>
 public void AttachToCorner(ScreenCorner corner)
 {
     if (corner == ScreenCorner.UpperLeft)
         SetPosition(new Point(0, 0));
     if (corner == ScreenCorner.UpperRight)
         SetPosition(new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Rect.Width, 0));
     if (corner == ScreenCorner.LowerRight)
         SetPosition(new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Rect.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Rect.Height));
     if (corner == ScreenCorner.LowerLeft)
         SetPosition(new Point(0, Screen.PrimaryScreen.WorkingArea.Height - this.Rect.Height));
 }
コード例 #24
0
        private void OnHotCorner(ScreenCorner corner)
        {
            if (DisableInFullscreen && IsInFullScreenMode()) return;

            var mousePressed = Native.GetAsyncKeyState(Keys.LButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.RButton) < 0 ||
                               Native.GetAsyncKeyState(Keys.MButton) < 0;
            if (!mousePressed && HotCornerTriggered != null) HotCornerTriggered(corner);
            //Console.WriteLine("+++++HotCorner:" + corner);
            //throw new NotImplementedException();
        }
コード例 #25
0
ファイル: GestureParser.cs プロジェクト: huipengly/WGestures
        void PathTracker_HotCornerTriggered(ScreenCorner corner)
        {
            if (!EnableHotCorners) return;
            Debug.WriteLine("HotCorner: " + corner);

            var cmd = IntentFinder.IntentStore.HotCornerCommands[(int)corner];
            if(cmd != null)
            {
                var shouldInit = cmd as INeedInit;
                if (shouldInit != null && !shouldInit.IsInitialized)
                {
                    shouldInit.Init();
                }
                cmd.Execute();
            }

            //previous hard-coded impl
            /*switch (corner)
            {
                case ScreenCorner.RightBottom:
                    Sim.KeyDown(VirtualKeyCode.LWIN);
                    Sim.KeyDown(VirtualKeyCode.VK_D);
                    Sim.KeyUp(VirtualKeyCode.VK_D);
                    Sim.KeyUp(VirtualKeyCode.LWIN);
                    break;
                case ScreenCorner.RightTop:
                    Sim.KeyDown(VirtualKeyCode.LMENU);
                    Sim.KeyDown(VirtualKeyCode.TAB);
                    Thread.Sleep(100);
                    Sim.KeyUp(VirtualKeyCode.TAB);
                    Sim.KeyUp(VirtualKeyCode.LMENU);
                    break;
                case ScreenCorner.LeftTop:
                    Sim.KeyPress(VirtualKeyCode.CANCEL);
                    break;
                case ScreenCorner.LeftBottom:
                    Sim.KeyPress(VirtualKeyCode.LWIN);
                    break;
            }*/
        }
コード例 #26
0
        private void HotCornerHitTest()
        {
            //FIXME: multi screen
            var       scr          = Native.GetScreenBounds();
            const int TRIGGER_DIST = 2;
            const int REST_DIST    = 40;

            //reset when dist > Rest_Dist
            float dist;

            var leftBottom = new Point(scr.Left, scr.Bottom);

            dist = GetPointDistance(ref leftBottom, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.LeftBottom && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset    = false;
                _lastTriggeredCorner = ScreenCorner.LeftBottom;
                Post(WM.HOT_CORNER, (int)ScreenCorner.LeftBottom);
                return;
            }


            var leftTop = new Point(scr.Left, scr.Top);

            dist = GetPointDistance(ref leftTop, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.LeftTop && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset    = false;
                _lastTriggeredCorner = ScreenCorner.LeftTop;
                Post(WM.HOT_CORNER, (int)ScreenCorner.LeftTop);
                return;
            }


            var rightTop = new Point(scr.Right, scr.Top);

            dist = GetPointDistance(ref rightTop, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.RightTop && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset    = false;
                _lastTriggeredCorner = ScreenCorner.RightTop;
                Post(WM.HOT_CORNER, (int)ScreenCorner.RightTop);
                return;
            }


            var rightBottom = new Point(scr.Right, scr.Bottom);

            dist = GetPointDistance(ref rightBottom, ref _curPos);
            if (!_isHotCornerReset && _lastTriggeredCorner == ScreenCorner.RightBottom && dist > REST_DIST)
            {
                _isHotCornerReset = true;
            }
            else if (dist <= TRIGGER_DIST && _isHotCornerReset)
            {
                _isHotCornerReset    = false;
                _lastTriggeredCorner = ScreenCorner.RightBottom;
                Post(WM.HOT_CORNER, (int)ScreenCorner.RightBottom);
                return;
            }
        }
コード例 #27
0
        private void Update()
        {
            float xin = Input.GetAxis("Horizontal");
            float zin = Input.GetAxis("Vertical");


            ScreenCorner corner = SlidingCameraBehaviour.GetScreenCornerForMousePosition(
                _borderPanningOffset, _borderPanningCornerSize);

            // if we translate the camera manually then take us off orbit mode.. This will need
            // to be refactored to make this entire component more flexible.
            if (corner != ScreenCorner.None || xin != 0 || zin != 0)
            {
                gameObject.GetComponentInParent <SlidingCameraBehaviour>().enabled = true;
                enabled = false;
            }

            if (!_target)
            {
                return;
            }

            float scroll = Input.GetAxis("Mouse ScrollWheel");

            if (scroll != 0)
            {
                // do not allow us to scroll past a certain point
                if ((_camOffset.magnitude < _maxZoom || scroll > 0) && (_camOffset.magnitude > minZoom || scroll < 0))
                {
                    Vector3 calcOffset = transform.position;

                    // lerp the zoom factor to zoom fast when far away from target and much slower when close
                    float zoomFNew = Mathf.Lerp(_zoomFactor / 10, _zoomFactor * 4, _camOffset.magnitude / _maxZoom);

                    calcOffset += transform.forward * scroll * _zoomSpeed * zoomFNew;
                    _camOffset  = (calcOffset - _target.transform.position);
                }
            }

            if (Input.GetMouseButton(2))
            {
                float dy = -Input.GetAxis("Mouse Y");
                float dx = Input.GetAxis("Mouse X");

                if ((Vector3.Angle(_camOffset, Vector3.up) > _upperAngleLimit || dy < 0) &&
                    (Vector3.Angle(_camOffset, Vector3.up) < _lowerAngleLimit || dy > 0))
                {
                    _camOffset = Vector3.RotateTowards(_camOffset, Vector3.up, dy * _verticalRotationSpeed, 0f);
                }

                _camOffset = Quaternion.AngleAxis(dx * _horizontalRotationSpeed, Vector3.up) * _camOffset;
            }

            transform.position = Vector3.Lerp(transform.position, _target.transform.position + _camOffset, Time.deltaTime * _rotLerpSpeed);

            // if we are not rotating.. then we want a smooth look at.. means we are switching units
            // if we dont have this logic here our rotation becomes too smooth and looks unnatural
            if (!Input.GetMouseButton(2))
            {
                //// smooth the lookat/rotation
                Quaternion lookOnLook = Quaternion.LookRotation(
                    _target.transform.position - transform.position);
                transform.rotation = Quaternion.Slerp(
                    transform.rotation, lookOnLook, Time.deltaTime * _rotLerpSpeed);
            }
            else
            {
                transform.LookAt(_target.transform.position);
            }
        }
コード例 #28
0
    public static void PlaceTransformAtScreenCorner(Transform trans, ScreenCorner corner, int xMargin, int yMargin)
    {
        int width = Screen.width, height = Screen.height;

        switch (corner) {
            case ScreenCorner.TOP_LEFT:
                PlaceTransformOnScreen(trans, xMargin, height - yMargin);
                break;
            case ScreenCorner.TOP_RIGHT:
                PlaceTransformOnScreen(trans, width - xMargin, height - yMargin);
                break;
            case ScreenCorner.BOTTOM_RIGHT:
                PlaceTransformOnScreen(trans, width - xMargin, yMargin);
                break;
            case ScreenCorner.BOTTOM_LEFT:
                PlaceTransformOnScreen(trans, xMargin, yMargin);
                break;
        }
    }
コード例 #29
0
 public HotCorner(ScreenCorner corner, HotCornerAction command)
 {
     _corner  = corner;
     _command = command;
 }
コード例 #30
0
ファイル: GestureParser.cs プロジェクト: duanbaodi/WGestures
 //FIXME: MUST REFACTOR
 void PathTracker_HotCornerTriggered(ScreenCorner corner)
 {
     if (!EnableHotCorners) return;
     Debug.WriteLine("HotCorner: " + corner);
     switch (corner)
     {
         case ScreenCorner.RightBottom:
             Sim.KeyDown(VirtualKeyCode.LWIN);
             Sim.KeyDown(VirtualKeyCode.VK_D);
             Sim.KeyUp(VirtualKeyCode.VK_D);
             Sim.KeyUp(VirtualKeyCode.LWIN);
             break;
         case ScreenCorner.RightTop:
             Sim.KeyDown(VirtualKeyCode.LMENU);
             Sim.KeyDown(VirtualKeyCode.TAB);
             Thread.Sleep(100);
             Sim.KeyUp(VirtualKeyCode.TAB);
             Sim.KeyUp(VirtualKeyCode.LMENU);
             break;
         case ScreenCorner.LeftTop:
             Sim.KeyPress(VirtualKeyCode.CANCEL);
             break;
         case ScreenCorner.LeftBottom:
             Sim.KeyPress(VirtualKeyCode.LWIN);
             break;
     }
 }
コード例 #31
0
    private void Update()
    {
        Vector3 movement = Vector3.zero;

        float xin = Input.GetAxis("Horizontal");
        float zin = Input.GetAxis("Vertical");

        //TODO: Will need to clean this up.. maybe make some basic camera input util class or something

        /**
         * if (Input.GetKey(KeyCode.W)) {
         *  movement += Vector3.forward;
         * }
         * if (Input.GetKey(KeyCode.S)) {
         *  movement += Vector3.back;
         * }
         * if (Input.GetKey(KeyCode.A)) {
         *  movement += Vector3.left;
         * }
         * if (Input.GetKey(KeyCode.D)) {
         *  movement += Vector3.right;
         * }
         **/


        ScreenCorner corner = SlidingCameraBehaviour.GetScreenCornerForMousePosition(
            _borderPanningOffset, _borderPanningCornerSize);

        if (corner != ScreenCorner.None || xin != 0 || zin != 0)
        {
            gameObject.GetComponentInParent <SlidingCameraBehaviour>().enabled = true;
            enabled = false;
        }

        float scroll = Input.GetAxis("Mouse ScrollWheel");

        camOffset *= Mathf.Pow(zoomFactor, -scroll);

        if (camOffset.magnitude > maxZoom)
        {
            camOffset *= (maxZoom / camOffset.magnitude);
        }
        if (camOffset.magnitude < minZoom)
        {
            camOffset *= (minZoom / camOffset.magnitude);
        }

        if (Input.GetMouseButton(2))
        {
            float dy = -Input.GetAxis("Mouse Y");
            if ((Vector3.Angle(camOffset, Vector3.up) > upperAngleLimit || dy < 0) &&
                (Vector3.Angle(camOffset, Vector3.up) < lowerAngleLimit || dy > 0))
            {
                camOffset = Vector3.RotateTowards(camOffset, Vector3.up, dy * verticalROtationSpeed, 0f);
            }
            float dx = Input.GetAxis("Mouse X");
            camOffset = Quaternion.AngleAxis(dx * horizontalROtationSpeed, Vector3.up) * camOffset;
        }

        Vector3 off = camOffset;

        off.y                = 0;
        movement             = Quaternion.FromToRotation(Vector3.forward, off) * -movement;
        orbitPoint.position += Time.deltaTime * BASE_MOVEMENT_SPEED * movement * camOffset.magnitude;
        if (FollowObject)
        {
            // maybe add a lerp here for smoothness
            orbitPoint.position = Vector3.Lerp(orbitPoint.position, FollowObject.transform.position, Time.deltaTime * _rotLerpSpeed);
        }
        transform.localPosition = Vector3.Lerp(transform.localPosition, camOffset, Time.deltaTime * _zoomSpeed);

        // smooth the lookat/rotation
        Quaternion lookOnLook = Quaternion.LookRotation(
            orbitPoint.transform.position - transform.position);

        transform.rotation = Quaternion.Slerp(
            transform.rotation, lookOnLook, Time.deltaTime * _rotLerpSpeed);

        // old code just in case
        //transform.LookAt(orbitPoint, Vector3.up);
    }