Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_edit.c
| Show First 20 Lines • Show All 831 Lines • ▼ Show 20 Lines | |||||
| /* ********************** size widget operator ******************** */ | /* ********************** size widget operator ******************** */ | ||||
| typedef struct NodeSizeWidget { | typedef struct NodeSizeWidget { | ||||
| float mxstart, mystart; | float mxstart, mystart; | ||||
| float oldlocx, oldlocy; | float oldlocx, oldlocy; | ||||
| float oldoffsetx, oldoffsety; | float oldoffsetx, oldoffsety; | ||||
| float oldwidth, oldheight; | float oldwidth, oldheight; | ||||
| float oldminiwidth; | |||||
| int directions; | int directions; | ||||
| } NodeSizeWidget; | } NodeSizeWidget; | ||||
| 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, int dir) | ||||
| { | { | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data"); | NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data"); | ||||
| op->customdata = nsw; | op->customdata = nsw; | ||||
| nsw->mxstart = snode->cursor[0] * UI_DPI_FAC; | nsw->mxstart = snode->cursor[0] * UI_DPI_FAC; | ||||
| nsw->mystart = snode->cursor[1] * UI_DPI_FAC; | nsw->mystart = snode->cursor[1] * UI_DPI_FAC; | ||||
| /* store old */ | /* store old */ | ||||
| nsw->oldlocx = node->locx; | nsw->oldlocx = node->locx; | ||||
| nsw->oldlocy = node->locy; | nsw->oldlocy = node->locy; | ||||
| nsw->oldoffsetx = node->offsetx; | nsw->oldoffsetx = node->offsetx; | ||||
| nsw->oldoffsety = node->offsety; | nsw->oldoffsety = node->offsety; | ||||
| nsw->oldwidth = node->width; | nsw->oldwidth = node->width; | ||||
| nsw->oldheight = node->height; | nsw->oldheight = node->height; | ||||
| nsw->oldminiwidth = node->miniwidth; | |||||
| nsw->directions = dir; | nsw->directions = dir; | ||||
| WM_cursor_modal_set(CTX_wm_window(C), node_get_resize_cursor(dir)); | WM_cursor_modal_set(CTX_wm_window(C), node_get_resize_cursor(dir)); | ||||
| /* add modal handler */ | /* add modal handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| } | } | ||||
| static void node_resize_exit(bContext *C, wmOperator *op, bool UNUSED(cancel)) | static void node_resize_exit(bContext *C, wmOperator *op, bool UNUSED(cancel)) | ||||
| Show All 15 Lines | static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case MOUSEMOVE: | case MOUSEMOVE: | ||||
| UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my); | UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my); | ||||
| dx = (mx - nsw->mxstart) / UI_DPI_FAC; | dx = (mx - nsw->mxstart) / UI_DPI_FAC; | ||||
| dy = (my - nsw->mystart) / UI_DPI_FAC; | dy = (my - nsw->mystart) / UI_DPI_FAC; | ||||
| if (node) { | if (node) { | ||||
| /* width can use node->width or node->miniwidth (hidden nodes) */ | |||||
| float *pwidth; | float *pwidth; | ||||
| float oldwidth, widthmin, widthmax; | float oldwidth, widthmin, widthmax; | ||||
| /* ignore hidden flag for frame nodes */ | |||||
| bool use_hidden = (node->type != NODE_FRAME); | |||||
| if (use_hidden && node->flag & NODE_HIDDEN) { | |||||
| pwidth = &node->miniwidth; | |||||
| oldwidth = nsw->oldminiwidth; | |||||
| widthmin = 0.0f; | |||||
| } | |||||
| else { | |||||
| pwidth = &node->width; | pwidth = &node->width; | ||||
| oldwidth = nsw->oldwidth; | oldwidth = nsw->oldwidth; | ||||
| widthmin = node->typeinfo->minwidth; | widthmin = node->typeinfo->minwidth; | ||||
JacquesLucke: I found another minor issue, but that does not seem worth the hassle for now.
The problem is… | |||||
| } | |||||
| widthmax = node->typeinfo->maxwidth; | widthmax = node->typeinfo->maxwidth; | ||||
| { | { | ||||
| if (nsw->directions & NODE_RESIZE_RIGHT) { | if (nsw->directions & NODE_RESIZE_RIGHT) { | ||||
| *pwidth = oldwidth + dx; | *pwidth = oldwidth + dx; | ||||
| CLAMP(*pwidth, widthmin, widthmax); | CLAMP(*pwidth, widthmin, widthmax); | ||||
| } | } | ||||
| if (nsw->directions & NODE_RESIZE_LEFT) { | if (nsw->directions & NODE_RESIZE_LEFT) { | ||||
| ▲ Show 20 Lines • Show All 1,835 Lines • Show Last 20 Lines | |||||
I found another minor issue, but that does not seem worth the hassle for now.
The problem is that node->typeinfo->minwidth does not contain the real minimum width when the node is collapsed.
This is due to the clamping in the drawing function.