public void KeyCommands() { mousePos = Event.current.mousePosition; if (Event.current.type == EventType.keyDown) { KeyCmd_HotkeyDown(Event.current.keyCode); if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace) { KeyCmd_Delete(); } } if (Event.current.type == EventType.keyUp) { KeyCmd_HotkeyUp(Event.current.keyCode); KeyCmd_CopyPaste(); } if (Event.current.alt) { if (Event.current.type == EventType.ScrollWheel) { KeyCmd_Scroll(Event.current.delta); } //1 drag map else if (SWCommon.GetMouse(0)) { Vector2 move = Event.current.mousePosition - mousePosLast; KeyCmd_Dragmove(move); } } else { KeyCmd_Select(); } if (SWCommon.GetMouseDown(0)) { mousePosDown = Event.current.mousePosition; mousePosLast = Event.current.mousePosition; mousePressing = true; } if (SWCommon.GetMouse(0)) { mousePosLast = Event.current.mousePosition; } if (SWCommon.GetMouseUp(0)) { mousePressing = false; } }
void LineEditUpdate() { if (!InMap()) { return; } if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { return; } if (!drawRect.Contains(mousePos)) { return; } RemapWayPoint cp = CloestPt(mousePos); if (SWCommon.GetMouseDown(0)) { editingPoint = cp; } if (SWCommon.GetMouse(0)) { if (editingPoint != null) { SWUndo.Record(node.lineInfo); UpdateRemapWayPoint(editingPoint, Event.current.mousePosition); } } if (SWCommon.GetMouseUp(0)) { if (editingPoint != null) { SWUndo.Record(node.lineInfo); UpdateRemapWayPoint(editingPoint, Event.current.mousePosition); } editingPoint = null; } if (SWCommon.GetMouseUp(1)) { if (cp != null) { SWUndo.Record(node.lineInfo); node.lineInfo.pts.Remove(cp); } } }
public void KeyCommandsOut() { if ((Event.current.alt && SWCommon.GetMouse(0)) || SWCommon.GetMouse(2)) { Vector2 move = Event.current.mousePosition - mousePosOutLast; KeyCmd_DragmoveOut(move); mousePosOutLast = Event.current.mousePosition; } if (SWCommon.GetMouseDown(0) || SWCommon.GetMouseDown(2)) { mousePosOutLast = Event.current.mousePosition; } if (SWCommon.GetMouse(0) || SWCommon.GetMouse(2)) { mousePosOutLast = Event.current.mousePosition; } }
protected void Op() { brush.mode = (SWBrushMode)slotBox_left.selection; if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { return; } if (Event.current.control || Event.current.alt) { return; } if (!drawRect.Contains(mousePos)) { return; } if (brush.mode == SWBrushMode.dropper || brush.mode == SWBrushMode.wand) { ApplyWand_Dropper(); } else if (brush.mode == SWBrushMode.brush || brush.mode == SWBrushMode.erase) { if (SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { if (Event.current.shift && hasFirstPoint) { GoLine(); } else { GoPoint(); } } else if (SWCommon.GetMouse(0)) { GoLine(); } } }
void Op() { // Debug.Log (Event.current.type); brush.mode = (SWBrushMode)slotBox_left.selection; if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { return; } if (Event.current.control || Event.current.alt) { return; } if (!drawRect.Contains(mousePos)) { return; } if (brush.mode == SWBrushMode.dropper) { if (SWWindowMain.Instance.nRoot.texture != null && SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { CalUV(); SWTexture2DEx _tex = SWTextureProcess.TextureResize(SWWindowMain.Instance.nRoot.texture, texWidth, texHeight); SWTextureProcess.ProcessMask_Dropper(node.texMask, _tex, uv, brush, tolerance); lastUV = uv; node.data.dirty = true; hasFirstPoint = false; } } else if (brush.mode == SWBrushMode.wand) { if (SWWindowMain.Instance.nRoot.texture != null && SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { CalUV(); SWTexture2DEx _tex = SWTextureProcess.TextureResize(SWWindowMain.Instance.nRoot.texture, texWidth, texHeight); SWTextureProcess.ProcessMask_Wand(node.texMask, _tex, uv, brush, tolerance); lastUV = uv; node.data.dirty = true; hasFirstPoint = false; } } else if (brush.mode == SWBrushMode.brush || brush.mode == SWBrushMode.erase) { if (SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { if (Event.current.shift && hasFirstPoint) { GoLine(); } else { GoPoint(); } } else if (SWCommon.GetMouse(0)) { GoLine(); } } }
void OnGUI() { baseRect = new Rect(Gap, Gap, position.width - Gap * 2, 20); texRect = new Rect(Gap, baseRect.yMax, position.width - Gap * 2, 50); timeRect = new Rect(Gap, texRect.yMax + Gap, position.width - Gap * 2, 20); valueRect = new Rect(Gap, timeRect.yMax, position.width - Gap * 2, 20); if (SWCommon.GetMouseDown(1)) { if (!baseRect.Contains(Event.current.mousePosition)) { mode = SWGradientMode.no; opItem = null; } } if (SWCommon.GetMouseDown(0)) { bool doit = false; if (mode == SWGradientMode.no) { for (int i = 0; i < gradient.frames.Count; i++) { var item = gradient.frames [i]; Rect rect = CalRect(item); if (rect.Contains(Event.current.mousePosition)) { doit = true; mode = SWGradientMode.select; opItem = item; } } } else if (mode == SWGradientMode.select) { for (int i = 0; i < gradient.frames.Count; i++) { var item = gradient.frames [i]; Rect rect = CalRect(item); if (rect.Contains(Event.current.mousePosition)) { doit = true; opItem = item; if (opItem == item) { mode = SWGradientMode.move; } } } } else if (mode == SWGradientMode.move) { doit = true; opItem.time = TimeOnPos(); } if (!doit) { if (baseRect.Contains(Event.current.mousePosition)) { var item = new SWGradientFrame(); item.time = TimeOnPos(); gradient.frames.Add(item); mode = SWGradientMode.select; opItem = item; } } } if (SWCommon.GetMouse(0)) { if (mode == SWGradientMode.no) { } else if (mode == SWGradientMode.select) { } else if (mode == SWGradientMode.move) { opItem.time = TimeOnPos(); } } if (SWCommon.GetMouseUp(0)) { if (mode == SWGradientMode.no) { } else if (mode == SWGradientMode.select) { } else if (mode == SWGradientMode.move) { mode = SWGradientMode.select; } } if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Delete) { if (mode == SWGradientMode.select && opItem != null) { gradient.frames.Remove(opItem); } } } gradient.Sort(); GUI.color = Color.black; GUI.DrawTexture(baseRect, SWEditorTools.blankTexture); GUI.color = Color.white; SWEditorTools.DrawTiledTexture(texRect, SWEditorTools.backdropTexture); GUI.DrawTexture(texRect, gradient.Tex); bool uppperEvent = false; for (int i = 0; i < gradient.frames.Count; i++) { var item = gradient.frames [i]; Rect rect = CalRect(item); GUI.DrawTexture(rect, icon); if (opItem == item) { GUI.DrawTexture(rect, iconSelect); } } if (opItem != null) { opItem.time = EditorGUI.Slider(timeRect, "Position:", opItem.time, 0, 1); opItem.value = EditorGUI.Slider(valueRect, "Value:", opItem.value, 0, 1); } }
void DrawDir() { Cursor.visible = true; var rect = SWCommon.GetRect(drawRect.center + ArrowOff, new Vector2(IconSize_Arrow, IconSize_Arrow)); Set_Material(matBase, Vector2.zero, 0, Vector2.one); matBase.SetColor("_Color", dragging ? Color.green:Color.white); Graphics.DrawTexture(SWCommon.GetRect(drawRect.center, new Vector2(8, 8)), SWEditorUI.Texture(SWUITex.effectCenter), matBase); matBase.SetFloat("r", -SWCommon.Vector2Angle(ArrowOff)); Graphics.DrawTexture(rect, SWEditorUI.Texture(SWUITex.effectArrow), matBase); matBase.SetFloat("r", 0f); matBase.SetTexture("_MainTex", SWEditorUI.Texture(SWUITex.effectLine)); SWDraw.DrawLine(drawRect.center, rect.center, Color.white, 3f, matBase); float factor = 1f / drawRect.size.x; if (SWCommon.GetMouseDown(0) && InMap()) { RepaintGetDirty(); if (rect.Contains(Event.current.mousePosition)) { dragging = true; lastMousePos = Event.current.mousePosition; } else { dragging = false; } } else if (dragging) { if (SWCommon.GetMouse(0) && InMap()) { RepaintGetDirty(); ArrowOff += Event.current.mousePosition - lastMousePos; if (Event.current.shift) { if (Mathf.Abs(ArrowOff.x) > Mathf.Abs(ArrowOff.y)) { ArrowOff = new Vector2(ArrowOff.x, 0); } else { ArrowOff = new Vector2(0, ArrowOff.y); } } lastMousePos = Event.current.mousePosition; SWUndo.Record(this); rData.d.v = new Vector2(ArrowOff.x * factor, -ArrowOff.y * factor); } if (SWCommon.GetMouseUp(0)) { dragging = false; SWUndo.Record(this); rData.d.v = new Vector2(ArrowOff.x * factor, -ArrowOff.y * factor); } } else { ArrowOff = new Vector2(rData.d.v.x / factor, -rData.d.v.y / factor); } if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Return) { node.data.dirty = true; SWTextureProcess.ProcessRemap_Dir(node.textureEx, node.texChildResized, new Vector2(rData.d.v.x, -rData.d.v.y), rData.d.pre, rData.d.pb); } } }
public void KeyCommands() { mousePos = Event.current.mousePosition; if (Event.current.type == EventType.KeyDown) { KeyCmd_HotkeyDown(Event.current.keyCode); #if UNITY_EDITOR_WIN if (Event.current.keyCode == KeyCode.Delete) #else if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace) #endif { KeyCmd_Delete(); } } if (Event.current.type == EventType.KeyUp) { KeyCmd_HotkeyUp(Event.current.keyCode); KeyCmd_CopyPaste(); } // //Depricated: do it in CalZoom // if (Event.current.alt) { // if (Event.current.type == EventType.ScrollWheel) { // KeyCmd_Scroll (Event.current.delta); // } // } if (InMap()) { if ((Event.current.alt && SWCommon.GetMouse(0)) || SWCommon.GetMouse(1) || SWCommon.GetMouse(2)) { Vector2 move = Event.current.mousePosition - mousePosLast; KeyCmd_Dragmove(move); } } if (!Event.current.alt) { KeyCmd_Select(); } if (Event.current.rawType == EventType.MouseDown) { mousePosDown = Event.current.mousePosition; mousePosLast = Event.current.mousePosition; mousePressing = true; } if (Event.current.rawType == EventType.MouseDrag) { mousePosLast = Event.current.mousePosition; } if (Event.current.rawType == EventType.MouseUp) { mousePressing = false; } // if (SWCommon.GetMouseDown (0)) { // mousePosDown = Event.current.mousePosition; // mousePosLast = Event.current.mousePosition; // mousePressing = true; // } // if (SWCommon.GetMouse (0)) { // mousePosLast = Event.current.mousePosition; // } // if (SWCommon.GetMouseUp (0)) { // mousePressing = false; // } }
void OnGUIImage() { DrawMainTex(); info.mousePos = mousePos; foreach (var item in showOps) { ops[item].OnGUITool(info, item == op); } if (SWCommon.GetMouseDown(0) && InMap()) { op = SWEffectWindowOp.none; List <SWEffectWindowOp> _opsIsPressed = new List <SWEffectWindowOp> (); foreach (var item in showOps) { if (ops[item] is OpTool_angle) { OpTool_angle en = (OpTool_angle)ops[item]; float dis = Vector2.Distance(info.mousePos, info.imageRect.center); float checkRange = Mathf.Max(en.roundRad * 0.02f, 1); if (Mathf.Abs(dis - en.roundRad) < checkRange) { op = item; RepaintGetDirty(); } continue; } if (ops[item].rect.Contains(info.mousePosRotated)) { _opsIsPressed.Add(item); } } //use other tool rather then angle ring, while overlap if (_opsIsPressed.Count == 1) { op = _opsIsPressed [0]; RepaintGetDirty(); } else if (_opsIsPressed.Count > 1) { foreach (var oopp in _opsIsPressed) { if (oopp == SWEffectWindowOp.angle) { continue; } op = oopp; RepaintGetDirty(); break; } } info.mousePosRotatedLast = info.mousePosRotated; info.mousePosLast = info.mousePos; } if (SWCommon.GetMouse(0)) { if (ops.ContainsKey(op)) { info.movement = mousePos; ops [op].UI2Data(info); if (ops [op].repaintDirty) { ops [op].repaintDirty = false; RepaintGetDirty(); } } info.mousePosRotatedLast = info.mousePosRotated; info.mousePosLast = info.mousePos; } else { } if (SWCommon.GetMouseUp(0)) { op = SWEffectWindowOp.none; info.mousePosRotatedLast = info.mousePosRotated; RepaintGetDirty(); } }
void OnGUIImage() { info.mousePos = mousePos; //Half of the extra grids int exHalf = 5; float widthAbs = Mathf.Abs(info.imageRect.width); float heightAbs = Mathf.Abs(info.imageRect.height); float widthSign = Mathf.Sign(info.imageRect.width); float heightSign = Mathf.Sign(info.imageRect.height); Graphics.DrawTexture(new Rect( info.imageRect.x - exHalf * widthAbs, info.imageRect.y - exHalf * heightAbs, (1 + exHalf * 2) * widthAbs, (1 + exHalf * 2) * heightAbs), info.effector.texture, new Rect(-exHalf * widthSign, -exHalf * heightSign, (1 + exHalf * 2) * widthSign, (1 + exHalf * 2) * heightSign), 0, 0, 0, 0, MainTexMat); foreach (var item in showOps) { ops[item].OnGUITool(info, item == op); } if (SWCommon.GetMouseDown(0) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { op = SWEffectWindowOp.none; List <SWEffectWindowOp> _opsIsPressed = new List <SWEffectWindowOp> (); foreach (var item in showOps) { if (ops[item] is OpTool_angle) { OpTool_angle en = (OpTool_angle)ops[item]; float dis = Vector2.Distance(info.mousePos, info.imageRect.center); float checkRange = Mathf.Max(en.roundRad * 0.02f, 1); if (Mathf.Abs(dis - en.roundRad) < checkRange) { op = item; } continue; } if (ops[item].rect.Contains(info.mousePosRotated)) { _opsIsPressed.Add(item); } } //use other tool rather then angle ring, while overlap if (_opsIsPressed.Count == 1) { op = _opsIsPressed [0]; } else if (_opsIsPressed.Count > 1) { foreach (var oopp in _opsIsPressed) { if (oopp == SWEffectWindowOp.angle) { continue; } op = oopp; break; } } info.mousePosRotatedLast = info.mousePosRotated; info.mousePosLast = info.mousePos; } if (SWCommon.GetMouse(0)) { if (ops.ContainsKey(op)) { info.movement = mousePos; ops [op].UI2Data(info); } info.mousePosRotatedLast = info.mousePosRotated; info.mousePosLast = info.mousePos; } else { } if (SWCommon.GetMouseUp(0)) { op = SWEffectWindowOp.none; info.mousePosRotatedLast = info.mousePosRotated; } }