Improve paint vector handling
This commit is contained in:
@@ -463,6 +463,27 @@ class App {
|
||||
static function render(g: kha.graphics2.Graphics) {
|
||||
if (System.windowWidth() == 0 || System.windowHeight() == 0) return;
|
||||
|
||||
if (Context.frame == 2) {
|
||||
RenderUtil.makeMaterialPreview();
|
||||
UISidebar.inst.hwnd1.redraws = 2;
|
||||
MaterialParser.parseMeshMaterial();
|
||||
MaterialParser.parsePaintMaterial();
|
||||
Context.ddirty = 0;
|
||||
History.reset();
|
||||
if (History.undoLayers == null) {
|
||||
History.undoLayers = [];
|
||||
for (i in 0...Config.raw.undo_steps) {
|
||||
var l = new LayerSlot("_undo" + History.undoLayers.length);
|
||||
l.createMask(0, false);
|
||||
History.undoLayers.push(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Context.frame == 3) {
|
||||
Context.ddirty = 1;
|
||||
}
|
||||
Context.frame++;
|
||||
|
||||
var mouse = Input.getMouse();
|
||||
if (isDragging) {
|
||||
Krom.setMouseCursor(1); // Hand
|
||||
@@ -488,6 +509,28 @@ class App {
|
||||
uiEnabled = !UIBox.show && !usingMenu;
|
||||
if (UIBox.show) UIBox.render(g);
|
||||
if (UIMenu.show) UIMenu.render(g);
|
||||
|
||||
// Save last pos for continuos paint
|
||||
if (mouse.down()) {
|
||||
Context.lastPaintVecX = Context.paintVec.x;
|
||||
Context.lastPaintVecY = Context.paintVec.y;
|
||||
}
|
||||
else {
|
||||
if (Context.splitView) {
|
||||
Context.viewIndex = Input.getMouse().viewX > arm.App.w() / 2 ? 1 : 0;
|
||||
}
|
||||
|
||||
Context.lastPaintVecX = mouse.viewX / iron.App.w();
|
||||
Context.lastPaintVecY = mouse.viewY / iron.App.h();
|
||||
|
||||
Context.viewIndex = -1;
|
||||
|
||||
#if (krom_android || krom_ios)
|
||||
// No mouse move events for touch, re-init last paint position on touch start
|
||||
Context.lastPaintX = -1;
|
||||
Context.lastPaintY = -1;
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
public static function enumTexts(nodeType: String): Array<String> {
|
||||
|
||||
@@ -284,17 +284,20 @@ class Uniforms {
|
||||
#if arm_painter
|
||||
if (link == "_brushDirection") {
|
||||
v = iron.object.Uniforms.helpVec;
|
||||
if (Context.lastPaintVecX != Context.paintVec.x) Context.prevPaintVecX = Context.lastPaintVecX;
|
||||
if (Context.lastPaintVecY != Context.paintVec.y) Context.prevPaintVecY = Context.lastPaintVecY;
|
||||
// Discard first paint for directional brush
|
||||
var allowPaint = Context.prevPaintVecX != Context.lastPaintVecX &&
|
||||
Context.prevPaintVecY != Context.lastPaintVecY &&
|
||||
Context.prevPaintVecX > 0 &&
|
||||
Context.prevPaintVecY > 0;
|
||||
var x = Context.paintVec.x;
|
||||
var y = Context.paintVec.y;
|
||||
var lastx = Context.prevPaintVecX;
|
||||
var lasty = Context.prevPaintVecY;
|
||||
if (Context.paint2d) { x -= 1.0; lastx -= 1.0; }
|
||||
var angle = Math.atan2(-y + lasty, x - lastx) - Math.PI / 2;
|
||||
// Discard first paint for directional brush
|
||||
var allowPaint = (Context.prevPaintVecX > 0 && Context.prevPaintVecY > 0) ? 1 : 0;
|
||||
v.set(Math.cos(angle), Math.sin(angle), allowPaint);
|
||||
v.set(Math.cos(angle), Math.sin(angle), allowPaint ? 1 : 0);
|
||||
Context.prevPaintVecX = Context.lastPaintVecX;
|
||||
Context.prevPaintVecY = Context.lastPaintVecY;
|
||||
return v;
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -129,52 +129,6 @@ class UISidebar {
|
||||
world.envmap = Context.showEnvmap ? Context.savedEnvmap : Context.emptyEnvmap;
|
||||
Context.ddirty = 1;
|
||||
|
||||
// Save last pos for continuos paint
|
||||
iron.App.notifyOnRender(function(g: kha.graphics4.Graphics) { //
|
||||
if (Context.frame == 2) {
|
||||
RenderUtil.makeMaterialPreview();
|
||||
hwnd1.redraws = 2;
|
||||
MaterialParser.parseMeshMaterial();
|
||||
MaterialParser.parsePaintMaterial();
|
||||
Context.ddirty = 0;
|
||||
History.reset();
|
||||
if (History.undoLayers == null) {
|
||||
History.undoLayers = [];
|
||||
for (i in 0...Config.raw.undo_steps) {
|
||||
var l = new LayerSlot("_undo" + History.undoLayers.length);
|
||||
l.createMask(0, false);
|
||||
History.undoLayers.push(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Context.frame == 3) {
|
||||
Context.ddirty = 1;
|
||||
}
|
||||
Context.frame++;
|
||||
|
||||
var mouse = Input.getMouse();
|
||||
if (mouse.down()) { //
|
||||
Context.lastPaintVecX = Context.paintVec.x; //
|
||||
Context.lastPaintVecY = Context.paintVec.y; //
|
||||
} //
|
||||
else {
|
||||
if (Context.splitView) {
|
||||
Context.viewIndex = Input.getMouse().viewX > arm.App.w() / 2 ? 1 : 0;
|
||||
}
|
||||
|
||||
Context.lastPaintVecX = mouse.viewX / iron.App.w();
|
||||
Context.lastPaintVecY = mouse.viewY / iron.App.h();
|
||||
|
||||
Context.viewIndex = -1;
|
||||
|
||||
#if (krom_android || krom_ios)
|
||||
// No mouse move events for touch, re-init last paint position on touch start
|
||||
Context.lastPaintX = -1;
|
||||
Context.lastPaintY = -1;
|
||||
#end
|
||||
}
|
||||
}); //
|
||||
|
||||
var scale = Config.raw.window_scale;
|
||||
ui = new Zui( { theme: App.theme, font: App.font, scaleFactor: scale, color_wheel: App.colorWheel } );
|
||||
Zui.onBorderHover = onBorderHover;
|
||||
|
||||
Reference in New Issue
Block a user