示例#1
0
        /// <summary>
        /// Tries to get the adjacent location to NotifyIcon using specified window width and height.
        /// </summary>
        /// <param name="windowWidth">Window width</param>
        /// <param name="windowHeight">Window height</param>
        /// <param name="location">Location of window</param>
        /// <returns>True if succeeded</returns>
        protected bool TryGetAdjacentLocationToTaskbar(double windowWidth, double windowHeight, out Point location)
        {
            if (!WindowHelper.TryGetTaskbar(out Rect taskbarRect, out TaskbarAlignment taskbarAlignment))
            {
                location = default(Point);
                return(false);
            }

            if (!NotifyIconHelper.TryGetNotifyIconRect(_notifyIcon, out Rect iconRect))
            {
                iconRect = taskbarRect;                 // Fallback
            }
            if (!WindowHelper.TryGetDwmWindowMargin(_window, out Thickness windowMargin))
            {
                windowMargin = new Thickness(0);                 // Fallback
            }
            double x = 0;
            double y = 0;

            switch (taskbarAlignment)
            {
            case TaskbarAlignment.Top:
            case TaskbarAlignment.Bottom:
                x = iconRect.Right - windowWidth + windowMargin.Right;

                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Top:
                    y = taskbarRect.Bottom - windowMargin.Top;
                    PivotAlignment = PivotAlignment.TopRight;
                    break;

                case TaskbarAlignment.Bottom:
                    y = taskbarRect.Top - windowHeight + windowMargin.Bottom;
                    PivotAlignment = PivotAlignment.BottomRight;
                    break;
                }
                break;

            case TaskbarAlignment.Left:
            case TaskbarAlignment.Right:
                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Left:
                    x = taskbarRect.Right - windowMargin.Left;
                    PivotAlignment = PivotAlignment.BottomLeft;
                    break;

                case TaskbarAlignment.Right:
                    x = taskbarRect.Left - windowWidth + windowMargin.Right;
                    PivotAlignment = PivotAlignment.BottomRight;
                    break;
                }

                y = iconRect.Bottom - windowHeight + windowMargin.Bottom;
                break;
            }
            location = new Point(x, y);
            return(true);
        }
    void LateUpdate()
    {
        switch (pivotAnchor)
        {
        case PivotAlignment.Center:
            transform.position = character.transform.position + centerPivotOffset;
            pivotAnchor        = PivotAlignment.Center;
            break;

        case PivotAlignment.BottomLeft:
            transform.position = character.transform.position + bottomLeftPivotOffset;
            pivotAnchor        = PivotAlignment.BottomLeft;
            break;

        case PivotAlignment.BottomRight:
            transform.position = character.transform.position + bottomRightPivotOffset;
            pivotAnchor        = PivotAlignment.BottomRight;
            break;
        }

        if (lastPivotAnchor != pivotAnchor)
        {
            anchorPivot(pivotAnchor);
            lastPivotAnchor = pivotAnchor;
        }
    }
