diff options
Diffstat (limited to 'source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c')
-rw-r--r-- | source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c | 80 |
1 files changed, 47 insertions, 33 deletions
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 bbfe17485cf..0487903163a 100644 --- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c +++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c @@ -74,7 +74,7 @@ enum { ARROW_CUSTOM_RANGE_SET = (1 << 1), }; -typedef struct ArrowManipulator { +typedef struct ArrowManipulator3D { wmManipulator manipulator; ManipulatorCommonData data; @@ -86,20 +86,20 @@ typedef struct ArrowManipulator { float direction[3]; float up[3]; float aspect[2]; /* cone style only */ -} ArrowManipulator; +} ArrowManipulator3D; /* -------------------------------------------------------------------- */ static void manipulator_arrow_get_final_pos(wmManipulator *manipulator, float r_pos[3]) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; mul_v3_v3fl(r_pos, arrow->direction, arrow->data.offset); add_v3_v3(r_pos, arrow->manipulator.origin); } -static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, const float color[4]) +static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select, const float color[4]) { unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); bool unbind_shader = true; @@ -186,7 +186,7 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co } } -static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, const bool highlight) +static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, const bool highlight) { const float up[3] = {0.0f, 0.0f, 1.0f}; float col[4]; @@ -244,12 +244,12 @@ static void manipulator_arrow_render_3d_intersect( int selectionbase) { GPU_select_load_id(selectionbase); - arrow_draw_intern((ArrowManipulator *)manipulator, true, false); + arrow_draw_intern((ArrowManipulator3D *)manipulator, true, false); } static void manipulator_arrow_draw(const bContext *UNUSED(C), wmManipulator *manipulator) { - arrow_draw_intern((ArrowManipulator *)manipulator, false, (manipulator->state & WM_MANIPULATOR_HIGHLIGHT) != 0); + arrow_draw_intern((ArrowManipulator3D *)manipulator, false, (manipulator->state & WM_MANIPULATOR_HIGHLIGHT) != 0); } /** @@ -258,7 +258,7 @@ static void manipulator_arrow_draw(const bContext *UNUSED(C), wmManipulator *man */ static void manipulator_arrow_handler(bContext *C, wmManipulator *manipulator, const wmEvent *event, const int flag) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; ManipulatorInteraction *inter = manipulator->interaction_data; ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = ar->regiondata; @@ -372,7 +372,7 @@ static void manipulator_arrow_handler(bContext *C, wmManipulator *manipulator, c static void manipulator_arrow_invoke( bContext *UNUSED(C), wmManipulator *manipulator, const wmEvent *event) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__); PointerRNA ptr = manipulator->ptr[ARROW_SLOT_OFFSET_WORLD_SPACE]; PropertyRNA *prop = manipulator->props[ARROW_SLOT_OFFSET_WORLD_SPACE]; @@ -395,11 +395,11 @@ static void manipulator_arrow_invoke( static void manipulator_arrow_prop_data_update(wmManipulator *manipulator, const int slot) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; manipulator_property_data_update( - manipulator, &arrow->data, slot, - arrow->style & MANIPULATOR_ARROW_STYLE_CONSTRAINED, - arrow->style & MANIPULATOR_ARROW_STYLE_INVERTED); + manipulator, &arrow->data, slot, + (arrow->style & MANIPULATOR_ARROW_STYLE_CONSTRAINED) != 0, + (arrow->style & MANIPULATOR_ARROW_STYLE_INVERTED) != 0); } static void manipulator_arrow_exit(bContext *C, wmManipulator *manipulator, const bool cancel) @@ -407,7 +407,7 @@ static void manipulator_arrow_exit(bContext *C, wmManipulator *manipulator, cons if (!cancel) return; - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; ManipulatorCommonData *data = &arrow->data; ManipulatorInteraction *inter = manipulator->interaction_data; @@ -423,6 +423,9 @@ static void manipulator_arrow_exit(bContext *C, wmManipulator *manipulator, cons wmManipulator *MANIPULATOR_arrow_new(wmManipulatorGroup *mgroup, const char *name, const int style) { + const wmManipulatorType *mpt = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", false); + ArrowManipulator3D *arrow = (ArrowManipulator3D *)WM_manipulator_new(mpt, mgroup, name); + int real_style = style; /* inverted only makes sense in a constrained arrow */ @@ -430,18 +433,8 @@ wmManipulator *MANIPULATOR_arrow_new(wmManipulatorGroup *mgroup, const char *nam real_style |= MANIPULATOR_ARROW_STYLE_CONSTRAINED; } - - ArrowManipulator *arrow = MEM_callocN(sizeof(ArrowManipulator), name); const float dir_default[3] = {0.0f, 0.0f, 1.0f}; - 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; @@ -449,9 +442,7 @@ wmManipulator *MANIPULATOR_arrow_new(wmManipulatorGroup *mgroup, const char *nam arrow->data.range_fac = 1.0f; copy_v3_v3(arrow->direction, dir_default); - wm_manipulator_register(mgroup, &arrow->manipulator, name); - - return (wmManipulator *)arrow; + return &arrow->manipulator; } /** @@ -459,7 +450,7 @@ wmManipulator *MANIPULATOR_arrow_new(wmManipulatorGroup *mgroup, const char *nam */ void MANIPULATOR_arrow_set_direction(wmManipulator *manipulator, const float direction[3]) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; copy_v3_v3(arrow->direction, direction); normalize_v3(arrow->direction); @@ -470,7 +461,7 @@ void MANIPULATOR_arrow_set_direction(wmManipulator *manipulator, const float dir */ void MANIPULATOR_arrow_set_up_vector(wmManipulator *manipulator, const float direction[3]) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; if (direction) { copy_v3_v3(arrow->up, direction); @@ -487,7 +478,7 @@ void MANIPULATOR_arrow_set_up_vector(wmManipulator *manipulator, const float dir */ void MANIPULATOR_arrow_set_line_len(wmManipulator *manipulator, const float len) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; arrow->len = len; } @@ -498,7 +489,7 @@ void MANIPULATOR_arrow_set_line_len(wmManipulator *manipulator, const float len) */ void MANIPULATOR_arrow_set_ui_range(wmManipulator *manipulator, const float min, const float max) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; BLI_assert(min < max); BLI_assert(!(arrow->manipulator.props[0] && "Make sure this function " @@ -516,7 +507,7 @@ void MANIPULATOR_arrow_set_ui_range(wmManipulator *manipulator, const float min, */ void MANIPULATOR_arrow_set_range_fac(wmManipulator *manipulator, const float range_fac) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; BLI_assert(!(arrow->manipulator.props[0] && "Make sure this function " "is called before WM_manipulator_set_property")); @@ -529,11 +520,34 @@ void MANIPULATOR_arrow_set_range_fac(wmManipulator *manipulator, const float ran */ void MANIPULATOR_arrow_cone_set_aspect(wmManipulator *manipulator, const float aspect[2]) { - ArrowManipulator *arrow = (ArrowManipulator *)manipulator; + ArrowManipulator3D *arrow = (ArrowManipulator3D *)manipulator; copy_v2_v2(arrow->aspect, aspect); } +static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt) +{ + /* identifiers */ + wt->idname = "MANIPULATOR_WT_arrow_3d"; + + /* api callbacks */ + wt->draw = manipulator_arrow_draw; + wt->draw_select = manipulator_arrow_render_3d_intersect; + wt->position_get = manipulator_arrow_get_final_pos; + wt->intersect = NULL; + wt->handler = manipulator_arrow_handler; + wt->invoke = manipulator_arrow_invoke; + wt->prop_data_update = manipulator_arrow_prop_data_update; + wt->exit = manipulator_arrow_exit; + + wt->size = sizeof(ArrowManipulator3D); +} + +void ED_manipulatortypes_arrow_3d(void) +{ + WM_manipulatortype_append(MANIPULATOR_WT_arrow_3d); +} + /** \} */ /* Arrow Manipulator API */ |