From 2dd81d42d24c0807ede37fc834ca3b51ad4ecdad Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 12 Jan 2025 15:44:22 +0100 Subject: [PATCH] Cleanup --- ...utput_node.ts => brush_output_node_ext.ts} | 42 +++--- ...utput_node.ts => brush_output_node_ext.ts} | 120 +++++++++++------- armorpaint/sources/nodes/input_node.ts | 1 + ...utput_node.ts => brush_output_node_ext.ts} | 119 ++++++++++------- base/sources/context.ts | 5 + base/sources/nodes/brush_output_node.ts | 11 ++ base/sources/ui_toolbar.ts | 15 ++- 7 files changed, 190 insertions(+), 123 deletions(-) rename armorlab/sources/nodes/{brush_output_node.ts => brush_output_node_ext.ts} (89%) rename armorpaint/sources/nodes/{brush_output_node.ts => brush_output_node_ext.ts} (71%) rename armorsculpt/sources/nodes/{brush_output_node.ts => brush_output_node_ext.ts} (58%) create mode 100644 base/sources/nodes/brush_output_node.ts diff --git a/armorlab/sources/nodes/brush_output_node.ts b/armorlab/sources/nodes/brush_output_node_ext.ts similarity index 89% rename from armorlab/sources/nodes/brush_output_node.ts rename to armorlab/sources/nodes/brush_output_node_ext.ts index de5c2c98..e2499cec 100644 --- a/armorlab/sources/nodes/brush_output_node.ts +++ b/armorlab/sources/nodes/brush_output_node_ext.ts @@ -1,6 +1,8 @@ type brush_output_node_t = { base?: logic_node_t; + raw?: ui_node_t; + id?: i32; texpaint?: image_t; texpaint_nor?: image_t; @@ -9,14 +11,11 @@ type brush_output_node_t = { texpaint_pack_empty?: image_t; }; -let brush_output_node_inst: brush_output_node_t = null; +function brush_output_node_create_ext(n: brush_output_node_t) { -function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_output_node_t { - let n: brush_output_node_t = {}; - n.base = logic_node_create(n); n.base.get_as_image = brush_output_node_get_as_image; - if (brush_output_node_inst == null) { + if (context_raw.brush_output_node_inst == null) { { let t: render_target_t = render_target_create(); t.name = "texpaint"; @@ -59,26 +58,32 @@ function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_outp } } else { - n.texpaint = brush_output_node_inst.texpaint; - n.texpaint_nor = brush_output_node_inst.texpaint_nor; - n.texpaint_pack = brush_output_node_inst.texpaint_pack; + n.texpaint = context_raw.brush_output_node_inst.texpaint; + n.texpaint_nor = context_raw.brush_output_node_inst.texpaint_nor; + n.texpaint_pack = context_raw.brush_output_node_inst.texpaint_pack; } - brush_output_node_inst = n; - - context_raw.run_brush = brush_output_node_run; - context_raw.parse_brush_inputs = brush_output_node_parse_inputs; - - return n; + context_raw.brush_output_node_inst = n; } function brush_output_node_get_as_image(self: brush_output_node_t, from: i32): image_t { return logic_node_input_get_as_image(self.base.inputs[from]); } +function brush_output_node_parse_inputs() { + if (!context_raw.registered) { + context_raw.registered = true; + app_notify_on_update(brush_output_node_update); + } + + context_raw.paint_vec = context_raw.coords; +} + function brush_output_node_run(from: i32) { let left: f32 = 0.0; let right: f32 = 1.0; + let top: f32 = 0.0; + let bottom: f32 = 1.0; // First time init if (context_raw.last_paint_x < 0 || context_raw.last_paint_y < 0) { @@ -125,15 +130,6 @@ function brush_output_node_run(from: i32) { } } -function brush_output_node_parse_inputs() { - if (!context_raw.registered) { - context_raw.registered = true; - app_notify_on_update(brush_output_node_update); - } - - context_raw.paint_vec = context_raw.coords; -} - function brush_output_node_update() { let paint_x: f32 = mouse_view_x() / app_w(); let paint_y: f32 = mouse_view_y() / app_h(); diff --git a/armorpaint/sources/nodes/brush_output_node.ts b/armorpaint/sources/nodes/brush_output_node_ext.ts similarity index 71% rename from armorpaint/sources/nodes/brush_output_node.ts rename to armorpaint/sources/nodes/brush_output_node_ext.ts index ff8ebed8..eef4e7cc 100644 --- a/armorpaint/sources/nodes/brush_output_node.ts +++ b/armorpaint/sources/nodes/brush_output_node_ext.ts @@ -4,14 +4,8 @@ type brush_output_node_t = { raw?: ui_node_t; }; -function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_output_node_t { - let n: brush_output_node_t = {}; - n.base = logic_node_create(n); - context_raw.run_brush = brush_output_node_run; - context_raw.parse_brush_inputs = brush_output_node_parse_inputs; +function brush_output_node_create_ext(n: brush_output_node_t) { context_raw.brush_output_node_inst = n; - n.raw = raw; - return n; } function brush_output_node_parse_inputs(self: brush_output_node_t) { @@ -77,68 +71,96 @@ function brush_output_node_parse_inputs(self: brush_output_node_t) { function brush_output_node_run(self: brush_output_node_t, from: i32) { let left: f32 = 0.0; let right: f32 = 1.0; + let top: f32 = 0.0; + let bottom: f32 = 1.0; + if (context_raw.paint2d) { left = 1.0; right = (context_raw.split_view ? 2.0 : 1.0) + ui_view2d_ww / base_w(); } + // Do not paint over floating toolbar + if (context_is_floating_toolbar()) { + let w: i32 = ui_toolbar_get_x() + ui_toolbar_get_w(); + left += w / app_w(); + top += w / app_h(); + } + // First time init if (context_raw.last_paint_x < 0 || context_raw.last_paint_y < 0) { context_raw.last_paint_vec_x = context_raw.paint_vec.x; context_raw.last_paint_vec_y = context_raw.paint_vec.y; } + // Paint bounds + if (context_raw.paint_vec.x < left || + context_raw.paint_vec.x > right || + context_raw.paint_vec.y < top || + context_raw.paint_vec.y > bottom) { + return; + } + // Do not paint over fill layer - let fill_layer: bool = context_raw.layer.fill_layer != null && context_raw.tool != workspace_tool_t.PICKER && context_raw.tool != workspace_tool_t.MATERIAL && context_raw.tool != workspace_tool_t.COLORID; + let fill_layer: bool = context_raw.layer.fill_layer != null && + context_raw.tool != workspace_tool_t.PICKER && + context_raw.tool != workspace_tool_t.MATERIAL && + context_raw.tool != workspace_tool_t.COLORID; + if (fill_layer) { + return; + } // Do not paint over groups - let group_layer: bool = slot_layer_is_group(context_raw.layer); + if (slot_layer_is_group(context_raw.layer)) { + return; + } - // Paint bounds - if (context_raw.paint_vec.x > left && - context_raw.paint_vec.x < right && - context_raw.paint_vec.y > 0 && - context_raw.paint_vec.y < 1 && - !fill_layer && - !group_layer && - (slot_layer_is_visible(context_raw.layer) || context_raw.paint2d) && - !ui_base_ui.is_hovered && - !base_is_dragging && - !base_is_resizing && - !base_is_scrolling() && - !base_is_combo_selected()) { + if (!slot_layer_is_visible(context_raw.layer) && !context_raw.paint2d) { + return; + } - // Set color pick - let down: bool = mouse_down() || pen_down(); - if (down && context_raw.tool == workspace_tool_t.COLORID && project_assets.length > 0) { - context_raw.colorid_picked = true; - ui_toolbar_handle.redraws = 1; - } + if (ui_base_ui.is_hovered || + base_is_dragging || + base_is_resizing || + base_is_scrolling() || + base_is_combo_selected()) { + return; + } - // Prevent painting the same spot - let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y; - let lazy: bool = context_raw.tool == workspace_tool_t.BRUSH && context_raw.brush_lazy_radius > 0; - if (down && (same_spot || lazy)) { - context_raw.painted++; - } - else { - context_raw.painted = 0; - } - context_raw.last_paint_x = context_raw.paint_vec.x; - context_raw.last_paint_y = context_raw.paint_vec.y; + brush_output_paint(self); +} - if (context_raw.tool == workspace_tool_t.PARTICLE) { - context_raw.painted = 0; // Always paint particles - } +function brush_output_paint(self: brush_output_node_t) { + let down: bool = mouse_down() || pen_down(); - if (context_raw.painted == 0) { - brush_output_node_parse_inputs(self); - } + // Set color pick + if (down && context_raw.tool == workspace_tool_t.COLORID && project_assets.length > 0) { + context_raw.colorid_picked = true; + ui_toolbar_handle.redraws = 1; + } - if (context_raw.painted <= 1) { - context_raw.pdirty = 1; - context_raw.rdirty = 2; - } + // Prevent painting the same spot + let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y; + let lazy: bool = context_raw.tool == workspace_tool_t.BRUSH && context_raw.brush_lazy_radius > 0; + if (down && (same_spot || lazy)) { + context_raw.painted++; + } + else { + context_raw.painted = 0; + } + context_raw.last_paint_x = context_raw.paint_vec.x; + context_raw.last_paint_y = context_raw.paint_vec.y; + + if (context_raw.tool == workspace_tool_t.PARTICLE) { + context_raw.painted = 0; // Always paint particles + } + + if (context_raw.painted == 0) { + brush_output_node_parse_inputs(self); + } + + if (context_raw.painted <= 1) { + context_raw.pdirty = 1; + context_raw.rdirty = 2; } } diff --git a/armorpaint/sources/nodes/input_node.ts b/armorpaint/sources/nodes/input_node.ts index 7af39bb0..36a4109b 100644 --- a/armorpaint/sources/nodes/input_node.ts +++ b/armorpaint/sources/nodes/input_node.ts @@ -41,6 +41,7 @@ function input_node_update(self: float_node_t) { let paint_x: f32 = mouse_view_x() / app_w(); let paint_y: f32 = mouse_view_y() / app_h(); + if (mouse_started()) { input_node_start_x = mouse_view_x() / app_w(); input_node_start_y = mouse_view_y() / app_h(); diff --git a/armorsculpt/sources/nodes/brush_output_node.ts b/armorsculpt/sources/nodes/brush_output_node_ext.ts similarity index 58% rename from armorsculpt/sources/nodes/brush_output_node.ts rename to armorsculpt/sources/nodes/brush_output_node_ext.ts index a11ede98..15711678 100644 --- a/armorsculpt/sources/nodes/brush_output_node.ts +++ b/armorsculpt/sources/nodes/brush_output_node_ext.ts @@ -1,16 +1,11 @@ type brush_output_node_t = { base?: logic_node_t; - Directional?: bool; + raw?: ui_node_t; }; -function brush_output_node_create(arg: any): brush_output_node_t { - let n: brush_output_node_t = {}; - n.base = logic_node_create(n); - context_raw.run_brush = brush_output_node_run; - context_raw.parse_brush_inputs = brush_output_node_parse_inputs; +function brush_output_node_create_ext(n: brush_output_node_t) { context_raw.brush_output_node_inst = n; - return n; } function brush_output_node_parse_inputs(self: brush_output_node_t) { @@ -66,69 +61,103 @@ function brush_output_node_parse_inputs(self: brush_output_node_t) { make_material_parse_paint_material(); } - context_raw.brush_directional = self.Directional; + context_raw.brush_directional = self.raw.buttons[0].default_value[0] > 0.0; } function brush_output_node_run(self: brush_output_node_t, from: i32) { let left: f32 = 0.0; let right: f32 = 1.0; + let top: f32 = 0.0; + let bottom: f32 = 1.0; + if (context_raw.paint2d) { left = 1.0; right = (context_raw.split_view ? 2.0 : 1.0) + ui_view2d_ww / base_w(); } + // Do not paint over floating toolbar + if (context_is_floating_toolbar()) { + let w: i32 = ui_toolbar_get_x() + ui_toolbar_get_w(); + left += w / app_w(); + top += w / app_h(); + } + // First time init if (context_raw.last_paint_x < 0 || context_raw.last_paint_y < 0) { context_raw.last_paint_vec_x = context_raw.paint_vec.x; context_raw.last_paint_vec_y = context_raw.paint_vec.y; } + // Paint bounds + if (context_raw.paint_vec.x < left || + context_raw.paint_vec.x > right || + context_raw.paint_vec.y < top || + context_raw.paint_vec.y > bottom) { + return; + } + // Do not paint over fill layer let fill_layer: bool = context_raw.layer.fill_layer != null; + if (fill_layer) { + return; + } // Do not paint over groups - let group_layer: bool = slot_layer_is_group(context_raw.layer); + if (slot_layer_is_group(context_raw.layer)) { + return; + } - // Paint bounds - if (context_raw.paint_vec.x > left && - context_raw.paint_vec.x < right && - context_raw.paint_vec.y > 0 && - context_raw.paint_vec.y < 1 && - !fill_layer && - !group_layer && - (slot_layer_is_visible(context_raw.layer) || context_raw.paint2d) && - !ui_base_ui.is_hovered && - !base_is_dragging && - !base_is_resizing && - !base_is_scrolling() && - !base_is_combo_selected()) { + if (!slot_layer_is_visible(context_raw.layer) && !context_raw.paint2d) { + return; + } - let down: bool = mouse_down() || pen_down(); + if (ui_base_ui.is_hovered || + base_is_dragging || + base_is_resizing || + base_is_scrolling() || + base_is_combo_selected()) { + return; + } - // Prevent painting the same spot - let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y; - let lazy: bool = context_raw.tool == workspace_tool_t.BRUSH && context_raw.brush_lazy_radius > 0; - if (down && (same_spot || lazy)) { - context_raw.painted++; - } - else { - context_raw.painted = 0; - } - context_raw.last_paint_x = context_raw.paint_vec.x; - context_raw.last_paint_y = context_raw.paint_vec.y; + brush_output_paint(self); - if (context_raw.tool == workspace_tool_t.PARTICLE) { - context_raw.painted = 0; // Always paint particles - } + if (ui_base_ui.is_hovered || + base_is_dragging || + base_is_resizing || + base_is_scrolling() || + base_is_combo_selected()) { + return; + } - if (context_raw.painted == 0) { - brush_output_node_parse_inputs(self); - } + brush_output_paint(self); +} - if (context_raw.painted == 0) { - context_raw.pdirty = 1; - context_raw.rdirty = 2; - history_push_undo2 = true; //// - } +function brush_output_paint(self: brush_output_node_t) { + let down: bool = mouse_down() || pen_down(); + + // Prevent painting the same spot + let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y; + let lazy: bool = context_raw.tool == workspace_tool_t.BRUSH && context_raw.brush_lazy_radius > 0; + if (down && (same_spot || lazy)) { + context_raw.painted++; + } + else { + context_raw.painted = 0; + } + context_raw.last_paint_x = context_raw.paint_vec.x; + context_raw.last_paint_y = context_raw.paint_vec.y; + + if (context_raw.tool == workspace_tool_t.PARTICLE) { + context_raw.painted = 0; // Always paint particles + } + + if (context_raw.painted == 0) { + brush_output_node_parse_inputs(self); + } + + if (context_raw.painted == 0) { + context_raw.pdirty = 1; + context_raw.rdirty = 2; + history_push_undo2 = true; //// } } diff --git a/base/sources/context.ts b/base/sources/context.ts index 4ada7d30..4c59f5ae 100644 --- a/base/sources/context.ts +++ b/base/sources/context.ts @@ -707,6 +707,11 @@ function context_is_decal_mask_paint(): bool { return context_is_decal() && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN); } +function context_is_floating_toolbar(): bool { + // Header is off -> floating toolbar + return config_raw.layout[layout_size_t.HEADER] == 0; +} + function context_get_area_type(): area_type_t { if (context_in_viewport()) { return area_type_t.VIEWPORT; diff --git a/base/sources/nodes/brush_output_node.ts b/base/sources/nodes/brush_output_node.ts new file mode 100644 index 00000000..e5891050 --- /dev/null +++ b/base/sources/nodes/brush_output_node.ts @@ -0,0 +1,11 @@ + +function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_output_node_t { + context_raw.run_brush = brush_output_node_run; + context_raw.parse_brush_inputs = brush_output_node_parse_inputs; + + let n: brush_output_node_t = {}; + n.base = logic_node_create(n); + n.raw = raw; + brush_output_node_create_ext(n); + return n; +} diff --git a/base/sources/ui_toolbar.ts b/base/sources/ui_toolbar.ts index 5e0a3e69..e5ecccb0 100644 --- a/base/sources/ui_toolbar.ts +++ b/base/sources/ui_toolbar.ts @@ -82,6 +82,11 @@ function ui_toolbar_get_w(): i32 { return w; } +function ui_toolbar_get_x(): i32 { + let ui: ui_t = ui_base_ui; + return 5 * ui_SCALE(ui); +} + function ui_toolbar_render_ui() { let ui: ui_t = ui_base_ui; @@ -92,10 +97,9 @@ function ui_toolbar_render_ui() { let h: i32 = sys_height() - ui_header_h; let _WINDOW_BG_COL: i32 = ui.ops.theme.WINDOW_BG_COL; - if (config_raw.layout[layout_size_t.HEADER] == 0) { - // Header is off -> floating toolbar - x += 5 * ui_SCALE(ui); - y += 5 * ui_SCALE(ui); + if (context_is_floating_toolbar()) { + x += ui_toolbar_get_x(); + y += ui_toolbar_get_x(); h = ui_toolbar_tool_names.length * (ui_toolbar_w + 2); ui.ops.theme.WINDOW_BG_COL = ui.ops.theme.SEPARATOR_COL; } @@ -208,8 +212,7 @@ function ui_toolbar_render_ui() { ui.image_scroll_align = true; } - if (config_raw.layout[layout_size_t.HEADER] == 0) { - // Header is off -> floating toolbar + if (context_is_floating_toolbar()) { ui_toolbar_w = 0; ui.ops.theme.WINDOW_BG_COL = _WINDOW_BG_COL; }