示例#3
0
        /// <summary>
        /// Attempts to get the adjacent location to pivot point using specified window width and height.
        /// </summary>
        /// <param name="windowWidth">Window width</param>
        /// <param name="windowHeight">Window height</param>
        /// <param name="location">Location of window</param>
        /// <returns>True if successfully gets</returns>
        protected bool TryGetAdjacentLocationToPivot(double windowWidth, double windowHeight, out Rect location)
        {
            if (!WindowHelper.TryGetTaskbar(out _, out TaskbarAlignment taskbarAlignment, out _))
            {
                location = default;
                return(false);
            }

            var isLeftToRight = !CultureInfoAddition.UserDefaultUICulture.TextInfo.IsRightToLeft;

            PivotAlignment = (taskbarAlignment, isLeftToRight) switch
            {
                (TaskbarAlignment.Top, true) => PivotAlignment.TopRight,
                (TaskbarAlignment.Top, false) => PivotAlignment.TopLeft,
                (TaskbarAlignment.Bottom, true) => PivotAlignment.BottomRight,
                (TaskbarAlignment.Bottom, false) => PivotAlignment.BottomLeft,
                (TaskbarAlignment.Left, { }) => PivotAlignment.BottomLeft,
    void Start()
    {
        float charWidth  = character.GetComponent <Renderer>().bounds.size.x;
        float charHeight = character.GetComponent <Renderer>().bounds.size.y;

        dialogPanel = GetComponent <RectMask2D>();

        centerPivotOffset      = new Vector3(0, charHeight);
        bottomLeftPivotOffset  = new Vector3(-charWidth / 2, charHeight / 2);
        bottomRightPivotOffset = new Vector3(charWidth / 2, charHeight / 2);

        anchorPivot(pivotAnchor);
        lastPivotAnchor = pivotAnchor;

        if (lerpSpeed <= 0)
        {
            lerpSpeed = DefaultLerpSpeed;
        }
    }
    void anchorPivot(PivotAlignment alignment)
    {
        switch (alignment)
        {
        case PivotAlignment.Center:
            dialogPanel.rectTransform.pivot = new Vector2(0.5f, 0.5f);
            pivotAnchor = PivotAlignment.Center;
            break;

        case PivotAlignment.BottomLeft:
            dialogPanel.rectTransform.pivot = new Vector2(1, 0);
            pivotAnchor = PivotAlignment.BottomLeft;
            break;

        case PivotAlignment.BottomRight:
            dialogPanel.rectTransform.pivot = new Vector2(0, 0);
            pivotAnchor = PivotAlignment.BottomRight;
            break;
        }
    }
示例#6
0
        /// <summary>
        /// Tries to get the adjacent location to pivot point using specified window width and height.
        /// </summary>
        /// <param name="windowWidth">Window width</param>
        /// <param name="windowHeight">Window height</param>
        /// <param name="location">Location of window</param>
        /// <returns>True if succeeded</returns>
        protected bool TryGetAdjacentLocationToPivot(double windowWidth, double windowHeight, out Point location)
        {
            var x = _pivot.X;
            var y = _pivot.Y;

            var taskbarAlignment = WindowHelper.GetTaskbarAlignment();

            switch (taskbarAlignment)
            {
            case TaskbarAlignment.Left:
                // Place this window at the top-right of the pivot.
                x += 1;
                y += -windowHeight - 1;
                PivotAlignment = PivotAlignment.BottomLeft;
                break;

            case TaskbarAlignment.Top:
                // Place this window at the bottom-left of the pivot.
                x += -windowWidth - 1;
                y += 1;
                PivotAlignment = PivotAlignment.TopRight;
                break;

            case TaskbarAlignment.Right:
            case TaskbarAlignment.Bottom:
                // Place this window at the top-left of the pivot.
                x += -windowWidth - 1;
                y += -windowHeight - 1;
                PivotAlignment = PivotAlignment.BottomRight;
                break;

            default:
                location = default(Point);
                return(false);
            }
            location = new Point(x, y);
            return(true);
        }
示例#7
0
    protected void UpdatePivot()
    {
        if (_vertices == null)
        {
            _vertices    = new Vector3[4];
            _vertices[0] = Vector3.zero;
            _vertices[1] = Vector3.zero;
            _vertices[2] = Vector3.zero;
            _vertices[3] = Vector3.zero;
        }

        // horizontal
        if ((_pivot == PivotAlignment.TopLeft) ||
            (_pivot == PivotAlignment.Left) ||
            (_pivot == PivotAlignment.BottomLeft))
        {
            _vertices[0].x = _vertices[2].x = 0f;
            _vertices[1].x = _vertices[3].x = 1f;
        }
        else if ((_pivot == PivotAlignment.TopRight) ||
                 (_pivot == PivotAlignment.Right) ||
                 (_pivot == PivotAlignment.BottomRight))
        {
            _vertices[0].x = _vertices[2].x = -1f;
            _vertices[1].x = _vertices[3].x = 0f;
        }
        else
        {
            _vertices[0].x = _vertices[2].x = -0.5f;
            _vertices[1].x = _vertices[3].x = 0.5f;
        }

        // vertical
        if ((_pivot == PivotAlignment.TopLeft) ||
            (_pivot == PivotAlignment.Top) ||
            (_pivot == PivotAlignment.TopRight))
        {
            _vertices[0].y = _vertices[1].y = -1f;
            _vertices[2].y = _vertices[3].y = 0f;
        }
        else if ((_pivot == PivotAlignment.BottomLeft) ||
                 (_pivot == PivotAlignment.Bottom) ||
                 (_pivot == PivotAlignment.BottomRight))
        {
            _vertices[0].y = _vertices[1].y = 0f;
            _vertices[2].y = _vertices[3].y = 1f;
        }
        else
        {
            _vertices[0].y = _vertices[1].y = -0.5f;
            _vertices[2].y = _vertices[3].y = 0.5f;
        }

        if (_mesh == null)
        {
            _mesh           = new Mesh();
            _mesh.name      = "SysFontTextMesh";
            _mesh.hideFlags = HideFlags.DontSave | HideFlags.DontSave;
        }
        _mesh.vertices  = _vertices;
        _mesh.uv        = _uv;
        _mesh.triangles = _triangles;
        _mesh.RecalculateBounds();
        _filter.mesh = _mesh;

        _lastPivot = _pivot;
    }
示例#8
0
        /// <summary>
        /// Attempts to get the adjacent location to NotifyIcon using specified window width and height.
        /// </summary>
        /// <param name="windowWidth">Window width</param>
        /// <param name="windowHeight">Window height</param>
        /// <param name="location">Location of window</param>
        /// <returns>True if successfully gets</returns>
        protected bool TryGetAdjacentLocationToTaskbar(double windowWidth, double windowHeight, out Rect location)
        {
            if (!WindowHelper.TryGetTaskbar(out Rect taskbarRect, out TaskbarAlignment taskbarAlignment))
            {
                location = default;
                return(false);
            }

            var iconPlacement    = IconPlacement.Unknown;
            var overflowAreaRect = default(Rect);

            if (NotifyIconHelper.TryGetNotifyIconRect(_notifyIcon, out Rect iconRect))
            {
                if (taskbarRect.Contains(iconRect))
                {
                    iconPlacement = IconPlacement.InTaskbar;
                }
                else if (WindowHelper.TryGetOverflowAreaRect(out overflowAreaRect))
                {
                    iconPlacement = IconPlacement.InOverflowArea;
                }
            }

            if (!WindowHelper.TryGetDwmWindowMargin(_window, out Thickness windowMargin))
            {
                windowMargin = new Thickness(0);                 // Fallback
            }
            double x = 0, y = 0;

            switch (taskbarAlignment)
            {
            case TaskbarAlignment.Top:
            case TaskbarAlignment.Bottom:
                x = iconPlacement switch
                {
                    IconPlacement.InTaskbar => iconRect.Right,
                    IconPlacement.InOverflowArea => overflowAreaRect.Left,
                    _ => taskbarRect.Right,                            // Fallback
                };
                x -= (windowWidth - windowMargin.Right);

                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Top:
                    y = taskbarRect.Bottom - windowMargin.Top;
                    PivotAlignment = PivotAlignment.TopRight;
                    break;

                case TaskbarAlignment.Bottom:
                    y = taskbarRect.Top - (windowHeight - windowMargin.Bottom);
                    PivotAlignment = PivotAlignment.BottomRight;
                    break;
                }
                break;

            case TaskbarAlignment.Left:
            case TaskbarAlignment.Right:
                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Left:
                    x = taskbarRect.Right - windowMargin.Left;
                    PivotAlignment = PivotAlignment.BottomLeft;
                    break;

                case TaskbarAlignment.Right:
                    x = taskbarRect.Left - (windowWidth - windowMargin.Right);
                    PivotAlignment = PivotAlignment.BottomRight;
                    break;
                }

                y = iconPlacement switch
                {
                    IconPlacement.InTaskbar => iconRect.Bottom,
                    IconPlacement.InOverflowArea => overflowAreaRect.Top,
                    _ => taskbarRect.Bottom,                            // Fallback
                };
                y -= (windowHeight - windowMargin.Bottom);
                break;
            }
            location = new Rect(x, y, windowWidth, windowHeight);
            return(true);
        }
