Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_draw.c
| Show First 20 Lines • Show All 656 Lines • ▼ Show 20 Lines | static void node_circle_draw(float x, float y, float size, const float col[4], int highlight) | ||||
| glBegin(GL_LINE_LOOP); | glBegin(GL_LINE_LOOP); | ||||
| for (a = 0; a < 16; a++) | for (a = 0; a < 16; a++) | ||||
| glVertex2f(x + size * si[a], y + size * co[a]); | glVertex2f(x + size * si[a], y + size * co[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) | static void node_diamond_draw(float x, float y, float size, const float col[4], int highlight) | ||||
| { | |||||
| static const float px[4] = { | |||||
| 0.0f, | |||||
| 1.2f, | |||||
| 0.0f, | |||||
| -1.2f, | |||||
| }; | |||||
| static const float py[4] = { | |||||
| 1.2f, | |||||
| 0.0f, | |||||
| -1.2f, | |||||
| 0.0f, | |||||
| }; | |||||
| int a; | |||||
| glColor4fv(col); | |||||
| glEnable(GL_BLEND); | |||||
| glBegin(GL_POLYGON); | |||||
| for (a = 0; a < 4; a++) | |||||
| glVertex2f(x + size * px[a], y + size * py[a]); | |||||
| glEnd(); | |||||
| glDisable(GL_BLEND); | |||||
| if (highlight) { | |||||
| UI_ThemeColor(TH_TEXT_HI); | |||||
| glLineWidth(1.5f); | |||||
| } | |||||
| else { | |||||
| glColor4ub(0, 0, 0, 150); | |||||
| } | |||||
| glEnable(GL_BLEND); | |||||
| glEnable(GL_LINE_SMOOTH); | |||||
| glBegin(GL_LINE_LOOP); | |||||
| for (a = 0; a < 4; a++) | |||||
| glVertex2f(x + size * px[a], y + size * py[a]); | |||||
| glEnd(); | |||||
| glDisable(GL_LINE_SMOOTH); | |||||
| glDisable(GL_BLEND); | |||||
| } | |||||
| static void node_square_draw(float x, float y, float size, const float col[4], int highlight) | |||||
| { | |||||
| static const float px[4] = { | |||||
| -0.9f, | |||||
| 0.9f, | |||||
| 0.9f, | |||||
| -0.9f, | |||||
| }; | |||||
| static const float py[4] = { | |||||
| 0.9f, | |||||
| 0.9f, | |||||
| -0.9f, | |||||
| -0.9f, | |||||
| }; | |||||
| int a; | |||||
| glColor4fv(col); | |||||
| glEnable(GL_BLEND); | |||||
| glBegin(GL_POLYGON); | |||||
| for (a = 0; a < 4; a++) | |||||
| glVertex2f(x + size * px[a], y + size * py[a]); | |||||
| glEnd(); | |||||
| glDisable(GL_BLEND); | |||||
| if (highlight) { | |||||
| UI_ThemeColor(TH_TEXT_HI); | |||||
| glLineWidth(1.5f); | |||||
| } | |||||
| else { | |||||
| glColor4ub(0, 0, 0, 150); | |||||
| } | |||||
| glEnable(GL_BLEND); | |||||
| glEnable(GL_LINE_SMOOTH); | |||||
| glBegin(GL_LINE_LOOP); | |||||
| for (a = 0; a < 4; a++) | |||||
| glVertex2f(x + size * px[a], y + size * py[a]); | |||||
| glEnd(); | |||||
| glDisable(GL_LINE_SMOOTH); | |||||
| glDisable(GL_BLEND); | |||||
| } | |||||
| 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); | ||||
| switch (sock->shape) { | |||||
| case SOCK_SHAPE_DIAMOND: | |||||
| node_diamond_draw(sock->locx, sock->locy, size, color, highlight); | |||||
| break; | |||||
| case SOCK_SHAPE_SQUARE: | |||||
| node_square_draw(sock->locx, sock->locy, size, color, highlight); | |||||
| break; | |||||
| default: | |||||
| case SOCK_SHAPE_CIRCLE: | |||||
| node_circle_draw(sock->locx, sock->locy, size, color, highlight); | node_circle_draw(sock->locx, sock->locy, size, color, highlight); | ||||
| break; | |||||
| } | |||||
| } | } | ||||
| /* ************** 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; | ||||
| /* 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); | ||||
| for (y = rect->ymin; y < rect->ymax; y += tile * 2) { | for (y = rect->ymin; y < rect->ymax; y += tile * 2) { | ||||
| for (x = rect->xmin; x < rect->xmax; x += tile * 2) { | for (x = rect->xmin; x < rect->xmax; x += tile * 2) { | ||||
| float tilex = tile, tiley = tile; | float tilex = tile, tiley = tile; | ||||
| if (x + tile > rect->xmax) | if (x + tile > rect->xmax) | ||||
campbellbarton: Mixing different shapes into the same arrays seems unnecessarily confusing.
Why not have 3x… | |||||
| tilex = rect->xmax - x; | tilex = rect->xmax - x; | ||||
| if (y + tile > rect->ymax) | if (y + tile > rect->ymax) | ||||
| tiley = rect->ymax - y; | tiley = rect->ymax - y; | ||||
| glRectf(x, y, x + tilex, y + tiley); | glRectf(x, y, x + tilex, y + tiley); | ||||
| } | } | ||||
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… | |||||
| } | } | ||||
| for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) { | for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) { | ||||
| for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) { | for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) { | ||||
| float tilex = tile, tiley = tile; | float tilex = tile, tiley = tile; | ||||
| if (x + tile > rect->xmax) | if (x + tile > rect->xmax) | ||||
| tilex = rect->xmax - x; | tilex = rect->xmax - x; | ||||
| if (y + tile > rect->ymax) | if (y + tile > rect->ymax) | ||||
| ▲ Show 20 Lines • Show All 224 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));