From 0a21ce08f563a05dbddbe56bc2755c9a582eb470 Mon Sep 17 00:00:00 2001 From: Neil Sarkar Date: Sun, 19 Jul 2020 23:32:52 -0700 Subject: [PATCH] Rename drawing utility RectExtensions to avoid collision with BCI --- Editor/RectExtensions.cs | 128 +++++++++++++++++++-------------------- Editor/ScreenEditor.cs | 13 ++-- 2 files changed, 70 insertions(+), 71 deletions(-) diff --git a/Editor/RectExtensions.cs b/Editor/RectExtensions.cs index b4d91b3..2a6f89e 100644 --- a/Editor/RectExtensions.cs +++ b/Editor/RectExtensions.cs @@ -4,39 +4,39 @@ /// Utility extensions for manipulating Rect values. //TODO: Go through this /// public static class RectExtMethods { - public static Rect SetPosition(this Rect rect, Vector2 position) { - return rect.SetPosition(position.x, position.y); + public static Rect VioletSetPosition(this Rect rect, Vector2 position) { + return rect.VioletSetPosition(position.x, position.y); } - public static Rect SetPosition(this Rect rect, float x, float y) { + public static Rect VioletSetPosition(this Rect rect, float x, float y) { return new Rect(x, y, rect.width, rect.height); } - public static Rect DisplaceX(this Rect rect, float x) { + public static Rect VioletDisplaceX(this Rect rect, float x) { return new Rect(rect.x + x, rect.y, rect.width, rect.height); } - public static Rect DisplaceY(this Rect rect, float y) { + public static Rect VioletDisplaceY(this Rect rect, float y) { return new Rect(rect.x, rect.y + y, rect.width, rect.height); } - public static Rect Displace(this Rect rect, float x, float y) { + public static Rect VioletDisplace(this Rect rect, float x, float y) { return new Rect(rect.x + x, rect.y + y, rect.width, rect.height); } - public static Rect Displace(this Rect rect, Vector2 displacement) { + public static Rect VioletDisplace(this Rect rect, Vector2 displacement) { return new Rect(rect.position + displacement, rect.size); } - public static Rect SetWidth(this Rect rect, float width) { + public static Rect VioletSetWidth(this Rect rect, float width) { return new Rect(rect.x, rect.y, width, rect.height); } - public static Rect SetHeight(this Rect rect, float height) { + public static Rect VioletSetHeight(this Rect rect, float height) { return new Rect(rect.x, rect.y, rect.width, height); } - public static Rect Transform(this Rect rect, Matrix4x4 matrix) { + public static Rect VioletTransform(this Rect rect, Matrix4x4 matrix) { return new Rect(matrix.MultiplyPoint3x4(rect.position), matrix.MultiplyVector(rect.size)); } @@ -48,36 +48,36 @@ public static float longestSide(this Rect rect) { return Mathf.Max(rect.width, rect.height); } - public static Rect SetSize(this Rect rect, float size) { - return rect.SetSize(Vector2.one * size); + public static Rect VioletSetSize(this Rect rect, float size) { + return rect.VioletSetSize(Vector2.one * size); } - public static Rect SetSize(this Rect rect, float width, float height) { - return rect.SetSize(new Vector2(width, height)); + public static Rect VioletSetSize(this Rect rect, float width, float height) { + return rect.VioletSetSize(new Vector2(width, height)); } - public static Rect SetSize(this Rect rect, Vector2 size) { + public static Rect VioletSetSize(this Rect rect, Vector2 size) { return new Rect(rect.position, size); } - public static Rect SetSizeCentered(this Rect rect, float size) { - return rect.SetSizeCentered(Vector2.one * size); + public static Rect VioletSetSizeCentered(this Rect rect, float size) { + return rect.VioletSetSizeCentered(Vector2.one * size); } - public static Rect SetSizeCentered(this Rect rect, float width, float height) { - return rect.SetSizeCentered(new Vector2(width, height)); + public static Rect VioletSetSizeCentered(this Rect rect, float width, float height) { + return rect.VioletSetSizeCentered(new Vector2(width, height)); } - public static Rect SetSizeCentered(this Rect rect, Vector2 size) { + public static Rect VioletSetSizeCentered(this Rect rect, Vector2 size) { return new Rect(rect.center - size * 0.5f, size); } #region Transalation - public static Rect Translate(this Rect rect, float x, float y) { - return Translate(rect, new Vector2(x, y)); + public static Rect VioletTranslate(this Rect rect, float x, float y) { + return VioletTranslate(rect, new Vector2(x, y)); } - public static Rect Translate(this Rect rect, Vector2 translation) { + public static Rect VioletTranslate(this Rect rect, Vector2 translation) { return new Rect(rect.position + translation, rect.size); } #endregion @@ -90,10 +90,10 @@ public static Rect Translate(this Rect rect, Vector2 translation) { /// Inset width. /// Inset Rect. /// - public static Rect SplitRight(this Rect rect, float inset, out Rect result) { + public static Rect VioletSplitRight(this Rect rect, float inset, out Rect result) { result = new Rect(rect.x + rect.width - inset, rect.y, inset, rect.height); - return rect.PadRight(inset); + return rect.VioletPadRight(inset); } /// @@ -103,10 +103,10 @@ public static Rect SplitRight(this Rect rect, float inset, out Rect result) { /// Inset width. /// Inset Rect. /// - public static Rect SplitLeft(this Rect rect, float inset, out Rect result) { + public static Rect VioletSplitLeft(this Rect rect, float inset, out Rect result) { result = new Rect(rect.x, rect.y, inset, rect.height); - return rect.PadLeft(inset); + return rect.VioletPadLeft(inset); } /// @@ -116,10 +116,10 @@ public static Rect SplitLeft(this Rect rect, float inset, out Rect result) { /// Inset height. /// Inset Rect. /// - public static Rect SplitBottom(this Rect rect, float inset, out Rect result) { + public static Rect VioletSplitBottom(this Rect rect, float inset, out Rect result) { result = new Rect(rect.x, rect.y + rect.height - inset, rect.width, inset); - return rect.PadBottom(inset); + return rect.VioletPadBottom(inset); } /// @@ -129,10 +129,10 @@ public static Rect SplitBottom(this Rect rect, float inset, out Rect result) { /// Inset height. /// Inset Rect. /// - public static Rect SplitTop(this Rect rect, float inset, out Rect result) { + public static Rect VioletSplitTop(this Rect rect, float inset, out Rect result) { result = new Rect(rect.x, rect.y, rect.width, inset); - return rect.PadTop(inset); + return rect.VioletPadTop(inset); } #endregion @@ -143,8 +143,8 @@ public static Rect SplitTop(this Rect rect, float inset, out Rect result) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect Pad(this Rect rect, float padding) { - return Pad(rect, padding, padding, padding, padding); + public static Rect VioletPad(this Rect rect, float padding) { + return VioletPad(rect, padding, padding, padding, padding); } /// @@ -153,8 +153,8 @@ public static Rect Pad(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadLeft(this Rect rect, float padding) { - return Pad(rect, padding, 0.0f, 0.0f, 0.0f); + public static Rect VioletPadLeft(this Rect rect, float padding) { + return VioletPad(rect, padding, 0.0f, 0.0f, 0.0f); } /// @@ -163,8 +163,8 @@ public static Rect PadLeft(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadRight(this Rect rect, float padding) { - return Pad(rect, 0.0f, padding, 0.0f, 0.0f); + public static Rect VioletPadRight(this Rect rect, float padding) { + return VioletPad(rect, 0.0f, padding, 0.0f, 0.0f); } /// @@ -173,8 +173,8 @@ public static Rect PadRight(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadTop(this Rect rect, float padding) { - return Pad(rect, 0.0f, 0.0f, padding, 0.0f); + public static Rect VioletPadTop(this Rect rect, float padding) { + return VioletPad(rect, 0.0f, 0.0f, padding, 0.0f); } /// @@ -183,8 +183,8 @@ public static Rect PadTop(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadBottom(this Rect rect, float padding) { - return Pad(rect, 0.0f, 0.0f, 0.0f, padding); + public static Rect VioletPadBottom(this Rect rect, float padding) { + return VioletPad(rect, 0.0f, 0.0f, 0.0f, padding); } /// @@ -193,8 +193,8 @@ public static Rect PadBottom(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadHorizontal(this Rect rect, float padding) { - return Pad(rect, padding, padding, 0.0f, 0.0f); + public static Rect VioletPadHorizontal(this Rect rect, float padding) { + return VioletPad(rect, padding, padding, 0.0f, 0.0f); } /// @@ -203,8 +203,8 @@ public static Rect PadHorizontal(this Rect rect, float padding) { /// Rect to pad. /// Amount to pad. /// Padded Rect. - public static Rect PadVertical(this Rect rect, float padding) { - return Pad(rect, 0.0f, 0.0f, padding, padding); + public static Rect VioletPadVertical(this Rect rect, float padding) { + return VioletPad(rect, 0.0f, 0.0f, padding, padding); } /// @@ -212,67 +212,67 @@ public static Rect PadVertical(this Rect rect, float padding) { /// /// Rect to pad. /// Amount to pad left edge. - /// Amount to pad left edge. - /// Amount to pad left edge. + /// Amount to pad right edge. + /// Amount to pad top edge. /// Amount to pad left edge. /// Padded Rect. - public static Rect Pad(this Rect rect, float left, float right, float top, float bottom) { + public static Rect VioletPad(this Rect rect, float left, float right, float top, float bottom) { return new Rect(rect.x + left, rect.y + top, rect.width - left - right, rect.height - top - bottom); } #endregion #region Sequencing - public static Rect StepDown(this Rect rect, float padding = 0.0f) { + public static Rect VioletStepDown(this Rect rect, float padding = 0.0f) { return new Rect(rect.x, rect.y + rect.height + padding, rect.width, rect.height); } - public static Rect StepUp(this Rect rect, float padding = 0.0f) { + public static Rect VioletStepUp(this Rect rect, float padding = 0.0f) { return new Rect(rect.x, rect.y - rect.height - padding, rect.width, rect.height); } - public static Rect StepLeft(this Rect rect, float padding = 0.0f) { + public static Rect VioletStepLeft(this Rect rect, float padding = 0.0f) { return new Rect(rect.x - rect.width - padding, rect.y, rect.width, rect.height); } - public static Rect StepRight(this Rect rect, float padding = 0.0f) { + public static Rect VioletStepRight(this Rect rect, float padding = 0.0f) { return new Rect(rect.x + rect.width + padding, rect.y, rect.width, rect.height); } #endregion #region Extrusions - public static Rect ExtrudeLeft(this Rect rect, float width) { + public static Rect VioletExtrudeLeft(this Rect rect, float width) { return new Rect(rect.x - width, rect.y, width, rect.height); } - public static Rect ExtrudeRight(this Rect rect, float width) { + public static Rect VioletExtrudeRight(this Rect rect, float width) { return new Rect(rect.x + rect.width, rect.y, width, rect.height); } - public static Rect ExtrudeTop(this Rect rect, float height) { + public static Rect VioletExtrudeTop(this Rect rect, float height) { return new Rect(rect.x, rect.y - height, rect.width, height); } - public static Rect ExtrudeBottom(this Rect rect, float height) { + public static Rect VioletExtrudeBottom(this Rect rect, float height) { return new Rect(rect.x, rect.y + rect.height, rect.width, height); } #endregion #region Backfills - public static Rect BackfillLeft(this Rect rect, float width) { - return rect.PadRight(rect.width - width); + public static Rect VioletBackfillLeft(this Rect rect, float width) { + return rect.VioletPadRight(rect.width - width); } - public static Rect BackfillRight(this Rect rect, float width) { - return rect.PadLeft(rect.width - width); + public static Rect VioletBackfillRight(this Rect rect, float width) { + return rect.VioletPadLeft(rect.width - width); } - public static Rect BackfillTop(this Rect rect, float height) { - return rect.PadBottom(rect.height - height); + public static Rect VioletBackfillTop(this Rect rect, float height) { + return rect.VioletPadBottom(rect.height - height); } - public static Rect BackfillBottom(this Rect rect, float height) { - return rect.PadTop(rect.height - height); + public static Rect VioletBackfillBottom(this Rect rect, float height) { + return rect.VioletPadTop(rect.height - height); } #endregion diff --git a/Editor/ScreenEditor.cs b/Editor/ScreenEditor.cs index 1af16ef..8740f5a 100644 --- a/Editor/ScreenEditor.cs +++ b/Editor/ScreenEditor.cs @@ -77,9 +77,8 @@ private static GUIStyle InitStyle(ref GUIStyle style, GUIStyle original, TextAnc return style; } - private static bool Button(Rect rect, string label, string tooltip, Color color, FontStyle fontStyle = FontStyle.Normal, int dot = 0, int i = 0, int n = 1) { - rect = rect.BackfillRight(BUTTON_WIDTH); + rect = rect.VioletBackfillRight(BUTTON_WIDTH); GUIStyle style = null; @@ -108,20 +107,20 @@ private static bool Button(Rect rect, string label, string tooltip, Color color, shadowColor.a = 0.8f; if (dot > 0) { - var dotRect = rect.BackfillRight(rect.height).DisplaceX(1f)/*.Pad( 4f )*/; + var dotRect = rect.VioletBackfillRight(rect.width - rect.height).VioletDisplaceX(1f)/*.Pad( 4f )*/; var dotColor = dot == 2 ? color : Color.grey; dotColor.a = 0.5f; GUI.Box(dotRect, GUIContent.none); - EditorGUI.DrawRect(dotRect.Pad(3f).DisplaceX(-1f), dotColor); + EditorGUI.DrawRect(dotRect.VioletPad(3f).VioletDisplaceX(-1f), dotColor); } - rect = rect.SetWidth(3f).DisplaceX(4f).PadVertical(1f); + rect = rect.VioletSetWidth(3f).VioletDisplaceX(4f).VioletPadVertical(1f); - EditorGUI.DrawRect(rect.ExtrudeLeft(1f), shadowColor); - EditorGUI.DrawRect(rect.ExtrudeRight(1f), shadowColor); + EditorGUI.DrawRect(rect.VioletExtrudeLeft(1f), shadowColor); + EditorGUI.DrawRect(rect.VioletExtrudeRight(1f), shadowColor); color.a = 0.5f;