diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 19 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.cc | 13 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.cc | 4 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.cc | 15 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_intern.hh | 2 |
5 files changed, 30 insertions, 23 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index ebbc149fceb..776845b4c99 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -25,6 +25,7 @@ #include "BLI_compiler_compat.h" #include "BLI_ghash.h" +#include "BLI_utildefines.h" #include "DNA_listBase.h" @@ -222,6 +223,16 @@ typedef int (*NodeGPUExecFunction)(struct GPUMaterial *mat, struct GPUNodeStack *in, struct GPUNodeStack *out); +typedef enum NodeResizeDirection { + NODE_RESIZE_NONE = 0, + NODE_RESIZE_TOP = (1 << 0), + NODE_RESIZE_BOTTOM = (1 << 1), + NODE_RESIZE_RIGHT = (1 << 2), + NODE_RESIZE_LEFT = (1 << 3), +} NodeResizeDirection; + +ENUM_OPERATORS(NodeResizeDirection, NODE_RESIZE_LEFT); + /** * \brief Defines a node type. * @@ -274,7 +285,7 @@ typedef struct bNodeType { */ void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); /** Optional custom resize handle polling. */ - int (*resize_area_func)(struct bNode *node, int x, int y); + NodeResizeDirection (*resize_area_func)(struct bNode *node, int x, int y); /** Optional selection area polling. */ int (*select_area_func)(struct bNode *node, int x, int y); /** Optional tweak area polling (for grabbing). */ @@ -379,12 +390,6 @@ typedef struct bNodeType { #define NODE_CLASS_ATTRIBUTE 42 #define NODE_CLASS_LAYOUT 100 -/* node resize directions */ -#define NODE_RESIZE_TOP 1 -#define NODE_RESIZE_BOTTOM 2 -#define NODE_RESIZE_RIGHT 4 -#define NODE_RESIZE_LEFT 8 - typedef enum eNodeSizePreset { NODE_SIZE_DEFAULT, NODE_SIZE_SMALL, diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 97fa93ab0bc..0602bc7e124 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -250,7 +250,7 @@ static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *pt uiItemR(layout, ptr, "use_clamp", DEFAULT_FLAGS, nullptr, ICON_NONE); } -static int node_resize_area_default(bNode *node, int x, int y) +static NodeResizeDirection node_resize_area_default(bNode *node, const int x, const int y) { if (node->flag & NODE_HIDDEN) { rctf totr = node->totr; @@ -260,12 +260,12 @@ static int node_resize_area_default(bNode *node, int x, int y) return NODE_RESIZE_RIGHT; } - return 0; + return NODE_RESIZE_NONE; } const float size = NODE_RESIZE_MARGIN; rctf totr = node->totr; - int dir = 0; + NodeResizeDirection dir = NODE_RESIZE_NONE; if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { dir |= NODE_RESIZE_RIGHT; @@ -478,18 +478,19 @@ static void node_draw_frame(const bContext *C, node->block = nullptr; } -static int node_resize_area_frame(bNode *node, int x, int y) +static NodeResizeDirection node_resize_area_frame(bNode *node, const int x, const 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; + return NODE_RESIZE_NONE; } + NodeResizeDirection dir = NODE_RESIZE_NONE; + if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { dir |= NODE_RESIZE_RIGHT; } diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index dcdfd909d9d..6452dc54544 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2284,7 +2284,7 @@ static void node_draw_hidden(const bContext *C, node->block = nullptr; } -int node_get_resize_cursor(int directions) +int node_get_resize_cursor(NodeResizeDirection directions) { if (directions == 0) { return WM_CURSOR_DEFAULT; @@ -2317,7 +2317,7 @@ void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) } } if (node) { - int dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); wmcursor = node_get_resize_cursor(dir); } } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 30c9f7ea56b..e6dae26e174 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -938,13 +938,15 @@ struct NodeSizeWidget { int directions; }; -static void node_resize_init( - bContext *C, wmOperator *op, const wmEvent *UNUSED(event), bNode *node, int dir) +static void node_resize_init(bContext *C, + wmOperator *op, + const wmEvent *UNUSED(event), + bNode *node, + NodeResizeDirection dir) { SpaceNode *snode = CTX_wm_space_node(C); - NodeSizeWidget *nsw = (NodeSizeWidget *)MEM_callocN(sizeof(NodeSizeWidget), - "size widget op data"); + NodeSizeWidget *nsw = (NodeSizeWidget *)MEM_callocN(sizeof(NodeSizeWidget), __func__); op->customdata = nsw; nsw->mxstart = snode->runtime->cursor[0] * UI_DPI_FAC; @@ -1090,15 +1092,14 @@ static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event) SpaceNode *snode = CTX_wm_space_node(C); ARegion *region = CTX_wm_region(C); bNode *node = nodeGetActive(snode->edittree); - int dir; if (node) { float cursor[2]; /* convert mouse coordinates to v2d space */ UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); - dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); - if (dir != 0) { + const NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + if (dir != NODE_RESIZE_NONE) { node_resize_init(C, op, event, node, dir); return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 6dc57c1fb79..7a1bd918745 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -97,7 +97,7 @@ void node_link_calculate_multi_input_position(const float socket_x, int node_get_colorid(bNode *node); void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node); -int node_get_resize_cursor(int directions); +int node_get_resize_cursor(NodeResizeDirection directions); void node_draw_shadow(const SpaceNode *snode, const bNode *node, float radius, float alpha); void node_draw_default(const bContext *C, ARegion *region, |