Node fixes
This commit is contained in:
@@ -87,6 +87,7 @@ float UI_LINE_H() {
|
||||
}
|
||||
|
||||
float UI_BUTTONS_H(ui_node_t *node) {
|
||||
if (node->flags & NODE_FLAG_COLLAPSED) return 0.0;
|
||||
float h = 0.0;
|
||||
for (int i = 0; i < node->buttons->length; ++i) {
|
||||
ui_node_button_t *but = node->buttons->buffer[i];
|
||||
@@ -107,9 +108,10 @@ float UI_BUTTONS_H(ui_node_t *node) {
|
||||
return h;
|
||||
}
|
||||
|
||||
float UI_OUTPUTS_H(int sockets_count, int length) {
|
||||
float UI_OUTPUTS_H(ui_node_t *node, int length) {
|
||||
if (node->flags & NODE_FLAG_COLLAPSED) return 0.0;
|
||||
float h = 0.0;
|
||||
for (int i = 0; i < (length < 0 ? sockets_count : length); ++i) {
|
||||
for (int i = 0; i < (length < 0 ? node->outputs->length : length); ++i) {
|
||||
h += UI_LINE_H();
|
||||
}
|
||||
return h;
|
||||
@@ -140,7 +142,7 @@ float UI_INPUTS_H(ui_node_canvas_t *canvas, ui_node_socket_t **sockets, int sock
|
||||
|
||||
float UI_NODE_H(ui_node_canvas_t *canvas, ui_node_t *node) {
|
||||
if (node->flags & NODE_FLAG_COLLAPSED) return UI_LINE_H() * 1.2;
|
||||
return UI_LINE_H() * 1.2 + UI_INPUTS_H(canvas, node->inputs->buffer, node->inputs->length, -1) + UI_OUTPUTS_H(node->outputs->length, -1) + UI_BUTTONS_H(node);
|
||||
return UI_LINE_H() * 1.2 + UI_INPUTS_H(canvas, node->inputs->buffer, node->inputs->length, -1) + UI_OUTPUTS_H(node, -1) + UI_BUTTONS_H(node);
|
||||
}
|
||||
|
||||
float UI_NODE_W(ui_node_t *node) {
|
||||
@@ -162,7 +164,7 @@ float UI_INPUT_Y(ui_node_canvas_t *canvas, ui_node_t *node, int pos) {
|
||||
|
||||
float UI_OUTPUT_Y(ui_node_t *node, int pos) {
|
||||
if (node->flags & NODE_FLAG_COLLAPSED) return UI_LINE_H() * 0.5;
|
||||
return UI_LINE_H() * 1.62 + UI_OUTPUTS_H(node->outputs->length, pos);
|
||||
return UI_LINE_H() * 1.62 + UI_OUTPUTS_H(node, pos);
|
||||
}
|
||||
|
||||
float ui_p(float f) {
|
||||
@@ -880,7 +882,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) {
|
||||
float from_x = from == NULL ? current->input_x : wx + UI_NODE_X(from) + UI_NODE_W(from);
|
||||
float from_y = from == NULL ? current->input_y : wy + UI_NODE_Y(from) + UI_OUTPUT_Y(from, link->from_socket);
|
||||
float to_x = to == NULL ? current->input_x : wx + UI_NODE_X(to);
|
||||
float to_y = to == NULL ? current->input_y : wy + UI_NODE_Y(to) + UI_INPUT_Y(canvas, to, link->to_socket) + UI_OUTPUTS_H(to->outputs->length, -1) + UI_BUTTONS_H(to);
|
||||
float to_y = to == NULL ? current->input_y : wy + UI_NODE_Y(to) + UI_INPUT_Y(canvas, to, link->to_socket) + UI_OUTPUTS_H(to, -1) + UI_BUTTONS_H(to);
|
||||
|
||||
// Cull
|
||||
float left = to_x > from_x ? from_x : to_x;
|
||||
@@ -930,7 +932,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) {
|
||||
else if (to == NULL && node->id != from->id) { // Snap to input
|
||||
for (int k = 0; k < node->inputs->length; ++k) {
|
||||
float sx = wx + UI_NODE_X(node);
|
||||
float sy = wy + UI_NODE_Y(node) + UI_INPUT_Y(canvas, node, k) + UI_OUTPUTS_H(node->outputs->length, -1) + UI_BUTTONS_H(node);
|
||||
float sy = wy + UI_NODE_Y(node) + UI_INPUT_Y(canvas, node, k) + UI_OUTPUTS_H(node, -1) + UI_BUTTONS_H(node);
|
||||
float rx = sx - UI_LINE_H() / 2.0;
|
||||
float ry = sy - UI_LINE_H() / 2.0;
|
||||
if (ui_input_in_rect(rx, ry, UI_LINE_H(), UI_LINE_H())) {
|
||||
@@ -971,7 +973,11 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) {
|
||||
|
||||
// Resize node
|
||||
float node_h = UI_NODE_H(canvas, node);
|
||||
if (current->input_enabled && ui_input_in_rect(wx + UI_NODE_X(node) + UI_NODE_W(node), wy + UI_NODE_Y(node), 5, node_h)) {
|
||||
float top_h = UI_LINE_H() + UI_OUTPUTS_H(node, -1) + ui_p(5);
|
||||
if (current->input_enabled &&
|
||||
(ui_input_in_rect(wx + UI_NODE_X(node) + UI_NODE_W(node), wy + UI_NODE_Y(node), 5, UI_LINE_H()) ||
|
||||
ui_input_in_rect(wx + UI_NODE_X(node) + UI_NODE_W(node), wy + UI_NODE_Y(node) + top_h, 5, node_h - top_h))) {
|
||||
|
||||
iron_mouse_set_cursor(IRON_CURSOR_SIZEWE);
|
||||
if (current->input_started) {
|
||||
node_resize = node;
|
||||
@@ -1033,7 +1039,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) {
|
||||
if (current_nodes->link_drag_id == -1) {
|
||||
for (int j = 0; j < node->inputs->length; ++j) {
|
||||
float sx = wx + UI_NODE_X(node);
|
||||
float sy = wy + UI_NODE_Y(node) + UI_INPUT_Y(canvas, node, j) + UI_OUTPUTS_H(node->outputs->length, -1) + UI_BUTTONS_H(node);
|
||||
float sy = wy + UI_NODE_Y(node) + UI_INPUT_Y(canvas, node, j) + UI_OUTPUTS_H(node, -1) + UI_BUTTONS_H(node);
|
||||
if (ui_input_in_rect(sx - UI_LINE_H() / 2.0, sy - UI_LINE_H() / 2.0, UI_LINE_H(), UI_LINE_H())) {
|
||||
// Already has a link - disconnect
|
||||
for (int k = 0; k < canvas->links->length; ++k) {
|
||||
|
||||
@@ -149,7 +149,7 @@ float UI_NODE_W(ui_node_t *node);
|
||||
float UI_NODE_H(ui_node_canvas_t *canvas, ui_node_t *node);
|
||||
float UI_OUTPUT_Y(ui_node_t *node, int pos);
|
||||
float UI_INPUT_Y(ui_node_canvas_t *canvas, ui_node_t *node, int pos);
|
||||
float UI_OUTPUTS_H(int sockets_count, int length);
|
||||
float UI_OUTPUTS_H(ui_node_t *node, int length);
|
||||
float UI_BUTTONS_H(ui_node_t *node);
|
||||
float UI_LINE_H();
|
||||
float UI_NODES_PAN_X();
|
||||
|
||||
@@ -961,7 +961,7 @@ declare function UI_SCALE(): f32;
|
||||
declare function UI_ELEMENT_OFFSET(): f32;
|
||||
declare function UI_ELEMENT_W(): f32;
|
||||
declare function UI_ELEMENT_H(): f32;
|
||||
declare function UI_OUTPUTS_H(sockets_count: i32, length: i32 = -1): f32;
|
||||
declare function UI_OUTPUTS_H(node: ui_node_t, length: i32 = -1): f32;
|
||||
|
||||
function ui_MENUBAR_H(ui: ui_t): f32 {
|
||||
let button_offset_y: f32 = (ui.ops.theme.ELEMENT_H * UI_SCALE() - ui.ops.theme.BUTTON_H * UI_SCALE()) / 2;
|
||||
|
||||
@@ -360,7 +360,7 @@ function base_update() {
|
||||
|
||||
// Create image texture
|
||||
if (context_in_nodes()) {
|
||||
ui_nodes_accept_asset_drag(array_index_of(project_assets, base_drag_asset));
|
||||
ui_nodes_accept_asset_drop(array_index_of(project_assets, base_drag_asset));
|
||||
}
|
||||
else if (context_in_3d_view()) {
|
||||
if (ends_with(to_lower_case(base_drag_asset.file), ".hdr")) {
|
||||
@@ -377,13 +377,13 @@ function base_update() {
|
||||
else if (base_drag_swatch != null) {
|
||||
// Create RGB node
|
||||
if (context_in_nodes()) {
|
||||
ui_nodes_accept_swatch_drag(base_drag_swatch);
|
||||
ui_nodes_accept_swatch_drop(base_drag_swatch);
|
||||
}
|
||||
else if (context_in_swatches()) {
|
||||
tab_swatches_accept_swatch_drag(base_drag_swatch);
|
||||
tab_swatches_accept_swatch_drop(base_drag_swatch);
|
||||
}
|
||||
else if (context_in_materials()) {
|
||||
tab_materials_accept_swatch_drag(base_drag_swatch);
|
||||
tab_materials_accept_swatch_drop(base_drag_swatch);
|
||||
}
|
||||
else if (context_in_3d_view()) {
|
||||
let color: i32 = base_drag_swatch.base;
|
||||
@@ -420,7 +420,7 @@ function base_update() {
|
||||
}
|
||||
else if (base_drag_layer != null) {
|
||||
if (context_in_nodes()) {
|
||||
ui_nodes_accept_layer_drag(array_index_of(project_layers, base_drag_layer));
|
||||
ui_nodes_accept_layer_drop(array_index_of(project_layers, base_drag_layer));
|
||||
}
|
||||
else if (context_in_layers() && base_is_dragging) {
|
||||
slot_layer_move(base_drag_layer, context_raw.drag_dest);
|
||||
@@ -469,7 +469,7 @@ function base_material_dropped() {
|
||||
layers_create_fill_layer(uv_type, decal_mat, context_raw.drag_dest);
|
||||
}
|
||||
else if (context_in_nodes()) {
|
||||
ui_nodes_accept_material_drag(array_index_of(project_materials, base_drag_material));
|
||||
ui_nodes_accept_material_drop(array_index_of(project_materials, base_drag_material));
|
||||
}
|
||||
base_drag_material = null;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ function import_asset_run(path: string, drop_x: f32 = -1.0, drop_y: f32 = -1.0,
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui_nodes_accept_asset_drag(asset_index);
|
||||
ui_nodes_accept_asset_drop(asset_index);
|
||||
ui_nodes_get_nodes().nodes_drag = false;
|
||||
ui_nodes_hwnd.redraws = 2;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ let make_material_emis_used: bool = false;
|
||||
let make_material_subs_used: bool = false;
|
||||
|
||||
function make_material_get_mout(): bool {
|
||||
for (let i: i32 = 0; i < ui_nodes_get_canvas_material().nodes.length; ++i) {
|
||||
let n: ui_node_t = ui_nodes_get_canvas_material().nodes[i];
|
||||
for (let i: i32 = 0; i < context_raw.material.canvas.nodes.length; ++i) {
|
||||
let n: ui_node_t = context_raw.material.canvas.nodes[i];
|
||||
if (n.type == "OUTPUT_MATERIAL_PBR") {
|
||||
return true;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ function make_material_parse_paint_material(bake_previews: bool = true) {
|
||||
|
||||
let sdata: material_t = {
|
||||
name: "Material",
|
||||
canvas: ui_nodes_get_canvas_material()
|
||||
canvas: context_raw.material.canvas
|
||||
};
|
||||
let tmcon: material_context_t = {
|
||||
name: "paint",
|
||||
@@ -216,7 +216,7 @@ function make_material_bake_node_previews() {
|
||||
context_raw.node_previews = map_create();
|
||||
}
|
||||
let empty: ui_node_t[] = [];
|
||||
make_material_traverse_nodes(ui_nodes_get_canvas_material().nodes, null, empty);
|
||||
make_material_traverse_nodes(context_raw.material.canvas.nodes, null, empty);
|
||||
|
||||
let keys: string[] = map_keys(context_raw.node_previews);
|
||||
for (let i: i32 = 0; i < keys.length; ++i) {
|
||||
@@ -264,7 +264,7 @@ function make_material_bake_node_preview(node: ui_node_t, group: ui_node_canvas_
|
||||
}
|
||||
|
||||
parser_material_blur_passthrough = true;
|
||||
util_render_make_node_preview(ui_nodes_get_canvas_material(), node, image, group, parents);
|
||||
util_render_make_node_preview(context_raw.material.canvas, node, image, group, parents);
|
||||
parser_material_blur_passthrough = false;
|
||||
}
|
||||
else if (node.type == "DIRECT_WARP") {
|
||||
@@ -282,7 +282,7 @@ function make_material_bake_node_preview(node: ui_node_t, group: ui_node_canvas_
|
||||
}
|
||||
|
||||
parser_material_warp_passthrough = true;
|
||||
util_render_make_node_preview(ui_nodes_get_canvas_material(), node, image, group, parents);
|
||||
util_render_make_node_preview(context_raw.material.canvas, node, image, group, parents);
|
||||
parser_material_warp_passthrough = false;
|
||||
}
|
||||
else if (node.type == "BAKE_CURVATURE") {
|
||||
@@ -348,7 +348,7 @@ function make_material_parse_node_preview_material(node: ui_node_t, group: ui_no
|
||||
}
|
||||
let sdata: material_t = {
|
||||
name: "Material",
|
||||
canvas: ui_nodes_get_canvas_material()
|
||||
canvas: context_raw.material.canvas
|
||||
};
|
||||
let mcon_raw: material_context_t = {
|
||||
name: "mesh",
|
||||
|
||||
@@ -45,7 +45,7 @@ function make_mesh_preview_run(data: material_t, matcon: material_context_t): no
|
||||
parser_material_sample_uv_scale = brush_scale;
|
||||
parser_material_parse_height = make_material_height_used;
|
||||
parser_material_parse_height_as_channel = true;
|
||||
let sout: shader_out_t = parser_material_parse(ui_nodes_get_canvas_material(), con_mesh, kong, matcon);
|
||||
let sout: shader_out_t = parser_material_parse(context_raw.material.canvas, con_mesh, kong, matcon);
|
||||
parser_material_parse_height = false;
|
||||
parser_material_parse_height_as_channel = false;
|
||||
parser_material_sample_keep_aspect = false;
|
||||
|
||||
@@ -228,7 +228,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
|
||||
parser_material_triplanar = uv_type == uv_type_t.TRIPLANAR && !decal;
|
||||
parser_material_sample_keep_aspect = decal;
|
||||
parser_material_sample_uv_scale = "constants.brush_scale";
|
||||
let sout: shader_out_t = parser_material_parse(ui_nodes_get_canvas_material(), con_paint, kong, matcon);
|
||||
let sout: shader_out_t = parser_material_parse(context_raw.material.canvas, con_paint, kong, matcon);
|
||||
parser_material_parse_emission = false;
|
||||
parser_material_parse_subsurface = false;
|
||||
parser_material_parse_height_as_channel = false;
|
||||
|
||||
@@ -4775,7 +4775,7 @@ function nodes_material_create_node(node_type: string, group: node_group_t = nul
|
||||
if (n == null) {
|
||||
return null;
|
||||
}
|
||||
let canvas: ui_node_canvas_t = group != null ? group.canvas : context_raw.material.canvas;
|
||||
let canvas: ui_node_canvas_t = group != null ? group.canvas : ui_nodes_get_canvas();
|
||||
let nodes: ui_nodes_t = group != null ? group.nodes : context_raw.material.nodes;
|
||||
let node: ui_node_t = ui_nodes_make_node(n, nodes, canvas);
|
||||
array_push(canvas.nodes, node);
|
||||
|
||||
@@ -328,7 +328,7 @@ function tab_materials_update_material_pointers(nodes: ui_node_t[], i: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
function tab_materials_accept_swatch_drag(swatch: swatch_color_t) {
|
||||
function tab_materials_accept_swatch_drop(swatch: swatch_color_t) {
|
||||
context_raw.material = slot_material_create(project_materials[0].data);
|
||||
for (let i: i32 = 0; i < context_raw.material.canvas.nodes.length; ++i) {
|
||||
let node: ui_node_t = context_raw.material.canvas.nodes[i];
|
||||
|
||||
@@ -206,7 +206,7 @@ function tab_swatches_draw(htab: ui_handle_t) {
|
||||
tab_swatches_delete_swatch(project_raw.swatches[i]);
|
||||
}
|
||||
else if (ui_menu_button(tr("Create Material"))) {
|
||||
tab_materials_accept_swatch_drag(project_raw.swatches[i]);
|
||||
tab_materials_accept_swatch_drop(project_raw.swatches[i]);
|
||||
}
|
||||
else if (ui_menu_button(tr("Create Color Layer"))) {
|
||||
let color: i32 = project_raw.swatches[i].base;
|
||||
@@ -245,7 +245,7 @@ function tab_swatches_draw(htab: ui_handle_t) {
|
||||
}
|
||||
}
|
||||
|
||||
function tab_swatches_accept_swatch_drag(swatch: swatch_color_t) {
|
||||
function tab_swatches_accept_swatch_drop(swatch: swatch_color_t) {
|
||||
// No valid position available
|
||||
if (tab_swatches_drag_pos == -1) {
|
||||
return;
|
||||
|
||||
+10
-20
@@ -84,7 +84,7 @@ function ui_viewnodes_on_link_drag(link_drag_id: i32, is_new_link: bool) {
|
||||
}
|
||||
else {
|
||||
link_y += ui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node, link_drag.to_socket) +
|
||||
UI_OUTPUTS_H(node.outputs.length) + UI_BUTTONS_H(node);
|
||||
UI_OUTPUTS_H(node) + UI_BUTTONS_H(node);
|
||||
}
|
||||
|
||||
if (math_abs(mouse_x - link_x) > 5 || math_abs(mouse_y - link_y) > 5) { // Link length
|
||||
@@ -470,7 +470,7 @@ function ui_nodes_get_canvas(groups: bool = false): ui_node_canvas_t {
|
||||
return ui_nodes_tabs[ui_nodes_tab_index()].canvas;
|
||||
}
|
||||
else {
|
||||
return ui_nodes_get_canvas_material();
|
||||
return context_raw.material.canvas;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -478,10 +478,6 @@ function ui_nodes_get_canvas(groups: bool = false): ui_node_canvas_t {
|
||||
}
|
||||
}
|
||||
|
||||
function ui_nodes_get_canvas_material(): ui_node_canvas_t {
|
||||
return context_raw.material.canvas;
|
||||
}
|
||||
|
||||
function ui_nodes_get_nodes(): ui_nodes_t {
|
||||
if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
|
||||
if (ui_nodes_group_stack.length > 0) {
|
||||
@@ -743,17 +739,11 @@ function ui_nodes_recompile() {
|
||||
ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
|
||||
}
|
||||
else {
|
||||
|
||||
let _material: slot_material_t = context_raw.material;
|
||||
|
||||
if (ui_nodes_is_tab_selected()) {
|
||||
context_raw.material = ui_nodes_tabs[ui_nodes_tab_index()];
|
||||
}
|
||||
|
||||
layers_is_fill_material() ?
|
||||
layers_update_fill_layers() :
|
||||
util_render_make_material_preview();
|
||||
|
||||
layers_is_fill_material() ? layers_update_fill_layers() : util_render_make_material_preview();
|
||||
context_raw.material = _material;
|
||||
|
||||
if (ui_view2d_show && ui_view2d_type == view_2d_type_t.NODE) {
|
||||
@@ -1314,7 +1304,7 @@ function ui_nodes_push_undo(last_canvas: ui_node_canvas_t = null) {
|
||||
history_edit_nodes(last_canvas, ui_nodes_canvas_type, canvas_group);
|
||||
}
|
||||
|
||||
function ui_nodes_accept_asset_drag(index: i32) {
|
||||
function ui_nodes_accept_asset_drop(index: i32) {
|
||||
ui_nodes_push_undo();
|
||||
let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
|
||||
let n: ui_node_t =
|
||||
@@ -1326,7 +1316,7 @@ function ui_nodes_accept_asset_drag(index: i32) {
|
||||
ui_nodes_get_nodes().nodes_selected_id = [n.id];
|
||||
}
|
||||
|
||||
function ui_nodes_accept_layer_drag(index: i32) {
|
||||
function ui_nodes_accept_layer_drop(index: i32) {
|
||||
ui_nodes_push_undo();
|
||||
if (slot_layer_is_group(project_layers[index])) {
|
||||
return;
|
||||
@@ -1337,7 +1327,7 @@ function ui_nodes_accept_layer_drag(index: i32) {
|
||||
ui_nodes_get_nodes().nodes_selected_id = [n.id];
|
||||
}
|
||||
|
||||
function ui_nodes_accept_material_drag(index: i32) {
|
||||
function ui_nodes_accept_material_drop(index: i32) {
|
||||
ui_nodes_push_undo();
|
||||
let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
|
||||
let n: ui_node_t = nodes_material_create_node("MATERIAL", g);
|
||||
@@ -1345,7 +1335,7 @@ function ui_nodes_accept_material_drag(index: i32) {
|
||||
ui_nodes_get_nodes().nodes_selected_id = [n.id];
|
||||
}
|
||||
|
||||
function ui_nodes_accept_swatch_drag(swatch: swatch_color_t) {
|
||||
function ui_nodes_accept_swatch_drop(swatch: swatch_color_t) {
|
||||
ui_nodes_push_undo();
|
||||
let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
|
||||
let n: ui_node_t = nodes_material_create_node("RGB", g);
|
||||
@@ -1464,12 +1454,12 @@ function ui_nodes_make_group_node(group_canvas: ui_node_canvas_t, nodes: ui_node
|
||||
}
|
||||
|
||||
function ui_nodes_make_node_preview() {
|
||||
let ui_nodes: ui_nodes_t = context_raw.material.nodes;
|
||||
let ui_nodes: ui_nodes_t = ui_nodes_get_nodes();
|
||||
if (ui_nodes.nodes_selected_id.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nodes: ui_node_t[] = context_raw.material.canvas.nodes;
|
||||
let nodes: ui_node_t[] = ui_nodes_get_canvas().nodes;
|
||||
let node: ui_node_t = ui_get_node(nodes, ui_nodes.nodes_selected_id[0]);
|
||||
context_raw.node_preview_name = node.name;
|
||||
|
||||
@@ -1490,7 +1480,7 @@ function ui_nodes_make_node_preview() {
|
||||
|
||||
context_raw.node_preview_dirty = false;
|
||||
ui_nodes_hwnd.redraws = 2;
|
||||
util_render_make_node_preview(context_raw.material.canvas, node, context_raw.node_preview);
|
||||
util_render_make_node_preview(ui_nodes_get_canvas(), node, context_raw.node_preview);
|
||||
}
|
||||
|
||||
function ui_nodes_has_group(c: ui_node_canvas_t): bool {
|
||||
|
||||
Reference in New Issue
Block a user