A number of new features for the node editor in general and the Frame node in particular.

For an detailed user-level description of new features see the following blogpost:

http://code.blender.org/index.php/2012/05/node-editing-tweaks/

TL;DR:
* Frame node gets more usable bounding-box behavior
* Node resizing has helpful mouse cursor indicators and works on all borders
* Node selection/active colors are themeable independently
* Customizable background colors for nodes (useful for frames visual
distinction).
This commit is contained in:
Lukas Toenne
2012-05-22 14:13:33 +00:00
parent 85923aff28
commit 53b01d9002
26 changed files with 12408 additions and 11499 deletions

View File

@@ -53,6 +53,8 @@
#include "BKE_main.h"
#include "BKE_node.h"
#include "BLF_api.h"
#include "NOD_composite.h"
#include "NOD_shader.h"
@@ -79,6 +81,9 @@
#include "node_intern.h"
// XXX interface.h
extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select);
/* ****************** SOCKET BUTTON DRAW FUNCTIONS ***************** */
static void node_sync_cb(bContext *UNUSED(C), void *snode_v, void *node_v)
@@ -474,15 +479,21 @@ static int node_resize_area_default(bNode *node, int x, int y)
rctf totr= node->totr;
/* right part of node */
totr.xmin = node->totr.xmax-20.0f;
return BLI_in_rctf(&totr, x, y);
if (BLI_in_rctf(&totr, x, y))
return NODE_RESIZE_RIGHT;
else
return 0;
}
else {
/* rect we're interested in is just the bottom right corner */
const float size = 10.0f;
rctf totr= node->totr;
/* bottom right corner */
totr.xmin = totr.xmax-10.0f;
totr.ymax = totr.ymin+10.0f;
return BLI_in_rctf(&totr, x, y);
int dir = 0;
if (x >= totr.xmax-size && x < totr.xmax && y >= totr.ymin && y < totr.ymax)
dir |= NODE_RESIZE_RIGHT;
if (x >= totr.xmin && x < totr.xmin+size && y >= totr.ymin && y < totr.ymax)
dir |= NODE_RESIZE_LEFT;
return dir;
}
}
@@ -511,7 +522,7 @@ static void node_update_group(const bContext *C, bNodeTree *ntree, bNode *gnode)
int dy;
/* get "global" coords */
nodeSpaceCoords(gnode, &locx, &locy);
nodeToView(gnode, 0.0f, 0.0f, &locx, &locy);
/* center them, is a bit of abuse of locx and locy though */
node_update_nodetree(C, ngroup, locx, locy);
@@ -906,20 +917,166 @@ static void node_common_buts_whileloop(uiLayout *layout, bContext *UNUSED(C), Po
uiItemR(layout, ptr, "max_iterations", 0, NULL, 0);
}
static void node_update_frame(const bContext *UNUSED(C), bNodeTree *UNUSED(ntree), bNode *node)
/* XXX Does a bounding box update by iterating over all children.
* Not ideal to do this in every draw call, but doing as transform callback doesn't work,
* since the child node totr rects are not updated properly at that point.
*/
static void node_update_frame(const bContext *UNUSED(C), bNodeTree *ntree, bNode *node)
{
float locx, locy;
const float margin = 30.0f;
NodeFrame *data = (NodeFrame *)node->storage;
int bbinit;
bNode *tnode;
rctf rect, noderect;
float xmax, ymax;
/* init rect from current frame size */
nodeToView(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax);
nodeToView(node, node->offsetx+node->width, node->offsety-node->height, &rect.xmax, &rect.ymin);
/* frame can be resized manually only if shrinking is disabled or no children are attached */
data->flag |= NODE_FRAME_RESIZEABLE;
/* for shrinking bbox, initialize the rect from first child node */
bbinit = (data->flag & NODE_FRAME_SHRINK);
/* fit bounding box to all children */
for (tnode=ntree->nodes.first; tnode; tnode=tnode->next) {
if (tnode->parent!=node)
continue;
/* add margin to node rect */
noderect = tnode->totr;
noderect.xmin -= margin;
noderect.xmax += margin;
noderect.ymin -= margin;
noderect.ymax += margin;
/* first child initializes frame */
if (bbinit) {
bbinit = 0;
rect = noderect;
data->flag &= ~NODE_FRAME_RESIZEABLE;
}
else
BLI_union_rctf(&rect, &noderect);
}
/* now adjust the frame size from view-space bounding box */
nodeFromView(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety);
nodeFromView(node, rect.xmax, rect.ymin, &xmax, &ymax);
node->width = xmax - node->offsetx;
node->height = -ymax + node->offsety;
node->totr = rect;
}
/* get "global" coords */
nodeSpaceCoords(node, &locx, &locy);
static void node_draw_frame_label(bNode *node)
{
/* XXX font id is crap design */
const int fontid = blf_mono_font;
NodeFrame *data = (NodeFrame *)node->storage;
rctf *rct= &node->totr;
int color_id= node_get_colorid(node);
char label[128];
/* XXX a bit hacky, should use separate align values for x and y */
float width, ascender;
float x, y;
BLI_strncpy(label, nodeLabel(node), sizeof(label));
BLF_size(fontid, data->label_size, U.dpi);
/* title color */
UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.8f, 10);
node->prvr.xmin = locx + NODE_DYS;
node->prvr.xmax = locx + node->width- NODE_DYS;
width = BLF_width(fontid, label);
ascender = BLF_ascender(fontid);
x = 0.5f*(rct->xmin + rct->xmax) - 0.5f*width;
y = rct->ymax - NODE_DYS - ascender;
BLF_position(fontid, x, y, 0);
BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX);
}
node->totr.xmin = locx;
node->totr.xmax = locx + node->width;
node->totr.ymax = locy;
node->totr.ymin = locy - node->height;
static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *UNUSED(ntree), bNode *node)
{
rctf *rct= &node->totr;
int color_id= node_get_colorid(node);
/* skip if out of view */
if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) {
uiEndBlock(C, node->block);
node->block= NULL;
return;
}
/* shadow */
node_draw_shadow(snode, node, BASIS_RAD);
/* body */
if (node->flag & NODE_CUSTOM_COLOR)
glColor3fv(node->color);
else
UI_ThemeColor4(TH_NODE);
glEnable(GL_BLEND);
uiSetRoundBox(UI_CNR_ALL);
uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
glDisable(GL_BLEND);
/* outline active and selected emphasis */
if ( node->flag & (NODE_ACTIVE|SELECT) ) {
glEnable(GL_BLEND);
glEnable( GL_LINE_SMOOTH );
if (node->flag & NODE_ACTIVE)
UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
else
UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
uiSetRoundBox(UI_CNR_ALL);
uiDrawBox(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
glDisable( GL_LINE_SMOOTH );
glDisable(GL_BLEND);
}
/* label */
node_draw_frame_label(node);
UI_ThemeClearColor(color_id);
uiEndBlock(C, node->block);
uiDrawBlock(C, node->block);
node->block= NULL;
}
static int node_resize_area_frame(bNode *node, int x, int y)
{
const float size = 10.0f;
NodeFrame *data = (NodeFrame *)node->storage;
rctf totr= node->totr;
int dir = 0;
/* shrinking frame size is determined by child nodes */
if (!(data->flag & NODE_FRAME_RESIZEABLE))
return 0;
if (x >= totr.xmax-size && x < totr.xmax && y >= totr.ymin && y < totr.ymax)
dir |= NODE_RESIZE_RIGHT;
if (x >= totr.xmin && x < totr.xmin+size && y >= totr.ymin && y < totr.ymax)
dir |= NODE_RESIZE_LEFT;
if (x >= totr.xmin && x < totr.xmax && y >= totr.ymax-size && y < totr.ymax)
dir |= NODE_RESIZE_TOP;
if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin+size)
dir |= NODE_RESIZE_BOTTOM;
return dir;
}
static void node_buts_frame_details(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "label_size", 0, "Label Size", ICON_NONE);
uiItemR(layout, ptr, "shrink", 0, "Shrink", ICON_NONE);
}
static void node_common_set_butfunc(bNodeType *ntype)
@@ -941,7 +1098,10 @@ static void node_common_set_butfunc(bNodeType *ntype)
ntype->drawupdatefunc= node_update_group;
break;
case NODE_FRAME:
ntype->drawfunc= node_draw_frame;
ntype->drawupdatefunc= node_update_frame;
ntype->uifuncbut= node_buts_frame_details;
ntype->resize_area_func= node_resize_area_frame;
break;
}
}
@@ -1136,7 +1296,6 @@ static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *
/* only once called */
static void node_shader_set_butfunc(bNodeType *ntype)
{
ntype->uifuncbut = NULL;
switch (ntype->type) {
/* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
@@ -1215,7 +1374,6 @@ static void node_shader_set_butfunc(bNodeType *ntype)
ntype->uifunc= node_shader_buts_dynamic;
break;
}
if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
}
/* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
@@ -2233,7 +2391,6 @@ static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C),
/* only once called */
static void node_composit_set_butfunc(bNodeType *ntype)
{
ntype->uifuncbut = NULL;
switch (ntype->type) {
/* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
@@ -2424,8 +2581,6 @@ static void node_composit_set_butfunc(bNodeType *ntype)
default:
ntype->uifunc= NULL;
}
if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
}
/* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
@@ -2536,7 +2691,6 @@ static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), Poin
/* only once called */
static void node_texture_set_butfunc(bNodeType *ntype)
{
ntype->uifuncbut = NULL;
if ( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
ntype->uifunc = node_texture_buts_proc;
}
@@ -2580,10 +2734,6 @@ static void node_texture_set_butfunc(bNodeType *ntype)
break;
}
}
if (ntype->uifuncbut == NULL) {
ntype->uifuncbut = ntype->uifunc;
}
}
/* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */