From 442afbab209c97fef05e14e23c8b91ba6f59be52 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 24 Nov 2019 10:32:10 +0100 Subject: [PATCH] Layer node previews --- Sources/arm/App.hx | 9 ++++++++- Sources/arm/ui/TabLayers.hx | 18 +++++++++--------- Sources/arm/ui/UINodes.hx | 30 ++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 8cc99a8e..d9caacb1 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -399,13 +399,20 @@ class App { if (Zui.alwaysRedrawWindow && Context.ddirty < 0) Context.ddirty = 0; } + static function getDragImage():kha.Image { + if (dragAsset != null) return UITrait.inst.getImage(dragAsset); + if (dragMaterial != null) return dragMaterial.imageIcon; + if (dragLayer != null && Context.layerIsMask) return dragLayer.texpaint_mask_preview; + else return dragLayer.texpaint_preview; + } + static function render(g:kha.graphics2.Graphics) { if (System.windowWidth() == 0 || System.windowHeight() == 0) return; var mouse = Input.getMouse(); if (isDragging) { Krom.setMouseCursor(1); // Hand - var img = dragAsset != null ? UITrait.inst.getImage(dragAsset) : dragMaterial != null ? dragMaterial.imageIcon : dragLayer.texpaint_preview; + var img = getDragImage(); @:privateAccess var size = 50 * UITrait.inst.ui.SCALE(); var ratio = size / img.width; var h = img.height * ratio; diff --git a/Sources/arm/ui/TabLayers.hx b/Sources/arm/ui/TabLayers.hx index b7f1c48d..a384be0f 100644 --- a/Sources/arm/ui/TabLayers.hx +++ b/Sources/arm/ui/TabLayers.hx @@ -116,10 +116,8 @@ class TabLayers { if (ui.isHovered && ui.inputReleasedR) { contextMenu = true; } - if (ui.isReleased) { - Context.setLayer(l); - } if (state == State.Started) { + Context.setLayer(l); if (Time.time() - UITrait.inst.selectTime < 0.25) UITrait.inst.show2DView(); UITrait.inst.selectTime = Time.time(); var mouse = Input.getMouse(); @@ -129,6 +127,8 @@ class TabLayers { } if (l.texpaint_mask != null) { + var uix = ui._x; + var uiy = ui._y; ui._x += Std.int(4 * ui.SCALE()); ui._y += 3; var state = ui.image(l.texpaint_mask_preview, 0xffffffff, (ui.ELEMENT_H() - 3) * 2); @@ -161,12 +161,14 @@ class TabLayers { } }); } - if (ui.isReleased) { - Context.setLayer(l, true); - } if (state == State.Started) { + Context.setLayer(l, true); if (Time.time() - UITrait.inst.selectTime < 0.25) UITrait.inst.show2DView(); UITrait.inst.selectTime = Time.time(); + var mouse = Input.getMouse(); + App.dragOffX = -(mouse.x - uix - ui._windowX - 3); + App.dragOffY = -(mouse.y - uiy - ui._windowY + 1); + App.dragLayer = Context.layer; } } @@ -174,10 +176,8 @@ class TabLayers { var state = ui.text(l.name); ui._y -= center; - if (ui.isReleased) { - Context.setLayer(l); - } if (state == State.Started) { + Context.setLayer(l); if (Time.time() - UITrait.inst.selectTime < 0.25) UITrait.inst.show2DView(); UITrait.inst.selectTime = Time.time(); } diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index a2b876b1..7ae8456f 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -364,11 +364,29 @@ class UINodes { var c = getCanvas(); nodes.nodeCanvas(ui, c); - // Image node preview - if (nodes.nodesSelected.length > 0 && nodes.nodesSelected[0].type == 'TEX_IMAGE') { - var id = nodes.nodesSelected[0].buttons[0].default_value; - if (id < Project.assets.length) { - var img = UITrait.inst.getImage(Project.assets[id]); + // Node previews + if (nodes.nodesSelected.length > 0) { + var img:kha.Image = null; + var sel = nodes.nodesSelected[0]; + if (sel.type == "TEX_IMAGE") { + var id = sel.buttons[0].default_value; + if (id < Project.assets.length) { + img = UITrait.inst.getImage(Project.assets[id]); + } + } + else if (sel.type == "LAYER") { + var id = sel.buttons[0].default_value; + if (id < Project.layers.length) { + img = Project.layers[id].texpaint_preview; + } + } + else if (sel.type == "LAYER_MASK") { + var id = sel.buttons[0].default_value; + if (id < Project.layers.length) { + img = Project.layers[id].texpaint_mask_preview; + } + } + if (img != null) { var tw = 64 * ui.SCALE(); var th = tw * (img.height / img.width); ui.g.drawScaledImage(img, ww - tw - 8 * ui.SCALE(), wh - th - 40 * ui.SCALE(), tw, th); @@ -482,7 +500,7 @@ class UINodes { } public function acceptLayerDrag(layerIndex:Int) { - var n = NodesMaterial.createNode("LAYER"); + var n = NodesMaterial.createNode(Context.layerIsMask ? "LAYER_MASK" : "LAYER"); n.buttons[0].default_value = layerIndex; nodes.nodesSelected = [n]; }