Files
armorpaint/Sources/arm/ui/TabBrushes.hx
T
2019-07-10 07:56:45 +02:00

91 lines
2.9 KiB
Haxe

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")) {
// 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
}
}
}
}