Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_draw.c
| Show First 20 Lines • Show All 611 Lines • ▼ Show 20 Lines | static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node) | ||||
| for (link = node->internal_links.first; link; link = link->next) | for (link = node->internal_links.first; link; link = link->next) | ||||
| node_draw_link_bezier(v2d, snode, link, TH_REDALERT, 0, TH_WIRE, 0, TH_WIRE); | node_draw_link_bezier(v2d, snode, link, TH_REDALERT, 0, TH_WIRE, 0, TH_WIRE); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glDisable(GL_LINE_SMOOTH); | glDisable(GL_LINE_SMOOTH); | ||||
| } | } | ||||
| /* this might have some more generic use */ | static void node_socket_shape_draw(float x, float y, float size, const float col[4], int highlight, const float px[24], const float py[24], int start, int end) | ||||
| static void node_circle_draw(float x, float y, float size, const float col[4], int highlight) | |||||
| { | { | ||||
| /* 16 values of sin function */ | |||||
| static const float si[16] = { | |||||
| 0.00000000f, 0.39435585f, 0.72479278f, 0.93775213f, | |||||
| 0.99871650f, 0.89780453f, 0.65137248f, 0.29936312f, | |||||
| -0.10116832f, -0.48530196f, -0.79077573f, -0.96807711f, | |||||
| -0.98846832f, -0.84864425f, -0.57126821f, -0.20129852f | |||||
| }; | |||||
| /* 16 values of cos function */ | |||||
| static const float co[16] = { | |||||
| 1.00000000f, 0.91895781f, 0.68896691f, 0.34730525f, | |||||
| -0.05064916f, -0.44039415f, -0.75875812f, -0.95413925f, | |||||
| -0.99486932f, -0.87434661f, -0.61210598f, -0.25065253f, | |||||
| 0.15142777f, 0.52896401f, 0.82076344f, 0.97952994f, | |||||
| }; | |||||
| int a; | int a; | ||||
| glColor4fv(col); | glColor4fv(col); | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glBegin(GL_POLYGON); | glBegin(GL_POLYGON); | ||||
| for (a = 0; a < 16; a++) | for (a = start; a < end; a++) | ||||
| glVertex2f(x + size * si[a], y + size * co[a]); | glVertex2f(x + size * px[a], y + size * py[a]); | ||||
| glEnd(); | glEnd(); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| if (highlight) { | if (highlight) { | ||||
| UI_ThemeColor(TH_TEXT_HI); | UI_ThemeColor(TH_TEXT_HI); | ||||
| glLineWidth(1.5f); | glLineWidth(1.5f); | ||||
| } | } | ||||
| else { | else { | ||||
| glColor4ub(0, 0, 0, 150); | glColor4ub(0, 0, 0, 150); | ||||
| } | } | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glEnable(GL_LINE_SMOOTH); | glEnable(GL_LINE_SMOOTH); | ||||
| glBegin(GL_LINE_LOOP); | glBegin(GL_LINE_LOOP); | ||||
| for (a = 0; a < 16; a++) | for (a = start; a < end; a++) | ||||
| glVertex2f(x + size * si[a], y + size * co[a]); | glVertex2f(x + size * px[a], y + size * py[a]); | ||||
| glEnd(); | glEnd(); | ||||
| glDisable(GL_LINE_SMOOTH); | glDisable(GL_LINE_SMOOTH); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| } | } | ||||
| void node_socket_circle_draw(const bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *sock, float size, int highlight) | |||||
| void node_socket_draw(const bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *sock, float size, int highlight) | |||||
| { | { | ||||
| PointerRNA ptr, node_ptr; | PointerRNA ptr, node_ptr; | ||||
| float color[4]; | float color[4]; | ||||
| RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); | RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); | ||||
| RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr); | RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr); | ||||
| sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); | sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); | ||||
| node_circle_draw(sock->locx, sock->locy, size, color, highlight); | |||||
| /* 16 values of sin function + other shape data */ | |||||
| static const float px[24] = { | |||||
| 0.00000000f, 0.39435585f, 0.72479278f, 0.93775213f, | |||||
| 0.99871650f, 0.89780453f, 0.65137248f, 0.29936312f, | |||||
| -0.10116832f, -0.48530196f, -0.79077573f, -0.96807711f, | |||||
| -0.98846832f, -0.84864425f, -0.57126821f, -0.20129852f, //circle end | |||||
| 0.0f, 1.2f, 0.0f, -1.2f, //diamond | |||||
| -0.9f, 0.9f, 0.9f, -0.9f, //square | |||||
| }; | |||||
| /* 16 values of cos function + other shape data */ | |||||
| static const float py[24] = { | |||||
| 1.00000000f, 0.91895781f, 0.68896691f, 0.34730525f, | |||||
| -0.05064916f, -0.44039415f, -0.75875812f, -0.95413925f, | |||||
| -0.99486932f, -0.87434661f, -0.61210598f, -0.25065253f, | |||||
| 0.15142777f, 0.52896401f, 0.82076344f, 0.97952994f, //circle end | |||||
| 1.2f, 0.0f, -1.2f, 0.0f, //diamond | |||||
| 0.9f, 0.9f, -0.9f, -0.9f, //square | |||||
| }; | |||||
| switch (sock->shape) { | |||||
| default: | |||||
| case SOCK_SHAPE_CIRCLE: | |||||
| node_socket_shape_draw(sock->locx, sock->locy, size, color, highlight, px, py, 0, 16); | |||||
| break; | |||||
| case SOCK_SHAPE_DIAMOND: | |||||
| node_socket_shape_draw(sock->locx, sock->locy, size, color, highlight, px, py, 16, 20); | |||||
| break; | |||||
| case SOCK_SHAPE_SQUARE: | |||||
| node_socket_shape_draw(sock->locx, sock->locy, size, color, highlight, px, py, 20, 24); | |||||
| break; | |||||
campbellbarton: Mixing different shapes into the same arrays seems unnecessarily confusing.
Why not have 3x… | |||||
| } | |||||
| } | } | ||||
| /* ************** Socket callbacks *********** */ | /* ************** Socket callbacks *********** */ | ||||
| static void node_draw_preview_background(float tile, rctf *rect) | static void node_draw_preview_background(float tile, rctf *rect) | ||||
Not Done Inline ActionsWhy not use ARRAY_SIZE like Campbell suggested? Makes things less error prone when changing array size. Severin: Why not use `ARRAY_SIZE` like Campbell suggested? Makes things less error prone when changing… | |||||
| { | { | ||||
| float x, y; | float x, y; | ||||
| /* draw checkerboard backdrop to show alpha */ | /* draw checkerboard backdrop to show alpha */ | ||||
| glColor3ub(120, 120, 120); | glColor3ub(120, 120, 120); | ||||
| glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); | glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); | ||||
| glColor3ub(160, 160, 160); | glColor3ub(160, 160, 160); | ||||
| ▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | if (node->flag & NODE_MUTED) | ||||
| node_draw_mute_line(v2d, snode, node); | node_draw_mute_line(v2d, snode, node); | ||||
| /* socket inputs, buttons */ | /* socket inputs, buttons */ | ||||
| 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; | ||||
| node_socket_circle_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT); | node_socket_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT); | ||||
| } | } | ||||
| /* 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; | ||||
| node_socket_circle_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT); | node_socket_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT); | ||||
| } | } | ||||
| /* preview */ | /* preview */ | ||||
| if (node->flag & NODE_PREVIEW && previews) { | if (node->flag & NODE_PREVIEW && previews) { | ||||
| bNodePreview *preview = BKE_node_instance_hash_lookup(previews, key); | bNodePreview *preview = BKE_node_instance_hash_lookup(previews, key); | ||||
| if (preview && (preview->xsize && preview->ysize)) { | if (preview && (preview->xsize && preview->ysize)) { | ||||
| if (preview->rect && !BLI_rctf_is_empty(&node->prvr)) { | if (preview->rect && !BLI_rctf_is_empty(&node->prvr)) { | ||||
| node_draw_preview(preview, &node->prvr); | node_draw_preview(preview, &node->prvr); | ||||
| ▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key)) | ||||
| UI_ThemeColorShade(color_id, +30); | UI_ThemeColorShade(color_id, +30); | ||||
| dx -= snode->aspect; | dx -= snode->aspect; | ||||
| fdrawline(rct->xmax - dx, centy - 4.0f, rct->xmax - dx, centy + 4.0f); | fdrawline(rct->xmax - dx, centy - 4.0f, rct->xmax - dx, centy + 4.0f); | ||||
| fdrawline(rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); | fdrawline(rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); | ||||
| /* sockets */ | /* sockets */ | ||||
| for (sock = node->inputs.first; sock; sock = sock->next) { | for (sock = node->inputs.first; sock; sock = sock->next) { | ||||
| if (!nodeSocketIsHidden(sock)) | if (!nodeSocketIsHidden(sock)) | ||||
| node_socket_circle_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT); | node_socket_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT); | ||||
| } | } | ||||
| for (sock = node->outputs.first; sock; sock = sock->next) { | for (sock = node->outputs.first; sock; sock = sock->next) { | ||||
| if (!nodeSocketIsHidden(sock)) | if (!nodeSocketIsHidden(sock)) | ||||
| node_socket_circle_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT); | node_socket_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT); | ||||
| } | } | ||||
| UI_block_end(C, node->block); | UI_block_end(C, node->block); | ||||
| UI_block_draw(C, node->block); | UI_block_draw(C, node->block); | ||||
| node->block = NULL; | node->block = NULL; | ||||
| } | } | ||||
| int node_get_resize_cursor(int directions) | int node_get_resize_cursor(int directions) | ||||
| ▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines | |||||
Mixing different shapes into the same arrays seems unnecessarily confusing.
Why not have 3x arrays:
shape_cirlce[][2] = {...}; shape_diamond[][2] = {...}; shape_square[][2] = {...};Then pass each as a single argument & length: node_socket_shape_draw(..., shape_diamond, ARRAY_SIZE(shape_diamond));