Cleanup: Use typed enum for node resize direction
This commit is contained in:
parent
ab927f5ca7
commit
cb0fbe1fde
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue