Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_gizmo.cc
| Show All 32 Lines | |||||
| namespace blender::ed::space_node { | namespace blender::ed::space_node { | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Local Utilities | /** \name Local Utilities | ||||
| * \{ */ | * \{ */ | ||||
| static void node_gizmo_calc_matrix_space(const SpaceNode *snode, | static void node_gizmo_calc_matrix_space(const SpaceNode *snode, | ||||
| const ARegion *region, | const ARegion *region, | ||||
| const float image_offset[2], | |||||
| float matrix_space[4][4]) | float matrix_space[4][4]) | ||||
| { | { | ||||
| unit_m4(matrix_space); | unit_m4(matrix_space); | ||||
| mul_v3_fl(matrix_space[0], snode->zoom); | mul_v3_fl(matrix_space[0], snode->zoom); | ||||
| mul_v3_fl(matrix_space[1], snode->zoom); | mul_v3_fl(matrix_space[1], snode->zoom); | ||||
| matrix_space[3][0] = (region->winx / 2) + snode->xof; | const float offset_x = snode->xof + image_offset[0]; | ||||
| matrix_space[3][1] = (region->winy / 2) + snode->yof; | const float offset_y = snode->yof + image_offset[1]; | ||||
| matrix_space[3][0] = (region->winx / 2) + offset_x; | |||||
| matrix_space[3][1] = (region->winy / 2) + offset_y; | |||||
| } | } | ||||
| static void node_gizmo_calc_matrix_space_with_image_dims(const SpaceNode *snode, | static void node_gizmo_calc_matrix_space_with_image_dims(const SpaceNode *snode, | ||||
| const ARegion *region, | const ARegion *region, | ||||
| const float image_offset[2], | |||||
| const float image_dims[2], | const float image_dims[2], | ||||
| float matrix_space[4][4]) | float matrix_space[4][4]) | ||||
| { | { | ||||
| unit_m4(matrix_space); | unit_m4(matrix_space); | ||||
| mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]); | mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]); | ||||
| mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]); | mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]); | ||||
| matrix_space[3][0] = ((region->winx / 2) + snode->xof) - ((image_dims[0] / 2.0f) * snode->zoom); | const float offset_x = snode->xof + image_offset[0]; | ||||
| matrix_space[3][1] = ((region->winy / 2) + snode->yof) - ((image_dims[1] / 2.0f) * snode->zoom); | const float offset_y = snode->yof + image_offset[1]; | ||||
| matrix_space[3][0] = ((region->winx / 2) + offset_x) - ((image_dims[0] / 2.0f) * snode->zoom); | |||||
| matrix_space[3][1] = ((region->winy / 2) + offset_y) - ((image_dims[1] / 2.0f) * snode->zoom); | |||||
| } | |||||
| static void get_viewer_image_offset(const bContext *C, float r_offset[2]) | |||||
| { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| const Image *image = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); | |||||
| r_offset[0] = image->display_offset_x; | |||||
| r_offset[1] = image->display_offset_y; | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Backdrop Gizmo | /** \name Backdrop Gizmo | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | static void WIDGETGROUP_node_transform_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) | ||||
| gzgroup->customdata = wwrapper; | gzgroup->customdata = wwrapper; | ||||
| } | } | ||||
| static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| wmGizmo *cage = ((wmGizmoWrapper *)gzgroup->customdata)->gizmo; | wmGizmo *cage = ((wmGizmoWrapper *)gzgroup->customdata)->gizmo; | ||||
| const ARegion *region = CTX_wm_region(C); | const ARegion *region = CTX_wm_region(C); | ||||
| /* center is always at the origin */ | |||||
| const float origin[3] = {float(region->winx / 2), float(region->winy / 2), 0.0f}; | |||||
| void *lock; | |||||
| Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); | Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); | ||||
| /* Center is always at the origin. */ | |||||
| const float origin[3] ={ (region->winx / 2) + (float)ima->display_offset_x, | |||||
| (region->winy / 2) + (float)ima->display_offset_y}; | |||||
| void *lock; | |||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock); | ||||
| if (ibuf) { | if (ibuf) { | ||||
| const float dims[2] = { | const float dims[2] = { | ||||
| (ibuf->x > 0) ? ibuf->x : 64.0f, | (ibuf->x > 0) ? ibuf->x : 64.0f, | ||||
| (ibuf->y > 0) ? ibuf->y : 64.0f, | (ibuf->y > 0) ? ibuf->y : 64.0f, | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | |||||
| static void WIDGETGROUP_node_crop_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_crop_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| wmGizmo *gz = (wmGizmo *)gzgroup->gizmos.first; | wmGizmo *gz = (wmGizmo *)gzgroup->gizmos.first; | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| node_gizmo_calc_matrix_space(snode, region, gz->matrix_space); | float image_offset[2]; | ||||
| get_viewer_image_offset(C, image_offset); | |||||
| node_gizmo_calc_matrix_space(snode, region, image_offset, gz->matrix_space); | |||||
| } | } | ||||
| static void WIDGETGROUP_node_crop_refresh(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_crop_refresh(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| NodeCropWidgetGroup *crop_group = (NodeCropWidgetGroup *)gzgroup->customdata; | NodeCropWidgetGroup *crop_group = (NodeCropWidgetGroup *)gzgroup->customdata; | ||||
| wmGizmo *gz = crop_group->border; | wmGizmo *gz = crop_group->border; | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | |||||
| static void WIDGETGROUP_node_sbeam_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_sbeam_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| NodeSunBeamsWidgetGroup *sbeam_group = (NodeSunBeamsWidgetGroup *)gzgroup->customdata; | NodeSunBeamsWidgetGroup *sbeam_group = (NodeSunBeamsWidgetGroup *)gzgroup->customdata; | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| wmGizmo *gz = (wmGizmo *)gzgroup->gizmos.first; | wmGizmo *gz = (wmGizmo *)gzgroup->gizmos.first; | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| float image_offset[2]; | |||||
| get_viewer_image_offset(C, image_offset); | |||||
| node_gizmo_calc_matrix_space_with_image_dims( | node_gizmo_calc_matrix_space_with_image_dims( | ||||
| snode, region, sbeam_group->state.dims, gz->matrix_space); | snode, region, image_offset, sbeam_group->state.dims, gz->matrix_space); | ||||
| } | } | ||||
| static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| NodeSunBeamsWidgetGroup *sbeam_group = (NodeSunBeamsWidgetGroup *)gzgroup->customdata; | NodeSunBeamsWidgetGroup *sbeam_group = (NodeSunBeamsWidgetGroup *)gzgroup->customdata; | ||||
| wmGizmo *gz = sbeam_group->gizmo; | wmGizmo *gz = sbeam_group->gizmo; | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
| static void WIDGETGROUP_node_corner_pin_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_corner_pin_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| NodeCornerPinWidgetGroup *cpin_group = (NodeCornerPinWidgetGroup *)gzgroup->customdata; | NodeCornerPinWidgetGroup *cpin_group = (NodeCornerPinWidgetGroup *)gzgroup->customdata; | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| float image_offset[2]; | |||||
| get_viewer_image_offset(C, image_offset); | |||||
| float matrix_space[4][4]; | float matrix_space[4][4]; | ||||
| node_gizmo_calc_matrix_space_with_image_dims( | node_gizmo_calc_matrix_space_with_image_dims( | ||||
| snode, region, cpin_group->state.dims, matrix_space); | snode, region, image_offset, cpin_group->state.dims, matrix_space); | ||||
| for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
| wmGizmo *gz = cpin_group->gizmos[i]; | wmGizmo *gz = cpin_group->gizmos[i]; | ||||
| copy_m4_m4(gz->matrix_space, matrix_space); | copy_m4_m4(gz->matrix_space, matrix_space); | ||||
| } | } | ||||
| } | } | ||||
| static void WIDGETGROUP_node_corner_pin_refresh(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_node_corner_pin_refresh(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||