diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-06-06 10:07:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-06-06 10:09:01 +0300 |
commit | 443904f1f4f9f0b45e4ef10ec4b5c9392559ada0 (patch) | |
tree | 2aac246c487c8b8cf7f068f4554d369005741257 /source/blender | |
parent | 2ebde4c82bd478d19a9b3116ac600e715ffc0165 (diff) |
WM: functions for assigning all manipulator callbacks
- Move callbacks into type struct.
- Rename render_3d_intersection -> draw_select.
- Add header for function signatures (needed for types and api headers).
- Add WM_manipulatormaptype_find
Diffstat (limited to 'source/blender')
15 files changed, 269 insertions, 151 deletions
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index df529b0054d..c652e2e0324 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -1150,7 +1150,7 @@ static void WIDGETGROUP_manipulator_init(const bContext *UNUSED(C), wmManipulato manipulator_get_axis_constraint(axis_idx, constraint_axis); /* custom handler! */ - WM_manipulator_set_custom_handler(axis, manipulator_handler); + WM_manipulator_set_fn_handler(axis, manipulator_handler); switch(axis_idx) { case MAN_AXIS_TRANS_X: diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index ffdc0a59dee..b61b4472c4a 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -97,6 +97,7 @@ set(SRC manipulators/WM_manipulator_api.h manipulators/WM_manipulator_types.h manipulators/WM_manipulator_library.h + manipulators/wm_manipulator_fn.h manipulators/wm_manipulator_wmapi.h manipulators/intern/wm_manipulator_intern.h manipulators/intern/manipulator_library/manipulator_geometry.h diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h index 09d050b363e..76053ed48e0 100644 --- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h +++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h @@ -39,31 +39,40 @@ struct ARegion; struct Main; struct wmKeyConfig; +struct wmManipulator; +struct wmManipulatorGroup; struct wmManipulatorGroupType; struct wmManipulatorMap; struct wmManipulatorMapType; struct wmManipulatorMapType_Params; +#include "wm_manipulator_fn.h" + /* -------------------------------------------------------------------- */ /* wmManipulator */ struct wmManipulator *WM_manipulator_new( - void (*draw)(const struct bContext *, struct wmManipulator *), - void (*render_3d_intersection)(const struct bContext *, struct wmManipulator *, int), - int (*intersect)(struct bContext *, const struct wmEvent *, struct wmManipulator *), - int (*handler)(struct bContext *, const struct wmEvent *, struct wmManipulator *, const int)); + struct wmManipulatorGroup *mgroup, const char *name); void WM_manipulator_delete( ListBase *manipulatorlist, struct wmManipulatorMap *mmap, struct wmManipulator *manipulator, struct bContext *C); +struct wmManipulatorGroup *WM_manipulator_get_parent_group(struct wmManipulator *manipulator); void WM_manipulator_set_property(struct wmManipulator *, int slot, struct PointerRNA *ptr, const char *propname); struct PointerRNA *WM_manipulator_set_operator(struct wmManipulator *, const char *opname); -void WM_manipulator_set_custom_handler( - struct wmManipulator *manipulator, - int (*handler)(struct bContext *, const struct wmEvent *, struct wmManipulator *, const int)); -void WM_manipulator_set_func_select( - struct wmManipulator *manipulator, - void (*select)(struct bContext *, struct wmManipulator *, const int action)); /* wmManipulatorSelectFunc */ + +/* callbacks */ +void WM_manipulator_set_fn_draw(struct wmManipulator *manipulator, wmManipulatorFnDraw fn); +void WM_manipulator_set_fn_draw_select(struct wmManipulator *manipulator, wmManipulatorFnDrawSelect fn); +void WM_manipulator_set_fn_intersect(struct wmManipulator *manipulator, wmManipulatorFnIntersect fn); +void WM_manipulator_set_fn_handler(struct wmManipulator *manipulator, wmManipulatorFnHandler fn); +void WM_manipulator_set_fn_prop_data_update(struct wmManipulator *mpr, wmManipulatorFnPropDataUpdate fn); +void WM_manipulator_set_fn_final_position_get(struct wmManipulator *mpr, wmManipulatorFnFinalPositionGet fn); +void WM_manipulator_set_fn_invoke(struct wmManipulator *mpr, wmManipulatorFnInvoke fn); +void WM_manipulator_set_fn_exit(struct wmManipulator *mpr, wmManipulatorFnExit fn); +void WM_manipulator_set_fn_cursor_get(struct wmManipulator *mpr, wmManipulatorFnCursorGet fn); +void WM_manipulator_set_fn_select(struct wmManipulator *manipulator, wmManipulatorFnSelect fn); + void WM_manipulator_set_origin(struct wmManipulator *manipulator, const float origin[3]); void WM_manipulator_set_offset(struct wmManipulator *manipulator, const float offset[3]); void WM_manipulator_set_flag(struct wmManipulator *manipulator, const int flag, const bool enable); @@ -75,6 +84,9 @@ void WM_manipulator_set_colors(struct wmManipulator *manipulator, const float co /* -------------------------------------------------------------------- */ /* wmManipulatorGroup */ +struct wmManipulatorGroupType *WM_manipulatorgrouptype_find( + struct wmManipulatorMapType *mmaptype, + const char *idname); struct wmManipulatorGroupType *WM_manipulatorgrouptype_append( struct wmManipulatorMapType *mmaptype, void (*mgrouptype_func)(struct wmManipulatorGroupType *)); diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_types.h b/source/blender/windowmanager/manipulators/WM_manipulator_types.h index 8de33ca923e..5fb909b06cf 100644 --- a/source/blender/windowmanager/manipulators/WM_manipulator_types.h +++ b/source/blender/windowmanager/manipulators/WM_manipulator_types.h @@ -40,13 +40,10 @@ struct wmManipulatorGroupType; struct wmManipulatorGroup; +struct wmManipulator; struct wmKeyConfig; -typedef bool (*wmManipulatorGroupPollFunc)(const struct bContext *, struct wmManipulatorGroupType *) ATTR_WARN_UNUSED_RESULT; -typedef void (*wmManipulatorGroupInitFunc)(const struct bContext *, struct wmManipulatorGroup *); -typedef void (*wmManipulatorGroupRefreshFunc)(const struct bContext *, struct wmManipulatorGroup *); -typedef void (*wmManipulatorGroupDrawPrepareFunc)(const struct bContext *, struct wmManipulatorGroup *); - +#include "wm_manipulator_fn.h" /* -------------------------------------------------------------------- */ /* wmManipulator */ @@ -79,27 +76,33 @@ typedef struct wmManipulatorGroupType { const char *name; /* manipulator-group name - displayed in UI (keymap editor) */ /* poll if manipulator-map should be visible */ - wmManipulatorGroupPollFunc poll; + wmManipulatorGroupFnPoll poll; /* initially create manipulators and set permanent data - stuff you only need to do once */ - wmManipulatorGroupInitFunc init; + wmManipulatorGroupFnInit init; /* refresh data, only called if recreate flag is set (WM_manipulatormap_tag_refresh) */ - wmManipulatorGroupRefreshFunc refresh; + wmManipulatorGroupFnRefresh refresh; /* refresh data for drawing, called before each redraw */ - wmManipulatorGroupDrawPrepareFunc draw_prepare; + wmManipulatorGroupFnDrawPrepare draw_prepare; /* keymap init callback for this manipulator-group */ struct wmKeyMap *(*keymap_init)(const struct wmManipulatorGroupType *, struct wmKeyConfig *); /* keymap created with callback from above */ struct wmKeyMap *keymap; + /* Disable for now, maybe some day we want properties. */ +#if 0 /* rna for properties */ struct StructRNA *srna; +#endif /* RNA integration */ ExtensionRNA ext; int flag; + /* Weak, but needed to store which functions we have. */ + int rna_func_flag; + /* if type is spawned from operator this is set here */ void *op; diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c index ad5f2f6251b..842e66656a2 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c @@ -193,12 +193,12 @@ struct wmManipulator *MANIPULATOR_arrow2d_new(wmManipulatorGroup *mgroup, const { ArrowManipulator2D *arrow = MEM_callocN(sizeof(ArrowManipulator2D), __func__); - arrow->manipulator.draw = manipulator_arrow2d_draw; - arrow->manipulator.invoke = manipulator_arrow2d_invoke; -// arrow->manipulator.bind_to_prop = manipulator_arrow2d_bind_to_prop; -// arrow->manipulator.handler = manipulator_arrow2d_handler; - arrow->manipulator.intersect = manipulator_arrow2d_intersect; -// arrow->manipulator.exit = manipulator_arrow2d_exit; + arrow->manipulator.type.draw = manipulator_arrow2d_draw; + arrow->manipulator.type.invoke = manipulator_arrow2d_invoke; +// arrow->manipulator.type.bind_to_prop = manipulator_arrow2d_bind_to_prop; +// arrow->manipulator.type.handler = manipulator_arrow2d_handler; + arrow->manipulator.type.intersect = manipulator_arrow2d_intersect; +// arrow->manipulator.type.exit = manipulator_arrow2d_exit; arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; arrow->line_len = 1.0f; diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c index b2e04849c34..6e9abb9137e 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c @@ -437,14 +437,14 @@ wmManipulator *MANIPULATOR_arrow_new(wmManipulatorGroup *mgroup, const char *nam ArrowManipulator *arrow = MEM_callocN(sizeof(ArrowManipulator), name); const float dir_default[3] = {0.0f, 0.0f, 1.0f}; - arrow->manipulator.draw = manipulator_arrow_draw; - arrow->manipulator.get_final_position = manipulator_arrow_get_final_pos; - arrow->manipulator.intersect = NULL; - arrow->manipulator.handler = manipulator_arrow_handler; - arrow->manipulator.invoke = manipulator_arrow_invoke; - arrow->manipulator.render_3d_intersection = manipulator_arrow_render_3d_intersect; - arrow->manipulator.prop_data_update = manipulator_arrow_prop_data_update; - arrow->manipulator.exit = manipulator_arrow_exit; + arrow->manipulator.type.draw = manipulator_arrow_draw; + arrow->manipulator.type.draw_select = manipulator_arrow_render_3d_intersect; + arrow->manipulator.type.final_position_get = manipulator_arrow_get_final_pos; + arrow->manipulator.type.intersect = NULL; + arrow->manipulator.type.handler = manipulator_arrow_handler; + arrow->manipulator.type.invoke = manipulator_arrow_invoke; + arrow->manipulator.type.prop_data_update = manipulator_arrow_prop_data_update; + arrow->manipulator.type.exit = manipulator_arrow_exit; arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; arrow->style = real_style; diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c index 45973fbf2fe..0ce430383ea 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c @@ -557,13 +557,13 @@ wmManipulator *MANIPULATOR_rect_transform_new(wmManipulatorGroup *mgroup, const { RectTransformManipulator *cage = MEM_callocN(sizeof(RectTransformManipulator), name); - cage->manipulator.draw = manipulator_rect_transform_draw; - cage->manipulator.invoke = manipulator_rect_transform_invoke; - cage->manipulator.prop_data_update = manipulator_rect_transform_prop_data_update; - cage->manipulator.handler = manipulator_rect_transform_handler; - cage->manipulator.intersect = manipulator_rect_transform_intersect; - cage->manipulator.exit = manipulator_rect_transform_exit; - cage->manipulator.get_cursor = manipulator_rect_transform_get_cursor; + cage->manipulator.type.draw = manipulator_rect_transform_draw; + cage->manipulator.type.invoke = manipulator_rect_transform_invoke; + cage->manipulator.type.prop_data_update = manipulator_rect_transform_prop_data_update; + cage->manipulator.type.handler = manipulator_rect_transform_handler; + cage->manipulator.type.intersect = manipulator_rect_transform_intersect; + cage->manipulator.type.exit = manipulator_rect_transform_exit; + cage->manipulator.type.cursor_get = manipulator_rect_transform_get_cursor; cage->manipulator.max_prop = 2; cage->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; cage->scale[0] = cage->scale[1] = 1.0f; diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c index 0fa6cbfbb28..1069684dab6 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c @@ -338,10 +338,10 @@ wmManipulator *MANIPULATOR_dial_new(wmManipulatorGroup *mgroup, const char *name DialManipulator *dial = MEM_callocN(sizeof(DialManipulator), name); const float dir_default[3] = {0.0f, 0.0f, 1.0f}; - dial->manipulator.draw = manipulator_dial_draw; - dial->manipulator.intersect = NULL; - dial->manipulator.render_3d_intersection = manipulator_dial_render_3d_intersect; - dial->manipulator.invoke = manipulator_dial_invoke; + dial->manipulator.type.draw = manipulator_dial_draw; + dial->manipulator.type.draw_select = manipulator_dial_render_3d_intersect; + dial->manipulator.type.intersect = NULL; + dial->manipulator.type.invoke = manipulator_dial_invoke; dial->style = style; diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c index bf53705a6e2..38fb10c3059 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c @@ -198,10 +198,10 @@ wmManipulator *MANIPULATOR_primitive_new(wmManipulatorGroup *mgroup, const char PrimitiveManipulator *prim = MEM_callocN(sizeof(PrimitiveManipulator), name); const float dir_default[3] = {0.0f, 0.0f, 1.0f}; - prim->manipulator.draw = manipulator_primitive_draw; - prim->manipulator.invoke = manipulator_primitive_invoke; - prim->manipulator.intersect = NULL; - prim->manipulator.render_3d_intersection = manipulator_primitive_render_3d_intersect; + prim->manipulator.type.draw = manipulator_primitive_draw; + prim->manipulator.type.draw_select = manipulator_primitive_render_3d_intersect; + prim->manipulator.type.invoke = manipulator_primitive_invoke; + prim->manipulator.type.intersect = NULL; prim->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; prim->style = style; diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c index 3d44e0c5d59..7b755cace36 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c @@ -125,30 +125,29 @@ void wm_manipulator_vec_draw( immEnd(); } -/* Still unused */ -wmManipulator *WM_manipulator_new( - void (*draw)(const bContext *C, wmManipulator *customdata), - void (*render_3d_intersection)(const bContext *C, wmManipulator *customdata, int selectionbase), - int (*intersect)(bContext *C, const wmEvent *event, wmManipulator *manipulator), - int (*handler)(bContext *C, const wmEvent *event, wmManipulator *manipulator, const int flag)) -{ - wmManipulator *manipulator = MEM_callocN(sizeof(wmManipulator), "manipulator"); - - manipulator->draw = draw; - manipulator->handler = handler; - manipulator->intersect = intersect; - manipulator->render_3d_intersection = render_3d_intersection; - - /* XXX */ - fix_linking_manipulator_arrow(); - fix_linking_manipulator_arrow2d(); - fix_linking_manipulator_cage(); - fix_linking_manipulator_dial(); - fix_linking_manipulator_primitive(); +wmManipulator *WM_manipulator_new(wmManipulatorGroup *mgroup, const char *name) +{ + wmManipulator *manipulator = MEM_callocN(sizeof(wmManipulator), __func__); + + wm_manipulator_register(mgroup, manipulator, name); + + /* XXX: never happens */ + if (name[0] == '\n') { + fix_linking_manipulator_arrow(); + fix_linking_manipulator_arrow2d(); + fix_linking_manipulator_cage(); + fix_linking_manipulator_dial(); + fix_linking_manipulator_primitive(); + } return manipulator; } +wmManipulatorGroup *WM_manipulator_get_parent_group(wmManipulator *manipulator) +{ + return manipulator->parent_mgroup; +} + /** * Assign an idname that is unique in \a mgroup to \a manipulator. * @@ -255,8 +254,9 @@ void WM_manipulator_set_property(wmManipulator *manipulator, const int slot, Poi manipulator->ptr[slot] = *ptr; manipulator->props[slot] = RNA_struct_find_property(ptr, propname); - if (manipulator->prop_data_update) - manipulator->prop_data_update(manipulator, slot); + if (manipulator->type.prop_data_update) { + manipulator->type.prop_data_update(manipulator, slot); + } } PointerRNA *WM_manipulator_set_operator(wmManipulator *manipulator, const char *opname) @@ -280,25 +280,6 @@ PointerRNA *WM_manipulator_set_operator(wmManipulator *manipulator, const char * return NULL; } - -void WM_manipulator_set_custom_handler( - struct wmManipulator *manipulator, - int (*handler)(struct bContext *, const wmEvent *, struct wmManipulator *, const int)) -{ - manipulator->handler = handler; -} - -/** - * \brief Set manipulator select callback. - * - * Callback is called when manipulator gets selected/deselected. - */ -void WM_manipulator_set_func_select(wmManipulator *manipulator, wmManipulatorSelectFunc select) -{ - BLI_assert(manipulator->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SELECTABLE); - manipulator->select = select; -} - void WM_manipulator_set_origin(wmManipulator *manipulator, const float origin[3]) { copy_v3_v3(manipulator->origin, origin); @@ -340,11 +321,60 @@ void WM_manipulator_set_colors(wmManipulator *manipulator, const float col[4], c copy_v4_v4(manipulator->col, col); copy_v4_v4(manipulator->col_hi, col_hi); } - /** \} */ // Manipulator Creation API /* -------------------------------------------------------------------- */ +/** \name Manipulator Callback Assignment + * + * \{ */ + +void WM_manipulator_set_fn_draw(wmManipulator *mpr, wmManipulatorFnDraw draw_fn) +{ + mpr->type.draw = draw_fn; +} +void WM_manipulator_set_fn_draw_select(struct wmManipulator *mpr, wmManipulatorFnDrawSelect fn) +{ + mpr->type.draw_select = fn; +} +void WM_manipulator_set_fn_intersect(wmManipulator *mpr, wmManipulatorFnIntersect fn) +{ + mpr->type.intersect = fn; +} +void WM_manipulator_set_fn_handler(struct wmManipulator *mpr, wmManipulatorFnHandler fn) +{ + mpr->type.handler = fn; +} +void WM_manipulator_set_fn_prop_data_update(struct wmManipulator *mpr, wmManipulatorFnPropDataUpdate fn) +{ + mpr->type.prop_data_update = fn; +} +void WM_manipulator_set_fn_final_position_get(struct wmManipulator *mpr, wmManipulatorFnFinalPositionGet fn) +{ + mpr->type.final_position_get = fn; +} +void WM_manipulator_set_fn_invoke(struct wmManipulator *mpr, wmManipulatorFnInvoke fn) +{ + mpr->type.invoke = fn; +} +void WM_manipulator_set_fn_exit(struct wmManipulator *mpr, wmManipulatorFnExit fn) +{ + mpr->type.exit = fn; +} +void WM_manipulator_set_fn_cursor_get(struct wmManipulator *mpr, wmManipulatorFnCursorGet fn) +{ + mpr->type.cursor_get = fn; +} +void WM_manipulator_set_fn_select(wmManipulator *mpr, wmManipulatorFnSelect fn) +{ + BLI_assert(mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SELECTABLE); + mpr->type.select = fn; +} + +/** \} */ + + +/* -------------------------------------------------------------------- */ /** * Remove \a manipulator from selection. @@ -408,8 +438,8 @@ bool wm_manipulator_select(bContext *C, wmManipulatorMap *mmap, wmManipulator *m (*sel)[(*tot_selected) - 1] = manipulator; manipulator->state |= WM_MANIPULATOR_SELECTED; - if (manipulator->select) { - manipulator->select(C, manipulator, SEL_SELECT); + if (manipulator->type.select) { + manipulator->type.select(C, manipulator, SEL_SELECT); } wm_manipulatormap_set_highlighted_manipulator(mmap, C, manipulator, manipulator->highlighted_part); @@ -423,10 +453,10 @@ void wm_manipulator_calculate_scale(wmManipulator *manipulator, const bContext * if (manipulator->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SCALE_3D) { if (rv3d /*&& (U.manipulator_flag & V3D_DRAW_MANIPULATOR) == 0*/) { /* UserPref flag might be useful for later */ - if (manipulator->get_final_position) { + if (manipulator->type.final_position_get) { float position[3]; - manipulator->get_final_position(manipulator, position); + manipulator->type.final_position_get(manipulator, position); scale = ED_view3d_pixel_size(rv3d, position) * (float)U.manipulator_scale; } else { @@ -444,10 +474,10 @@ void wm_manipulator_calculate_scale(wmManipulator *manipulator, const bContext * static void manipulator_update_prop_data(wmManipulator *manipulator) { /* manipulator property might have been changed, so update manipulator */ - if (manipulator->props && manipulator->prop_data_update) { + if (manipulator->props && manipulator->type.prop_data_update) { for (int i = 0; i < manipulator->max_prop; i++) { if (manipulator->props[i]) { - manipulator->prop_data_update(manipulator, i); + manipulator->type.prop_data_update(manipulator, i); } } } diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h b/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h index d2f81951f28..9a5cf6c1f01 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h @@ -43,36 +43,39 @@ struct wmManipulator { /* pointer back to group this manipulator is in (just for quick access) */ struct wmManipulatorGroup *parent_mgroup; - /* could become wmManipulatorType */ - /* draw manipulator */ - void (*draw)(const struct bContext *, struct wmManipulator *); + /* While we don't have a real type, use this to put type-like vars. */ + struct { + /* could become wmManipulatorType */ + /* draw manipulator */ + wmManipulatorFnDraw draw; - /* determine if the mouse intersects with the manipulator. The calculation should be done in the callback itself */ - int (*intersect)(struct bContext *, const struct wmEvent *, struct wmManipulator *); + /* determines 3d intersection by rendering the manipulator in a selection routine. */ + wmManipulatorFnDrawSelect draw_select; - /* determines 3d intersection by rendering the manipulator in a selection routine. */ - void (*render_3d_intersection)(const struct bContext *, struct wmManipulator *, int); + /* determine if the mouse intersects with the manipulator. The calculation should be done in the callback itself */ + wmManipulatorFnIntersect intersect; - /* handler used by the manipulator. Usually handles interaction tied to a manipulator type */ - int (*handler)(struct bContext *, const struct wmEvent *, struct wmManipulator *, const int); + /* handler used by the manipulator. Usually handles interaction tied to a manipulator type */ + wmManipulatorFnHandler handler; - /* manipulator-specific handler to update manipulator attributes based on the property value */ - void (*prop_data_update)(struct wmManipulator *, int); + /* manipulator-specific handler to update manipulator attributes based on the property value */ + wmManipulatorFnPropDataUpdate prop_data_update; - /* returns the final position which may be different from the origin, depending on the manipulator. - * used in calculations of scale */ - void (*get_final_position)(struct wmManipulator *, float[]); + /* returns the final position which may be different from the origin, depending on the manipulator. + * used in calculations of scale */ + wmManipulatorFnFinalPositionGet final_position_get; - /* activate a manipulator state when the user clicks on it */ - int (*invoke)(struct bContext *, const struct wmEvent *, struct wmManipulator *); + /* activate a manipulator state when the user clicks on it */ + wmManipulatorFnInvoke invoke; - /* called when manipulator tweaking is done - used to free data and reset property when cancelling */ - void (*exit)(struct bContext *, struct wmManipulator *, const bool ); + /* called when manipulator tweaking is done - used to free data and reset property when cancelling */ + wmManipulatorFnExit exit; - int (*get_cursor)(struct wmManipulator *); + wmManipulatorFnCursorGet cursor_get; - /* called when manipulator selection state changes */ - wmManipulatorSelectFunc select; + /* called when manipulator selection state changes */ + wmManipulatorFnSelect select; + } type; int flag; /* flags that influence the behavior or how the manipulators are drawn */ short state; /* state flags (active, highlighted, selected) */ diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c b/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c index ad31b1f7618..0097b3210b2 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c @@ -33,6 +33,7 @@ */ #include <stdlib.h> +#include <string.h> #include "BKE_context.h" #include "BKE_main.h" @@ -50,6 +51,7 @@ #include "MEM_guardedalloc.h" #include "RNA_access.h" +#include "RNA_define.h" #include "WM_api.h" #include "WM_types.h" @@ -157,8 +159,8 @@ wmManipulator *wm_manipulatorgroup_find_intersected_mainpulator( unsigned char *part) { for (wmManipulator *manipulator = mgroup->manipulators.first; manipulator; manipulator = manipulator->next) { - if (manipulator->intersect && (manipulator->flag & WM_MANIPULATOR_HIDDEN) == 0) { - if ((*part = manipulator->intersect(C, event, manipulator))) { + if (manipulator->type.intersect && (manipulator->flag & WM_MANIPULATOR_HIDDEN) == 0) { + if ((*part = manipulator->type.intersect(C, event, manipulator))) { return manipulator; } } @@ -174,8 +176,8 @@ void wm_manipulatorgroup_intersectable_manipulators_to_list(const wmManipulatorG { for (wmManipulator *manipulator = mgroup->manipulators.first; manipulator; manipulator = manipulator->next) { if ((manipulator->flag & WM_MANIPULATOR_HIDDEN) == 0) { - if (((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_IS_3D) && manipulator->render_3d_intersection) || - ((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_IS_3D) == 0 && manipulator->intersect)) + if (((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_IS_3D) && manipulator->type.draw_select) || + ((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_IS_3D) == 0 && manipulator->type.intersect)) { BLI_addhead(listbase, BLI_genericNodeN(manipulator)); } @@ -295,8 +297,8 @@ typedef struct ManipulatorTweakData { static void manipulator_tweak_finish(bContext *C, wmOperator *op, const bool cancel) { ManipulatorTweakData *mtweak = op->customdata; - if (mtweak->active->exit) { - mtweak->active->exit(C, mtweak->active, cancel); + if (mtweak->active->type.exit) { + mtweak->active->type.exit(C, mtweak->active, cancel); } wm_manipulatormap_set_active_manipulator(mtweak->mmap, C, NULL, NULL); MEM_freeN(mtweak); @@ -336,8 +338,8 @@ static int manipulator_tweak_modal(bContext *C, wmOperator *op, const wmEvent *e } /* handle manipulator */ - if (manipulator->handler) { - manipulator->handler(C, event, manipulator, mtweak->flag); + if (manipulator->type.handler) { + manipulator->type.handler(C, event, manipulator, mtweak->flag); } /* Ugly hack to send manipulator events */ @@ -491,6 +493,23 @@ wmKeyMap *WM_manipulatorgroup_keymap_common_sel(const struct wmManipulatorGroupT * * \{ */ +struct wmManipulatorGroupType *WM_manipulatorgrouptype_find( + struct wmManipulatorMapType *mmaptype, + const char *idname) +{ + /* could use hash lookups as operator types do, for now simple search. */ + for (wmManipulatorGroupType *mgrouptype = mmaptype->manipulator_grouptypes.first; + mgrouptype; + mgrouptype = mgrouptype->next) + { + if (STREQ(idname, mgrouptype->idname)) { + return mgrouptype; + } + } + return NULL; +} + + static wmManipulatorGroupType *wm_manipulatorgrouptype_append__begin(void) { wmManipulatorGroupType *mgrouptype = MEM_callocN(sizeof(wmManipulatorGroupType), "manipulator-group"); @@ -576,7 +595,7 @@ void WM_manipulatorgrouptype_init_runtime( ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; for (ARegion *ar = lb->first; ar; ar = ar->next) { wmManipulatorMap *mmap = ar->manipulator_map; - if (mmap->type == mmaptype) { + if (mmap && mmap->type == mmaptype) { wm_manipulatorgroup_new_from_type(mmap, mgrouptype); /* just add here, drawing will occur on next update */ @@ -597,14 +616,15 @@ void WM_manipulatorgrouptype_unregister(bContext *C, Main *bmain, wmManipulatorG ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; for (ARegion *ar = lb->first; ar; ar = ar->next) { wmManipulatorMap *mmap = ar->manipulator_map; - wmManipulatorGroup *mgroup, *mgroup_next; - - for (mgroup = mmap->manipulator_groups.first; mgroup; mgroup = mgroup_next) { - mgroup_next = mgroup->next; - if (mgroup->type == mgrouptype) { - BLI_assert(mgroup->parent_mmap == mmap); - wm_manipulatorgroup_free(C, mgroup); - ED_region_tag_redraw(ar); + if (mmap) { + wmManipulatorGroup *mgroup, *mgroup_next; + for (mgroup = mmap->manipulator_groups.first; mgroup; mgroup = mgroup_next) { + mgroup_next = mgroup->next; + if (mgroup->type == mgrouptype) { + BLI_assert(mgroup->parent_mmap == mmap); + wm_manipulatorgroup_free(C, mgroup); + ED_region_tag_redraw(ar); + } } } } diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c b/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c index faf76a47d7a..f1655fcef1b 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c @@ -255,7 +255,7 @@ static void manipulators_draw_list(const wmManipulatorMap *mmap, const bContext wmManipulator *manipulator = link->data; link_next = link->next; - manipulator->draw(C, manipulator); + manipulator->type.draw(C, manipulator); /* free/remove manipulator link after drawing */ BLI_freelinkN(draw_manipulators, link); } @@ -282,7 +282,7 @@ static void manipulator_find_active_3D_loop(const bContext *C, ListBase *visible for (LinkData *link = visible_manipulators->first; link; link = link->next) { manipulator = link->data; /* pass the selection id shifted by 8 bits. Last 8 bits are used for selected manipulator part id */ - manipulator->render_3d_intersection(C, manipulator, selectionbase << 8); + manipulator->type.draw_select(C, manipulator, selectionbase << 8); selectionbase++; } @@ -423,10 +423,10 @@ void wm_manipulatormaps_handled_modal_update( /* regular update for running operator */ if (modal_running) { - if (manipulator && manipulator->handler && manipulator->opname && + if (manipulator && manipulator->type.handler && manipulator->opname && STREQ(manipulator->opname, handler->op->idname)) { - manipulator->handler(C, event, manipulator, 0); + manipulator->type.handler(C, event, manipulator, 0); } } /* operator not running anymore */ @@ -492,8 +492,8 @@ static bool wm_manipulatormap_select_all_intern( changed = true; } manipulator_iter->state |= WM_MANIPULATOR_SELECTED; - if (manipulator_iter->select) { - manipulator_iter->select(C, manipulator_iter, action); + if (manipulator_iter->type.select) { + manipulator_iter->type.select(C, manipulator_iter, action); } (*sel)[i] = manipulator_iter; BLI_assert(i < (*tot_sel)); @@ -576,8 +576,8 @@ bool WM_manipulatormap_cursor_set(const wmManipulatorMap *mmap, wmWindow *win) { for (; mmap; mmap = mmap->next) { wmManipulator *manipulator = mmap->mmap_context.highlighted_manipulator; - if (manipulator && manipulator->get_cursor) { - WM_cursor_set(win, manipulator->get_cursor(manipulator)); + if (manipulator && manipulator->type.cursor_get) { + WM_cursor_set(win, manipulator->type.cursor_get(manipulator)); return true; } } @@ -603,9 +603,9 @@ void wm_manipulatormap_set_highlighted_manipulator( manipulator->state |= WM_MANIPULATOR_HIGHLIGHT; manipulator->highlighted_part = part; - if (C && manipulator->get_cursor) { + if (C && manipulator->type.cursor_get) { wmWindow *win = CTX_wm_window(C); - WM_cursor_set(win, manipulator->get_cursor(manipulator)); + WM_cursor_set(win, manipulator->type.cursor_get(manipulator)); } } else { @@ -640,8 +640,8 @@ void wm_manipulatormap_set_active_manipulator( if (ot) { /* first activate the manipulator itself */ - if (manipulator->invoke && manipulator->handler) { - manipulator->invoke(C, event, manipulator); + if (manipulator->type.invoke && manipulator->type.handler) { + manipulator->type.invoke(C, event, manipulator); } WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &manipulator->opptr); @@ -664,8 +664,8 @@ void wm_manipulatormap_set_active_manipulator( } } else { - if (manipulator->invoke && manipulator->handler) { - manipulator->invoke(C, event, manipulator); + if (manipulator->type.invoke && manipulator->type.handler) { + manipulator->type.invoke(C, event, manipulator); } } WM_cursor_grab_enable(CTX_wm_window(C), true, true, NULL); diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h new file mode 100644 index 00000000000..99ef75d21ea --- /dev/null +++ b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h @@ -0,0 +1,51 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/windowmanager/manipulators/wm_manipulator_fn.h + * \ingroup wm + * + * Callback function definitions, needed for both Types & API headers. + */ + + +#ifndef __WM_MANIPULATOR_FN_H__ +#define __WM_MANIPULATOR_FN_H__ + +#include "BLI_compiler_attrs.h" + +/* wmManipulatorGroup */ +typedef bool (*wmManipulatorGroupFnPoll)(const struct bContext *, struct wmManipulatorGroupType *) ATTR_WARN_UNUSED_RESULT; +typedef void (*wmManipulatorGroupFnInit)(const struct bContext *, struct wmManipulatorGroup *); +typedef void (*wmManipulatorGroupFnRefresh)(const struct bContext *, struct wmManipulatorGroup *); +typedef void (*wmManipulatorGroupFnDrawPrepare)(const struct bContext *, struct wmManipulatorGroup *); + +/* wmManipulator */ +typedef void (*wmManipulatorFnDraw)(const struct bContext *, struct wmManipulator *); +typedef void (*wmManipulatorFnDrawSelect)(const struct bContext *, struct wmManipulator *, int); +typedef int (*wmManipulatorFnIntersect)(struct bContext *, const struct wmEvent *, struct wmManipulator *); +typedef int (*wmManipulatorFnHandler)(struct bContext *, const struct wmEvent *, struct wmManipulator *, const int); +typedef void (*wmManipulatorFnPropDataUpdate)(struct wmManipulator *, int); +typedef void (*wmManipulatorFnFinalPositionGet)(struct wmManipulator *, float[]); +typedef int (*wmManipulatorFnInvoke)(struct bContext *, const struct wmEvent *, struct wmManipulator *); +typedef void (*wmManipulatorFnExit)(struct bContext *, struct wmManipulator *, const bool); +typedef int (*wmManipulatorFnCursorGet)(struct wmManipulator *); +typedef void (*wmManipulatorFnSelect)(struct bContext *, struct wmManipulator *, const int); + +#endif /* __WM_MANIPULATOR_FN_H__ */ diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h index c5008cef896..d33d93ddde4 100644 --- a/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h +++ b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h @@ -47,8 +47,6 @@ struct wmOperator; /* -------------------------------------------------------------------- */ /* wmManipulator */ -typedef void (*wmManipulatorSelectFunc)(struct bContext *, struct wmManipulator *, const int); - struct wmManipulatorGroup *wm_manipulator_get_parent_group(const struct wmManipulator *manipulator); /* -------------------------------------------------------------------- */ |