From 1a88c8ba90540be3c2db90d440d669f8b8cfb8c1 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 18 May 2026 11:30:34 +0200 Subject: [PATCH] paint: fix brush previews on project load --- paint/sources/base.c | 5 +- paint/sources/brush_nodes/brush_output_node.c | 126 +++++++++--------- paint/sources/brush_nodes/input_node.c | 2 +- paint/sources/import_arm.c | 14 +- paint/sources/types.h | 3 - 5 files changed, 67 insertions(+), 83 deletions(-) diff --git a/paint/sources/base.c b/paint/sources/base.c index 0d74a31b..9f619266 100644 --- a/paint/sources/base.c +++ b/paint/sources/base.c @@ -919,10 +919,7 @@ void ui_base_update_ui() { } g_context->brush_time += sys_delta(); - - if (g_context->run_brush != NULL) { - g_context->run_brush(g_context->brush_output_node_inst, 0); - } + brush_output_node_run(); } } } diff --git a/paint/sources/brush_nodes/brush_output_node.c b/paint/sources/brush_nodes/brush_output_node.c index a134c0d1..7078c6b7 100644 --- a/paint/sources/brush_nodes/brush_output_node.c +++ b/paint/sources/brush_nodes/brush_output_node.c @@ -1,9 +1,12 @@ #include "../global.h" -void brush_output_node_parse_inputs(brush_output_node_t *self) { - gpu_texture_t *last_mask = g_context->brush_mask_image; - gpu_texture_t *last_stencil = g_context->brush_stencil_image; +static brush_output_node_t *brush_output_node_inst; + +void brush_output_node_parse_inputs() { + brush_output_node_t *self = brush_output_node_inst; + gpu_texture_t *last_mask = g_context->brush_mask_image; + gpu_texture_t *last_stencil = g_context->brush_stencil_image; logic_node_value_t *input0 = logic_node_input_get(self->base->inputs->buffer[0]); logic_node_value_t *input1 = logic_node_input_get(self->base->inputs->buffer[1]); @@ -63,60 +66,7 @@ void brush_output_node_parse_inputs(brush_output_node_t *self) { g_context->brush_directional = self->raw->buttons->buffer[0]->default_value->buffer[0] > 0.0; } -void brush_output_paint(brush_output_node_t *self) { - bool down = mouse_down("left") || pen_down("tip"); - bool started = mouse_started("left") || pen_started("tip"); - - // Set color pick - if (down && g_context->tool == TOOL_TYPE_COLORID && project_assets->length > 0) { - g_context->colorid_picked = true; - ui_toolbar_handle->redraws = 1; - } - - // Path layer - add path points only - if (slot_layer_is_path(g_context->layer) && !started) { - return; - } - - // Path layer - dragging existing path point - if (slot_layer_is_path(g_context->layer) && util_layer_is_path_point_dragging()) { - return; - } - - // Prevent painting the same spot - bool same_spot = g_context->paint_vec.x == g_context->last_paint_x && g_context->paint_vec.y == g_context->last_paint_y; - bool lazy = g_context->tool == TOOL_TYPE_BRUSH && g_context->brush_lazy_radius > 0; - if (down && (same_spot || lazy)) { - g_context->painted++; - } - else { - g_context->painted = 0; - } - g_context->last_paint_x = g_context->paint_vec.x; - g_context->last_paint_y = g_context->paint_vec.y; - - if (g_context->tool == TOOL_TYPE_PARTICLE) { - g_context->painted = 0; // Always paint particles - } - - if (g_context->painted == 0) { - brush_output_node_parse_inputs(self); - } - - // Path layer - add point and repaint - if (slot_layer_is_path(g_context->layer)) { - util_layer_add_path_point(g_context->layer, g_context->paint_vec.x, g_context->paint_vec.y); - return; - } - - if (g_context->painted <= 1) { - g_context->pdirty = 1; - g_context->rdirty = 2; - sculpt_push_undo = true; - } -} - -void brush_output_node_run(brush_output_node_t *self, i32 from) { +void brush_output_node_run() { f32 left = 0.0; f32 right = 1.0; f32 top = 0.0; @@ -174,17 +124,63 @@ void brush_output_node_run(brush_output_node_t *self, i32 from) { return; } - brush_output_paint(self); + bool down = mouse_down("left") || pen_down("tip"); + bool started = mouse_started("left") || pen_started("tip"); + + // Set color pick + if (down && g_context->tool == TOOL_TYPE_COLORID && project_assets->length > 0) { + g_context->colorid_picked = true; + ui_toolbar_handle->redraws = 1; + } + + // Path layer - add path points only + if (slot_layer_is_path(g_context->layer) && !started) { + return; + } + + // Path layer - dragging existing path point + if (slot_layer_is_path(g_context->layer) && util_layer_is_path_point_dragging()) { + return; + } + + // Prevent painting the same spot + bool same_spot = g_context->paint_vec.x == g_context->last_paint_x && g_context->paint_vec.y == g_context->last_paint_y; + bool lazy = g_context->tool == TOOL_TYPE_BRUSH && g_context->brush_lazy_radius > 0; + if (down && (same_spot || lazy)) { + g_context->painted++; + } + else { + g_context->painted = 0; + } + g_context->last_paint_x = g_context->paint_vec.x; + g_context->last_paint_y = g_context->paint_vec.y; + + if (g_context->tool == TOOL_TYPE_PARTICLE) { + g_context->painted = 0; // Always paint particles + } + + if (g_context->painted == 0) { + brush_output_node_parse_inputs(); + } + + // Path layer - add point and repaint + if (slot_layer_is_path(g_context->layer)) { + util_layer_add_path_point(g_context->layer, g_context->paint_vec.x, g_context->paint_vec.y); + return; + } + + if (g_context->painted <= 1) { + g_context->pdirty = 1; + g_context->rdirty = 2; + sculpt_push_undo = true; + } } brush_output_node_t *brush_output_node_create(ui_node_t *raw, f32_array_t *args) { - g_context->run_brush = brush_output_node_run; - g_context->parse_brush_inputs = brush_output_node_parse_inputs; - - brush_output_node_t *n = GC_ALLOC_INIT(brush_output_node_t, {0}); - n->base = logic_node_create(n); - n->raw = raw; - g_context->brush_output_node_inst = n; + brush_output_node_t *n = GC_ALLOC_INIT(brush_output_node_t, {0}); + n->base = logic_node_create(n); + n->raw = raw; + brush_output_node_inst = n; return n; } diff --git a/paint/sources/brush_nodes/input_node.c b/paint/sources/brush_nodes/input_node.c index 0a40cf82..5f00b646 100644 --- a/paint/sources/brush_nodes/input_node.c +++ b/paint/sources/brush_nodes/input_node.c @@ -105,7 +105,7 @@ void input_node_update(float_node_t *self) { g_context->last_paint_y = -1; } - g_context->parse_brush_inputs(g_context->brush_output_node_inst); + brush_output_node_parse_inputs(); } logic_node_value_t *input_node_get(input_node_t *self, i32 from) { diff --git a/paint/sources/import_arm.c b/paint/sources/import_arm.c index 796a7572..fe3229b0 100644 --- a/paint/sources/import_arm.c +++ b/paint/sources/import_arm.c @@ -610,6 +610,7 @@ void import_arm_run_project(char *path) { g_context->brush = slot_brush_create(n); any_array_push(project_brushes, g_context->brush); make_material_parse_brush(); + brush_output_node_parse_inputs(); util_render_make_brush_preview(); } @@ -660,15 +661,6 @@ void import_arm_run_brush(char *path) { import_arm_run_brush_from_project(project, path); } -void import_arm_run_brush_from_project_on_next_frame(slot_brush_t_array_t *imported) { - for (i32 i = 0; i < imported->length; ++i) { - slot_brush_t *b = imported->buffer[i]; - context_set_brush(b); - make_material_parse_brush(); - util_render_make_brush_preview(); - } -} - void import_arm_run_brush_from_project(project_t *project, char *path) { char *base = path_base_dir(path); for (i32 i = 0; i < project->assets->length; ++i) { @@ -698,9 +690,11 @@ void import_arm_run_brush_from_project(project_t *project, char *path) { g_context->brush = slot_brush_create(c); any_array_push(project_brushes, g_context->brush); any_array_push(imported, g_context->brush); + make_material_parse_brush(); + brush_output_node_parse_inputs(); + util_render_make_brush_preview(); } - sys_notify_on_next_frame(&import_arm_run_brush_from_project_on_next_frame, imported); ui_base_hwnds->buffer[TAB_AREA_SIDEBAR1]->redraws = 2; data_delete_blob(path); } diff --git a/paint/sources/types.h b/paint/sources/types.h index bec0729f..749be700 100644 --- a/paint/sources/types.h +++ b/paint/sources/types.h @@ -292,9 +292,6 @@ typedef struct context { struct gpu_texture *text_tool_image; char *text_tool_text; i32 layer_filter; - struct brush_output_node *brush_output_node_inst; - void (*run_brush)(void *, i32); - void (*parse_brush_inputs)(void *); struct object *gizmo; struct object *gizmo_translate_x; struct object *gizmo_translate_y;