public void Add(InstantGuiElementPos e) { left += e.left; right += e.right; top += e.top; bottom += e.bottom; }
public void Subtract(InstantGuiElementPos e2) { left -= e2.left; right -= e2.right; top -= e2.top; bottom -= e2.bottom; }
static public InstantGuiElementPos DrawElementPos(string label, InstantGuiElementPos pos) { int space = 5; int labelWidth = 60; Rect rect = GUILayoutUtility.GetRect(50, 18, "TextField"); rect.x += EditorGUI.indentLevel * indentPixels; rect.width -= EditorGUI.indentLevel * indentPixels; int originalWidth = (int)rect.width; int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; rect.width = labelWidth; EditorGUI.LabelField(rect, label); rect.width = (originalWidth - labelWidth) * 0.25f - space; rect.x += labelWidth + space; pos.left = EditorGUI.IntField(rect, pos.left); rect.x += rect.width + space; pos.right = EditorGUI.IntField(rect, pos.right); rect.x += rect.width + space; pos.top = EditorGUI.IntField(rect, pos.top); rect.x += rect.width + space; pos.bottom = EditorGUI.IntField(rect, pos.bottom); EditorGUI.indentLevel = indent; return(pos); }
//transforming relative pos to absolute static public InstantGuiElementPos GetRelativeAbsolute ( InstantGuiElementPos parent , InstantGuiElementPos relative ){ return new InstantGuiElementPos ( Mathf.RoundToInt(parent.left + ((parent.right-parent.left) * relative.left * 0.01f)), Mathf.RoundToInt(parent.left + ((parent.right-parent.left) * relative.right * 0.01f)), Mathf.RoundToInt(parent.top + ((parent.bottom-parent.top) * relative.top * 0.01f)), Mathf.RoundToInt(parent.top + ((parent.bottom-parent.top) * relative.bottom * 0.01f)) ); }
public void GetAbsolute ( InstantGuiElementPos parent , InstantGuiElementPos relative , InstantGuiElementPos offset ){ InstantGuiElementPos relativeAbsolute = GetRelativeAbsolute(parent, relative); left = relativeAbsolute.left + offset.left; right = relativeAbsolute.right + offset.right; top = relativeAbsolute.top + offset.top; bottom = relativeAbsolute.bottom + offset.bottom; }
//transforming relative pos to absolute static public InstantGuiElementPos GetRelativeAbsolute(InstantGuiElementPos parent, InstantGuiElementPos relative) { return(new InstantGuiElementPos( Mathf.RoundToInt(parent.left + ((parent.right - parent.left) * relative.left * 0.01f)), Mathf.RoundToInt(parent.left + ((parent.right - parent.left) * relative.right * 0.01f)), Mathf.RoundToInt(parent.top + ((parent.bottom - parent.top) * relative.top * 0.01f)), Mathf.RoundToInt(parent.top + ((parent.bottom - parent.top) * relative.bottom * 0.01f)))); }
public void GetAbsolute(InstantGuiElementPos parent, InstantGuiElementPos relative, InstantGuiElementPos offset) { InstantGuiElementPos relativeAbsolute = GetRelativeAbsolute(parent, relative); left = relativeAbsolute.left + offset.left; right = relativeAbsolute.right + offset.right; top = relativeAbsolute.top + offset.top; bottom = relativeAbsolute.bottom + offset.bottom; }
public void GetRelative ( InstantGuiElementPos parent , InstantGuiElementPos absolute , InstantGuiElementPos offset ){ InstantGuiElementPos relativeAbsolute = new InstantGuiElementPos(absolute); relativeAbsolute.Subtract(offset); left = ((relativeAbsolute.left-parent.left)/(parent.right-parent.left))*100; right = ((relativeAbsolute.right-parent.left)/(parent.right-parent.left))*100; top = ((relativeAbsolute.top-parent.top)/(parent.bottom-parent.top))*100; bottom = ((relativeAbsolute.bottom-parent.top)/(parent.bottom-parent.top))*100; }
public void GetOffset ( InstantGuiElementPos parent , InstantGuiElementPos relative , InstantGuiElementPos absolute ){ InstantGuiElementPos relativeAbsolute = GetRelativeAbsolute(parent, relative); left = absolute.left - relativeAbsolute.left; right = absolute.right - relativeAbsolute.right; top = absolute.top - relativeAbsolute.top; bottom = absolute.bottom - relativeAbsolute.bottom; //Subtract(relativeAbsolute); }
public void GetRelative(InstantGuiElementPos parent, InstantGuiElementPos absolute, InstantGuiElementPos offset) { InstantGuiElementPos relativeAbsolute = new InstantGuiElementPos(absolute); relativeAbsolute.Subtract(offset); left = ((relativeAbsolute.left - parent.left) / (parent.right - parent.left)) * 100; right = ((relativeAbsolute.right - parent.left) / (parent.right - parent.left)) * 100; top = ((relativeAbsolute.top - parent.top) / (parent.bottom - parent.top)) * 100; bottom = ((relativeAbsolute.bottom - parent.top) / (parent.bottom - parent.top)) * 100; }
public void GetOffset(InstantGuiElementPos parent, InstantGuiElementPos relative, InstantGuiElementPos absolute) { InstantGuiElementPos relativeAbsolute = GetRelativeAbsolute(parent, relative); left = absolute.left - relativeAbsolute.left; right = absolute.right - relativeAbsolute.right; top = absolute.top - relativeAbsolute.top; bottom = absolute.bottom - relativeAbsolute.bottom; //Subtract(relativeAbsolute); }
static public InstantGuiElementPos DrawElementPos ( string label , InstantGuiElementPos pos ) { int space = 5; int labelWidth = 60; Rect rect = GUILayoutUtility.GetRect (50, 18, "TextField"); rect.x+=EditorGUI.indentLevel*indentPixels; rect.width-=EditorGUI.indentLevel*indentPixels; int originalWidth= (int)rect.width; int indent= EditorGUI.indentLevel; EditorGUI.indentLevel = 0; rect.width = labelWidth; EditorGUI.LabelField(rect,label); rect.width = (originalWidth-labelWidth)*0.25f - space; rect.x += labelWidth+space; pos.left = EditorGUI.IntField(rect,pos.left); rect.x += rect.width+space; pos.right = EditorGUI.IntField(rect,pos.right); rect.x += rect.width+space; pos.top = EditorGUI.IntField(rect,pos.top); rect.x += rect.width+space; pos.bottom = EditorGUI.IntField(rect,pos.bottom); EditorGUI.indentLevel = indent; return pos; }
static public Vector2 ScreenPointToRelative(InstantGuiElementPos parent, Vector2 point) { return(new Vector2( (point.x - parent.left) / (parent.right - parent.left) * 100.0f, (point.y - parent.top) / (parent.bottom - parent.top) * 100.0f)); }
static public InstantGuiStyle DrawStyle (InstantGuiStyle style, bool drawDefaultPos) { int indent= EditorGUI.indentLevel; EditorGUI.indentLevel=1; //EditorGUILayout.HelpBox("Style settings are not available in demo version.", MessageType.Info); DrawSubStyle (style.main, "Main"); DrawSubStyle (style.pointed, "Pointed"); DrawSubStyle (style.active, "Active"); DrawSubStyle (style.disabled, "Disabled"); EditorGUILayout.Space(); //texture borders EditorGUIUtility.LookLikeControls(15, 15); EditorGUI.indentLevel=0; Rect rect = GUILayoutUtility.GetRect (50, 44, "TextField"); rect.x+=indent*indentPixels; rect.width-=indent*indentPixels; rect.x = 150; rect.width = 75; rect.height = 16; style.borders.top = EditorGUI.IntField(rect, "T:", style.borders.top); rect.y+=18; rect.x -=40; style.borders.left = EditorGUI.IntField(rect, "L:", style.borders.left); rect.x += 80; style.borders.right = EditorGUI.IntField(rect, "R:", style.borders.right); rect.y+=18; rect.x -=40; style.borders.bottom = EditorGUI.IntField(rect, "B:", style.borders.bottom); rect.x -=120; rect.y-=36; EditorGUI.LabelField(rect,"Texture"); rect.y+=18; EditorGUI.LabelField(rect,"Borders:"); rect.y+=18; rect.x=32; rect.width = 60; if (GUI.Button(rect,"Half Size")) { Texture tex = GetUsedtexture(style); if (tex!=null) { style.borders.top = (int)(tex.height*0.5f); style.borders.bottom = (int)(tex.height*0.5f); style.borders.left = (int)(tex.width*0.5f); style.borders.right = (int)(tex.width*0.5f); } } GUILayoutUtility.GetRect (50, 18, "TextField"); EditorGUIUtility.LookLikeControls(); //fixed width rect = GUILayoutUtility.GetRect (50, 18, "TextField"); rect.x+=(indent+1)*indentPixels; rect.width-=(indent+1)*indentPixels; EditorGUI.indentLevel = 0; int rectwidth= (int)rect.width; rect.width = 30; style.fixedWidth = EditorGUI.Toggle(rect,style.fixedWidth); rect.x+=20; rect.width = rectwidth -45-30; style.fixedWidthSize = EditorGUI.IntField(rect, "Fixed Width:", style.fixedWidthSize); rect.x += rect.width+5; rect.width = 50; if (GUI.Button(rect, "Get")) { Texture tex = GetUsedtexture(style); if (tex!=null) style.fixedWidthSize = tex.width; } EditorGUI.indentLevel = 1; //fixed height rect = GUILayoutUtility.GetRect (50, 18, "TextField"); rect.x+=(indent+1)*indentPixels; rect.width-=(indent+1)*indentPixels; EditorGUI.indentLevel = 0; rectwidth = (int)rect.width; rect.width = 30; style.fixedHeight = EditorGUI.Toggle(rect,style.fixedHeight); rect.x+=20; rect.width = rectwidth -45-30; style.fixedHeightSize = EditorGUI.IntField(rect, "Fixed Height:", style.fixedHeightSize); rect.x += rect.width+5; rect.width = 50; if (GUI.Button(rect, "Get")) { Texture tex = GetUsedtexture(style); if (tex!=null) style.fixedHeightSize = tex.height; } EditorGUI.indentLevel = 1; //proportional rect = GUILayoutUtility.GetRect (50, 18, "TextField"); rect.x+=(indent)*indentPixels; rect.width-=(indent)*indentPixels; rect.width -= 100; style.proportional = EditorGUI.ToggleLeft(rect, "Proportional", style.proportional); rect.x += 100; style.proportionalAspect = EditorGUI.FloatField(rect, style.proportionalAspect); //pointOffset InstantGuiElementPos tmp = new InstantGuiElementPos(style.pointOffset.left, style.pointOffset.right, style.pointOffset.top, style.pointOffset.bottom); tmp = InstantGuiInspector.DrawElementPos("ClickOffset:", tmp); style.pointOffset = new RectOffset(tmp.left, tmp.right, tmp.top, tmp.bottom); //other controls style.blendSpeed = EditorGUILayout.FloatField("Blend Speed:", style.blendSpeed); EditorGUILayout.Space(); style.font = (Font)EditorGUILayout.ObjectField("Font:", style.font, typeof(Font), false); style.fontSize = EditorGUILayout.IntField("Font Size:", style.fontSize); style.textAligment = (InstantGuiTextAligment)EditorGUILayout.EnumPopup("Text Aligment:", style.textAligment); Vector2 textOffset = DrawVector2("Text Offset", new Vector2(style.textOffsetX, style.textOffsetY)); style.textOffsetX = (int)(textOffset.x); style.textOffsetY = (int)(textOffset.y); EditorGUILayout.Space(); //text offset if (drawDefaultPos) { EditorGUILayout.LabelField("Default Placement:"); InstantGuiInspector.DrawElementPosLabels("", "Left", "Right", "Top", "Bottom"); style.relative = InstantGuiInspector.DrawElementPos("Relative:", style.relative); style.offset = InstantGuiInspector.DrawElementPos("Offset:", style.offset); style.layerOffset = DrawLayerOffset("Layer Offset:", style.layerOffset); } EditorGUILayout.Space(); EditorGUI.indentLevel = indent; return style; }
public override void Action() { base.Action(); //moving if (movable) { if (pointed && Input.GetMouseButtonDown(0)) { dragging = true; sizeX = absolute.right - absolute.left; sizeY = absolute.bottom - absolute.top; dragOffset = new Vector2( offset.left - Input.mousePosition.x, offset.top - InstantGui.Invert(Input.mousePosition.y)); //negative, in common } if (Input.GetMouseButtonUp(0)) { dragging = false; } if (dragging) { offset.left = (int)(Input.mousePosition.x + dragOffset.x); offset.top = (int)(InstantGui.Invert(Input.mousePosition.y) + dragOffset.y); absolute.GetAbsolute(parentpos, relative, offset); //limiting window movement if (scape == InstantGuiWindowScape.screen) { absolute.left = Mathf.Max(absolute.left, 0); absolute.top = Mathf.Max(absolute.top, 0); if (absolute.left > UnityEngine.Screen.width - sizeX) { absolute.left = UnityEngine.Screen.width - sizeX; } if (absolute.top > UnityEngine.Screen.height - sizeY) { absolute.top = UnityEngine.Screen.height - sizeY; } } if (scape == InstantGuiWindowScape.parent) { absolute.left = Mathf.Max(absolute.left, parentpos.left); absolute.top = Mathf.Max(absolute.top, parentpos.top); if (absolute.left > parentpos.right - sizeX) { absolute.left = parentpos.right - sizeX; } if (absolute.top > parentpos.bottom - sizeY) { absolute.top = parentpos.bottom - sizeY; } } offset.GetOffset(parentpos, relative, new InstantGuiElementPos(absolute.left, absolute.left + sizeX, absolute.top, absolute.top + sizeY)); } } //closing if (closeButton != null && closeButton.activated) { gameObject.SetActive(false); } //expanding if (expandButton != null) { if (expandButton.activated && expandButton.check) { nonMaximizedRelative = new InstantGuiElementPos(relative); nonMaximizedOffset = new InstantGuiElementPos(offset); if (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off) { relative = new InstantGuiElementPos(0, 0, 0, 0); offset = new InstantGuiElementPos(0, UnityEngine.Screen.width, 0, UnityEngine.Screen.height); } if (scape == InstantGuiWindowScape.parent) { relative = new InstantGuiElementPos(0, 100, 0, 100); offset = new InstantGuiElementPos(0, 0, 0, 0); } } if (expandButton.activated && !expandButton.check) { relative = nonMaximizedRelative; offset = nonMaximizedOffset; } //re-calc offset on resolution change if (expandButton.check && (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off)) { offset = new InstantGuiElementPos(0, UnityEngine.Screen.width, 0, UnityEngine.Screen.height); } } }
public virtual void Align () { if (!this) return; //element could be deleted to this time! //assigning vars if they do not exist if (guiTexts == null) guiTexts = new GUIText[0]; //using style position if (styleSet!=null && useStylePlacement) { //if (style==null) style = styleSet.FindStyle(styleName, styleNum); if (style!=null) { relative.Set(style.relative); offset.Set(style.offset); } } else { if (relative.isStyle) relative = new InstantGuiElementPos(relative); if (offset.isStyle) offset = new InstantGuiElementPos(offset); } //setting layer Transform parentTfm= transform.parent; if (parentTfm != null) { Vector3 localPos = parentTfm.localPosition; localPos.z += layerOffset; transform.localPosition = localPos;} //refreshing parent absolute pos InstantGuiElement parentElement = null; if (parentTfm!=null) parentElement = parentTfm.GetComponent<InstantGuiElement>(); if (parentElement!=null) parentpos = parentElement.absolute; else //parentpos = InstantGuiElementPos(0,Screen.width,0,Screen.height); { if (InstantGui.instance == null) InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); parentpos = new InstantGuiElementPos(0,InstantGui.width,0,InstantGui.height); } //checking if there is a need to re-allign if (!InstantGuiElementPos.Equals(parentpos, oldParentpos) || !InstantGuiElementPos.Equals(relative, oldRelative) || !InstantGuiElementPos.Equals(offset, oldOffset) || InstantGui.oldScreenWidth != Screen.width || InstantGui.oldScreenHeight != Screen.height || true) { //transforming relative pos to absolute //if (!absolute || !parentpos || !relative || !offset) return; absolute.GetAbsolute(parentpos, relative, offset); //setting fixed size (if on) if (style!=null) { if (style.fixedWidth) absolute.right = absolute.left+style.fixedWidthSize; if (style.fixedHeight) absolute.bottom = absolute.top+style.fixedHeightSize; } //preventing negative size int minWidth = 10; int minHeight = 10; if (style!=null) { minWidth = style.borders.left + style.borders.right; minHeight = style.borders.bottom + style.borders.top; } if (absolute.right < absolute.left+minWidth) absolute.right = absolute.left+minWidth; if (absolute.bottom < absolute.top+minHeight) absolute.bottom = absolute.top+minHeight; //writing compare-data oldParentpos = new InstantGuiElementPos(parentpos); oldRelative = new InstantGuiElementPos(relative); oldOffset = new InstantGuiElementPos(offset); } //recursive for (int i=0; i<childElements.Count; i++) childElements[i].Align(); }
public void Set(InstantGuiElementPos s) { left = s.left; right = s.right; top = s.top; bottom = s.bottom; }
static public Vector2 ScreenPointToRelative ( InstantGuiElementPos parent , Vector2 point ){ return new Vector2 ( (point.x-parent.left)/(parent.right-parent.left)*100.0f, (point.y-parent.top)/(parent.bottom-parent.top)*100.0f ); }
public void Set ( InstantGuiElementPos s ){ left=s.left; right=s.right; top=s.top; bottom=s.bottom; }
static public bool Equals(InstantGuiElementPos e1, InstantGuiElementPos e2) { return(e1.left == e2.left && e1.right == e2.right && e1.top == e2.top && e1.bottom == e2.bottom); }
public override void Action() { //if (initialText != text) text = initialText; //assigning text when it changed from somewhere else base.Action(); if (activated) { check = true; initialText = text; cursorBlinkTimeLeft = cursorBlinkTime; } //if clicked esc - returning text if (Input.GetKey(KeyCode.Escape)) { check = false; text = initialText; } //if clicked somewhere else if (Input.GetMouseButtonDown(0) && !activated) { if (confirmOnEnterOnly) { check = false; text = initialText; } else { check = false; initialText = text; } } //if (alwaysTyping) check = true; if (check) { //input text foreach (char c in Input.inputString) { //backspace if (c == "\b"[0]) { if (text.Length != 0 && cursorPos != 0) //no &&: if only "\b"[0] than add nothing to text { cursorPos--; text = text.Remove(cursorPos, 1); } } //end of entry else if (c == "\n"[0] || c == "\r"[0]) { check = false; initialText = text; break; } //normal text input else { text = text.Insert(cursorPos, c.ToString()); // += c; cursorPos++; } } if (Input.GetKeyDown(KeyCode.Delete) && text.Length != 0 && cursorPos != text.Length) { text = text.Remove(cursorPos, 1); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { cursorPos = Mathf.Max(cursorPos - 1, 0); } if (Input.GetKeyDown(KeyCode.RightArrow)) { cursorPos = Mathf.Min(cursorPos + 1, text.Length); } #if UNITY_EDITOR if ((Input.GetKeyDown(KeyCode.V) || Input.GetKeyDown(KeyCode.G)) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { text += UnityEditor.EditorGUIUtility.systemCopyBuffer; } #endif //set cursor appearance if (cursor != null) { if (cursorBlinkTimeLeft > 0) { if (!cursor.enabled) { cursor.enabled = true; } } else { if (cursor.enabled) { cursor.enabled = false; } } if (cursorBlinkTimeLeft < -cursorBlinkTime) { cursorBlinkTimeLeft = cursorBlinkTime; } cursorBlinkTimeLeft -= Time.deltaTime; } //setting cursor by mouse if (check && pressed) { FindCursorPos((int)Input.mousePosition.x); } //setting a cursor texture on any change if (activated || text != oldText || cursorPos != oldCursorPos || !InstantGuiElementPos.Equals(absolute, oldAbsolute)) { DrawCursor(); } oldAbsolute.Set(absolute); oldText = text; oldCursorPos = cursorPos; } if (!check && cursor != null && cursor.enabled) { cursor.enabled = false; } }
static public void EditFrame(InstantGuiElement element) { Undo.RecordObject(element, "InstantGui Move"); //getting mouse pos Vector2 mousePos = Event.current.mousePosition; mousePos.y = InstantGui.Invert(mousePos.y); //shift-aligning if (Event.current.shift) { if (Mathf.Abs(mousePos.x - dragStart.x) < Mathf.Abs(mousePos.y - dragStart.y)) { mousePos.x = dragStart.x; } else { mousePos.y = dragStart.y; } } //getting mouse button bool mouseDown = false; bool mouseUp = false; if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { mouseDown = true; dragStart = mousePos; } if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { mouseUp = true; } //selecting locked element if (lockedElement != null) { //element = lockedElement; //Selection.activeGameObject = lockedElement.gameObject; } //duplicating element if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "Duplicate") { GameObject newElement = (GameObject)GameObject.Instantiate(element.gameObject); newElement.name = element.gameObject.name; if (element.transform.parent != null) { newElement.transform.parent = element.transform.parent; } newElement.transform.localPosition = element.transform.localPosition; newElement.transform.localRotation = element.transform.localRotation; newElement.transform.localScale = element.transform.localScale; Selection.activeGameObject = newElement; element = newElement.GetComponent <InstantGuiElement>(); } //key events if (Event.current.type == EventType.keyDown) { //Undo.RegisterUndo(element, "Move PureGUI"); //locking element if (Event.current.keyCode == KeyCode.L) { if (!lockedElement) { lockedElement = element; } else { lockedElement = null; } } //hiding frame if (Event.current.keyCode == KeyCode.H) { drawFrames = !drawFrames; } //moving with keys if (Event.current.keyCode == KeyCode.UpArrow) { element.offset.top--; element.offset.bottom--; } if (Event.current.keyCode == KeyCode.DownArrow) { element.offset.top++; element.offset.bottom++; } if (Event.current.keyCode == KeyCode.LeftArrow) { element.offset.left--; element.offset.right--; } if (Event.current.keyCode == KeyCode.RightArrow) { element.offset.left++; element.offset.right++; } } Rect rect = new Rect(0, 0, frameSize, frameSize); Rect textRect = new Rect(0, 0, 40, 20); //getting if any of dimension is fixed bool fixedWidth = false; bool fixedHeight = false; if (element.style != null) { if (element.style.fixedWidth) { fixedWidth = true; } if (element.style.fixedHeight) { fixedHeight = true; } } if (mouseDown) { nonGridOffset.left = element.offset.left; nonGridOffset.right = element.offset.right; nonGridOffset.top = element.offset.top; nonGridOffset.bottom = element.offset.bottom; nonGridRelative.left = element.relative.left; nonGridRelative.right = element.relative.right; nonGridRelative.top = element.relative.top; nonGridRelative.bottom = element.relative.bottom; } if (mouseUp || mouseDown) { dragging = 0; } //storing borders to assign comfortable int left = element.absolute.left; int right = element.absolute.right; int top = element.absolute.top; int bottom = element.absolute.bottom; //relative left rect.width = frameSize * 1.5f; rect.height = frameSize; rect.x = left - element.offset.left - rect.width * 0.5f; rect.y = element.absolute.GetCenter().y - rect.height * 0.5f; textRect.x = rect.x; textRect.y = rect.y + 16; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 1; } if (dragging == 1) { nonGridRelative.left = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).x); if (Event.current.control) { element.relative.left = (Mathf.RoundToInt(nonGridRelative.left * 0.2f)) * 5; } else { element.relative.left = nonGridRelative.left; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } //relative right if (!fixedWidth) { rect.x = right - element.offset.right - rect.width * 0.5f; rect.y = element.absolute.GetCenter().y - rect.height * 0.5f; textRect.x = rect.x; textRect.y = rect.y - 20; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 2; } if (dragging == 2) { nonGridRelative.right = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).x); if (Event.current.control) { element.relative.right = (Mathf.RoundToInt(nonGridRelative.right * 0.2f)) * 5; } else { element.relative.right = nonGridRelative.right; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } } else { element.relative.right = element.relative.left; } //relative top rect.width = frameSize; rect.height = frameSize * 1.5f; rect.x = element.absolute.GetCenter().x - rect.width * 0.5f; rect.y = top - element.offset.top - rect.height * 0.5f; textRect.x = rect.x + 20; textRect.y = rect.y - 2; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 3; } if (dragging == 3) { nonGridRelative.top = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).y); if (Event.current.control) { element.relative.top = (Mathf.RoundToInt(nonGridRelative.top * 0.2f)) * 5; } else { element.relative.top = nonGridRelative.top; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } //relative bottom if (!fixedHeight) { rect.x = element.absolute.GetCenter().x - rect.width * 0.5f; rect.y = bottom - element.offset.bottom - rect.height * 0.5f; textRect.x = rect.x - 30; textRect.y = rect.y - 2; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 4; } if (dragging == 4) { nonGridRelative.bottom = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).y); if (Event.current.control) { element.relative.bottom = (Mathf.RoundToInt(nonGridRelative.bottom * 0.2f)) * 5; } else { element.relative.bottom = nonGridRelative.bottom; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } } else { element.relative.bottom = element.relative.top; } rect = new Rect(0, 0, frameSize, frameSize); if (!fixedWidth || !fixedHeight) { //left-top rect.x = element.absolute.left - frameSize * 0.5f; rect.y = element.absolute.top - frameSize * 0.5f; textRect.x = rect.x - 25; textRect.y = (top + bottom) * 0.5f + (top - bottom) * 0.25f; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 5; } if (dragging == 5) { element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } } //left-bottom rect.x = element.absolute.left - frameSize * 0.5f; rect.y = element.absolute.bottom - frameSize * 0.5f; textRect.x = (left + right) * 0.5f + (right - left) * 0.25f; textRect.y = rect.y + 10; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 6; } if (dragging == 6) { element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.bottom = (int)(nonGridOffset.bottom + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.bottom = Mathf.RoundToInt(element.offset.bottom * 0.1f) * 10; } } //right-top rect.x = element.absolute.right - frameSize * 0.5f; rect.y = element.absolute.top - frameSize * 0.5f; textRect.x = (left + right) * 0.5f + (left - right) * 0.25f; textRect.y = rect.y - 13; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 7; } if (dragging == 7) { element.offset.right = (int)(nonGridOffset.right + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.right = Mathf.RoundToInt(element.offset.right * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } } //right-bottom rect.x = element.absolute.right - frameSize * 0.5f; rect.y = element.absolute.bottom - frameSize * 0.5f; textRect.x = rect.x + 15; textRect.y = (top + bottom) * 0.5f + (bottom - top) * 0.25f; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 8; } if (dragging == 8) { element.offset.right = (int)(nonGridOffset.right + (mousePos.x - dragStart.x)); element.offset.bottom = (int)(nonGridOffset.bottom + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.right = Mathf.RoundToInt(element.offset.right * 0.1f) * 10; element.offset.bottom = Mathf.RoundToInt(element.offset.bottom * 0.1f) * 10; } } } //aligning if (!InstantGui.instance) { InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); } if (!EditorApplication.isPlaying) { //InstantGui.instance.Update(); //InstantGui.instance.element.Point(mousePos); InstantGui.width = Screen.width; InstantGui.height = Screen.height; InstantGui.instance.element = InstantGui.instance.GetComponent <InstantGuiElement>(); InstantGui.pointed = null; InstantGui.instance.element.GetChildren(); InstantGui.instance.element.Align(); //element.PreventZeroSize(true); InstantGui.instance.element.Point(true); InstantGui.instance.element.Action(); InstantGui.instance.element.ApplyStyle(); } //moving selected element (or setting fixed) rect = element.absolute.ToRect(); if (InstantGui.pointed == element && mouseDown && dragging == 0 && !Event.current.alt && !element.lockPosition && !selectionChanged) { dragging = 9; } if (dragging == 9) { //Undo.RecordObject(element, "InstantGui Move"); int sizeX = element.absolute.right - element.absolute.left; int sizeY = element.absolute.bottom - element.absolute.top; element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } element.absolute.GetAbsolute(element.parentpos, element.relative, element.offset); element.offset.GetOffset(element.parentpos, element.relative, new InstantGuiElementPos(element.absolute.left, element.absolute.left + sizeX, element.absolute.top, element.absolute.top + sizeY)); } //selecting other objs if (mouseDown && dragging == 0 && InstantGui.pointed != element && InstantGui.pointed != null && !lockedElement && !Event.current.alt) { Selection.activeGameObject = InstantGui.pointed.gameObject; element = InstantGui.pointed; nonGridOffset.left = element.offset.left; nonGridOffset.right = element.offset.right; nonGridOffset.top = element.offset.top; nonGridOffset.bottom = element.offset.bottom; nonGridRelative.left = element.relative.left; nonGridRelative.right = element.relative.right; nonGridRelative.top = element.relative.top; nonGridRelative.bottom = element.relative.bottom; selectionChanged = true; } else if (selectionChanged) { selectionChanged = false; } }
public void Add ( InstantGuiElementPos e ){ left += e.left; right += e.right; top += e.top; bottom += e.bottom; }
static public bool Equals ( InstantGuiElementPos e1 , InstantGuiElementPos e2 ){ return (e1.left==e2.left && e1.right==e2.right && e1.top==e2.top && e1.bottom==e2.bottom); }
static public InstantGuiStyle DrawStyle(InstantGuiStyle style, bool drawDefaultPos) { int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 1; //EditorGUILayout.HelpBox("Style settings are not available in demo version.", MessageType.Info); DrawSubStyle(style.main, "Main"); DrawSubStyle(style.pointed, "Pointed"); DrawSubStyle(style.active, "Active"); DrawSubStyle(style.disabled, "Disabled"); EditorGUILayout.Space(); //texture borders EditorGUIUtility.LookLikeControls(15, 15); EditorGUI.indentLevel = 0; Rect rect = GUILayoutUtility.GetRect(50, 44, "TextField"); rect.x += indent * indentPixels; rect.width -= indent * indentPixels; rect.x = 150; rect.width = 75; rect.height = 16; style.borders.top = EditorGUI.IntField(rect, "T:", style.borders.top); rect.y += 18; rect.x -= 40; style.borders.left = EditorGUI.IntField(rect, "L:", style.borders.left); rect.x += 80; style.borders.right = EditorGUI.IntField(rect, "R:", style.borders.right); rect.y += 18; rect.x -= 40; style.borders.bottom = EditorGUI.IntField(rect, "B:", style.borders.bottom); rect.x -= 120; rect.y -= 36; EditorGUI.LabelField(rect, "Texture"); rect.y += 18; EditorGUI.LabelField(rect, "Borders:"); rect.y += 18; rect.x = 32; rect.width = 60; if (GUI.Button(rect, "Half Size")) { Texture tex = GetUsedtexture(style); if (tex != null) { style.borders.top = (int)(tex.height * 0.5f); style.borders.bottom = (int)(tex.height * 0.5f); style.borders.left = (int)(tex.width * 0.5f); style.borders.right = (int)(tex.width * 0.5f); } } GUILayoutUtility.GetRect(50, 18, "TextField"); EditorGUIUtility.LookLikeControls(); //fixed width rect = GUILayoutUtility.GetRect(50, 18, "TextField"); rect.x += (indent + 1) * indentPixels; rect.width -= (indent + 1) * indentPixels; EditorGUI.indentLevel = 0; int rectwidth = (int)rect.width; rect.width = 30; style.fixedWidth = EditorGUI.Toggle(rect, style.fixedWidth); rect.x += 20; rect.width = rectwidth - 45 - 30; style.fixedWidthSize = EditorGUI.IntField(rect, "Fixed Width:", style.fixedWidthSize); rect.x += rect.width + 5; rect.width = 50; if (GUI.Button(rect, "Get")) { Texture tex = GetUsedtexture(style); if (tex != null) { style.fixedWidthSize = tex.width; } } EditorGUI.indentLevel = 1; //fixed height rect = GUILayoutUtility.GetRect(50, 18, "TextField"); rect.x += (indent + 1) * indentPixels; rect.width -= (indent + 1) * indentPixels; EditorGUI.indentLevel = 0; rectwidth = (int)rect.width; rect.width = 30; style.fixedHeight = EditorGUI.Toggle(rect, style.fixedHeight); rect.x += 20; rect.width = rectwidth - 45 - 30; style.fixedHeightSize = EditorGUI.IntField(rect, "Fixed Height:", style.fixedHeightSize); rect.x += rect.width + 5; rect.width = 50; if (GUI.Button(rect, "Get")) { Texture tex = GetUsedtexture(style); if (tex != null) { style.fixedHeightSize = tex.height; } } EditorGUI.indentLevel = 1; //proportional rect = GUILayoutUtility.GetRect(50, 18, "TextField"); rect.x += (indent) * indentPixels; rect.width -= (indent) * indentPixels; rect.width -= 100; style.proportional = EditorGUI.ToggleLeft(rect, "Proportional", style.proportional); rect.x += 100; style.proportionalAspect = EditorGUI.FloatField(rect, style.proportionalAspect); //pointOffset InstantGuiElementPos tmp = new InstantGuiElementPos(style.pointOffset.left, style.pointOffset.right, style.pointOffset.top, style.pointOffset.bottom); tmp = InstantGuiInspector.DrawElementPos("ClickOffset:", tmp); style.pointOffset = new RectOffset(tmp.left, tmp.right, tmp.top, tmp.bottom); //other controls style.blendSpeed = EditorGUILayout.FloatField("Blend Speed:", style.blendSpeed); EditorGUILayout.Space(); style.font = (Font)EditorGUILayout.ObjectField("Font:", style.font, typeof(Font), false); style.fontSize = EditorGUILayout.IntField("Font Size:", style.fontSize); style.textAligment = (InstantGuiTextAligment)EditorGUILayout.EnumPopup("Text Aligment:", style.textAligment); Vector2 textOffset = DrawVector2("Text Offset", new Vector2(style.textOffsetX, style.textOffsetY)); style.textOffsetX = (int)(textOffset.x); style.textOffsetY = (int)(textOffset.y); EditorGUILayout.Space(); //text offset if (drawDefaultPos) { EditorGUILayout.LabelField("Default Placement:"); InstantGuiInspector.DrawElementPosLabels("", "Left", "Right", "Top", "Bottom"); style.relative = InstantGuiInspector.DrawElementPos("Relative:", style.relative); style.offset = InstantGuiInspector.DrawElementPos("Offset:", style.offset); style.layerOffset = DrawLayerOffset("Layer Offset:", style.layerOffset); } EditorGUILayout.Space(); EditorGUI.indentLevel = indent; return(style); }
public void Subtract ( InstantGuiElementPos e2 ){ left -= e2.left; right -= e2.right; top -= e2.top; bottom -= e2.bottom; }
public virtual void Align() { if (!this) { return; //element could be deleted to this time! } //assigning vars if they do not exist if (guiTexts == null) { guiTexts = new GUIText[0]; } //using style position if (styleSet != null && useStylePlacement) { //if (style==null) style = styleSet.FindStyle(styleName, styleNum); if (style != null) { relative.Set(style.relative); offset.Set(style.offset); } } else { if (relative.isStyle) { relative = new InstantGuiElementPos(relative); } if (offset.isStyle) { offset = new InstantGuiElementPos(offset); } } //setting layer Transform parentTfm = transform.parent; if (parentTfm != null) { Vector3 localPos = parentTfm.localPosition; localPos.z += layerOffset; transform.localPosition = localPos; } //refreshing parent absolute pos InstantGuiElement parentElement = null; if (parentTfm != null) { parentElement = parentTfm.GetComponent <InstantGuiElement>(); } if (parentElement != null) { parentpos = parentElement.absolute; } else //parentpos = InstantGuiElementPos(0,Screen.width,0,Screen.height); { if (InstantGui.instance == null) { InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); } parentpos = new InstantGuiElementPos(0, InstantGui.width, 0, InstantGui.height); } //checking if there is a need to re-allign if (!InstantGuiElementPos.Equals(parentpos, oldParentpos) || !InstantGuiElementPos.Equals(relative, oldRelative) || !InstantGuiElementPos.Equals(offset, oldOffset) || InstantGui.oldScreenWidth != UnityEngine.Screen.width || InstantGui.oldScreenHeight != UnityEngine.Screen.height || true) { //transforming relative pos to absolute //if (!absolute || !parentpos || !relative || !offset) return; absolute.GetAbsolute(parentpos, relative, offset); //setting fixed size (if on) if (style != null) { if (style.fixedWidth) { absolute.right = absolute.left + style.fixedWidthSize; } if (style.fixedHeight) { absolute.bottom = absolute.top + style.fixedHeightSize; } } //preventing negative size int minWidth = 10; int minHeight = 10; if (style != null) { minWidth = style.borders.left + style.borders.right; minHeight = style.borders.bottom + style.borders.top; } if (absolute.right < absolute.left + minWidth) { absolute.right = absolute.left + minWidth; } if (absolute.bottom < absolute.top + minHeight) { absolute.bottom = absolute.top + minHeight; } //writing compare-data oldParentpos = new InstantGuiElementPos(parentpos); oldRelative = new InstantGuiElementPos(relative); oldOffset = new InstantGuiElementPos(offset); } //recursive for (int i = 0; i < childElements.Count; i++) { childElements[i].Align(); } }
public override void Action () { base.Action(); //moving if (movable) { if (pointed && Input.GetMouseButtonDown(0)) { dragging = true; sizeX = absolute.right-absolute.left; sizeY = absolute.bottom-absolute.top; dragOffset = new Vector2( offset.left-Input.mousePosition.x, offset.top-InstantGui.Invert(Input.mousePosition.y) ); //negative, in common } if (Input.GetMouseButtonUp(0)) dragging = false; if (dragging) { offset.left = (int)(Input.mousePosition.x + dragOffset.x); offset.top = (int)(InstantGui.Invert(Input.mousePosition.y) + dragOffset.y); absolute.GetAbsolute (parentpos, relative, offset); //limiting window movement if (scape == InstantGuiWindowScape.screen) { absolute.left = Mathf.Max(absolute.left, 0); absolute.top = Mathf.Max(absolute.top, 0); if (absolute.left > Screen.width - sizeX) absolute.left = Screen.width - sizeX; if (absolute.top > Screen.height - sizeY) absolute.top = Screen.height - sizeY; } if (scape == InstantGuiWindowScape.parent) { absolute.left = Mathf.Max(absolute.left, parentpos.left); absolute.top = Mathf.Max(absolute.top, parentpos.top); if (absolute.left > parentpos.right - sizeX) absolute.left = parentpos.right - sizeX; if (absolute.top > parentpos.bottom - sizeY) absolute.top = parentpos.bottom - sizeY; } offset.GetOffset(parentpos, relative, new InstantGuiElementPos(absolute.left, absolute.left + sizeX, absolute.top, absolute.top + sizeY)); } } //closing if (closeButton!=null && closeButton.activated) gameObject.SetActive(false); //expanding if (expandButton!=null) { if (expandButton.activated && expandButton.check) { nonMaximizedRelative = new InstantGuiElementPos(relative); nonMaximizedOffset = new InstantGuiElementPos(offset); if (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off) { relative = new InstantGuiElementPos(0, 0, 0, 0); offset = new InstantGuiElementPos(0, Screen.width, 0, Screen.height); } if (scape == InstantGuiWindowScape.parent) { relative = new InstantGuiElementPos(0, 100, 0, 100); offset = new InstantGuiElementPos(0, 0, 0, 0); } } if (expandButton.activated && !expandButton.check) { relative = nonMaximizedRelative; offset = nonMaximizedOffset; } //re-calc offset on resolution change if (expandButton.check && (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off)) offset = new InstantGuiElementPos(0, Screen.width, 0, Screen.height); } }