protected void ApplyWand_Dropper() { if (SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { CalUV(); var firstNode = LayerMask_WandDropperNode(node); if (firstNode.texture == null) { return; } // SWTexture2DEx _tex = SWTextureProcess.TextureResize (firstNode.texture, texWidth, texHeight); SWTexture2DEx _tex = SWTextureProcess.TextureResizeTRS(firstNode.texture, texWidth, texHeight, firstNode.data.effectData); if (brush.mode == SWBrushMode.wand) { SWTextureProcess.ProcessMask_Wand(node.texMask, _tex, uv, brush, tolerance); } else if (brush.mode == SWBrushMode.dropper) { SWTextureProcess.ProcessMask_Dropper(node.texMask, _tex, uv, brush, tolerance); } lastUV = uv; node.data.dirty = true; hasFirstPoint = false; } }
protected override void DrawNodeWindow(int id) { base.DrawNodeWindow(id); GUILayout.Space(7); GUILayout.BeginHorizontal(); GUILayout.Space(7); GUILayout.BeginVertical(); float labelWith = 42; EffectDataColor _data = data.effectDataColor; string name = _data.hdr ? "[HDR]" : "Color"; GUILayout.BeginHorizontal(); GUILayout.Label(name, SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(labelWith)); var rect = GUILayoutUtility.GetLastRect(); if (SWCommon.GetMouseDown(1)) { if (rect.Contains(Event.current.mousePosition)) { data.effectDataColor.hdr = !data.effectDataColor.hdr; } } _data.color = EditorGUILayout.ColorField(new GUIContent(""), _data.color, true, true, _data.hdr, null, GUILayout.Width(128 - labelWith)); GUILayout.EndHorizontal(); GUILayout.Space(2); GUILayout.BeginHorizontal(); GUILayout.Label("Op", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(labelWith)); _data.op = (SWOutputOP)EditorGUILayout.EnumPopup(_data.op, GUILayout.Width(128 - labelWith)); GUILayout.EndHorizontal(); GUILayout.Space(2); SWWindowMain.Instance.Factor_Pick(ref _data.param, PickParamType.node, "Factor", null, 128); GUILayout.Space(2); GUILayout.BeginHorizontal(); GUILayout.Label("Depth", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(labelWith)); var dep = EditorGUILayout.IntField(data.depth, GUILayout.Width(128 - labelWith)); if (dep != 0 && dep != data.depth) { SWUndo.Record(this); data.depth = dep; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); DrawNodeWindowEnd(); }
void DrawLine() { //Add Point if (SWCommon.GetMouseDown(0) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { return; } if (!drawRect.Contains(mousePos)) { return; } SWUndo.Record(info); Vector2 m = Event.current.mousePosition; m = m - drawRect.position; m = SWTextureProcess.TexUV(size, size, (int)m.x, (int)m.y); RemapWayPoint pt = new RemapWayPoint(); pt.uv = m; pt.mousePos = mousePos; pt.matArrow = new Material(SWEditorUI.GetShader("RectTRS")); info.pts.Add(pt); } DrawPoints(); //Draw Cursor if (focusedWindow == this) { if (al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)) && drawRect.Contains(mousePos)) { GUI.DrawTexture(new Rect(mousePos.x - brushSize * 1f, mousePos.y - brushSize * 1f, brushSize * 2f, brushSize * 2f), SWEditorUI.Texture(SWUITex.cursor)); GUI.DrawTexture(new Rect(mousePos.x - 8, mousePos.y - 8, 16, 16), SWEditorUI.Texture(SWUITex.cursorCenter)); Cursor.visible = false; } else { Cursor.visible = true; } } //Key Command if (Event.current.type == EventType.keyDown) { if (Event.current.keyCode == KeyCode.Return) { node.data.dirty = true; SWTextureProcess.ProcessRemap_Line(node.textureEx, info, brushSizeUV); } } }
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; } }
public static void HRDColor_Switch(SWWindowBase window, ref bool hdr) { var rect = GUILayoutUtility.GetLastRect(); if (SWCommon.GetMouseDown(1)) { if (rect.Contains(Event.current.mousePosition)) { hdr = !hdr; window.RepaintGetDirty(); } } }
protected void UI_Color(string name, ref Color v, ref bool hdr, System.Action <SWBaseInfo, bool> act = null, bool before = false, bool isRightUp = false) { if (isRightUp) { GUILayout.BeginHorizontal(); } Color temp; if (hdr) { name += " [HDR]"; } GUILayout.Label(name, SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(SWGlobalSettings.LabelWidthLong)); var rect = GUILayoutUtility.GetLastRect(); if (SWCommon.GetMouseDown(1)) { if (rect.Contains(Event.current.mousePosition)) { hdr = !hdr; } } temp = EditorGUILayout.ColorField(new GUIContent(""), v, true, true, false, null, GUILayout.Width(SWGlobalSettings.FieldWidth)); if (temp != v) { if (before) { if (act != null) { act(info, true); } } v = temp; if (!before) { if (act != null) { act(info, true); } } } if (isRightUp) { GUILayout.EndHorizontal(); } }
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); } } }
protected override void DrawNodeWindow(int id) { base.DrawNodeWindow(id); if (SWWindowMain.Instance.data.shaderType == SWShaderType.normal) { DrawNormal(); } else if (SWWindowMain.Instance.data.shaderType == SWShaderType.sprite) { DrawSprite(); } else if (SWWindowMain.Instance.data.shaderType == SWShaderType.ui) { DrawUIImage(); } else if (SWWindowMain.Instance.data.shaderType == SWShaderType.uiFont) { DrawUIText(); } float labelWith = 38; GUILayout.Space(nodeHeight - 42); EffectDataColor _data = data.effectDataColor; string name = _data.hdr ? "[HDR]" : "Color"; GUILayout.BeginHorizontal(); GUILayout.Label(name, SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(labelWith)); var rect = GUILayoutUtility.GetLastRect(); if (SWCommon.GetMouseDown(1)) { if (rect.Contains(Event.current.mousePosition)) { data.effectDataColor.hdr = !data.effectDataColor.hdr; } } _data.color = EditorGUILayout.ColorField(new GUIContent(""), _data.color, false, true, _data.hdr, null, GUILayout.Width(nodeWidth - 15 - labelWith)); GUILayout.EndHorizontal(); DrawNodeWindowEnd(); }
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 LinePlaceUpdate() { //Add Point //if (SWCommon.GetMouseDown (0) && al_rectMain.Contains(mousePosOut+new Vector2(0,al_startY))) { if (SWCommon.GetMouseDown(0) && InMap()) { if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY))) { return; } if (!drawRect.Contains(mousePos)) { return; } SWUndo.Record(node.lineInfo); RemapWayPoint pt = new RemapWayPoint(); UpdateRemapWayPoint(pt, Event.current.mousePosition); pt.matArrow = new Material(SWEditorUI.GetShader("RectTRS")); node.lineInfo.pts.Add(pt); } }
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); } } }
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; } }