Exemplo n.º 1
0
        internal void drawToolTip()
        {
            if (!destroyed) {
                if (showTooltip && (command.ToolTip != null) && (command.ToolTip.Trim().Length > 0)) {
                    Vector2 mousePos = Utils.getMousePosition();
                    Vector2 size = TooltipStyle.CalcSize(new GUIContent(command.ToolTip));
                    Rect rect = new Rect(mousePos.x, mousePos.y + 20, size.x, size.y);
                    float origY = rect.y;
                    rect = rect.clampToScreen();
                    // clamping moved the tooltip up -> reposition above mouse cursor
                    if (rect.y < origY) {
                        rect.y = mousePos.y - size.y - 5;
                        rect = rect.clampToScreen();
                    }

                    int oldDepth = GUI.depth;
                    GUI.depth = -1000;
                    GUILayout.BeginArea(rect);
                    GUILayout.Label(command.ToolTip, TooltipStyle);
                    GUILayout.EndArea();
                    GUI.depth = oldDepth;
                }
            }
        }
Exemplo n.º 2
0
        private AutoPositionResult autoPositionAgainstParent(Vector2 size, Rect parentRect, bool parentIsSingleColumn, RelativePosition preferredPosition)
        {
            Vector2 posLeft = new Vector2(parentRect.x - size.x - BUTTON_SPACING, parentRect.y + (parentRect.height - size.y) / 2);
            Vector2 posRight = new Vector2(parentRect.x + parentRect.width + BUTTON_SPACING, posLeft.y);
            Vector2 posAbove = new Vector2(parentRect.x + (parentRect.width - size.x) / 2, parentRect.y - size.y - BUTTON_SPACING);
            Vector2 posBelow = new Vector2(posAbove.x, parentRect.y + parentRect.height + BUTTON_SPACING);

            // figure out potential positions based on blocking important GUI
            bool canUseLeft = !isBlockingImportantGUI(posLeft, size);
            bool canUseRight = !isBlockingImportantGUI(posRight, size);
            bool canUseAbove = !isBlockingImportantGUI(posAbove, size);
            bool canUseBelow = !isBlockingImportantGUI(posBelow, size);

            // all blocked, let's ignore blocking things
            if (!canUseLeft && !canUseRight && !canUseAbove && !canUseBelow) {
                canUseLeft = true;
                canUseRight = true;
                canUseAbove = true;
                canUseBelow = true;
            }

            // figure out potential positions based on being off-screen
            canUseLeft = canUseLeft && !isOffScreenX(posLeft, size);
            canUseRight = canUseRight && !isOffScreenX(posRight, size);
            canUseAbove = canUseAbove && !isOffScreenY(posAbove, size);
            canUseBelow = canUseBelow && !isOffScreenY(posBelow, size);

            // all off-screen, let's position it anywhere
            if (!canUseLeft && !canUseRight && !canUseAbove && !canUseBelow) {
                canUseLeft = true;
                canUseRight = true;
                canUseAbove = true;
                canUseBelow = true;
            }

            // switch preferred position to the opposite side if blocked
            if ((preferredPosition == RelativePosition.LEFT) && !canUseLeft && canUseRight) {
                preferredPosition = RelativePosition.RIGHT;
            } else if ((preferredPosition == RelativePosition.RIGHT) && !canUseRight && canUseLeft) {
                preferredPosition = RelativePosition.LEFT;
            } else if ((preferredPosition == RelativePosition.ABOVE) && !canUseAbove && canUseBelow) {
                preferredPosition = RelativePosition.BELOW;
            } else if ((preferredPosition == RelativePosition.BELOW) && !canUseBelow && canUseAbove) {
                preferredPosition = RelativePosition.ABOVE;
            }

            RelativePosition finalPosition;

            if (((preferredPosition == RelativePosition.ABOVE) && canUseAbove) ||
                ((preferredPosition == RelativePosition.BELOW) && canUseBelow) ||
                ((preferredPosition == RelativePosition.LEFT) && canUseLeft) ||
                ((preferredPosition == RelativePosition.RIGHT) && canUseRight)) {

                // preferred position is good to go
                finalPosition = preferredPosition;
            } else if (parentIsSingleColumn) {
                // default positioning for single column: right > left > above > below
                if (canUseRight) {
                    finalPosition = RelativePosition.RIGHT;
                } else if (canUseLeft) {
                    finalPosition = RelativePosition.LEFT;
                } else if (canUseAbove) {
                    finalPosition = RelativePosition.ABOVE;
                } else {
                    finalPosition = RelativePosition.BELOW;
                }
            } else {
                // default positioning: above > below > right > left
                if (canUseAbove) {
                    finalPosition = RelativePosition.ABOVE;
                } else if (canUseBelow) {
                    finalPosition = RelativePosition.BELOW;
                } else if (canUseRight) {
                    finalPosition = RelativePosition.RIGHT;
                } else {
                    finalPosition = RelativePosition.LEFT;
                }
            }

            Vector2 pos;
            switch (finalPosition) {
                case RelativePosition.ABOVE:
                    pos = posAbove;
                    break;
                case RelativePosition.BELOW:
                    pos = posBelow;
                    break;
                case RelativePosition.LEFT:
                    pos = posLeft;
                    break;
                case RelativePosition.RIGHT:
                    pos = posRight;
                    break;
                default:
                    throw new Exception("unknown final position: " + finalPosition);
            }

            Rect r = new Rect(pos.x, pos.y, size.x, size.y);
            r = r.clampToScreen();
            pos = new Vector2(r.x, r.y);

            return new AutoPositionResult(finalPosition, pos);
        }
