diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-06-17 03:01:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-06-17 03:02:54 +0300 |
commit | 8c22d31dccd47102d618dce605c6d5f490575b91 (patch) | |
tree | e939f22bc412891a0ced6ca471fe4f89eabce75d /source/blender/editors/manipulator_library | |
parent | 71b70b23b36008b4ac03001b7e691a0189b4d158 (diff) |
Manipulator: remove type specific 'new' functions
Instead use generic 'WM_manipulator_new', adding a new 'setup'
callback (like wmManipulatorGroup.setup) used to initialize type vars.
This moves conventions closer to wmOperator and simplifies exposing to
Python.
Diffstat (limited to 'source/blender/editors/manipulator_library')
6 files changed, 139 insertions, 97 deletions
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); |