Begin brush mask

This commit is contained in:
luboslenco
2019-07-10 07:56:45 +02:00
parent f2c1927791
commit 8321cb3f29
3 changed files with 145 additions and 1 deletions
+4
View File
@@ -1,8 +1,12 @@
package arm.data;
import kha.Image;
import zui.Nodes;
class BrushSlot {
public var nodes = new Nodes();
public var image:Image = null; // 200
public var imageIcon:Image = null; // 50
public var previewReady = false;
public function new() {}
}
+63
View File
@@ -340,7 +340,70 @@ class NodesBrush {
}
],
buttons: []
},
{
id: 0,
name: "Image Texture",
type: "TEX_IMAGE",
x: 0,
y: 0,
color: 0xff4982a0,
inputs: [
{
id: 0,
node_id: 0,
name: "Vector",
type: "VECTOR",
color: 0xff6363c7,
default_value: [0.0, 0.0, 0.0]
}
],
outputs: [
{
id: 0,
node_id: 0,
name: "Color",
type: "RGBA",
color: 0xffc7c729,
default_value: [0.0, 0.0, 0.0, 1.0]
},
{
id: 0,
node_id: 0,
name: "Alpha",
type: "VALUE",
color: 0xffa1a1a1,
default_value: 1.0
}
],
buttons: [
{
name: "File",
type: "ENUM",
default_value: 0,
data: ""
},
{
name: "Color Space",
type: "ENUM",
default_value: 0,
data: ["linear", "srgb"]
}
]
}
]
];
public static function createImageTexture():TNode {
for (n in list[categories.indexOf("Nodes")]) {
if (n.type == "TEX_IMAGE") {
var canvas = arm.ui.UINodes.inst.canvasBrush;
var nodes = arm.ui.UINodes.inst.nodes;
var node = arm.ui.UINodes.makeNode(n, nodes, canvas);
canvas.nodes.push(node);
return node;
}
}
return null;
}
}
+78 -1
View File
@@ -1,13 +1,90 @@
package arm.ui;
import iron.system.Time;
import iron.system.Input;
import zui.Zui;
import arm.data.BrushSlot;
class TabBrushes {
@:access(zui.Zui)
public static function draw() {
var ui = UITrait.inst.ui;
if (ui.tab(UITrait.inst.htab1, "Brushes")) {
ui.row([1/4,1/4]);
if (ui.button("New")) {}
if (ui.button("New")) {
// UITrait.inst.headerHandle.redraws = 2;
Context.brush = new BrushSlot();
Project.brushes.push(Context.brush);
UINodes.inst.updateCanvasBrushMap();
// MaterialParser.parsePaintMaterial();
// RenderUtil.makeMaterialPreview();
}
if (ui.button("Nodes")) UITrait.inst.showBrushNodes();
for (row in 0...Std.int(Math.ceil(Project.brushes.length / 5))) {
ui.row([1/5,1/5,1/5,1/5,1/5]);
if (row > 0) ui._y += 6;
for (j in 0...5) {
var imgw = ui.SCALE > 1 ? 100 : 50;
var i = j + row * 5;
if (i >= Project.brushes.length) {
@:privateAccess ui.endElement(imgw);
continue;
}
var img = ui.SCALE > 1 ? Project.brushes[i].image : Project.brushes[i].imageIcon;
var imgFull = Project.brushes[i].image;
if (Context.brush == Project.brushes[i]) {
// ui.fill(1, -2, img.width + 3, img.height + 3, ui.t.HIGHLIGHT_COL); // TODO
var off = row % 2 == 1 ? 1 : 0;
var w = 51 - Config.raw.window_scale;
ui.fill(1, -2, w + 3, 2, ui.t.HIGHLIGHT_COL);
ui.fill(1, w - off, w + 3, 2 + off, ui.t.HIGHLIGHT_COL);
ui.fill(1, -2, 2, w + 3, ui.t.HIGHLIGHT_COL);
ui.fill(w + 3, -2, 2, w + 4, ui.t.HIGHLIGHT_COL);
}
#if (kha_opengl || kha_webgl)
ui.imageInvertY = Project.brushes[i].previewReady;
#end
var uix = ui._x;
var uiy = ui._y;
var state = Project.brushes[i].previewReady ? ui.image(img) : ui.image(Res.get('icons.png'), -1, null, imgw, imgw, imgw, imgw);
if (state == State.Started) {
if (Context.brush != Project.brushes[i]) Context.selectBrush(i);
if (Time.time() - UITrait.inst.selectTime < 0.25) UITrait.inst.showBrushNodes();
UITrait.inst.selectTime = Time.time();
// var mouse = Input.getMouse();
// App.dragOffX = -(mouse.x - uix - ui._windowX + iron.App.x() - 3);
// App.dragOffY = -(mouse.y - uiy - ui._windowY + iron.App.y() + 1);
// App.dragBrush = Context.brush;
}
if (ui.isHovered && ui.inputReleasedR) {
UIMenu.draw(function(ui:Zui) {
var b = Project.brushes[i];
ui.fill(0, 0, ui._w, ui.t.ELEMENT_H * 2, ui.t.SEPARATOR_COL);
ui.text(UINodes.inst.canvasBrushMap.get(Project.brushes[i]).name, Right);
if (ui.button("Delete", Left) && Project.brushes.length > 1) {
Context.selectBrush(i == 0 ? 1 : 0);
Project.brushes.splice(i, 1);
UITrait.inst.hwnd1.redraws = 2;
}
});
}
if (ui.isHovered) ui.tooltipImage(imgFull);
}
ui._y += 6;
#if (kha_opengl || kha_webgl)
ui.imageInvertY = false; // Material preview
#end
}
}
}
}