示例#9
0
    protected void UpdatePivot()
    {
        if (_vertices == null)
        {
          _vertices = new Vector3[4];
          _vertices[0] = Vector3.zero;
          _vertices[1] = Vector3.zero;
          _vertices[2] = Vector3.zero;
          _vertices[3] = Vector3.zero;
        }

        // horizontal
        if ((_pivot == PivotAlignment.TopLeft) ||
        (_pivot == PivotAlignment.Left) ||
        (_pivot == PivotAlignment.BottomLeft))
        {
          _vertices[0].x = _vertices[2].x = 0f;
          _vertices[1].x = _vertices[3].x = 1f;
        }
        else if ((_pivot == PivotAlignment.TopRight) ||
        (_pivot == PivotAlignment.Right) ||
        (_pivot == PivotAlignment.BottomRight))
        {
          _vertices[0].x = _vertices[2].x = -1f;
          _vertices[1].x = _vertices[3].x = 0f;
        }
        else
        {
          _vertices[0].x = _vertices[2].x = -0.5f;
          _vertices[1].x = _vertices[3].x = 0.5f;
        }

        // vertical
        if ((_pivot == PivotAlignment.TopLeft) ||
        (_pivot == PivotAlignment.Top) ||
        (_pivot == PivotAlignment.TopRight))
        {
          _vertices[0].y = _vertices[1].y = -1f;
          _vertices[2].y = _vertices[3].y = 0f;
        }
        else if ((_pivot == PivotAlignment.BottomLeft) ||
        (_pivot == PivotAlignment.Bottom) ||
        (_pivot == PivotAlignment.BottomRight))
        {
          _vertices[0].y = _vertices[1].y = 0f;
          _vertices[2].y = _vertices[3].y = 1f;
        }
        else
        {
          _vertices[0].y = _vertices[1].y = -0.5f;
          _vertices[2].y = _vertices[3].y = 0.5f;
        }

        if (_mesh == null)
        {
          _mesh = new Mesh();
          _mesh.name = "SysFontTextMesh";
          _mesh.hideFlags = HideFlags.DontSave | HideFlags.DontSave;
        }
        _mesh.vertices = _vertices;
        _mesh.uv = _uv;
        _mesh.triangles = _triangles;
        _mesh.RecalculateBounds();
        _filter.mesh = _mesh;

        _lastPivot = _pivot;
    }
