[Bf-blender-cvs] [2af70acc3a6] master: Cleanup: reduce variable scopes in drawnode.c
Jacques Lucke
noreply at git.blender.org
Tue Sep 8 15:20:47 CEST 2020
Commit: 2af70acc3a66d49cf048e44ade55bdd71c65ed3c
Author: Jacques Lucke
Date: Tue Sep 8 15:20:07 2020 +0200
Branches: master
https://developer.blender.org/rB2af70acc3a66d49cf048e44ade55bdd71c65ed3c
Cleanup: reduce variable scopes in drawnode.c
===================================================================
M source/blender/editors/space_node/drawnode.c
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 82f3b71eb32..9db89ec1ba2 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -116,12 +116,10 @@ static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr
static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
- uiLayout *row, *col;
-
bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
- col = uiLayoutColumn(layout, false);
- row = uiLayoutRow(col, true);
+ uiLayout *col = uiLayoutColumn(layout, false);
+ uiLayout *row = uiLayoutRow(col, true);
uiItemR(row, ptr, "blend_type", DEFAULT_FLAGS, "", ICON_NONE);
if (ELEM(ntree->type, NTREE_COMPOSIT, NTREE_TEXTURE)) {
uiItemR(row, ptr, "use_alpha", DEFAULT_FLAGS, "", ICON_IMAGE_RGB_ALPHA);
@@ -132,7 +130,6 @@ static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA
static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
- uiLayout *row;
#if 0
/* XXX no context access here .. */
bNode *node = ptr->data;
@@ -148,7 +145,7 @@ static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *pt
uiTemplateCurveMapping(layout, ptr, "curve", 's', false, false, false, false);
- row = uiLayoutRow(layout, true);
+ uiLayout *row = uiLayoutRow(layout, true);
uiItemR(row, ptr, "frame_start", DEFAULT_FLAGS, IFACE_("Sta"), ICON_NONE);
uiItemR(row, ptr, "frame_end", DEFAULT_FLAGS, IFACE_("End"), ICON_NONE);
}
@@ -317,12 +314,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
{
const float margin = 1.5f * U.widget_unit;
NodeFrame *data = (NodeFrame *)node->storage;
- bool bbinit;
- bNode *tnode;
- rctf rect, noderect;
- float xmax, ymax;
/* init rect from current frame size */
+ rctf rect;
node_to_view(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax);
node_to_view(
node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin);
@@ -330,15 +324,15 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
/* 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);
+ bool bbinit = (data->flag & NODE_FRAME_SHRINK);
/* fit bounding box to all children */
- for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
+ LISTBASE_FOREACH (bNode *, tnode, &ntree->nodes) {
if (tnode->parent != node) {
continue;
}
/* add margin to node rect */
- noderect = tnode->totr;
+ rctf noderect = tnode->totr;
noderect.xmin -= margin;
noderect.xmax += margin;
noderect.ymin -= margin;
@@ -357,6 +351,7 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
/* now adjust the frame size from view-space bounding box */
node_from_view(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety);
+ float xmax, ymax;
node_from_view(node, rect.xmax, rect.ymin, &xmax, &ymax);
node->width = xmax - node->offsetx;
node->height = -ymax + node->offsety;
@@ -369,17 +364,9 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
/* XXX font id is crap design */
const int fontid = UI_style_get()->widgetlabel.uifont_id;
NodeFrame *data = (NodeFrame *)node->storage;
- rctf *rct = &node->totr;
- int color_id = node_get_colorid(node);
- char label[MAX_NAME];
- /* XXX a bit hacky, should use separate align values for x and y */
- float width, ascender;
- float x, y;
const int font_size = data->label_size / aspect;
- const float margin = (float)(NODE_DY / 4);
- int label_height;
- uchar color[3];
+ char label[MAX_NAME];
nodeLabel(ntree, node, label, sizeof(label));
BLF_enable(fontid, BLF_ASPECT);
@@ -388,16 +375,21 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
BLF_size(fontid, MIN2(24, font_size), U.dpi);
/* title color */
+ int color_id = node_get_colorid(node);
+ uchar color[3];
UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
BLF_color3ubv(fontid, color);
- width = BLF_width(fontid, label, sizeof(label));
- ascender = BLF_ascender(fontid);
- label_height = ((margin / aspect) + (ascender * aspect));
+ const float margin = (float)(NODE_DY / 4);
+ const float width = BLF_width(fontid, label, sizeof(label));
+ const float ascender = BLF_ascender(fontid);
+ const int label_height = ((margin / aspect) + (ascender * aspect));
/* 'x' doesn't need aspect correction */
- x = BLI_rctf_cent_x(rct) - (0.5f * width);
- y = rct->ymax - label_height;
+ rctf *rct = &node->totr;
+ /* XXX a bit hacky, should use separate align values for x and y */
+ float x = BLI_rctf_cent_x(rct) - (0.5f * width);
+ float y = rct->ymax - label_height;
BLF_position(fontid, x, y, 0);
BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX);
@@ -405,17 +397,15 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
/* draw text body */
if (node->id) {
Text *text = (Text *)node->id;
- TextLine *line;
const int line_height_max = BLF_height_max(fontid);
const float line_spacing = (line_height_max * aspect);
const float line_width = (BLI_rctf_size_x(rct) - margin) / aspect;
- int y_min;
/* 'x' doesn't need aspect correction */
x = rct->xmin + margin;
y = rct->ymax - (label_height + line_spacing);
/* early exit */
- y_min = y + ((margin * 2) - (y - rct->ymin));
+ int y_min = y + ((margin * 2) - (y - rct->ymin));
BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
BLF_clipping(fontid,
@@ -427,7 +417,7 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
BLF_wordwrap(fontid, line_width);
- for (line = text->lines.first; line; line = line->next) {
+ LISTBASE_FOREACH (TextLine *, line, &text->lines) {
struct ResultBLF info;
if (line->line[0]) {
BLF_position(fontid, x, y, 0);
@@ -455,9 +445,6 @@ static void node_draw_frame(const bContext *C,
bNode *node,
bNodeInstanceKey UNUSED(key))
{
- rctf *rct = &node->totr;
- float color[4];
- float alpha;
/* skip if out of view */
if (BLI_rctf_isect(&node->totr, ®ion->v2d.cur, NULL) == false) {
@@ -466,8 +453,9 @@ static void node_draw_frame(const bContext *C,
return;
}
+ float color[4];
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
- alpha = color[3];
+ const float alpha = color[3];
/* shadow */
node_draw_shadow(snode, node, BASIS_RAD, alpha);
@@ -480,6 +468,7 @@ static void node_draw_frame(const bContext *C,
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
}
+ const rctf *rct = &node->totr;
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color);
@@ -544,15 +533,12 @@ static void node_draw_reroute_prepare(const bContext *UNUSED(C),
bNodeTree *UNUSED(ntree),
bNode *node)
{
- bNodeSocket *nsock;
- float locx, locy;
- float size = NODE_REROUTE_SIZE;
-
/* get "global" coords */
+ float locx, locy;
node_to_view(node, 0.0f, 0.0f, &locx, &locy);
/* reroute node has exactly one input and one output, both in the same place */
- nsock = node->outputs.first;
+ bNodeSocket *nsock = node->outputs.first;
nsock->locx = locx;
nsock->locy = locy;
@@ -560,6 +546,7 @@ static void node_draw_reroute_prepare(const bContext *UNUSED(C),
nsock->locx = locx;
nsock->locy = locy;
+ const float size = NODE_REROUTE_SIZE;
node->width = size * 2;
node->totr.xmin = locx - size;
node->totr.xmax = locx + size;
@@ -687,18 +674,15 @@ static void node_buts_image_user(uiLayout *layout,
PointerRNA *iuserptr,
bool compositor)
{
- uiLayout *col;
- int source;
-
if (!imaptr->data) {
return;
}
- col = uiLayoutColumn(layout, false);
+ uiLayout *col = uiLayoutColumn(layout, false);
uiItemR(col, imaptr, "source", DEFAULT_FLAGS, "", ICON_NONE);
- source = RNA_enum_get(imaptr, "source");
+ const int source = RNA_enum_get(imaptr, "source");
if (source == IMA_SRC_SEQUENCE) {
/* don't use iuser->framenr directly
@@ -943,8 +927,8 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout,
bNode *node = ptr->data;
NodeShaderTexPointDensity *shader_point_density = node->storage;
Object *ob = (Object *)node->id;
- PointerRNA ob_ptr, obdata_ptr;
+ PointerRNA ob_ptr, obdata_ptr;
RNA_id_pointer_create((ID *)ob, &ob_ptr);
RNA_id_pointer_create(ob ? (ID *)ob->data : NULL, &obdata_ptr);
@@ -1398,8 +1382,8 @@ static void node_buts_image_views(uiLayout *layout,
static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = ptr->data;
- PointerRNA imaptr, iuserptr;
+ PointerRNA iuserptr;
RNA_pointer_create(ptr->owner_id, &RNA_ImageUser, node->storage, &iuserptr);
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
uiTemplateID(layout,
@@ -1416,7 +1400,7 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *
return;
}
- imaptr = RNA_pointer_get(ptr, "image");
+ PointerRNA imaptr = RNA_pointer_get(ptr, "image");
node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true);
@@ -1426,8 +1410,8 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *
static void node_composit_buts_image_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = ptr->data;
- PointerRNA iuserptr;
+ PointerRNA iuserptr;
RNA_pointer_create(ptr->owner_id, &RNA_ImageUser, node->storage, &iuserptr);
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list