Example #1
0
        public static bool SpriteButton(Sprite sprite, bool respectRatio = false, params GUILayoutOption[] options)
        {
            GUIStyle style       = UnityEngine.GUI.skin.button;
            Rect     controlRect = GUILayoutUtility.GetRect(GUIContent.none, style, options);

            return(GUIEx.SpriteButton(sprite, controlRect, style, respectRatio));
        }
Example #2
0
        public static bool WasClicked(Rect rect, int button)
        {
            var clicked = GUIEx.IsHovering(rect) &&
                          Event.current.type == EventType.MouseDown &&
                          Event.current.button == button;

            if (clicked)
            {
                Event.current.Use();
            }
            return(clicked);
        }
Example #3
0
 public static void DrawBorder(Rect area, float left, float right, float top, float bottom, Color color)
 {
     GUIEx.PushColor(color);
     // Top
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin + top, area.yMin, area.width - top * 2.0f, top), GUIEx.White);
     // Bottom
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin + bottom, area.yMax - bottom, area.width - bottom * 2.0f, bottom),
                                 GUIEx.White);
     // Left
     UnityEngine.GUI.DrawTexture(new Rect(area.xMin, area.yMin, left, area.height), GUIEx.White);
     // Right
     UnityEngine.GUI.DrawTexture(new Rect(area.xMax - right, area.yMin, right, area.height), GUIEx.White);
     GUIEx.PopColor();
 }
Example #4
0
        public static void DrawLabelAtCursor(GUIContent content, GUIStyle style, Color background)
        {
            GUIEx.PushBackgroundColor(background);
            var area = new Rect(Event.current.mousePosition, Vector2.zero);

            float width;

            style.CalcMinMaxWidth(content, out width, out width);
            float height = style.CalcHeight(content, width);

            area.width  = width;
            area.height = height;

            UnityEngine.GUI.Label(area, content, style);
            GUIEx.PopBackgroundColor();
        }
Example #5
0
        public static bool ImageButton(Texture2D image, GUIStyle style, params GUILayoutOption[] options)
        {
            Color    color      = Color.black;
            GUIStyle labelStyle = new GUIStyle(style);

            Rect labelRect = GUILayoutUtility.GetRect(new GUIContent(image), style, options);

            if (GUIEx.IsHovering(labelRect))
            {
                color = Color.blue;
            }

            GUIEx.PushColor(color);
            UnityEngine.GUI.DrawTexture(labelRect, image, ScaleMode.ScaleToFit);
            GUIEx.PopColor();

            return(GUIEx.WasClicked(labelRect, 0));
        }
Example #6
0
        public static bool SpriteButton(Sprite sprite, Rect position, GUIStyle style, bool respectRatio = false)
        {
            bool pressed = UnityEngine.GUI.Button(position, GUIContent.none, style);

            position = position.Expand(-style.border.horizontal, -style.border.vertical);

            if (respectRatio)
            {
                float ratio = sprite.textureRect.height / sprite.textureRect.width;
                if (sprite.textureRect.width > sprite.textureRect.height)
                {
                    position.height *= ratio;
                }
                else
                {
                    position.width *= ratio;
                }
            }

            GUIEx.DrawSprite(sprite, position);
            return(pressed);
        }
Example #7
0
        public static void DrawLines(Vector2[] points, Color[] colors, float width)
        {
            ThrowIf.ArgumentIsNull(points, "points");
            ThrowIf.ArgumentIsNull(colors, "colors");
            ThrowIf.False(points.Length == colors.Length, "Points and colors array must be the same length.");

            for (int i = 0; i < points.Length; ++i)
            {
                Vector2 start = points[i];
                Vector2 end   = points[MathEx.Wrap(i + 1, 0, points.Length - 1)];
                Color   color = colors[i];

                if (Mathf.Abs(start.x - end.x) > Mathf.Abs(start.y - end.y))
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, end.x - start.x, width), color);
                }
                else
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, width, end.y - start.y), color);
                }
                GUIEx.PopColor();
            }
        }
Example #8
0
        public static bool LabelButton(string label, GUIStyle style)
        {
            Color    color      = Color.black;
            GUIStyle labelStyle = new GUIStyle(style);

            Rect labelRect = GUILayoutUtility.GetRect(new GUIContent(label), style);

            if (GUIEx.IsHovering(labelRect))
            {
                color = Color.blue;
            }

            Rect underlineRect = labelRect;

            underlineRect.y      = underlineRect.yMax - 2.0f;
            underlineRect.height = 1.0f;

            labelStyle.normal.textColor = color;
            UnityEngine.GUI.Label(labelRect, label, labelStyle);
            GUIEx.DrawBox(underlineRect, color);

            return(false);
        }
Example #9
0
 public static bool WasClicked(Rect rect)
 {
     return(GUIEx.IsHovering(rect) && Event.current.type == EventType.MouseDown);
 }
Example #10
0
 public static bool SpriteButton(Sprite sprite, Rect position, bool respectRatio = false)
 {
     return(GUIEx.SpriteButton(sprite, position, UnityEngine.GUI.skin.button, respectRatio));
 }
Example #11
0
 public static void DrawLabelAtCursor(string text, Color background)
 {
     GUIEx.DrawLabelAtCursor(new GUIContent(text), UnityEngine.GUI.skin.label, background);
 }
Example #12
0
 public static void DrawBox(Rect area, float borderSize, Color borderColor, Color backgroundColor)
 {
     GUIEx.DrawBox(area, backgroundColor);
     GUIEx.DrawBorder(area, borderSize, borderColor);
 }
Example #13
0
 public static void DrawBox(Rect area, Color backgroundColor)
 {
     GUIEx.PushColor(backgroundColor);
     UnityEngine.GUI.DrawTexture(area, GUIEx.White);
     GUIEx.PopColor();
 }
Example #14
0
 public static void DrawBorder(Rect area, RectOffset border, Color color)
 {
     GUIEx.DrawBorder(area, border.left, border.right, border.top, border.bottom, color);
 }
Example #15
0
 public static void DrawBorder(Rect area, float border, Color color)
 {
     GUIEx.DrawBorder(area, border, border, border, border, color);
 }
Example #16
0
        public static void DrawSprite(Sprite sprite, params GUILayoutOption[] options)
        {
            Rect controlRect = GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle(), options);

            GUIEx.DrawSprite(sprite, controlRect);
        }