diff options
Diffstat (limited to 'source/blender/editors/space_node/node_draw.c')
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 67b4c43343e..08e073494bb 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -562,6 +562,18 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv) } +/* common handle function for operator buttons that need to select the node first */ +static void node_toggle_button_cb(struct bContext *C, void *node_argv, void *op_argv) +{ + bNode *node = (bNode*)node_argv; + const char *opname = (const char *)op_argv; + + /* select & activate only the button's node */ + node_select_single(C, node); + + WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, NULL); +} + static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node) { bNodeSocket *sock; @@ -601,39 +613,34 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT); uiRoundBox(rct->xmin, rct->ymax-NODE_DY, rct->xmax, rct->ymax, BASIS_RAD); - /* show/hide icons, note this sequence is copied in do_header_node() node_state.c */ + /* show/hide icons */ iconofs= rct->xmax - 7.0f; + /* preview */ if(node->typeinfo->flag & NODE_PREVIEW) { - float alpha = (node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))? 1.0f: 0.5f; - + uiBut *but; iconofs-=iconbutw; - uiDefIconBut(node->block, LABEL, B_REDR, ICON_MATERIAL, iconofs, rct->ymax-NODE_DY, - iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, alpha, ""); + uiBlockSetEmboss(node->block, UI_EMBOSSN); + but = uiDefIconBut(node->block, TOGBUT, B_REDR, ICON_MATERIAL, + iconofs, rct->ymax-NODE_DY, iconbutw, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); + uiButSetFunc(but, node_toggle_button_cb, node, (void*)"NODE_OT_preview_toggle"); + /* XXX this does not work when node is activated and the operator called right afterwards, + * since active ID is not updated yet (needs to process the notifier). + * This can only work as visual indicator! + */ +// if (!(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))) +// uiButSetFlag(but, UI_BUT_DISABLED); + uiBlockSetEmboss(node->block, UI_EMBOSS); } + /* group edit */ if(node->type == NODE_GROUP) { - - iconofs-=iconbutw; - uiDefIconBut(node->block, LABEL, B_REDR, ICON_NODETREE, iconofs, rct->ymax-NODE_DY, - iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5, ""); - } - if(node->typeinfo->flag & NODE_OPTIONS) { - iconofs-=iconbutw; - uiDefIconBut(node->block, LABEL, B_REDR, ICON_BUTS, iconofs, rct->ymax-NODE_DY, - iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5, ""); - } - { /* always hide/reveal unused sockets */ - // XXX re-enable - /* int shade; - if(node_has_hidden_sockets(node)) - shade= -40; - else - shade= -90; */ - + uiBut *but; iconofs-=iconbutw; - - uiDefIconBut(node->block, LABEL, B_REDR, ICON_PLUS, iconofs, rct->ymax-NODE_DY, - iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5, ""); + uiBlockSetEmboss(node->block, UI_EMBOSSN); + but = uiDefIconBut(node->block, TOGBUT, B_REDR, ICON_NODETREE, + iconofs, rct->ymax-NODE_DY, iconbutw, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); + uiButSetFunc(but, node_toggle_button_cb, node, (void*)"NODE_OT_group_edit"); + uiBlockSetEmboss(node->block, UI_EMBOSS); } /* title */ @@ -643,7 +650,19 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10); /* open/close entirely? */ - UI_DrawTriIcon(rct->xmin+10.0f, rct->ymax-NODE_DY/2.0f, 'v'); + { + uiBut *but; + int but_size = UI_UNIT_X *0.6f; + /* XXX button uses a custom triangle draw below, so make it invisible without icon */ + uiBlockSetEmboss(node->block, UI_EMBOSSN); + but = uiDefBut(node->block, TOGBUT, B_REDR, "", + rct->xmin+10.0f-but_size/2, rct->ymax-NODE_DY/2.0f-but_size/2, but_size, but_size, NULL, 0, 0, 0, 0, ""); + uiButSetFunc(but, node_toggle_button_cb, node, (void*)"NODE_OT_hide_toggle"); + uiBlockSetEmboss(node->block, UI_EMBOSS); + + /* custom draw function for this button */ + UI_DrawTriIcon(rct->xmin+10.0f, rct->ymax-NODE_DY/2.0f, 'v'); + } /* this isn't doing anything for the label, so commenting out if(node->flag & SELECT) @@ -789,7 +808,19 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10); /* open entirely icon */ - UI_DrawTriIcon(rct->xmin+10.0f, centy, 'h'); + { + uiBut *but; + int but_size = UI_UNIT_X *0.6f; + /* XXX button uses a custom triangle draw below, so make it invisible without icon */ + uiBlockSetEmboss(node->block, UI_EMBOSSN); + but = uiDefBut(node->block, TOGBUT, B_REDR, "", + rct->xmin+10.0f-but_size/2, centy-but_size/2, but_size, but_size, NULL, 0, 0, 0, 0, ""); + uiButSetFunc(but, node_toggle_button_cb, node, (void*)"NODE_OT_hide_toggle"); + uiBlockSetEmboss(node->block, UI_EMBOSS); + + /* custom draw function for this button */ + UI_DrawTriIcon(rct->xmin+10.0f, centy, 'h'); + } /* disable lines */ if(node->flag & NODE_MUTED) |