Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_view.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Background Image Operators | /** \name Background Image Operators | ||||
| * \{ */ | * \{ */ | ||||
| struct NodeViewMove { | struct NodeViewMove { | ||||
| int mvalo[2]; | int mvalo[2]; | ||||
| int xmin, ymin, xmax, ymax; | int xmin, ymin, xmax, ymax; | ||||
| /** Original Offset for cancel. */ | |||||
| float xof, yof; | |||||
campbellbarton: Best use `x/yofs_orig` otherwise it's not clear when reading the code elsewhere these are… | |||||
| }; | }; | ||||
| static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) | static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| NodeViewMove *nvm = (NodeViewMove *)op->customdata; | NodeViewMove *nvm = (NodeViewMove *)op->customdata; | ||||
| Show All 12 Lines | |||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| WM_main_add_notifier(NC_NODE | ND_DISPLAY, nullptr); | WM_main_add_notifier(NC_NODE | ND_DISPLAY, nullptr); | ||||
| WM_main_add_notifier(NC_SPACE | ND_SPACE_NODE_VIEW, nullptr); | WM_main_add_notifier(NC_SPACE | ND_SPACE_NODE_VIEW, nullptr); | ||||
| break; | break; | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| case MIDDLEMOUSE: | case MIDDLEMOUSE: | ||||
| case RIGHTMOUSE: | |||||
| if (event->val == KM_RELEASE) { | if (event->val == KM_RELEASE) { | ||||
| MEM_freeN(nvm); | MEM_freeN(nvm); | ||||
| op->customdata = nullptr; | op->customdata = nullptr; | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| break; | break; | ||||
| case EVT_ESCKEY: | |||||
| case RIGHTMOUSE: | |||||
| snode->xof = nvm->xof; | |||||
| snode->yof = nvm->yof; | |||||
| ED_region_tag_redraw(region); | |||||
| WM_main_add_notifier(NC_NODE | ND_DISPLAY, nullptr); | |||||
| WM_main_add_notifier(NC_SPACE | ND_SPACE_NODE_VIEW, nullptr); | |||||
| MEM_freeN(nvm); | |||||
| op->customdata = nullptr; | |||||
| return OPERATOR_CANCELLED; | |||||
| break; | |||||
| } | } | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Show All 19 Lines | |||||
| nvm->mvalo[0] = event->mval[0]; | nvm->mvalo[0] = event->mval[0]; | ||||
| nvm->mvalo[1] = event->mval[1]; | nvm->mvalo[1] = event->mval[1]; | ||||
| nvm->xmin = -(region->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; | nvm->xmin = -(region->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; | ||||
| nvm->xmax = (region->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; | nvm->xmax = (region->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; | ||||
| nvm->ymin = -(region->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; | nvm->ymin = -(region->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; | ||||
| nvm->ymax = (region->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; | nvm->ymax = (region->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; | ||||
| nvm->xof = snode->xof; | |||||
| nvm->yof = snode->yof; | |||||
| BKE_image_release_ibuf(ima, ibuf, lock); | BKE_image_release_ibuf(ima, ibuf, lock); | ||||
| /* add modal handler */ | /* add modal handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||
Best use x/yofs_orig otherwise it's not clear when reading the code elsewhere these are stored values (and not some other kind of offset).