public void OpenGuidePopup() { IconCanvasGuidePopup guidePopup = new IconCanvasGuidePopup(); guidePopup.Callback += (float val, IconCanvasGuideType type) => { IconCanvasGuide.AddGuide(val, type); }; PopupWindow.Show(new Rect(rulerSize + 5f, toolbarHeight + rulerSize + 5f, 0, 0), guidePopup); }
void OnEnable() { wantsMouseMove = true; wantsMouseEnterLeaveWindow = true; Prefs.DrawRulers.valueChanged.AddListener(Repaint); if (!canvas) { canvas = CreateInstance(typeof(IconCanvas)) as IconCanvas; canvas.Size.valueChanged.AddListener(Repaint); } canvas.Reset(); IconCanvasGuide.ClearAllGuides(); }
public void MouseDrag(Event e) { if (e.button == 0 && dragging) { localPosition = IconSetWindow.Instance.canvas.GetLocalMousePositionOnGrid(); localPosition = IconCanvasGuide.GetSnappedLocation(this); if (e.control) { localPosition = new Vector2(Handles.SnapValue(localPosition.x, 1f / IconSetWindow.Instance.canvas.cells), Handles.SnapValue(localPosition.y, 1f / IconSetWindow.Instance.canvas.cells)); } e.Use(); dirty = true; } }
void ReceiveFunctionCallback(string function) { if (function == "Add guide...") { popupDelegate = OpenGuidePopup; } if (function == "Clear points") { canvas.ClearPoints(); } if (function == "Reset grid") { canvas.Reset(); } if (function == "Toggle guide rulers") { Prefs.DrawRulers.value = !Prefs.DrawRulers.value; } if (function == "Clear guides") { IconCanvasGuide.ClearAllGuides(); } }
public void DrawDottedLine(IconCanvasGuide guide, Vector2 offset) { DrawDottedLine(guide[0], guide[1], guide.width, guide.dash, guide.space, (guide.hovered || guide == activeGuide) ? guide.hover : guide.color, guide.type, offset); }
public void DrawDottedLine(IconCanvasGuide guide) { DrawDottedLine(guide[0], guide[1], guide.width, guide.dash, guide.space, (guide.hovered || guide == activeGuide) ? guide.hover : guide.color); }
public void ProcessGuideEvents(Event e) { Vector2 localMouse = canvas.GetLocalMousePositionOnGrid(); if (e.type == EventType.MouseDown && e.button == 0) { if (topRuler.Contains(e.mousePosition)) { activeGuide = new IconCanvasGuide(canvas, localMouse, IconCanvasGuideType.Horizontal); } else if (leftRuler.Contains(e.mousePosition)) { activeGuide = new IconCanvasGuide(canvas, localMouse, IconCanvasGuideType.Vertical); } else { activeGuide = IconCanvasGuide.GetGuideAtPos(e.mousePosition); // May not need this if (activeGuide != null) { activeGuide.snap = e.control; activeGuide.SetLocalPosition(localMouse); } } if (activeGuide != null) { e.Use(); GUI.changed = true; } } if ((e.type == EventType.MouseMove || e.type == EventType.MouseDrag) && activeGuide != null) { activeGuide.snap = e.control; activeGuide.SetLocalPosition(localMouse); e.Use(); GUI.changed = true; } if (e.type == EventType.MouseUp && e.button == 0 && activeGuide != null) { if (activeGuide.Value < 0f || activeGuide.Value > 1f) { activeGuide.DeleteGuide(); } activeGuide = null; e.Use(); GUI.changed = true; } if (activeGuide != null && e.isKey) { activeGuide.snap = e.control; activeGuide.SetLocalPosition(localMouse); GUI.changed = true; } }