Exemplo n.º 3
0
        private Vector2 autoPositionAgainstParent(Vector2 size, Rect parentRect, bool parentIsSingleColumn)
        {
            Vector2 posRight = new Vector2(parentRect.x + parentRect.width + BUTTON_SPACING, parentRect.y + (parentRect.height - size.y) / 2);
            Vector2 posLeft = new Vector2(parentRect.x - size.x - BUTTON_SPACING, posRight.y);
            Vector2 posAbove = new Vector2(parentRect.x + (parentRect.width - size.x) / 2, parentRect.y - size.y - BUTTON_SPACING);
            Vector2 posBelow = new Vector2(posAbove.x, parentRect.y + parentRect.height + BUTTON_SPACING);

            bool canUseRight = !isOffScreenOrBlockingImportantGUI(posRight, size);
            bool canUseLeft = !isOffScreenOrBlockingImportantGUI(posLeft, size);
            bool canUseAbove = !isOffScreenOrBlockingImportantGUI(posAbove, size);
            bool canUseBelow = !isOffScreenOrBlockingImportantGUI(posBelow, size);

            Vector2 pos;
            if (!canUseRight && !canUseLeft && !canUseAbove && !canUseBelow) {
                // all blocked, use default
                pos = parentIsSingleColumn ? posRight : posAbove;
            } else if (parentIsSingleColumn) {
                // right > left > above > below
                if (canUseRight) {
                    pos = posRight;
                } else if (canUseLeft) {
                    pos = posLeft;
                } else if (canUseAbove) {
                    pos = posAbove;
                } else {
                    pos = posBelow;
                }
            } else {
                // above > below > right > left
                if (canUseAbove) {
                    pos = posAbove;
                } else if (canUseBelow) {
                    pos = posBelow;
                } else if (canUseRight) {
                    pos = posRight;
                } else {
                    pos = posLeft;
                }
            }

            Rect r = new Rect(pos.x, pos.y, size.x, size.y);
            r = r.clampToScreen();
            return new Vector2(r.x, r.y);
        }
Exemplo n.º 4
0
 private bool isOffScreenY(Vector2 pos, Vector2 size)
 {
     Rect r = new Rect(pos.x, pos.y, size.x, size.y);
     r = r.clampToScreen();
     return r.y != pos.y;
 }
Exemplo n.º 5
0
 private bool isOffScreenOrBlockingImportantGUI(Vector2 pos, Vector2 size)
 {
     Rect r = new Rect(pos.x, pos.y, size.x, size.y);
     if (!r.intersectsImportantGUI()) {
         r = r.clampToScreen();
         return (r.x != pos.x) || (r.y != pos.y);
     } else {
         return true;
     }
 }