internal static Vector2 PointSlider(Vector2 pos, MouseCursor cursor, GUIStyle dragDot, GUIStyle dragDotActive) { int controlId = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard); Vector2 vector2 = (Vector2)Handles.matrix.MultiplyPoint((Vector3)pos); Rect rect = new Rect(vector2.x - dragDot.fixedWidth * 0.5f, vector2.y - dragDot.fixedHeight * 0.5f, dragDot.fixedWidth, dragDot.fixedHeight); if (Event.current.GetTypeForControl(controlId) == EventType.Repaint) { if (GUIUtility.hotControl == controlId) { dragDotActive.Draw(rect, GUIContent.none, controlId); } else { dragDot.Draw(rect, GUIContent.none, controlId); } } return(SpriteEditorHandles.ScaleSlider(pos, cursor, rect)); }
internal static Vector2 ScaleSlider(Vector2 pos, MouseCursor cursor, Rect cursorRect) { int controlID = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard); return(SpriteEditorHandles.ScaleSlider(controlID, pos, cursor, cursorRect)); }
internal static Rect RectCreator(float textureWidth, float textureHeight, GUIStyle rectStyle) { Event current = Event.current; Vector2 mousePosition = current.mousePosition; int num = SpriteEditorHandles.s_RectSelectionID; Rect result = default(Rect); switch (current.GetTypeForControl(num)) { case EventType.MouseDown: if (current.button == 0) { GUIUtility.hotControl = num; Rect rect = new Rect(0f, 0f, textureWidth, textureHeight); Vector2 v = Handles.s_InverseMatrix.MultiplyPoint(mousePosition); v.x = Mathf.Min(Mathf.Max(v.x, rect.xMin), rect.xMax); v.y = Mathf.Min(Mathf.Max(v.y, rect.yMin), rect.yMax); SpriteEditorHandles.s_DragStartScreenPosition = Handles.s_Matrix.MultiplyPoint(v); SpriteEditorHandles.s_CurrentMousePosition = mousePosition; current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == num && current.button == 0) { if (SpriteEditorHandles.ValidRect(SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition)) { result = SpriteEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition); GUI.changed = true; current.Use(); } GUIUtility.hotControl = 0; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == num) { SpriteEditorHandles.s_CurrentMousePosition = new Vector2(mousePosition.x, mousePosition.y); current.Use(); } break; case EventType.KeyDown: if (GUIUtility.hotControl == num && current.keyCode == KeyCode.Escape) { GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); } break; case EventType.Repaint: if (GUIUtility.hotControl == num && SpriteEditorHandles.ValidRect(SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition)) { SpriteEditorUtility.BeginLines(Color.green * 1.5f); SpriteEditorUtility.DrawBox(SpriteEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition)); SpriteEditorUtility.EndLines(); } break; } return(result); }
internal static Rect SliderRect(Rect pos) { int controlID = GUIUtility.GetControlID("SliderRect".GetHashCode(), FocusType.Keyboard); Event current = Event.current; if (SpriteEditorWindow.s_OneClickDragStarted && current.type == EventType.Repaint) { SpriteEditorHandles.HandleSliderRectMouseDown(controlID, current, pos); SpriteEditorWindow.s_OneClickDragStarted = false; } switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: if (current.button == 0 && pos.Contains(Handles.s_InverseMatrix.MultiplyPoint(Event.current.mousePosition)) && !current.alt) { SpriteEditorHandles.HandleSliderRectMouseDown(controlID, current, pos); current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID) { SpriteEditorHandles.s_CurrentMousePosition += current.delta; Vector2 center = pos.center; pos.center = Handles.s_InverseMatrix.MultiplyPoint(SpriteEditorHandles.s_CurrentMousePosition - SpriteEditorHandles.s_DragScreenOffset); if (!Mathf.Approximately((center - pos.center).magnitude, 0f)) { GUI.changed = true; } current.Use(); } break; case EventType.KeyDown: if (GUIUtility.hotControl == controlID && current.keyCode == KeyCode.Escape) { pos.center = Handles.s_InverseMatrix.MultiplyPoint(SpriteEditorHandles.s_DragStartScreenPosition - SpriteEditorHandles.s_DragScreenOffset); GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); } break; case EventType.Repaint: { Vector2 vector = Handles.s_InverseMatrix.MultiplyPoint(new Vector2(pos.xMin, pos.yMin)); Vector2 vector2 = Handles.s_InverseMatrix.MultiplyPoint(new Vector2(pos.xMax, pos.yMax)); EditorGUIUtility.AddCursorRect(new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y), MouseCursor.Arrow, controlID); break; } } return(pos); }
internal static Rect RectCreator(float textureWidth, float textureHeight, GUIStyle rectStyle) { return(SpriteEditorHandles.RectCreator(new Rect(0f, 0f, textureWidth, textureHeight), rectStyle)); }