diff options
Diffstat (limited to 'source')
5 files changed, 110 insertions, 1 deletions
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c index ee8d0e85dfd..9ebdcb7fa33 100644 --- a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c +++ b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c @@ -662,11 +662,11 @@ static void MANIPULATOR_WT_cage_2d(wmManipulatorType *wt) /* api callbacks */ wt->draw = manipulator_rect_transform_draw; wt->draw_select = manipulator_rect_transform_draw_select; + wt->test_select = manipulator_rect_transform_test_select; wt->setup = manipulator_rect_transform_setup; wt->invoke = manipulator_rect_transform_invoke; wt->property_update = manipulator_rect_transform_property_update; wt->modal = manipulator_rect_transform_modal; - wt->test_select = manipulator_rect_transform_test_select; wt->exit = manipulator_rect_transform_exit; wt->cursor_get = manipulator_rect_transform_get_cursor; diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 7e8d092cdbe..449e28498a0 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -222,6 +222,7 @@ void NODE_OT_clear_viewer_border(struct wmOperatorType *ot); /* node_widgets.c */ void NODE_WGT_backdrop_transform(struct wmManipulatorGroupType *wgt); void NODE_WGT_backdrop_crop(struct wmManipulatorGroupType *wgt); +void NODE_WGT_backdrop_sun_beams(struct wmManipulatorGroupType *wgt); extern const char *node_context_dir[]; diff --git a/source/blender/editors/space_node/node_manipulators.c b/source/blender/editors/space_node/node_manipulators.c index 8f614137a84..0435e109922 100644 --- a/source/blender/editors/space_node/node_manipulators.c +++ b/source/blender/editors/space_node/node_manipulators.c @@ -373,3 +373,109 @@ void NODE_WGT_backdrop_crop(wmManipulatorGroupType *wgt) } /** \} */ + +/* -------------------------------------------------------------------- */ + +/** \name Sun Beams + * \{ */ + +struct NodeSunBeamsWidgetGroup { + wmManipulator *manipulator; + + struct { + float dims[2]; + } state; +}; + +static bool WIDGETGROUP_node_sbeam_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + + if ((snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } + + if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { + bNode *node = nodeGetActive(snode->edittree); + + if (node && ELEM(node->type, CMP_NODE_SUNBEAMS)) { + return true; + } + } + + return false; +} + +static void WIDGETGROUP_node_sbeam_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup) +{ + struct NodeSunBeamsWidgetGroup *sbeam_group = MEM_mallocN(sizeof(struct NodeSunBeamsWidgetGroup), __func__); + + sbeam_group->manipulator = WM_manipulator_new("MANIPULATOR_WT_grab_3d", mgroup, NULL); + wmManipulator *mpr = sbeam_group->manipulator; + + RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_CROSS); + + mpr->scale_basis = 0.05f; + + mgroup->customdata = sbeam_group; +} + +static void WIDGETGROUP_node_sbeam_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup) +{ + struct NodeSunBeamsWidgetGroup *sbeam_group = mgroup->customdata; + ARegion *ar = CTX_wm_region(C); + wmManipulator *mpr = mgroup->manipulators.first; + + SpaceNode *snode = CTX_wm_space_node(C); + + unit_m4(mpr->matrix_space); + mul_v3_fl(mpr->matrix_space[0], snode->zoom * sbeam_group->state.dims[0]); + mul_v3_fl(mpr->matrix_space[1], snode->zoom * sbeam_group->state.dims[1]); + mpr->matrix_space[3][0] = ((ar->winx / 2) + snode->xof) - ((sbeam_group->state.dims[0] / 2.0f) * snode->zoom); + mpr->matrix_space[3][1] = ((ar->winy / 2) + snode->yof) - ((sbeam_group->state.dims[1] / 2.0f) * snode->zoom); +} + +static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmManipulatorGroup *mgroup) +{ + struct NodeSunBeamsWidgetGroup *sbeam_group = mgroup->customdata; + wmManipulator *mpr = sbeam_group->manipulator; + + void *lock; + Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf) { + sbeam_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; + sbeam_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; + + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode->edittree); + + /* need to set property here for undo. TODO would prefer to do this in _init */ + PointerRNA nodeptr; + RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeSunBeams, node, &nodeptr); + WM_manipulator_target_property_def_rna(mpr, "offset", &nodeptr, "source", -1); + + WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_MODAL, true); + } + else { + WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true); + } + + BKE_image_release_ibuf(ima, ibuf, lock); +} + +void NODE_WGT_backdrop_sun_beams(wmManipulatorGroupType *wgt) +{ + wgt->name = "Sun Beams Widget"; + wgt->idname = "NODE_WGT_sbeam"; + + wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT; + + wgt->poll = WIDGETGROUP_node_sbeam_poll; + wgt->setup = WIDGETGROUP_node_sbeam_setup; + wgt->draw_prepare = WIDGETGROUP_node_sbeam_draw_prepare; + wgt->refresh = WIDGETGROUP_node_sbeam_refresh; +} + +/** \} */ diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index bc4918430ef..cf1c975db2f 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -867,6 +867,7 @@ static void node_widgets(void) &(const struct wmManipulatorMapType_Params){SPACE_NODE, RGN_TYPE_WINDOW}); WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_transform); WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_crop); + WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_sun_beams); } static void node_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id) diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index a07cb86fdf7..bf9881a4b0a 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -175,6 +175,7 @@ extern StructRNA RNA_CompositorNodeSepYCCA; extern StructRNA RNA_CompositorNodeSepYUVA; extern StructRNA RNA_CompositorNodeSetAlpha; extern StructRNA RNA_CompositorNodeSplitViewer; +extern StructRNA RNA_CompositorNodeSunBeams; extern StructRNA RNA_CompositorNodeSwitchView; extern StructRNA RNA_CompositorNodeTexture; extern StructRNA RNA_CompositorNodeTime; |