diff options
Diffstat (limited to 'source')
16 files changed, 262 insertions, 170 deletions
diff --git a/source/blender/editors/include/ED_manipulator_library.h b/source/blender/editors/include/ED_manipulator_library.h index 692d6cbdcd8..924ba7bf792 100644 --- a/source/blender/editors/include/ED_manipulator_library.h +++ b/source/blender/editors/include/ED_manipulator_library.h @@ -76,8 +76,7 @@ enum { ED_MANIPULATOR_ARROW_STYLE_CONE = (1 << 6), }; -struct wmManipulator *ED_manipulator_arrow3d_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style); +void ED_manipulator_arrow3d_set_style(struct wmManipulator *mpr, int style); void ED_manipulator_arrow3d_set_direction(struct wmManipulator *mpr, const float direction[3]); void ED_manipulator_arrow3d_set_up_vector(struct wmManipulator *mpr, const float direction[3]); void ED_manipulator_arrow3d_set_line_len(struct wmManipulator *mpr, const float len); @@ -89,7 +88,6 @@ void ED_manipulator_arrow3d_cone_set_aspect(struct wmManipulator *mpr, const flo /* -------------------------------------------------------------------- */ /* 2D Arrow Manipulator */ -struct wmManipulator *ED_manipulator_arrow2d_new(struct wmManipulatorGroup *mgroup, const char *name); void ED_manipulator_arrow2d_set_angle(struct wmManipulator *mpr, const float rot_fac); void ED_manipulator_arrow2d_set_line_len(struct wmManipulator *mpr, const float len); @@ -104,9 +102,8 @@ enum { ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM = (1 << 3), /* Manipulator scales uniformly */ }; -struct wmManipulator *ED_manipulator_rect_transform_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style); -void ED_manipulator_rect_transform_set_dimensions( +void ED_manipulator_cage2d_transform_set_style(struct wmManipulator *mpr, int style); +void ED_manipulator_cage2d_transform_set_dims( struct wmManipulator *mpr, const float width, const float height); @@ -119,8 +116,7 @@ enum { ED_MANIPULATOR_DIAL_STYLE_RING_FILLED = 2, }; -struct wmManipulator *ED_manipulator_dial3d_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style); +void ED_manipulator_dial3d_set_style(struct wmManipulator *mpr, int style); void ED_manipulator_dial3d_set_up_vector( struct wmManipulator *mpr, const float direction[3]); @@ -128,17 +124,17 @@ void ED_manipulator_dial3d_set_up_vector( /* -------------------------------------------------------------------- */ /* Grab Manipulator */ -struct wmManipulator *ED_manipulator_grab3d_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style); +enum { + ED_MANIPULATOR_GRAB_STYLE_RING = 0, +}; + +void ED_manipulator_grab3d_set_style(struct wmManipulator *mpr, int style); void ED_manipulator_grab3d_set_up_vector( struct wmManipulator *mpr, const float direction[3]); /* -------------------------------------------------------------------- */ /* Facemap Manipulator */ -struct wmManipulator *ED_manipulator_facemap_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style, - struct Object *ob, const int facemap); struct bFaceMap *ED_manipulator_facemap_get_fmap(struct wmManipulator *mpr); @@ -149,9 +145,9 @@ enum { ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE = 0, }; -struct wmManipulator *ED_manipulator_primitive3d_new( - struct wmManipulatorGroup *mgroup, const char *name, const int style); +void ED_manipulator_primitive3d_set_style(struct wmManipulator *mpr, int style); void ED_manipulator_primitive3d_set_direction(struct wmManipulator *mpr, const float direction[3]); void ED_manipulator_primitive3d_set_up_vector(struct wmManipulator *mpr, const float direction[3]); + #endif /* __ED_MANIPULATOR_LIBRARY_H__ */ diff --git a/source/blender/editors/manipulator_library/arrow2d_manipulator.c b/source/blender/editors/manipulator_library/arrow2d_manipulator.c index 1798a3dbd6d..f7d4926c7ca 100644 --- a/source/blender/editors/manipulator_library/arrow2d_manipulator.c +++ b/source/blender/editors/manipulator_library/arrow2d_manipulator.c @@ -125,6 +125,15 @@ static void manipulator_arrow2d_draw(const bContext *UNUSED(C), struct wmManipul } } +static void manipulator_arrow2d_setup(wmManipulator *mpr) +{ + ArrowManipulator2D *arrow = (ArrowManipulator2D *)mpr; + + arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; + + arrow->line_len = 1.0f; +} + static void manipulator_arrow2d_invoke( bContext *UNUSED(C), struct wmManipulator *mpr, const wmEvent *UNUSED(event)) { @@ -187,26 +196,18 @@ static int manipulator_arrow2d_test_select( * * \{ */ -struct wmManipulator *ED_manipulator_arrow2d_new(wmManipulatorGroup *mgroup, const char *name) -{ - ArrowManipulator2D *arrow = (ArrowManipulator2D *)WM_manipulator_new( - "MANIPULATOR_WT_arrow_2d", mgroup, name); - - arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; - - arrow->line_len = 1.0f; - - return &arrow->manipulator; -} +#define ASSERT_TYPE_CHECK(mpr) BLI_assert(mpr->type->draw == manipulator_arrow2d_draw) void ED_manipulator_arrow2d_set_angle(struct wmManipulator *mpr, const float angle) { + ASSERT_TYPE_CHECK(mpr); ArrowManipulator2D *arrow = (ArrowManipulator2D *)mpr; arrow->angle = angle; } void ED_manipulator_arrow2d_set_line_len(struct wmManipulator *mpr, const float len) { + ASSERT_TYPE_CHECK(mpr); ArrowManipulator2D *arrow = (ArrowManipulator2D *)mpr; arrow->line_len = len; } @@ -218,6 +219,7 @@ static void MANIPULATOR_WT_arrow_2d(wmManipulatorType *wt) /* api callbacks */ wt->draw = manipulator_arrow2d_draw; + wt->setup = manipulator_arrow2d_setup; wt->invoke = manipulator_arrow2d_invoke; wt->test_select = manipulator_arrow2d_test_select; diff --git a/source/blender/editors/manipulator_library/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/arrow3d_manipulator.c index 431bccf379f..10d5295edc5 100644 --- a/source/blender/editors/manipulator_library/arrow3d_manipulator.c +++ b/source/blender/editors/manipulator_library/arrow3d_manipulator.c @@ -369,6 +369,19 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve WM_event_add_mousemove(C); } +static void manipulator_arrow_setup(wmManipulator *mpr) +{ + ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr; + + const float dir_default[3] = {0.0f, 0.0f, 1.0f}; + + arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; + + arrow->style = -1; + arrow->len = 1.0f; + arrow->data.range_fac = 1.0f; + copy_v3_v3(arrow->direction, dir_default); +} static void manipulator_arrow_invoke( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event) @@ -423,28 +436,16 @@ static void manipulator_arrow_exit(bContext *C, wmManipulator *mpr, const bool c * * \{ */ -wmManipulator *ED_manipulator_arrow3d_new(wmManipulatorGroup *mgroup, const char *name, const int style) +void ED_manipulator_arrow3d_set_style(struct wmManipulator *mpr, int style) { - ArrowManipulator3D *arrow = (ArrowManipulator3D *)WM_manipulator_new( - "MANIPULATOR_WT_arrow_3d", mgroup, name); - - int real_style = style; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr; /* inverted only makes sense in a constrained arrow */ - if (real_style & ED_MANIPULATOR_ARROW_STYLE_INVERTED) { - real_style |= ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED; + if (style & ED_MANIPULATOR_ARROW_STYLE_INVERTED) { + style |= ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED; } - const float dir_default[3] = {0.0f, 0.0f, 1.0f}; - - arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; - - arrow->style = real_style; - arrow->len = 1.0f; - arrow->data.range_fac = 1.0f; - copy_v3_v3(arrow->direction, dir_default); - - return &arrow->manipulator; + arrow->style = style; } /** @@ -536,6 +537,7 @@ static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt) wt->draw_select = manipulator_arrow_draw_select; wt->position_get = manipulator_arrow_position_get; wt->modal = manipulator_arrow_modal; + wt->setup = manipulator_arrow_setup; wt->invoke = manipulator_arrow_invoke; wt->property_update = manipulator_arrow_property_update; wt->exit = manipulator_arrow_exit; diff --git a/source/blender/editors/manipulator_library/cage2d_manipulator.c b/source/blender/editors/manipulator_library/cage2d_manipulator.c index 5aacf6c8473..5030d68bbab 100644 --- a/source/blender/editors/manipulator_library/cage2d_manipulator.c +++ b/source/blender/editors/manipulator_library/cage2d_manipulator.c @@ -72,13 +72,13 @@ enum { #define MANIPULATOR_RECT_MIN_WIDTH 15.0f #define MANIPULATOR_RESIZER_WIDTH 20.0f -typedef struct RectTransformManipulator { +typedef struct Cage2D { wmManipulator manipulator; float w, h; /* dimensions of manipulator */ float rotation; /* rotation of the rectangle */ float scale[2]; /* scaling for the manipulator for non-destructive editing. */ int style; -} RectTransformManipulator; +} Cage2D; /* -------------------------------------------------------------------- */ @@ -203,18 +203,20 @@ static void rect_transform_draw_interaction( static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipulator *mpr) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; - rctf r; + Cage2D *cage = (Cage2D *)mpr; float w = cage->w; float h = cage->h; float aspx = 1.0f, aspy = 1.0f; const float half_w = w / 2.0f; const float half_h = h / 2.0f; + const rctf r = { + .xmin = -half_w, + .ymin = -half_h, + .xmax = half_w, + .ymax = half_h, + }; - r.xmin = -half_w; - r.ymin = -half_h; - r.xmax = half_w; - r.ymax = half_h; + BLI_assert(cage->style != -1); gpuPushMatrix(); gpuTranslate2f(mpr->origin[0] + mpr->offset[0], @@ -268,7 +270,7 @@ static int manipulator_rect_transform_get_cursor(wmManipulator *mpr) static int manipulator_rect_transform_test_select( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; const float mouse[2] = {event->mval[0], event->mval[1]}; //float matrot[2][2]; float point_local[2]; @@ -382,7 +384,7 @@ static bool manipulator_rect_transform_get_prop_value( RNA_property_float_get_array(&mpr_prop->ptr, mpr_prop->prop, value); } else if (STREQ(mpr_prop->idname, "scale")) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) { *value = RNA_property_float_get(&mpr_prop->ptr, mpr_prop->prop); } @@ -402,10 +404,19 @@ static bool manipulator_rect_transform_get_prop_value( return true; } +static void manipulator_rect_transform_setup(wmManipulator *mpr) +{ + Cage2D *cage = (Cage2D *)mpr; + + cage->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; + cage->scale[0] = cage->scale[1] = 1.0f; + cage->style = -1; +} + static void manipulator_rect_transform_invoke( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction"); copy_v2_v2(data->orig_offset, mpr->offset); @@ -421,7 +432,7 @@ static void manipulator_rect_transform_modal( bContext *C, wmManipulator *mpr, const wmEvent *event, const int UNUSED(flag)) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; RectTransformInteraction *data = mpr->interaction_data; /* needed here as well in case clamping occurs */ const float orig_ofx = mpr->offset[0], orig_ofy = mpr->offset[1]; @@ -509,7 +520,7 @@ static void manipulator_rect_transform_modal( static void manipulator_rect_transform_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; if (STREQ(mpr_prop->idname, "offset")) { manipulator_rect_transform_get_prop_value(mpr, mpr_prop, mpr->offset); @@ -524,7 +535,7 @@ static void manipulator_rect_transform_property_update(wmManipulator *mpr, wmMan static void manipulator_rect_transform_exit(bContext *C, wmManipulator *mpr, const bool cancel) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + Cage2D *cage = (Cage2D *)mpr; RectTransformInteraction *data = mpr->interaction_data; if (!cancel) @@ -557,32 +568,31 @@ static void manipulator_rect_transform_exit(bContext *C, wmManipulator *mpr, con * * \{ */ -wmManipulator *ED_manipulator_rect_transform_new(wmManipulatorGroup *mgroup, const char *name, const int style) -{ - RectTransformManipulator *cage = (RectTransformManipulator *)WM_manipulator_new( - "MANIPULATOR_WT_cage", mgroup, name); +#define ASSERT_TYPE_CHECK(mpr) BLI_assert(mpr->type->draw == manipulator_rect_transform_draw) - cage->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; - cage->scale[0] = cage->scale[1] = 1.0f; +void ED_manipulator_cage2d_transform_set_style(wmManipulator *mpr, int style) +{ + ASSERT_TYPE_CHECK(mpr); + Cage2D *cage = (Cage2D *)mpr; cage->style = style; - - return &cage->manipulator; } -void ED_manipulator_rect_transform_set_dimensions(wmManipulator *mpr, const float width, const float height) +void ED_manipulator_cage2d_transform_set_dims(wmManipulator *mpr, const float width, const float height) { - RectTransformManipulator *cage = (RectTransformManipulator *)mpr; + ASSERT_TYPE_CHECK(mpr); + Cage2D *cage = (Cage2D *)mpr; cage->w = width; cage->h = height; } -static void MANIPULATOR_WT_cage(wmManipulatorType *wt) +static void MANIPULATOR_WT_cage_2d(wmManipulatorType *wt) { /* identifiers */ - wt->idname = "MANIPULATOR_WT_cage"; + wt->idname = "MANIPULATOR_WT_cage_2d"; /* api callbacks */ wt->draw = manipulator_rect_transform_draw; + 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; @@ -590,12 +600,12 @@ static void MANIPULATOR_WT_cage(wmManipulatorType *wt) wt->exit = manipulator_rect_transform_exit; wt->cursor_get = manipulator_rect_transform_get_cursor; - wt->struct_size = sizeof(RectTransformManipulator); + wt->struct_size = sizeof(Cage2D); } void ED_manipulatortypes_cage_2d(void) { - WM_manipulatortype_append(MANIPULATOR_WT_cage); + WM_manipulatortype_append(MANIPULATOR_WT_cage_2d); } /** \} */ // Cage Manipulator API diff --git a/source/blender/editors/manipulator_library/dial3d_manipulator.c b/source/blender/editors/manipulator_library/dial3d_manipulator.c index 55d5f257eb4..ea406590e59 100644 --- a/source/blender/editors/manipulator_library/dial3d_manipulator.c +++ b/source/blender/editors/manipulator_library/dial3d_manipulator.c @@ -317,6 +317,8 @@ static void manipulator_dial_draw(const bContext *C, wmManipulator *mpr) float clip_plane_buf[4]; float *clip_plane = (!active && dial->style == ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED) ? clip_plane_buf : NULL; + BLI_assert(dial->style != -1); + /* enable clipping if needed */ if (clip_plane) { ARegion *ar = CTX_wm_region(C); @@ -362,6 +364,18 @@ static void manipulator_dial_modal(bContext *C, wmManipulator *mpr, const wmEven } } + +static void manipulator_dial_setup(wmManipulator *mpr) +{ + DialManipulator *dial = (DialManipulator *)mpr; + const float dir_default[3] = {0.0f, 0.0f, 1.0f}; + + dial->style = -1; + + /* defaults */ + copy_v3_v3(dial->direction, dir_default); +} + static void manipulator_dial_invoke( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event) { @@ -378,25 +392,18 @@ static void manipulator_dial_invoke( mpr->interaction_data = inter; } - /* -------------------------------------------------------------------- */ /** \name Dial Manipulator API * * \{ */ -wmManipulator *ED_manipulator_dial3d_new(wmManipulatorGroup *mgroup, const char *name, const int style) -{ - DialManipulator *dial = (DialManipulator *)WM_manipulator_new( - "MANIPULATOR_WT_dial", mgroup, name); - - const float dir_default[3] = {0.0f, 0.0f, 1.0f}; +#define ASSERT_TYPE_CHECK(mpr) BLI_assert(mpr->type->draw == manipulator_dial_draw) +void ED_manipulator_dial3d_set_style(struct wmManipulator *mpr, int style) +{ + ASSERT_TYPE_CHECK(mpr); + DialManipulator *dial = (DialManipulator *)mpr; dial->style = style; - - /* defaults */ - copy_v3_v3(dial->direction, dir_default); - - return (wmManipulator *)dial; } /** @@ -404,20 +411,22 @@ wmManipulator *ED_manipulator_dial3d_new(wmManipulatorGroup *mgroup, const char */ void ED_manipulator_dial3d_set_up_vector(wmManipulator *mpr, const float direction[3]) { + ASSERT_TYPE_CHECK(mpr); DialManipulator *dial = (DialManipulator *)mpr; copy_v3_v3(dial->direction, direction); normalize_v3(dial->direction); } -static void MANIPULATOR_WT_dial_3d(wmManipulatorType *wt) +static void MANIPULATOR_WT_dial_3d_3d(wmManipulatorType *wt) { /* identifiers */ - wt->idname = "MANIPULATOR_WT_dial"; + wt->idname = "MANIPULATOR_WT_dial_3d"; /* api callbacks */ wt->draw = manipulator_dial_draw; wt->draw_select = manipulator_dial_draw_select; + wt->setup = manipulator_dial_setup; wt->invoke = manipulator_dial_invoke; wt->modal = manipulator_dial_modal; @@ -426,7 +435,7 @@ static void MANIPULATOR_WT_dial_3d(wmManipulatorType *wt) void ED_manipulatortypes_dial_3d(void) { - WM_manipulatortype_append(MANIPULATOR_WT_dial_3d); + WM_manipulatortype_append(MANIPULATOR_WT_dial_3d_3d); } /** \} */ // Dial Manipulator API diff --git a/source/blender/editors/manipulator_library/grab3d_manipulator.c b/source/blender/editors/manipulator_library/grab3d_manipulator.c index a089356a79d..7d1fec5e345 100644 --- a/source/blender/editors/manipulator_library/grab3d_manipulator.c +++ b/source/blender/editors/manipulator_library/grab3d_manipulator.c @@ -191,6 +191,8 @@ static void manipulator_grab_draw(const bContext *C, wmManipulator *mpr) const bool active = mpr->state & WM_MANIPULATOR_STATE_ACTIVE; const bool highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0; + BLI_assert(grab->style != -1); + (void)active; glEnable(GL_BLEND); @@ -215,6 +217,18 @@ static void manipulator_grab_modal(bContext *C, wmManipulator *mpr, const wmEven } } +static void manipulator_grab_setup(wmManipulator *mpr) +{ + GrabManipulator *grab = (GrabManipulator *)mpr; + + const float dir_default[3] = {0.0f, 0.0f, 1.0f}; + + grab->style = -1; + + /* defaults */ + copy_v3_v3(grab->direction, dir_default); +} + static void manipulator_grab_invoke( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event) { @@ -231,25 +245,18 @@ static void manipulator_grab_invoke( mpr->interaction_data = inter; } - /* -------------------------------------------------------------------- */ /** \name Grab Manipulator API * * \{ */ -wmManipulator *ED_manipulator_grab3d_new(wmManipulatorGroup *mgroup, const char *name, const int style) -{ - GrabManipulator *grab = (GrabManipulator *)WM_manipulator_new( - "MANIPULATOR_WT_grab3d", mgroup, name); - - const float dir_default[3] = {0.0f, 0.0f, 1.0f}; +#define ASSERT_TYPE_CHECK(mpr) BLI_assert(mpr->type->draw == manipulator_grab_draw) +void ED_manipulator_grab3d_set_style(wmManipulator *mpr, int style) +{ + ASSERT_TYPE_CHECK(mpr); + GrabManipulator *grab = (GrabManipulator *)mpr; grab->style = style; - - /* defaults */ - copy_v3_v3(grab->direction, dir_default); - - return (wmManipulator *)grab; } /** @@ -257,6 +264,7 @@ wmManipulator *ED_manipulator_grab3d_new(wmManipulatorGroup *mgroup, const char */ void ED_manipulator_grab3d_set_up_vector(wmManipulator *mpr, const float direction[3]) { + ASSERT_TYPE_CHECK(mpr); GrabManipulator *grab = (GrabManipulator *)mpr; copy_v3_v3(grab->direction, direction); @@ -266,11 +274,12 @@ void ED_manipulator_grab3d_set_up_vector(wmManipulator *mpr, const float directi static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt) { /* identifiers */ - wt->idname = "MANIPULATOR_WT_grab3d"; + wt->idname = "MANIPULATOR_WT_grab_3d"; /* api callbacks */ wt->draw = manipulator_grab_draw; wt->draw_select = manipulator_grab_draw_select; + wt->setup = manipulator_grab_setup; wt->invoke = manipulator_grab_invoke; wt->modal = manipulator_grab_modal; diff --git a/source/blender/editors/manipulator_library/primitive3d_manipulator.c b/source/blender/editors/manipulator_library/primitive3d_manipulator.c index 08fa6766aeb..0f715501794 100644 --- a/source/blender/editors/manipulator_library/primitive3d_manipulator.c +++ b/source/blender/editors/manipulator_library/primitive3d_manipulator.c @@ -105,6 +105,8 @@ static void manipulator_primitive_draw_intern( float rot[3][3]; float mat[4][4]; + BLI_assert(prim->style != -1); + if (prim->flag & PRIM_UP_VECTOR_SET) { copy_v3_v3(rot[2], prim->direction); copy_v3_v3(rot[1], prim->up); @@ -171,6 +173,19 @@ static void manipulator_primitive_draw(const bContext *UNUSED(C), wmManipulator (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT)); } +static void manipulator_primitive_setup(wmManipulator *mpr) +{ + PrimitiveManipulator *prim = (PrimitiveManipulator *)mpr; + + const float dir_default[3] = {0.0f, 0.0f, 1.0f}; + + prim->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; + prim->style = -1; + + /* defaults */ + copy_v3_v3(prim->direction, dir_default); +} + static void manipulator_primitive_invoke( bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *UNUSED(event)) { @@ -182,26 +197,18 @@ static void manipulator_primitive_invoke( mpr->interaction_data = inter; } - /* -------------------------------------------------------------------- */ /** \name Primitive Manipulator API * * \{ */ -wmManipulator *ED_manipulator_primitive3d_new(wmManipulatorGroup *mgroup, const char *name, const int style) -{ - PrimitiveManipulator *prim = (PrimitiveManipulator *)WM_manipulator_new( - "MANIPULATOR_WT_primitive3d", mgroup, name); - - const float dir_default[3] = {0.0f, 0.0f, 1.0f}; +#define ASSERT_TYPE_CHECK(mpr) BLI_assert(mpr->type->draw == manipulator_primitive_draw) - prim->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE; +void ED_manipulator_primitive3d_set_style(struct wmManipulator *mpr, int style) +{ + ASSERT_TYPE_CHECK(mpr); + PrimitiveManipulator *prim = (PrimitiveManipulator *)mpr; prim->style = style; - - /* defaults */ - copy_v3_v3(prim->direction, dir_default); - - return (wmManipulator *)prim; } /** @@ -209,6 +216,7 @@ wmManipulator *ED_manipulator_primitive3d_new(wmManipulatorGroup *mgroup, const */ void ED_manipulator_primitive3d_set_direction(wmManipulator *mpr, const float direction[3]) { + ASSERT_TYPE_CHECK(mpr); PrimitiveManipulator *prim = (PrimitiveManipulator *)mpr; normalize_v3_v3(prim->direction, direction); @@ -219,6 +227,7 @@ void ED_manipulator_primitive3d_set_direction(wmManipulator *mpr, const float di */ void ED_manipulator_primitive3d_set_up_vector(wmManipulator *mpr, const float direction[3]) { + ASSERT_TYPE_CHECK(mpr); PrimitiveManipulator *prim = (PrimitiveManipulator *)mpr; if (direction) { @@ -238,6 +247,7 @@ static void MANIPULATOR_WT_primitive3d(wmManipulatorType *wt) /* api callbacks */ wt->draw = manipulator_primitive_draw; wt->draw_select = manipulator_primitive_draw_select; + wt->setup = manipulator_primitive_setup; wt->invoke = manipulator_primitive_invoke; wt->struct_size = sizeof(PrimitiveManipulator); diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c index 24dfc9aa92c..a041348b670 100644 --- a/source/blender/editors/mesh/editmesh_bisect.c +++ b/source/blender/editors/mesh/editmesh_bisect.c @@ -590,9 +590,17 @@ static void manipulator_mesh_bisect_setup(const bContext *C, wmManipulatorGroup struct ManipulatorGroup *man = MEM_callocN(sizeof(ManipulatorGroup), __func__); mgroup->customdata = man; - man->translate_z = ED_manipulator_arrow3d_new(mgroup, "translate_z", ED_MANIPULATOR_ARROW_STYLE_NORMAL); - man->translate_c = ED_manipulator_grab3d_new(mgroup, "translate_c", 0); - man->rotate_c = ED_manipulator_dial3d_new(mgroup, "rotate_c", ED_MANIPULATOR_DIAL_STYLE_RING); + const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); + const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true); + const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true); + + man->translate_z = WM_manipulator_new_ptr(wt_arrow, mgroup, "translate_z"); + man->translate_c = WM_manipulator_new_ptr(wt_grab, mgroup, "translate_c"); + man->rotate_c = WM_manipulator_new_ptr(wt_dial, mgroup, "rotate_c"); + + ED_manipulator_arrow3d_set_style(man->translate_z, ED_MANIPULATOR_ARROW_STYLE_NORMAL); + ED_manipulator_grab3d_set_style(man->translate_c, ED_MANIPULATOR_GRAB_STYLE_RING); + ED_manipulator_dial3d_set_style(man->rotate_c, ED_MANIPULATOR_DIAL_STYLE_RING); WM_manipulator_set_flag(man->translate_c, WM_MANIPULATOR_DRAW_VALUE, true); WM_manipulator_set_flag(man->rotate_c, WM_MANIPULATOR_DRAW_VALUE, true); diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index 9d87e16fc06..2f4a15284fc 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -1048,17 +1048,26 @@ static void manipulator_mesh_spin_setup(const bContext *C, wmManipulatorGroup *m struct ManipulatorSpinGroup *man = MEM_callocN(sizeof(ManipulatorSpinGroup), __func__); mgroup->customdata = man; - man->translate_z = ED_manipulator_arrow3d_new(mgroup, "translate_z", ED_MANIPULATOR_ARROW_STYLE_NORMAL); - man->translate_c = ED_manipulator_grab3d_new(mgroup, "translate_c", 0); - man->rotate_c = ED_manipulator_dial3d_new(mgroup, "rotate_c", ED_MANIPULATOR_DIAL_STYLE_RING); - man->angle_z = ED_manipulator_dial3d_new(mgroup, "angle_z", ED_MANIPULATOR_DIAL_STYLE_RING); + const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); + const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true); + const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true); - WM_manipulator_set_scale(man->angle_z, 0.5f); + man->translate_z = WM_manipulator_new_ptr(wt_arrow, mgroup, "translate_z"); + man->translate_c = WM_manipulator_new_ptr(wt_grab, mgroup, "translate_c"); + man->rotate_c = WM_manipulator_new_ptr(wt_dial, mgroup, "rotate_c"); + man->angle_z = WM_manipulator_new_ptr(wt_dial, mgroup, "angle_z"); + + ED_manipulator_arrow3d_set_style(man->translate_z, ED_MANIPULATOR_ARROW_STYLE_NORMAL); + ED_manipulator_grab3d_set_style(man->translate_c, ED_MANIPULATOR_GRAB_STYLE_RING); + ED_manipulator_dial3d_set_style(man->rotate_c, ED_MANIPULATOR_DIAL_STYLE_RING); + ED_manipulator_dial3d_set_style(man->angle_z, ED_MANIPULATOR_DIAL_STYLE_RING); WM_manipulator_set_flag(man->translate_c, WM_MANIPULATOR_DRAW_VALUE, true); WM_manipulator_set_flag(man->rotate_c, WM_MANIPULATOR_DRAW_VALUE, true); WM_manipulator_set_flag(man->angle_z, WM_MANIPULATOR_DRAW_VALUE, true); + WM_manipulator_set_scale(man->angle_z, 0.5f); + { man->data.context = (bContext *)C; man->data.op = op; diff --git a/source/blender/editors/space_node/node_manipulators.c b/source/blender/editors/space_node/node_manipulators.c index 0f3f53c6dca..db183483143 100644 --- a/source/blender/editors/space_node/node_manipulators.c +++ b/source/blender/editors/space_node/node_manipulators.c @@ -63,11 +63,13 @@ static void WIDGETGROUP_node_transform_setup(const bContext *UNUSED(C), wmManipu { wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__); - wwrapper->manipulator = ED_manipulator_rect_transform_new( - mgroup, "backdrop_cage", + wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, "backdrop_cage"); + + ED_manipulator_cage2d_transform_set_style( + wwrapper->manipulator, ED_MANIPULATOR_RECT_TRANSFORM_STYLE_TRANSLATE | ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM); - mgroup->customdata = wwrapper; + mgroup->customdata = wwrapper; } static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmManipulatorGroup *mgroup) @@ -85,7 +87,7 @@ static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmManipulatorG const float w = (ibuf->x > 0) ? ibuf->x : 64.0f; const float h = (ibuf->y > 0) ? ibuf->y : 64.0f; - ED_manipulator_rect_transform_set_dimensions(cage, w, h); + ED_manipulator_cage2d_transform_set_dims(cage, w, h); WM_manipulator_set_origin(cage, origin); WM_manipulator_set_flag(cage, WM_MANIPULATOR_HIDDEN, false); diff --git a/source/blender/editors/space_view3d/view3d_manipulators.c b/source/blender/editors/space_view3d/view3d_manipulators.c index 6ade2828ffa..a1fbb9b2957 100644 --- a/source/blender/editors/space_view3d/view3d_manipulators.c +++ b/source/blender/editors/space_view3d/view3d_manipulators.c @@ -78,7 +78,9 @@ static void WIDGETGROUP_lamp_setup(const bContext *UNUSED(C), wmManipulatorGroup wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__); - wwrapper->manipulator = ED_manipulator_arrow3d_new(mgroup, propname, ED_MANIPULATOR_ARROW_STYLE_INVERTED); + wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, propname); + ED_manipulator_arrow3d_set_style(wwrapper->manipulator, ED_MANIPULATOR_ARROW_STYLE_INVERTED); + mgroup->customdata = wwrapper; ED_manipulator_arrow3d_set_range_fac(wwrapper->manipulator, 4.0f); @@ -170,6 +172,8 @@ static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgro Camera *ca = ob->data; float dir[3]; + const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); + struct CameraWidgetGroup *camgroup = MEM_callocN(sizeof(struct CameraWidgetGroup), __func__); mgroup->customdata = camgroup; @@ -180,7 +184,8 @@ static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgro const float color[4] = {1.0f, 0.3f, 0.0f, 1.0f}; const float color_hi[4] = {1.0f, 0.3f, 0.0f, 1.0f}; - camgroup->dop_dist = ED_manipulator_arrow3d_new(mgroup, "dof_distance", ED_MANIPULATOR_ARROW_STYLE_CROSS); + camgroup->dop_dist = WM_manipulator_new_ptr(wt_arrow, mgroup, "dof_distance"); + ED_manipulator_arrow3d_set_style(camgroup->dop_dist, ED_MANIPULATOR_ARROW_STYLE_CROSS); WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_DRAW_HOVER, true); WM_manipulator_set_color(camgroup->dop_dist, color); WM_manipulator_set_color_highlight(camgroup->dop_dist, color_hi); @@ -192,16 +197,17 @@ static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgro const float color[4] = {1.0f, 1.0, 0.27f, 0.5f}; const float color_hi[4] = {1.0f, 1.0, 0.27f, 1.0f}; - camgroup->focal_len = ED_manipulator_arrow3d_new( - mgroup, "focal_len", - (ED_MANIPULATOR_ARROW_STYLE_CONE | ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED)); + camgroup->focal_len = WM_manipulator_new_ptr(wt_arrow, mgroup, "focal_len"); + ED_manipulator_arrow3d_set_style( + camgroup->focal_len, (ED_MANIPULATOR_ARROW_STYLE_CONE | ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED)); + WM_manipulator_set_color(camgroup->focal_len, color); WM_manipulator_set_color_highlight(camgroup->focal_len, color_hi); cameragroup_property_setup(camgroup->focal_len, ob, ca, false); - camgroup->ortho_scale = ED_manipulator_arrow3d_new( - mgroup, "ortho_scale", - (ED_MANIPULATOR_ARROW_STYLE_CONE | ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED)); + camgroup->ortho_scale = WM_manipulator_new_ptr(wt_arrow, mgroup, "ortho_scale"); + ED_manipulator_arrow3d_set_style( + camgroup->ortho_scale, (ED_MANIPULATOR_ARROW_STYLE_CONE | ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED)); WM_manipulator_set_color(camgroup->ortho_scale, color); WM_manipulator_set_color_highlight(camgroup->ortho_scale, color_hi); cameragroup_property_setup(camgroup->ortho_scale, ob, ca, true); @@ -316,8 +322,8 @@ static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmManipulato wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__); mgroup->customdata = wwrapper; - wwrapper->manipulator = ED_manipulator_arrow3d_new(mgroup, "field_strength", ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED); - + wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, "field_strength"); + ED_manipulator_arrow3d_set_style(wwrapper->manipulator, ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED); ED_manipulator_arrow3d_set_ui_range(wwrapper->manipulator, -200.0f, 200.0f); ED_manipulator_arrow3d_set_range_fac(wwrapper->manipulator, 6.0f); WM_manipulator_set_color(wwrapper->manipulator, col); diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index bd470bd08d9..4eeca3967cd 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -1086,30 +1086,52 @@ static ManipulatorGroup *manipulatorgroup_init(wmManipulatorGroup *mgroup) man = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data"); + const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); + const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true); + const wmManipulatorType *wt_prim = WM_manipulatortype_find("MANIPULATOR_WT_primitive3d", true); + +#define MANIPULATOR_NEW_ARROW(v, name, style) { \ + v = WM_manipulator_new_ptr(wt_arrow, mgroup, name); \ + ED_manipulator_arrow3d_set_style(v, style); \ +} ((void)0) +#define MANIPULATOR_NEW_DIAL(v, name, style) { \ + v = WM_manipulator_new_ptr(wt_dial, mgroup, name); \ + ED_manipulator_dial3d_set_style(v, style); \ +} ((void)0) +#define MANIPULATOR_NEW_PRIM(v, name, style) { \ + v = WM_manipulator_new_ptr(wt_prim, mgroup, name); \ + ED_manipulator_primitive3d_set_style(v, style); \ +} ((void)0) + /* add/init widgets - order matters! */ - man->rotate_t = ED_manipulator_dial3d_new(mgroup, "rotate_t", ED_MANIPULATOR_DIAL_STYLE_RING_FILLED); - - man->scale_c = ED_manipulator_dial3d_new(mgroup, "scale_c", ED_MANIPULATOR_DIAL_STYLE_RING); - man->scale_x = ED_manipulator_arrow3d_new(mgroup, "scale_x", ED_MANIPULATOR_ARROW_STYLE_BOX); - man->scale_y = ED_manipulator_arrow3d_new(mgroup, "scale_y", ED_MANIPULATOR_ARROW_STYLE_BOX); - man->scale_z = ED_manipulator_arrow3d_new(mgroup, "scale_z", ED_MANIPULATOR_ARROW_STYLE_BOX); - man->scale_xy = ED_manipulator_primitive3d_new(mgroup, "scale_xy", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); - man->scale_yz = ED_manipulator_primitive3d_new(mgroup, "scale_yz", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); - man->scale_zx = ED_manipulator_primitive3d_new(mgroup, "scale_zx", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); - - man->rotate_x = ED_manipulator_dial3d_new(mgroup, "rotate_x", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); - man->rotate_y = ED_manipulator_dial3d_new(mgroup, "rotate_y", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); - man->rotate_z = ED_manipulator_dial3d_new(mgroup, "rotate_z", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); + MANIPULATOR_NEW_DIAL(man->rotate_t, "rotate_t", ED_MANIPULATOR_DIAL_STYLE_RING_FILLED); + + MANIPULATOR_NEW_DIAL(man->scale_c, "scale_c", ED_MANIPULATOR_DIAL_STYLE_RING); + + MANIPULATOR_NEW_ARROW(man->scale_x, "scale_x", ED_MANIPULATOR_ARROW_STYLE_BOX); + MANIPULATOR_NEW_ARROW(man->scale_y, "scale_y", ED_MANIPULATOR_ARROW_STYLE_BOX); + MANIPULATOR_NEW_ARROW(man->scale_z, "scale_z", ED_MANIPULATOR_ARROW_STYLE_BOX); + + MANIPULATOR_NEW_PRIM(man->scale_xy, "scale_xy", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + MANIPULATOR_NEW_PRIM(man->scale_yz, "scale_yz", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + MANIPULATOR_NEW_PRIM(man->scale_zx, "scale_zx", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + + MANIPULATOR_NEW_DIAL(man->rotate_x, "rotate_x", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); + MANIPULATOR_NEW_DIAL(man->rotate_y, "rotate_y", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); + MANIPULATOR_NEW_DIAL(man->rotate_z, "rotate_z", ED_MANIPULATOR_DIAL_STYLE_RING_CLIPPED); + /* init screen aligned widget last here, looks better, behaves better */ - man->rotate_c = ED_manipulator_dial3d_new(mgroup, "rotate_c", ED_MANIPULATOR_DIAL_STYLE_RING); - - man->translate_c = ED_manipulator_dial3d_new(mgroup, "translate_c", ED_MANIPULATOR_DIAL_STYLE_RING); - man->translate_x = ED_manipulator_arrow3d_new(mgroup, "translate_x", ED_MANIPULATOR_ARROW_STYLE_NORMAL); - man->translate_y = ED_manipulator_arrow3d_new(mgroup, "translate_y", ED_MANIPULATOR_ARROW_STYLE_NORMAL); - man->translate_z = ED_manipulator_arrow3d_new(mgroup, "translate_z", ED_MANIPULATOR_ARROW_STYLE_NORMAL); - man->translate_xy = ED_manipulator_primitive3d_new(mgroup, "translate_xy", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); - man->translate_yz = ED_manipulator_primitive3d_new(mgroup, "translate_yz", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); - man->translate_zx = ED_manipulator_primitive3d_new(mgroup, "translate_zx", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + MANIPULATOR_NEW_DIAL(man->rotate_c, "rotate_c", ED_MANIPULATOR_DIAL_STYLE_RING); + + MANIPULATOR_NEW_DIAL(man->translate_c, "translate_c", ED_MANIPULATOR_DIAL_STYLE_RING); + + MANIPULATOR_NEW_ARROW(man->translate_x, "translate_x", ED_MANIPULATOR_ARROW_STYLE_NORMAL); + MANIPULATOR_NEW_ARROW(man->translate_y, "translate_y", ED_MANIPULATOR_ARROW_STYLE_NORMAL); + MANIPULATOR_NEW_ARROW(man->translate_z, "translate_z", ED_MANIPULATOR_ARROW_STYLE_NORMAL); + + MANIPULATOR_NEW_PRIM(man->translate_xy, "translate_xy", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + MANIPULATOR_NEW_PRIM(man->translate_yz, "translate_yz", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); + MANIPULATOR_NEW_PRIM(man->translate_zx, "translate_zx", ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE); return man; } diff --git a/source/blender/editors/transform/transform_manipulator2d.c b/source/blender/editors/transform/transform_manipulator2d.c index 7990834ed8c..0ea50b604fb 100644 --- a/source/blender/editors/transform/transform_manipulator2d.c +++ b/source/blender/editors/transform/transform_manipulator2d.c @@ -130,10 +130,12 @@ static void manipulator2d_get_axis_color(const int axis_idx, float *r_col, float static ManipulatorGroup2D *manipulatorgroup2d_init(wmManipulatorGroup *mgroup) { + const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_2d", true); + ManipulatorGroup2D *man = MEM_callocN(sizeof(ManipulatorGroup2D), __func__); - man->translate_x = ED_manipulator_arrow2d_new(mgroup, "translate_x"); - man->translate_y = ED_manipulator_arrow2d_new(mgroup, "translate_y"); + man->translate_x = WM_manipulator_new_ptr(wt_arrow, mgroup, "translate_x"); + man->translate_y = WM_manipulator_new_ptr(wt_arrow, mgroup, "translate_y"); return man; } diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_types.h b/source/blender/windowmanager/manipulators/WM_manipulator_types.h index cc487dadca2..ec009a5e7a0 100644 --- a/source/blender/windowmanager/manipulators/WM_manipulator_types.h +++ b/source/blender/windowmanager/manipulators/WM_manipulator_types.h @@ -175,6 +175,9 @@ typedef struct wmManipulatorType { * use so we can cant to other types without the hassle of a custom-data pointer. */ uint struct_size; + /* Initialize struct (calloc'd 'struct_size' region). */ + wmManipulatorFnSetup setup; + /* draw manipulator */ wmManipulatorFnDraw draw; diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c index b71cfdb15cf..f24bdb6e697 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c @@ -66,22 +66,26 @@ static void wm_manipulator_register( * \note Follow #wm_operator_create convention. */ static wmManipulator *wm_manipulator_create( - const wmManipulatorType *mpt) + const wmManipulatorType *wt) { - BLI_assert(mpt != NULL); - BLI_assert(mpt->struct_size >= sizeof(wmManipulator)); + BLI_assert(wt != NULL); + BLI_assert(wt->struct_size >= sizeof(wmManipulator)); - wmManipulator *mpr = MEM_callocN(mpt->struct_size, __func__); - mpr->type = mpt; + wmManipulator *mpr = MEM_callocN(wt->struct_size, __func__); + mpr->type = wt; return mpr; } -wmManipulator *WM_manipulator_new_ptr(const wmManipulatorType *mpt, wmManipulatorGroup *mgroup, const char *name) +wmManipulator *WM_manipulator_new_ptr(const wmManipulatorType *wt, wmManipulatorGroup *mgroup, const char *name) { - wmManipulator *mpr = wm_manipulator_create(mpt); + wmManipulator *mpr = wm_manipulator_create(wt); wm_manipulator_register(mgroup, mpr, name); + if (mpr->type->setup != NULL) { + mpr->type->setup(mpr); + } + return mpr; } @@ -93,11 +97,7 @@ wmManipulator *WM_manipulator_new_ptr(const wmManipulatorType *mpt, wmManipulato wmManipulator *WM_manipulator_new(const char *idname, wmManipulatorGroup *mgroup, const char *name) { const wmManipulatorType *wt = WM_manipulatortype_find(idname, false); - wmManipulator *mpr = wm_manipulator_create(wt); - - wm_manipulator_register(mgroup, mpr, name); - - return mpr; + return WM_manipulator_new_ptr(wt, mgroup, name); } /** diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h index 41e603fc521..90eaba74de1 100644 --- a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h +++ b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h @@ -45,6 +45,8 @@ typedef struct wmKeyMap *(*wmManipulatorGroupFnSetupKeymap)( /* wmManipulator */ /* See: wmManipulatorType for docs on each type. */ + +typedef void (*wmManipulatorFnSetup)(struct wmManipulator *); typedef void (*wmManipulatorFnDraw)(const struct bContext *, struct wmManipulator *); typedef void (*wmManipulatorFnDrawSelect)(const struct bContext *, struct wmManipulator *, int); typedef int (*wmManipulatorFnTestSelect)(struct bContext *, struct wmManipulator *, const struct wmEvent *); |