Layer node previews

This commit is contained in:
luboslenco
2019-11-24 10:32:10 +01:00
parent caef951d5b
commit 442afbab20
3 changed files with 41 additions and 16 deletions
+8 -1
View File
@@ -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;
+9 -9
View File
@@ -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();
}
+24 -6
View File
@@ -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];
}