示例#10
0
        /// <summary>
        /// Attempts to get the adjacent location to NotifyIcon using specified window width and height.
        /// </summary>
        /// <param name="windowWidth">Window width</param>
        /// <param name="windowHeight">Window height</param>
        /// <param name="location">Location of window</param>
        /// <returns>True if successfully gets</returns>
        protected bool TryGetAdjacentLocationToTaskbar(double windowWidth, double windowHeight, out Rect location)
        {
            if (!WindowHelper.TryGetTaskbar(out Rect taskbarRect, out TaskbarAlignment taskbarAlignment, out bool isShown))
            {
                location = default;
                return(false);
            }

            var iconPlacement    = IconPlacement.Unknown;
            var overflowAreaRect = default(Rect);

            if (NotifyIconHelper.TryGetNotifyIconRect(_notifyIcon, out Rect iconRect))
            {
                if (taskbarRect.Contains(
                        iconRect.X + iconRect.Width / 2D,
                        iconRect.Y + iconRect.Height / 2D))
                {
                    iconPlacement = IconPlacement.InTaskbar;
                }
                else if (WindowHelper.TryGetOverflowAreaRect(out overflowAreaRect) &&
                         overflowAreaRect.Contains(iconRect))
                {
                    iconPlacement = IconPlacement.InOverflowArea;
                }
            }

            if (!WindowHelper.TryGetDwmWindowMargin(_window, out Thickness windowMargin))
            {
                windowMargin = new Thickness(0);                 // Fallback
            }
            var isLeftToRight = !CultureInfoAddition.UserDefaultUICulture.TextInfo.IsRightToLeft;

            double x = 0, y = 0;

            // To avoid a gap between window and taskbar when taskbar alignment is right or bottom
            // and monitor DPI is 125%, 150%, 175%, the window width and height (in DIP) must be
            // a multiple of 4. Otherwise, the window width and height multiplied with those DPI
            // will have a fraction and it will cause a blurry edge looking as if there is a gap.
            switch (taskbarAlignment)
            {
            case TaskbarAlignment.Top:
            case TaskbarAlignment.Bottom:
                x = iconPlacement switch
                {
                    IconPlacement.InTaskbar => isLeftToRight ? iconRect.Right : iconRect.Left,
                    IconPlacement.InOverflowArea => isLeftToRight ? overflowAreaRect.Left : overflowAreaRect.Right,
                    _ => isLeftToRight ? taskbarRect.Right : taskbarRect.Left,                             // Fallback
                };
                x -= isLeftToRight ? (windowWidth - windowMargin.Right) : windowMargin.Left;

                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Top:
                    y = (isShown ? taskbarRect.Bottom : taskbarRect.Top) - windowMargin.Top;
                    PivotAlignment = isLeftToRight ? PivotAlignment.TopRight : PivotAlignment.TopLeft;
                    break;

                case TaskbarAlignment.Bottom:
                    y = (isShown ? taskbarRect.Top : taskbarRect.Bottom) - (windowHeight - windowMargin.Bottom);
                    PivotAlignment = isLeftToRight ? PivotAlignment.BottomRight : PivotAlignment.BottomLeft;
                    break;
                }
                break;

            case TaskbarAlignment.Left:
            case TaskbarAlignment.Right:
                switch (taskbarAlignment)
                {
                case TaskbarAlignment.Left:
                    x = (isShown ? taskbarRect.Right : taskbarRect.Left) - windowMargin.Left;
                    PivotAlignment = PivotAlignment.BottomLeft;
                    break;

                case TaskbarAlignment.Right:
                    x = (isShown ? taskbarRect.Left : taskbarRect.Right) - (windowWidth - windowMargin.Right);
                    PivotAlignment = PivotAlignment.BottomRight;
                    break;
                }

                y = iconPlacement switch
                {
                    IconPlacement.InTaskbar => iconRect.Bottom,
                    IconPlacement.InOverflowArea => overflowAreaRect.Top,
                    _ => taskbarRect.Bottom,                             // Fallback
                };
                y -= (windowHeight - windowMargin.Bottom);
                break;
            }
            location = new Rect(x, y, windowWidth, windowHeight);
            return(true);
        }