Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_draw.c
| Show First 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* flags used in gpu_shader_keyframe_diamond_frag.glsl */ | /* flags used in gpu_shader_keyframe_diamond_frag.glsl */ | ||||
| #define MARKER_SHAPE_DIAMOND 0x1 | #define MARKER_SHAPE_DIAMOND 0x1 | ||||
| #define MARKER_SHAPE_SQUARE 0xC | #define MARKER_SHAPE_SQUARE 0xC | ||||
| #define MARKER_SHAPE_CIRCLE 0x2 | #define MARKER_SHAPE_CIRCLE 0x2 | ||||
| #define MARKER_SHAPE_INNER_DOT 0x10 | #define MARKER_SHAPE_INNER_DOT 0x10 | ||||
| static void node_socket_draw(const bContext *C, | static uint node_socket_draw(const bNodeSocket *sock, | ||||
Severin: Don't ask why I changed this return type, no clue. (Will undo before committing.) | |||||
| bNodeTree *ntree, | const float color[4], | ||||
| PointerRNA node_ptr, | const float color_outline[4], | ||||
| bNodeSocket *sock, | float size, | ||||
| int locx, | |||||
| int locy, | |||||
| uint pos_id, | uint pos_id, | ||||
| uint col_id, | uint col_id, | ||||
| uint shape_id, | uint shape_id, | ||||
| uint size_id, | uint size_id, | ||||
| uint outline_col_id, | uint outline_col_id) | ||||
| float size, | |||||
| bool selected) | |||||
| { | { | ||||
| PointerRNA ptr; | int flags; | ||||
| float color[4]; | |||||
| float outline_color[4]; | |||||
| uint flags = 0; | |||||
| RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); | |||||
| sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); | |||||
| bNode *node = node_ptr.data; | |||||
| if (node->flag & NODE_MUTED) { | |||||
| color[3] *= 0.25f; | |||||
| } | |||||
| if (selected) { | |||||
| UI_GetThemeColor4fv(TH_TEXT_HI, outline_color); | |||||
| outline_color[3] = 0.9f; | |||||
| } | |||||
| else { | |||||
| copy_v4_fl(outline_color, 0.0f); | |||||
| outline_color[3] = 0.6f; | |||||
| } | |||||
| /* sets shape flags */ | /* sets shape flags */ | ||||
| switch (sock->display_shape) { | switch (sock->display_shape) { | ||||
| case SOCK_DISPLAY_SHAPE_DIAMOND: | case SOCK_DISPLAY_SHAPE_DIAMOND: | ||||
| case SOCK_DISPLAY_SHAPE_DIAMOND_DOT: | case SOCK_DISPLAY_SHAPE_DIAMOND_DOT: | ||||
| flags = MARKER_SHAPE_DIAMOND; | flags = MARKER_SHAPE_DIAMOND; | ||||
| break; | break; | ||||
| case SOCK_DISPLAY_SHAPE_SQUARE: | case SOCK_DISPLAY_SHAPE_SQUARE: | ||||
| Show All 12 Lines | if (ELEM(sock->display_shape, | ||||
| SOCK_DISPLAY_SHAPE_SQUARE_DOT, | SOCK_DISPLAY_SHAPE_SQUARE_DOT, | ||||
| SOCK_DISPLAY_SHAPE_CIRCLE_DOT)) { | SOCK_DISPLAY_SHAPE_CIRCLE_DOT)) { | ||||
| flags |= MARKER_SHAPE_INNER_DOT; | flags |= MARKER_SHAPE_INNER_DOT; | ||||
| } | } | ||||
| immAttr4fv(col_id, color); | immAttr4fv(col_id, color); | ||||
| immAttr1u(shape_id, flags); | immAttr1u(shape_id, flags); | ||||
| immAttr1f(size_id, size); | immAttr1f(size_id, size); | ||||
| immAttr4fv(outline_col_id, outline_color); | immAttr4fv(outline_col_id, color_outline); | ||||
| immVertex2f(pos_id, sock->locx, sock->locy); | immVertex2f(pos_id, locx, locy); | ||||
| return flags; | |||||
| } | |||||
| static void node_socket_outline_color_get(bool selected, float r_outline_color[4]) | |||||
| { | |||||
| if (selected) { | |||||
| UI_GetThemeColor4fv(TH_TEXT_HI, r_outline_color); | |||||
| r_outline_color[3] = 0.9f; | |||||
| } | |||||
| else { | |||||
| copy_v4_fl(r_outline_color, 0.0f); | |||||
| r_outline_color[3] = 0.6f; | |||||
| } | |||||
| } | |||||
| /* Usual convention here would be node_socket_get_color(), but that's already used (for setting a | |||||
| * color property socket). */ | |||||
| void node_socket_color_get( | |||||
| bContext *C, bNodeTree *ntree, PointerRNA *node_ptr, bNodeSocket *sock, float r_color[4]) | |||||
| { | |||||
| PointerRNA ptr; | |||||
| BLI_assert(RNA_struct_is_a(node_ptr->type, &RNA_Node)); | |||||
| RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); | |||||
| sock->typeinfo->draw_color(C, &ptr, node_ptr, r_color); | |||||
| bNode *node = node_ptr->data; | |||||
| if (node->flag & NODE_MUTED) { | |||||
| r_color[3] *= 0.25f; | |||||
| } | |||||
| } | |||||
| static void node_socket_draw_nested(const bContext *C, | |||||
| bNodeTree *ntree, | |||||
| PointerRNA *node_ptr, | |||||
| bNodeSocket *sock, | |||||
| uint pos_id, | |||||
| uint col_id, | |||||
| uint shape_id, | |||||
| uint size_id, | |||||
| uint outline_col_id, | |||||
| float size, | |||||
| bool selected) | |||||
| { | |||||
| float color[4]; | |||||
| float outline_color[4]; | |||||
| node_socket_color_get((bContext *)C, ntree, node_ptr, sock, color); | |||||
| node_socket_outline_color_get(selected, outline_color); | |||||
| node_socket_draw(sock, | |||||
| color, | |||||
| outline_color, | |||||
| size, | |||||
| sock->locx, | |||||
| sock->locy, | |||||
| pos_id, | |||||
| col_id, | |||||
| shape_id, | |||||
| size_id, | |||||
| outline_col_id); | |||||
| } | |||||
| /** | |||||
| * Draw a single node socket at default size. | |||||
| * \note this is only called from external code, internally #node_socket_draw_nested() is used for | |||||
| * optimized drawing of multiple/all sockets of a node. | |||||
| */ | |||||
| void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale) | |||||
| { | |||||
| const float size = 2.25f * NODE_SOCKSIZE * scale; | |||||
| rcti draw_rect = *rect; | |||||
| float outline_color[4] = {0}; | |||||
| node_socket_outline_color_get(sock->flag & SELECT, outline_color); | |||||
| BLI_rcti_resize(&draw_rect, size, size); | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| uint col_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| uint shape_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT); | |||||
| uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | |||||
| uint outline_col_id = GPU_vertformat_attr_add( | |||||
| format, "outlineColor", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| gpuPushAttr(GPU_BLEND_BIT); | |||||
| GPU_blend(true); | |||||
| GPU_program_point_size(true); | |||||
| immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND); | |||||
| immUniform1f("outline_scale", 0.7f); | |||||
| immUniform2f("ViewportSize", -1.0f, -1.0f); | |||||
| /* Single point */ | |||||
| immBegin(GPU_PRIM_POINTS, 1); | |||||
| node_socket_draw(sock, | |||||
| color, | |||||
| outline_color, | |||||
| BLI_rcti_size_y(&draw_rect), | |||||
| BLI_rcti_cent_x(&draw_rect), | |||||
| BLI_rcti_cent_y(&draw_rect), | |||||
| pos_id, | |||||
| col_id, | |||||
| shape_id, | |||||
| size_id, | |||||
| outline_col_id); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| GPU_program_point_size(false); | |||||
| gpuPopAttr(); | |||||
| } | } | ||||
| /* ************** Socket callbacks *********** */ | /* ************** Socket callbacks *********** */ | ||||
| static void node_draw_preview_background(float tile, rctf *rect) | static void node_draw_preview_background(float tile, rctf *rect) | ||||
| { | { | ||||
| float x, y; | float x, y; | ||||
| ▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | for (sock = node->inputs.first; sock; sock = sock->next) { | ||||
| if (nodeSocketIsHidden(sock)) { | if (nodeSocketIsHidden(sock)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (select_all || (sock->flag & SELECT)) { | if (select_all || (sock->flag & SELECT)) { | ||||
| selected_input_len++; | selected_input_len++; | ||||
| continue; | continue; | ||||
| } | } | ||||
| node_socket_draw(C, | node_socket_draw_nested(C, | ||||
| ntree, | ntree, | ||||
| node_ptr, | &node_ptr, | ||||
| sock, | sock, | ||||
| pos_id, | pos_id, | ||||
| col_id, | col_id, | ||||
| shape_id, | shape_id, | ||||
| size_id, | size_id, | ||||
| outline_col_id, | outline_col_id, | ||||
| scale, | scale, | ||||
| selected); | selected); | ||||
| } | } | ||||
| /* socket outputs */ | /* socket outputs */ | ||||
| short selected_output_len = 0; | short selected_output_len = 0; | ||||
| if (draw_outputs) { | if (draw_outputs) { | ||||
| for (sock = node->outputs.first; sock; sock = sock->next) { | for (sock = node->outputs.first; sock; sock = sock->next) { | ||||
| if (nodeSocketIsHidden(sock)) { | if (nodeSocketIsHidden(sock)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (select_all || (sock->flag & SELECT)) { | if (select_all || (sock->flag & SELECT)) { | ||||
| selected_output_len++; | selected_output_len++; | ||||
| continue; | continue; | ||||
| } | } | ||||
| node_socket_draw(C, | node_socket_draw_nested(C, | ||||
| ntree, | ntree, | ||||
| node_ptr, | &node_ptr, | ||||
| sock, | sock, | ||||
| pos_id, | pos_id, | ||||
| col_id, | col_id, | ||||
| shape_id, | shape_id, | ||||
| size_id, | size_id, | ||||
| outline_col_id, | outline_col_id, | ||||
| scale, | scale, | ||||
| selected); | selected); | ||||
| } | } | ||||
| } | } | ||||
| if (!select_all) { | if (!select_all) { | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| /* go back and draw selected sockets */ | /* go back and draw selected sockets */ | ||||
| if (selected_input_len + selected_output_len > 0) { | if (selected_input_len + selected_output_len > 0) { | ||||
| /* outline for selected sockets */ | /* outline for selected sockets */ | ||||
| selected = true; | selected = true; | ||||
| immBegin(GPU_PRIM_POINTS, selected_input_len + selected_output_len); | immBegin(GPU_PRIM_POINTS, selected_input_len + selected_output_len); | ||||
| if (selected_input_len) { | if (selected_input_len) { | ||||
| /* socket inputs */ | /* socket inputs */ | ||||
| for (sock = node->inputs.first; sock; sock = sock->next) { | for (sock = node->inputs.first; sock; sock = sock->next) { | ||||
| if (nodeSocketIsHidden(sock)) { | if (nodeSocketIsHidden(sock)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (select_all || (sock->flag & SELECT)) { | if (select_all || (sock->flag & SELECT)) { | ||||
| node_socket_draw(C, | node_socket_draw_nested(C, | ||||
| ntree, | ntree, | ||||
| node_ptr, | &node_ptr, | ||||
| sock, | sock, | ||||
| pos_id, | pos_id, | ||||
| col_id, | col_id, | ||||
| shape_id, | shape_id, | ||||
| size_id, | size_id, | ||||
| outline_col_id, | outline_col_id, | ||||
| scale, | scale, | ||||
| selected); | selected); | ||||
| if (--selected_input_len == 0) { | if (--selected_input_len == 0) { | ||||
| break; /* stop as soon as last one is drawn */ | break; /* stop as soon as last one is drawn */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (selected_output_len) { | if (selected_output_len) { | ||||
| /* socket outputs */ | /* socket outputs */ | ||||
| for (sock = node->outputs.first; sock; sock = sock->next) { | for (sock = node->outputs.first; sock; sock = sock->next) { | ||||
| if (nodeSocketIsHidden(sock)) { | if (nodeSocketIsHidden(sock)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (select_all || (sock->flag & SELECT)) { | if (select_all || (sock->flag & SELECT)) { | ||||
| node_socket_draw(C, | node_socket_draw_nested(C, | ||||
| ntree, | ntree, | ||||
| node_ptr, | &node_ptr, | ||||
| sock, | sock, | ||||
| pos_id, | pos_id, | ||||
| col_id, | col_id, | ||||
| shape_id, | shape_id, | ||||
| size_id, | size_id, | ||||
| outline_col_id, | outline_col_id, | ||||
| scale, | scale, | ||||
| selected); | selected); | ||||
| if (--selected_output_len == 0) { | if (--selected_output_len == 0) { | ||||
| break; /* stop as soon as last one is drawn */ | break; /* stop as soon as last one is drawn */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| ▲ Show 20 Lines • Show All 769 Lines • Show Last 20 Lines | |||||
Don't ask why I changed this return type, no clue. (Will undo before committing.)