From c4a4a89ef5ae569f8651de6e50a507adc0386ef9 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 2 Jun 2023 14:42:27 +0200 Subject: [PATCH] Transform: refactor modes by reorganizing their data in 'TransModeInfo' No functional changes. This commit reorganizes the transform mode functions by bundling them into a struct called `TransModeInfo` in the file. This structural change enhances the readability of the transform code and simplifies the process of adding or removing modes. Furthermore, this refactor allows for the inclusion of other essential mode-specific values, such as 'input', which cannot be separated from the code. Overall, this commit improves the maintainability and extensibility of the transform functionality. Pull Request: https://projects.blender.org/blender/blender/pulls/108467 --- source/blender/editors/transform/transform.c | 23 +- source/blender/editors/transform/transform.h | 27 +-- .../editors/transform/transform_generics.c | 3 +- .../editors/transform/transform_mode.c | 215 +++++++----------- .../editors/transform/transform_mode.h | 98 +++++--- .../editors/transform/transform_mode_align.c | 17 +- .../transform/transform_mode_baketime.c | 14 +- .../transform/transform_mode_bbone_resize.c | 14 +- .../editors/transform/transform_mode_bend.c | 17 +- .../transform/transform_mode_boneenvelope.c | 17 +- .../transform/transform_mode_boneroll.c | 16 +- .../transform_mode_curveshrinkfatten.c | 16 +- .../transform/transform_mode_customdata.c | 44 +++- .../transform_mode_edge_rotate_normal.c | 14 +- .../transform/transform_mode_edge_seq_slide.c | 16 +- .../transform/transform_mode_edge_slide.c | 102 +++++---- .../transform/transform_mode_gpopacity.c | 16 +- .../transform/transform_mode_gpshrinkfatten.c | 16 +- .../transform_mode_maskshrinkfatten.c | 16 +- .../editors/transform/transform_mode_mirror.c | 16 +- .../transform/transform_mode_push_pull.c | 14 +- .../editors/transform/transform_mode_resize.c | 37 ++- .../editors/transform/transform_mode_rotate.c | 17 +- .../editors/transform/transform_mode_shear.c | 17 +- .../transform/transform_mode_shrink_fatten.c | 17 +- .../transform/transform_mode_skin_resize.c | 14 +- .../editors/transform/transform_mode_tilt.c | 16 +- .../transform/transform_mode_timescale.c | 15 +- .../transform/transform_mode_timeslide.c | 14 +- .../transform/transform_mode_timetranslate.c | 15 +- .../transform/transform_mode_tosphere.c | 15 +- .../transform/transform_mode_trackball.c | 17 +- .../transform/transform_mode_translate.c | 19 +- .../transform/transform_mode_vert_slide.c | 108 +++++---- .../editors/transform/transform_snap.cc | 9 +- 35 files changed, 650 insertions(+), 411 deletions(-) diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 3c4d355c029..7e23f87fe4d 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1332,11 +1332,12 @@ int transformEvent(TransInfo *t, const wmEvent *event) } /* Per transform event, if present */ - if (t->handleEvent && (!handled || - /* Needed for vertex slide, see #38756. */ - (event->type == MOUSEMOVE))) + if (t->mode_info && t->mode_info->handle_event_fn && + (!handled || + /* Needed for vertex slide, see #38756. */ + (event->type == MOUSEMOVE))) { - t->redraw |= t->handleEvent(t, event); + t->redraw |= t->mode_info->handle_event_fn(t, event); } /* Try to init modal numinput now, if possible. */ @@ -1441,10 +1442,8 @@ static void drawTransformView(const struct bContext *C, ARegion *region, void *a drawPropCircle(C, t); drawSnapping(C, t); - if (region == t->region) { - /* edge slide, vert slide */ - drawEdgeSlide(t); - drawVertSlide(t); + if (region == t->region && t->mode_info && t->mode_info->draw_fn) { + t->mode_info->draw_fn(t); } } @@ -2066,8 +2065,8 @@ void transformApply(bContext *C, TransInfo *t) if (t->redraw == TREDRAW_HARD) { selectConstraint(t); - if (t->transform) { - t->transform(t, t->mval); /* calls recalcData() */ + if (t->mode_info) { + t->mode_info->transform_fn(t, t->mval); /* calls recalcData() */ } } @@ -2143,8 +2142,8 @@ bool checkUseAxisMatrix(TransInfo *t) bool transform_apply_matrix(TransInfo *t, float mat[4][4]) { - if (t->transform_matrix != NULL) { - t->transform_matrix(t, mat); + if (t->mode_info && t->mode_info->transform_matrix_fn) { + t->mode_info->transform_matrix_fn(t, mat); return true; } return false; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index ef5c59f1532..4daa60e3c0c 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -309,14 +309,6 @@ typedef struct TransSnap { double last; void (*snap_target_fn)(struct TransInfo *, float *); void (*snap_source_fn)(struct TransInfo *); - /** - * Get the transform distance between two points (used by Closest snap) - * - * \note Return value can be anything, - * where the smallest absolute value defines what's closest. - */ - float (*snap_mode_distance_fn)(struct TransInfo *t, const float p1[3], const float p2[3]); - void (*snap_mode_apply_fn)(struct TransInfo *, float *); /** * Re-usable snap context data. @@ -508,6 +500,11 @@ typedef struct TransInfo { /** TODO: It should be a member of #TransDataContainer. */ struct TransConvertTypeInfo *data_type; + /** Mode indicator as set for the operator. + * NOTE: A same `mode_info` can have different `mode`s. */ + eTfmMode mode; + struct TransModeInfo *mode_info; + /** Current context/options for transform. */ eTContext options; /** Generic flags for special behaviors. */ @@ -520,20 +517,6 @@ typedef struct TransInfo { eRedrawFlag redraw; /** Choice of custom cursor with or without a help line from the gizmo to the mouse position. */ eTHelpline helpline; - /** Current mode. */ - eTfmMode mode; - - /** Main transform mode function. */ - void (*transform)(struct TransInfo *, const int[2]); - /* Event handler function that determines whether the viewport needs to be redrawn. */ - eRedrawFlag (*handleEvent)(struct TransInfo *, const struct wmEvent *); - - /** - * Optional callback to transform a single matrix. - * - * \note used by the gizmo to transform the matrix used to position it. - */ - void (*transform_matrix)(struct TransInfo *t, float mat_xform[4][4]); /** Constraint Data. */ TransCon con; diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 68f4aee48ba..9323d1ada76 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -186,8 +186,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve copy_v2_v2_int(t->mouse.imval, mval); copy_v2_v2_int(t->con.imval, mval); - t->transform = NULL; - t->handleEvent = NULL; + t->mode_info = NULL; t->data_len_all = 0; diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c index 6e37ad93b13..927eb13aea8 100644 --- a/source/blender/editors/transform/transform_mode.c +++ b/source/blender/editors/transform/transform_mode.c @@ -1066,141 +1066,92 @@ void ElementResize(const TransInfo *t, /** \name Transform Mode Initialization * \{ */ +static TransModeInfo *mode_info_get(TransInfo *t, const int mode) +{ + switch (mode) { + case TFM_TRANSLATION: + return &TransMode_translate; + case TFM_ROTATION: + return &TransMode_rotate; + case TFM_RESIZE: + return &TransMode_resize; + case TFM_SKIN_RESIZE: + return &TransMode_skinresize; + case TFM_TOSPHERE: + return &TransMode_tosphere; + case TFM_SHEAR: + return &TransMode_shear; + case TFM_BEND: + return &TransMode_bend; + case TFM_SHRINKFATTEN: + return &TransMode_shrinkfatten; + case TFM_TILT: + return &TransMode_tilt; + case TFM_CURVE_SHRINKFATTEN: + return &TransMode_curveshrinkfatten; + case TFM_MASK_SHRINKFATTEN: + return &TransMode_maskshrinkfatten; + case TFM_GPENCIL_SHRINKFATTEN: + return &TransMode_gpshrinkfatten; + case TFM_TRACKBALL: + return &TransMode_trackball; + case TFM_PUSHPULL: + return &TransMode_pushpull; + case TFM_EDGE_CREASE: + return &TransMode_edgecrease; + case TFM_VERT_CREASE: + return &TransMode_vertcrease; + case TFM_BONESIZE: + return &TransMode_bboneresize; + case TFM_BONE_ENVELOPE: + case TFM_BONE_ENVELOPE_DIST: + return &TransMode_boneenvelope; + case TFM_EDGE_SLIDE: + return &TransMode_edgeslide; + case TFM_VERT_SLIDE: + return &TransMode_vertslide; + case TFM_BONE_ROLL: + return &TransMode_boneroll; + case TFM_TIME_TRANSLATE: + return &TransMode_translate; + case TFM_TIME_SLIDE: + return &TransMode_timeslide; + case TFM_TIME_SCALE: + return &TransMode_timescale; + case TFM_TIME_EXTEND: + /* Do TFM_TIME_TRANSLATE (for most Animation Editors because they have only 1D transforms for + * time values) or TFM_TRANSLATION (for Graph/NLA Editors only since they uses 'standard' + * transforms to get 2D movement) depending on which editor this was called from. */ + if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) { + return &TransMode_translate; + } + return &TransMode_timetranslate; + case TFM_BAKE_TIME: + return &TransMode_baketime; + case TFM_MIRROR: + return &TransMode_mirror; + case TFM_BWEIGHT: + return &TransMode_bevelweight; + case TFM_ALIGN: + return &TransMode_align; + case TFM_SEQ_SLIDE: + return &TransMode_seqslide; + case TFM_NORMAL_ROTATION: + return &TransMode_rotatenormal; + case TFM_GPENCIL_OPACITY: + return &TransMode_gpopacity; + } + return NULL; +} + void transform_mode_init(TransInfo *t, wmOperator *op, const int mode) { t->mode = mode; + t->mode_info = mode_info_get(t, mode); - switch (mode) { - case TFM_TRANSLATION: - initTranslation(t); - break; - case TFM_ROTATION: - initRotation(t); - break; - case TFM_RESIZE: { - float mouse_dir_constraint[3]; - if (op) { - PropertyRNA *prop = RNA_struct_find_property(op->ptr, "mouse_dir_constraint"); - if (prop) { - RNA_property_float_get_array(op->ptr, prop, mouse_dir_constraint); - } - else { - /* Resize is expected to have this property. */ - BLI_assert(!STREQ(op->idname, "TRANSFORM_OT_resize")); - } - } - else { - zero_v3(mouse_dir_constraint); - } - initResize(t, mouse_dir_constraint); - break; - } - case TFM_SKIN_RESIZE: - initSkinResize(t); - break; - case TFM_TOSPHERE: - initToSphere(t); - break; - case TFM_SHEAR: - initShear(t); - break; - case TFM_BEND: - initBend(t); - break; - case TFM_SHRINKFATTEN: - initShrinkFatten(t); - break; - case TFM_TILT: - initTilt(t); - break; - case TFM_CURVE_SHRINKFATTEN: - initCurveShrinkFatten(t); - break; - case TFM_MASK_SHRINKFATTEN: - initMaskShrinkFatten(t); - break; - case TFM_GPENCIL_SHRINKFATTEN: - initGPShrinkFatten(t); - break; - case TFM_TRACKBALL: - initTrackball(t); - break; - case TFM_PUSHPULL: - initPushPull(t); - break; - case TFM_EDGE_CREASE: - initEgdeCrease(t); - break; - case TFM_VERT_CREASE: - initVertCrease(t); - break; - case TFM_BONESIZE: - initBoneSize(t); - break; - case TFM_BONE_ENVELOPE: - case TFM_BONE_ENVELOPE_DIST: - initBoneEnvelope(t); - break; - case TFM_EDGE_SLIDE: - case TFM_VERT_SLIDE: { - const bool use_even = (op ? RNA_boolean_get(op->ptr, "use_even") : false); - const bool flipped = (op ? RNA_boolean_get(op->ptr, "flipped") : false); - const bool use_clamp = (op ? RNA_boolean_get(op->ptr, "use_clamp") : true); - if (mode == TFM_EDGE_SLIDE) { - const bool use_double_side = (op ? !RNA_boolean_get(op->ptr, "single_side") : true); - initEdgeSlide_ex(t, use_double_side, use_even, flipped, use_clamp); - } - else { - initVertSlide_ex(t, use_even, flipped, use_clamp); - } - break; - } - case TFM_BONE_ROLL: - initBoneRoll(t); - break; - case TFM_TIME_TRANSLATE: - initTimeTranslate(t); - break; - case TFM_TIME_SLIDE: - initTimeSlide(t); - break; - case TFM_TIME_SCALE: - initTimeScale(t); - break; - case TFM_TIME_EXTEND: - /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation - * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION - * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement) - * depending on which editor this was called from - */ - if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) { - initTranslation(t); - } - else { - initTimeTranslate(t); - } - break; - case TFM_BAKE_TIME: - initBakeTime(t); - break; - case TFM_MIRROR: - initMirror(t); - break; - case TFM_BWEIGHT: - initBevelWeight(t); - break; - case TFM_ALIGN: - initAlign(t); - break; - case TFM_SEQ_SLIDE: - initSeqSlide(t); - break; - case TFM_NORMAL_ROTATION: - initNormalRotation(t); - break; - case TFM_GPENCIL_OPACITY: - initGPOpacity(t); - break; + if (t->mode_info) { + t->flag |= t->mode_info->flags; + t->mode_info->init_fn(t, op); } if (t->data_type == &TransConvertType_Mesh) { @@ -1211,7 +1162,7 @@ void transform_mode_init(TransInfo *t, wmOperator *op, const int mode) transform_gizmo_3d_model_from_constraint_and_mode_set(t); - /* TODO(@germano): Some of these operations change the `t->mode`. + /* TODO(@mano-wii): Some of these operations change the `t->mode`. * This can be bad for Redo. */ // BLI_assert(t->mode == mode); } diff --git a/source/blender/editors/transform/transform_mode.h b/source/blender/editors/transform/transform_mode.h index bbaf449ea7f..89c33f05d51 100644 --- a/source/blender/editors/transform/transform_mode.h +++ b/source/blender/editors/transform/transform_mode.h @@ -16,6 +16,37 @@ struct TransInfo; struct bContext; struct wmOperator; +typedef struct TransModeInfo { + int flags; /* eTFlag */ + + void (*init_fn)(TransInfo *, struct wmOperator *); + + /** Main transform mode function. */ + void (*transform_fn)(TransInfo *, const int[2]); + + /** + * Optional callback to transform a single matrix. + * + * \note used by the gizmo to transform the matrix used to position it. + */ + void (*transform_matrix_fn)(TransInfo *, float[4][4]); + + /* Event handler function that determines whether the viewport needs to be redrawn. */ + eRedrawFlag (*handle_event_fn)(TransInfo *, const struct wmEvent *); + + /** + * Get the transform distance between two points (used by Closest snap) + * + * \note Return value can be anything, + * where the smallest absolute value defines what's closest. + */ + float (*snap_distance_fn)(struct TransInfo *t, const float p1[3], const float p2[3]); + void (*snap_apply_fn)(struct TransInfo *, float *); + + /** Custom drawing. */ + void (*draw_fn)(struct TransInfo *); +} TransModeInfo; + /* header of TransDataEdgeSlideVert, TransDataEdgeSlideEdge */ typedef struct TransDataGenericSlideVert { struct BMVert *v; @@ -68,125 +99,120 @@ void transform_mode_default_modal_orientation_set(TransInfo *t, int type); /* transform_mode_align.c */ -void initAlign(TransInfo *t); +extern TransModeInfo TransMode_align; /* transform_mode_baketime.c */ -void initBakeTime(TransInfo *t); +extern TransModeInfo TransMode_baketime; /* transform_mode_bbone_resize.c */ -void initBoneSize(TransInfo *t); +extern TransModeInfo TransMode_bboneresize; /* transform_mode_bend.c */ -void initBend(TransInfo *t); +extern TransModeInfo TransMode_bend; /* transform_mode_boneenvelope.c */ -void initBoneEnvelope(TransInfo *t); +extern TransModeInfo TransMode_boneenvelope; /* transform_mode_boneroll.c */ -void initBoneRoll(TransInfo *t); +extern TransModeInfo TransMode_boneroll; /* transform_mode_curveshrinkfatten.c */ -void initCurveShrinkFatten(TransInfo *t); +extern TransModeInfo TransMode_curveshrinkfatten; /* transform_mode_customdata.c */ -void initEgdeCrease(TransInfo *t); -void initVertCrease(TransInfo *t); -void initBevelWeight(TransInfo *t); +extern TransModeInfo TransMode_edgecrease; +extern TransModeInfo TransMode_vertcrease; +extern TransModeInfo TransMode_bevelweight; /* transform_mode_edge_rotate_normal.c */ -void initNormalRotation(TransInfo *t); +extern TransModeInfo TransMode_rotatenormal; /* transform_mode_edge_seq_slide.c */ -void initSeqSlide(TransInfo *t); +extern TransModeInfo TransMode_seqslide; /* transform_mode_edge_slide.c */ -void drawEdgeSlide(TransInfo *t); -void initEdgeSlide_ex( - TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp); -void initEdgeSlide(TransInfo *t); +extern TransModeInfo TransMode_edgeslide; void transform_mode_edge_slide_reproject_input(TransInfo *t); /* transform_mode_gpopacity.c */ -void initGPOpacity(TransInfo *t); +extern TransModeInfo TransMode_gpopacity; /* transform_mode_gpshrinkfatten.c */ -void initGPShrinkFatten(TransInfo *t); +extern TransModeInfo TransMode_gpshrinkfatten; /* transform_mode_maskshrinkfatten.c */ -void initMaskShrinkFatten(TransInfo *t); +extern TransModeInfo TransMode_maskshrinkfatten; /* transform_mode_mirror.c */ -void initMirror(TransInfo *t); +extern TransModeInfo TransMode_mirror; /* transform_mode_push_pull.c */ -void initPushPull(TransInfo *t); +extern TransModeInfo TransMode_pushpull; /* transform_mode_resize.c */ -void initResize(TransInfo *t, float mouse_dir_constraint[3]); +extern TransModeInfo TransMode_resize; /* transform_mode_rotate.c */ -void initRotation(TransInfo *t); +extern TransModeInfo TransMode_rotate; /* transform_mode_shear.c */ -void initShear(TransInfo *t); +extern TransModeInfo TransMode_shear; /* transform_mode_shrink_fatten.c */ -void initShrinkFatten(TransInfo *t); +extern TransModeInfo TransMode_shrinkfatten; /* transform_mode_skin_resize.c */ -void initSkinResize(TransInfo *t); +extern TransModeInfo TransMode_skinresize; /* transform_mode_tilt.c */ -void initTilt(TransInfo *t); +extern TransModeInfo TransMode_tilt; /* transform_mode_timescale.c */ -void initTimeScale(TransInfo *t); +extern TransModeInfo TransMode_timescale; /* transform_mode_timeslide.c */ -void initTimeSlide(TransInfo *t); +extern TransModeInfo TransMode_timeslide; /* transform_mode_timetranslate.c */ -void initTimeTranslate(TransInfo *t); +extern TransModeInfo TransMode_timetranslate; /* transform_mode_tosphere.c */ -void initToSphere(TransInfo *t); +extern TransModeInfo TransMode_tosphere; /* transform_mode_trackball.c */ -void initTrackball(TransInfo *t); +extern TransModeInfo TransMode_trackball; /* transform_mode_translate.c */ -void initTranslation(TransInfo *t); +extern TransModeInfo TransMode_translate; /* transform_mode_vert_slide.c */ -void drawVertSlide(TransInfo *t); -void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp); -void initVertSlide(TransInfo *t); +extern TransModeInfo TransMode_vertslide; void transform_mode_vert_slide_reproject_input(TransInfo *t); diff --git a/source/blender/editors/transform/transform_mode_align.c b/source/blender/editors/transform/transform_mode_align.c index 39f580960a9..c96352ed220 100644 --- a/source/blender/editors/transform/transform_mode_align.c +++ b/source/blender/editors/transform/transform_mode_align.c @@ -66,13 +66,20 @@ static void applyAlign(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, TIP_("Align")); } -void initAlign(TransInfo *t) +static void initAlign(TransInfo *t, struct wmOperator *UNUSED(op)) { - t->flag |= T_NO_CONSTRAINT; - - t->transform = applyAlign; - initMouseInputMode(t, &t->mouse, INPUT_NONE); } /** \} */ + +TransModeInfo TransMode_align = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initAlign, + /*transform_fn*/ applyAlign, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_baketime.c b/source/blender/editors/transform/transform_mode_baketime.c index e3041bf6f26..00bd158c7f4 100644 --- a/source/blender/editors/transform/transform_mode_baketime.c +++ b/source/blender/editors/transform/transform_mode_baketime.c @@ -103,9 +103,8 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) ED_area_status_text(t->area, str); } -void initBakeTime(TransInfo *t) +static void initBakeTime(TransInfo *t, struct wmOperator *UNUSED(op)) { - t->transform = applyBakeTime; initMouseInputMode(t, &t->mouse, INPUT_NONE); t->idx_max = 0; @@ -119,3 +118,14 @@ void initBakeTime(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_baketime = { + /*flags*/ 0, + /*init_fn*/ initBakeTime, + /*transform_fn*/ applyBakeTime, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_bbone_resize.c b/source/blender/editors/transform/transform_mode_bbone_resize.c index 82e826781be..68f4e2eb093 100644 --- a/source/blender/editors/transform/transform_mode_bbone_resize.c +++ b/source/blender/editors/transform/transform_mode_bbone_resize.c @@ -148,10 +148,9 @@ static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initBoneSize(TransInfo *t) +static void initBoneSize(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_BONESIZE; - t->transform = applyBoneSize; initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); @@ -172,3 +171,14 @@ void initBoneSize(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_bboneresize = { + /*flags*/ 0, + /*init_fn*/ initBoneSize, + /*transform_fn*/ applyBoneSize, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_bend.c b/source/blender/editors/transform/transform_mode_bend.c index a57a3566cdd..f1d37e8f4bd 100644 --- a/source/blender/editors/transform/transform_mode_bend.c +++ b/source/blender/editors/transform/transform_mode_bend.c @@ -324,7 +324,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initBend(TransInfo *t) +static void initBend(TransInfo *t, struct wmOperator *UNUSED(op)) { const float mval_fl[2] = {UNPACK2(t->mval)}; const float *curs; @@ -332,8 +332,6 @@ void initBend(TransInfo *t) struct BendCustomData *data; t->mode = TFM_BEND; - t->transform = Bend; - t->handleEvent = handleEventBend; initMouseInputMode(t, &t->mouse, INPUT_ANGLE_SPRING); @@ -348,8 +346,6 @@ void initBend(TransInfo *t) t->num.unit_type[0] = B_UNIT_ROTATION; t->num.unit_type[1] = B_UNIT_LENGTH; - t->flag |= T_NO_CONSTRAINT; - // copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view)); if ((t->flag & T_OVERRIDE_CENTER) == 0) { calculateCenterCursor(t, t->center_global); @@ -378,3 +374,14 @@ void initBend(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_bend = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initBend, + /*transform_fn*/ Bend, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ handleEventBend, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_boneenvelope.c b/source/blender/editors/transform/transform_mode_boneenvelope.c index 54758071f46..73947ce3f21 100644 --- a/source/blender/editors/transform/transform_mode_boneenvelope.c +++ b/source/blender/editors/transform/transform_mode_boneenvelope.c @@ -79,10 +79,8 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initBoneEnvelope(TransInfo *t) +static void initBoneEnvelope(TransInfo *t, struct wmOperator *UNUSED(op)) { - t->transform = applyBoneEnvelope; - initMouseInputMode(t, &t->mouse, INPUT_SPRING); t->idx_max = 0; @@ -93,8 +91,17 @@ void initBoneEnvelope(TransInfo *t) copy_v3_fl(t->num.val_inc, t->snap[0]); t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } /** \} */ + +TransModeInfo TransMode_boneenvelope = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initBoneEnvelope, + /*transform_fn*/ applyBoneEnvelope, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_boneroll.c b/source/blender/editors/transform/transform_mode_boneroll.c index 1cc5a86b82a..af0fbcaea15 100644 --- a/source/blender/editors/transform/transform_mode_boneroll.c +++ b/source/blender/editors/transform/transform_mode_boneroll.c @@ -73,10 +73,9 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initBoneRoll(TransInfo *t) +static void initBoneRoll(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_BONE_ROLL; - t->transform = applyBoneRoll; initMouseInputMode(t, &t->mouse, INPUT_ANGLE); @@ -89,8 +88,17 @@ void initBoneRoll(TransInfo *t) t->num.unit_sys = t->scene->unit.system; t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS); t->num.unit_type[0] = B_UNIT_ROTATION; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } /** \} */ + +TransModeInfo TransMode_boneroll = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initBoneRoll, + /*transform_fn*/ applyBoneRoll, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c index cd0793cc3e8..863c261bc67 100644 --- a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c @@ -84,10 +84,9 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initCurveShrinkFatten(TransInfo *t) +static void initCurveShrinkFatten(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_CURVE_SHRINKFATTEN; - t->transform = applyCurveShrinkFatten; initMouseInputMode(t, &t->mouse, INPUT_SPRING); @@ -100,8 +99,6 @@ void initCurveShrinkFatten(TransInfo *t) t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; - t->flag |= T_NO_CONSTRAINT; - float scale_factor = 0.0f; if (((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW) && (t->data_len_all == 1)) || @@ -117,3 +114,14 @@ void initCurveShrinkFatten(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_curveshrinkfatten = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initCurveShrinkFatten, + /*transform_fn*/ applyCurveShrinkFatten, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_customdata.c b/source/blender/editors/transform/transform_mode_customdata.c index cf416ce6991..bc7275dd180 100644 --- a/source/blender/editors/transform/transform_mode_customdata.c +++ b/source/blender/editors/transform/transform_mode_customdata.c @@ -159,29 +159,57 @@ static void init_mode_impl(TransInfo *t) copy_v3_fl(t->num.val_inc, t->snap[0]); t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } -void initEgdeCrease(TransInfo *t) +static void initEgdeCrease(TransInfo *t, struct wmOperator *UNUSED(op)) { init_mode_impl(t); t->mode = TFM_EDGE_CREASE; - t->transform = applyCrease; } -void initVertCrease(TransInfo *t) +static void initVertCrease(TransInfo *t, struct wmOperator *UNUSED(op)) { init_mode_impl(t); t->mode = TFM_VERT_CREASE; - t->transform = applyCrease; } -void initBevelWeight(TransInfo *t) +static void initBevelWeight(TransInfo *t, struct wmOperator *UNUSED(op)) { init_mode_impl(t); t->mode = TFM_BWEIGHT; - t->transform = applyBevelWeight; } /** \} */ + +TransModeInfo TransMode_edgecrease = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initEgdeCrease, + /*transform_fn*/ applyCrease, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; + +TransModeInfo TransMode_vertcrease = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initVertCrease, + /*transform_fn*/ applyCrease, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; + +TransModeInfo TransMode_bevelweight = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initBevelWeight, + /*transform_fn*/ applyBevelWeight, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c index 854214b746d..09e7fcede53 100644 --- a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c +++ b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c @@ -108,10 +108,9 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initNormalRotation(TransInfo *t) +static void initNormalRotation(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_NORMAL_ROTATION; - t->transform = applyNormalRotation; initMouseInputMode(t, &t->mouse, INPUT_ANGLE); @@ -139,3 +138,14 @@ void initNormalRotation(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_rotatenormal = { + /*flags*/ 0, + /*init_fn*/ initNormalRotation, + /*transform_fn*/ applyNormalRotation, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_edge_seq_slide.c b/source/blender/editors/transform/transform_mode_edge_seq_slide.c index d73a71eba7f..0a46bafa156 100644 --- a/source/blender/editors/transform/transform_mode_edge_seq_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_seq_slide.c @@ -108,11 +108,8 @@ static void applySeqSlide(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initSeqSlide(TransInfo *t) +static void initSeqSlide(TransInfo *t, struct wmOperator *UNUSED(op)) { - t->transform = applySeqSlide; - t->tsnap.snap_mode_apply_fn = transform_snap_sequencer_apply_translate; - initMouseInputMode(t, &t->mouse, INPUT_VECTOR); t->idx_max = 1; @@ -136,3 +133,14 @@ void initSeqSlide(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_seqslide = { + /*flags*/ 0, + /*init_fn*/ initSeqSlide, + /*transform_fn*/ applySeqSlide, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ transform_snap_sequencer_apply_translate, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_edge_slide.c b/source/blender/editors/transform/transform_mode_edge_slide.c index e2b5b6a7313..3d7a7b1d6ed 100644 --- a/source/blender/editors/transform/transform_mode_edge_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_slide.c @@ -29,6 +29,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "RNA_access.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -1081,50 +1083,44 @@ static void freeEdgeSlideVerts(TransInfo *UNUSED(t), static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event) { - if (t->mode == TFM_EDGE_SLIDE) { - EdgeSlideParams *slp = t->custom.mode.data; + EdgeSlideParams *slp = t->custom.mode.data; - if (slp) { - switch (event->type) { - case EVT_EKEY: - if (event->val == KM_PRESS) { - slp->use_even = !slp->use_even; - calcEdgeSlideCustomPoints(t); - return TREDRAW_HARD; - } - break; - case EVT_FKEY: - if (event->val == KM_PRESS) { - slp->flipped = !slp->flipped; - calcEdgeSlideCustomPoints(t); - return TREDRAW_HARD; - } - break; - case EVT_CKEY: - /* use like a modifier key */ - if (event->val == KM_PRESS) { - t->flag ^= T_ALT_TRANSFORM; - calcEdgeSlideCustomPoints(t); - return TREDRAW_HARD; - } - break; - case MOUSEMOVE: + if (slp) { + switch (event->type) { + case EVT_EKEY: + if (event->val == KM_PRESS) { + slp->use_even = !slp->use_even; calcEdgeSlideCustomPoints(t); - break; - default: - break; - } + return TREDRAW_HARD; + } + break; + case EVT_FKEY: + if (event->val == KM_PRESS) { + slp->flipped = !slp->flipped; + calcEdgeSlideCustomPoints(t); + return TREDRAW_HARD; + } + break; + case EVT_CKEY: + /* use like a modifier key */ + if (event->val == KM_PRESS) { + t->flag ^= T_ALT_TRANSFORM; + calcEdgeSlideCustomPoints(t); + return TREDRAW_HARD; + } + break; + case MOUSEMOVE: + calcEdgeSlideCustomPoints(t); + break; + default: + break; } } return TREDRAW_NOTHING; } -void drawEdgeSlide(TransInfo *t) +static void drawEdgeSlide(TransInfo *t) { - if (t->mode != TFM_EDGE_SLIDE) { - return; - } - EdgeSlideData *sld = edgeSlideFirstGet(t); if (sld == NULL) { return; @@ -1484,18 +1480,13 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initEdgeSlide_ex( +static void initEdgeSlide_ex( TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp) { EdgeSlideData *sld; bool ok = false; t->mode = TFM_EDGE_SLIDE; - t->transform = applyEdgeSlide; - t->handleEvent = handleEventEdgeSlide; - t->transform_matrix = NULL; - t->tsnap.snap_mode_apply_fn = edge_slide_snap_apply; - t->tsnap.snap_mode_distance_fn = transform_snap_distance_len_squared_fn; { EdgeSlideParams *slp = MEM_callocN(sizeof(*slp), __func__); @@ -1542,13 +1533,21 @@ void initEdgeSlide_ex( copy_v3_fl(t->num.val_inc, t->snap[0]); t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } -void initEdgeSlide(TransInfo *t) +static void initEdgeSlide(TransInfo *t, wmOperator *op) { - initEdgeSlide_ex(t, true, false, false, true); + bool use_double_side = true; + bool use_even = false; + bool flipped = false; + bool use_clamp = true; + if (op) { + use_double_side = !RNA_boolean_get(op->ptr, "single_side"); + use_even = RNA_boolean_get(op->ptr, "use_even"); + flipped = RNA_boolean_get(op->ptr, "flipped"); + use_clamp = RNA_boolean_get(op->ptr, "use_clamp"); + } + initEdgeSlide_ex(t, use_double_side, use_even, flipped, use_clamp); } /** \} */ @@ -1581,3 +1580,14 @@ void transform_mode_edge_slide_reproject_input(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_edgeslide = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initEdgeSlide, + /*transform_fn*/ applyEdgeSlide, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ handleEventEdgeSlide, + /*snap_distance_fn*/ transform_snap_distance_len_squared_fn, + /*snap_apply_fn*/ edge_slide_snap_apply, + /*draw_fn*/ drawEdgeSlide, +}; diff --git a/source/blender/editors/transform/transform_mode_gpopacity.c b/source/blender/editors/transform/transform_mode_gpopacity.c index bf70691a0da..b48dbe39993 100644 --- a/source/blender/editors/transform/transform_mode_gpopacity.c +++ b/source/blender/editors/transform/transform_mode_gpopacity.c @@ -88,10 +88,9 @@ static void applyGPOpacity(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initGPOpacity(TransInfo *t) +static void initGPOpacity(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_GPENCIL_OPACITY; - t->transform = applyGPOpacity; initMouseInputMode(t, &t->mouse, INPUT_SPRING); @@ -107,8 +106,17 @@ void initGPOpacity(TransInfo *t) #ifdef USE_NUM_NO_ZERO t->num.val_flag[0] |= NUM_NO_ZERO; #endif - - t->flag |= T_NO_CONSTRAINT; } /** \} */ + +TransModeInfo TransMode_gpopacity = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initGPOpacity, + /*transform_fn*/ applyGPOpacity, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c index 6eb0007fa31..6ab3cd53d2c 100644 --- a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c @@ -90,10 +90,9 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initGPShrinkFatten(TransInfo *t) +static void initGPShrinkFatten(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_GPENCIL_SHRINKFATTEN; - t->transform = applyGPShrinkFatten; initMouseInputMode(t, &t->mouse, INPUT_SPRING); @@ -109,8 +108,17 @@ void initGPShrinkFatten(TransInfo *t) #ifdef USE_NUM_NO_ZERO t->num.val_flag[0] |= NUM_NO_ZERO; #endif - - t->flag |= T_NO_CONSTRAINT; } /** \} */ + +TransModeInfo TransMode_gpshrinkfatten = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initGPShrinkFatten, + /*transform_fn*/ applyGPShrinkFatten, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c index 2015453b708..20ea54f6212 100644 --- a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c @@ -104,10 +104,9 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initMaskShrinkFatten(TransInfo *t) +static void initMaskShrinkFatten(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_MASK_SHRINKFATTEN; - t->transform = applyMaskShrinkFatten; initMouseInputMode(t, &t->mouse, INPUT_SPRING); @@ -123,8 +122,17 @@ void initMaskShrinkFatten(TransInfo *t) #ifdef USE_NUM_NO_ZERO t->num.val_flag[0] |= NUM_NO_ZERO; #endif - - t->flag |= T_NO_CONSTRAINT; } /** \} */ + +TransModeInfo TransMode_maskshrinkfatten = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initMaskShrinkFatten, + /*transform_fn*/ applyMaskShrinkFatten, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_mirror.c b/source/blender/editors/transform/transform_mode_mirror.c index 14d6dc7a6b4..bb9a7ba2c2b 100644 --- a/source/blender/editors/transform/transform_mode_mirror.c +++ b/source/blender/editors/transform/transform_mode_mirror.c @@ -216,12 +216,20 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) } } -void initMirror(TransInfo *t) +static void initMirror(TransInfo *t, struct wmOperator *UNUSED(op)) { - t->transform = applyMirror; initMouseInputMode(t, &t->mouse, INPUT_NONE); - - t->flag |= T_NULL_ONE; } /** \} */ + +TransModeInfo TransMode_mirror = { + /*flags*/ T_NULL_ONE, + /*init_fn*/ initMirror, + /*transform_fn*/ applyMirror, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_push_pull.c b/source/blender/editors/transform/transform_mode_push_pull.c index 1516d1c36a6..d3ce76e8e26 100644 --- a/source/blender/editors/transform/transform_mode_push_pull.c +++ b/source/blender/editors/transform/transform_mode_push_pull.c @@ -169,10 +169,9 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initPushPull(TransInfo *t) +static void initPushPull(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_PUSHPULL; - t->transform = applyPushPull; initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); @@ -187,3 +186,14 @@ void initPushPull(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_pushpull = { + /*flags*/ 0, + /*init_fn*/ initPushPull, + /*transform_fn*/ applyPushPull, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_resize.c b/source/blender/editors/transform/transform_mode_resize.c index 84340989622..439dc4ec257 100644 --- a/source/blender/editors/transform/transform_mode_resize.c +++ b/source/blender/editors/transform/transform_mode_resize.c @@ -8,6 +8,8 @@ #include +#include "DNA_windowmanager_types.h" + #include "BLI_math.h" #include "BLI_task.h" @@ -17,6 +19,8 @@ #include "ED_screen.h" +#include "RNA_access.h" + #include "UI_interface.h" #include "transform.h" @@ -282,13 +286,22 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initResize(TransInfo *t, float mouse_dir_constraint[3]) +static void initResize(TransInfo *t, wmOperator *op) { - t->mode = TFM_RESIZE; - t->transform = applyResize; - t->transform_matrix = NULL; - t->tsnap.snap_mode_apply_fn = ApplySnapResize; - t->tsnap.snap_mode_distance_fn = ResizeBetween; + float mouse_dir_constraint[3]; + if (op) { + PropertyRNA *prop = RNA_struct_find_property(op->ptr, "mouse_dir_constraint"); + if (prop) { + RNA_property_float_get_array(op->ptr, prop, mouse_dir_constraint); + } + else { + /* Resize is expected to have this property. */ + BLI_assert(!STREQ(op->idname, "TRANSFORM_OT_resize")); + } + } + else { + zero_v3(mouse_dir_constraint); + } if (is_zero_v3(mouse_dir_constraint)) { initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); @@ -323,7 +336,6 @@ void initResize(TransInfo *t, float mouse_dir_constraint[3]) initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO); } - t->flag |= T_NULL_ONE; t->num.val_flag[0] |= NUM_NULL_ONE; t->num.val_flag[1] |= NUM_NULL_ONE; t->num.val_flag[2] |= NUM_NULL_ONE; @@ -351,3 +363,14 @@ void initResize(TransInfo *t, float mouse_dir_constraint[3]) } /** \} */ + +TransModeInfo TransMode_resize = { + /*flags*/ T_NULL_ONE, + /*init_fn*/ initResize, + /*transform_fn*/ applyResize, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ ResizeBetween, + /*snap_apply_fn*/ ApplySnapResize, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_rotate.c b/source/blender/editors/transform/transform_mode_rotate.c index 65d13e480ec..a918ec37bf4 100644 --- a/source/blender/editors/transform/transform_mode_rotate.c +++ b/source/blender/editors/transform/transform_mode_rotate.c @@ -405,7 +405,7 @@ static void applyRotationMatrix(TransInfo *t, float mat_xform[4][4]) mul_m4_m4m4(mat_xform, mat4, mat_xform); } -void initRotation(TransInfo *t) +static void initRotation(TransInfo *t, struct wmOperator *UNUSED(op)) { if (t->spacetype == SPACE_ACTION) { BKE_report(t->reports, RPT_ERROR, "Rotation is not supported in the Dope Sheet Editor"); @@ -413,10 +413,6 @@ void initRotation(TransInfo *t) } t->mode = TFM_ROTATION; - t->transform = applyRotation; - t->transform_matrix = applyRotationMatrix; - t->tsnap.snap_mode_apply_fn = ApplySnapRotation; - t->tsnap.snap_mode_distance_fn = RotationBetween; initMouseInputMode(t, &t->mouse, INPUT_ANGLE); @@ -438,3 +434,14 @@ void initRotation(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_rotate = { + /*flags*/ 0, + /*init_fn*/ initRotation, + /*transform_fn*/ applyRotation, + /*transform_matrix_fn*/ applyRotationMatrix, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ RotationBetween, + /*snap_apply_fn*/ ApplySnapRotation, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_shear.c b/source/blender/editors/transform/transform_mode_shear.c index a9a22514ee2..4e8ef00998d 100644 --- a/source/blender/editors/transform/transform_mode_shear.c +++ b/source/blender/editors/transform/transform_mode_shear.c @@ -320,11 +320,9 @@ static void apply_shear(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initShear(TransInfo *t) +static void initShear(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_SHEAR; - t->transform = apply_shear; - t->handleEvent = handleEventShear; if (t->orient_axis == t->orient_axis_ortho) { t->orient_axis = 2; @@ -342,9 +340,18 @@ void initShear(TransInfo *t) t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; /* Don't think we have any unit here? */ - t->flag |= T_NO_CONSTRAINT; - transform_mode_default_modal_orientation_set(t, V3D_ORIENT_VIEW); } /** \} */ + +TransModeInfo TransMode_shear = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initShear, + /*transform_fn*/ apply_shear, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ handleEventShear, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_shrink_fatten.c b/source/blender/editors/transform/transform_mode_shrink_fatten.c index f290e42c873..27304c84eab 100644 --- a/source/blender/editors/transform/transform_mode_shrink_fatten.c +++ b/source/blender/editors/transform/transform_mode_shrink_fatten.c @@ -170,7 +170,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initShrinkFatten(TransInfo *t) +static void initShrinkFatten(TransInfo *t, struct wmOperator *UNUSED(op)) { if ((t->flag & T_EDIT) == 0 || (t->obedit_type != OB_MESH)) { BKE_report(t->reports, RPT_ERROR, "'Shrink/Fatten' meshes is only supported in edit mode"); @@ -178,8 +178,6 @@ void initShrinkFatten(TransInfo *t) } t->mode = TFM_SHRINKFATTEN; - t->transform = applyShrinkFatten; - t->handleEvent = shrinkfatten_handleEvent; initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); @@ -192,8 +190,6 @@ void initShrinkFatten(TransInfo *t) t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_LENGTH; - t->flag |= T_NO_CONSTRAINT; - if (t->keymap) { /* Workaround to use the same key as the modal keymap. */ t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE); @@ -201,3 +197,14 @@ void initShrinkFatten(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_shrinkfatten = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initShrinkFatten, + /*transform_fn*/ applyShrinkFatten, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ shrinkfatten_handleEvent, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_skin_resize.c b/source/blender/editors/transform/transform_mode_skin_resize.c index 86295e07951..86f1fab964a 100644 --- a/source/blender/editors/transform/transform_mode_skin_resize.c +++ b/source/blender/editors/transform/transform_mode_skin_resize.c @@ -134,10 +134,9 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initSkinResize(TransInfo *t) +static void initSkinResize(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_SKIN_RESIZE; - t->transform = applySkinResize; initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); @@ -167,3 +166,14 @@ void initSkinResize(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_skinresize = { + /*flags*/ 0, + /*init_fn*/ initSkinResize, + /*transform_fn*/ applySkinResize, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_tilt.c b/source/blender/editors/transform/transform_mode_tilt.c index 1c34457890a..759fef53cc6 100644 --- a/source/blender/editors/transform/transform_mode_tilt.c +++ b/source/blender/editors/transform/transform_mode_tilt.c @@ -77,10 +77,9 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initTilt(TransInfo *t) +static void initTilt(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_TILT; - t->transform = applyTilt; initMouseInputMode(t, &t->mouse, INPUT_ANGLE); @@ -93,8 +92,17 @@ void initTilt(TransInfo *t) t->num.unit_sys = t->scene->unit.system; t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS); t->num.unit_type[0] = B_UNIT_ROTATION; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } /** \} */ + +TransModeInfo TransMode_tilt = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initTilt, + /*transform_fn*/ applyTilt, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_timescale.c b/source/blender/editors/transform/transform_mode_timescale.c index 223bca35c4d..d14a1b965f0 100644 --- a/source/blender/editors/transform/transform_mode_timescale.c +++ b/source/blender/editors/transform/transform_mode_timescale.c @@ -94,7 +94,7 @@ static void applyTimeScale(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initTimeScale(TransInfo *t) +static void initTimeScale(TransInfo *t, struct wmOperator *UNUSED(op)) { float center[2]; @@ -106,7 +106,6 @@ void initTimeScale(TransInfo *t) } t->mode = TFM_TIME_SCALE; - t->transform = applyTimeScale; /* recalculate center2d to use scene->r.cfra and mouse Y, since that's * what is used in time scale */ @@ -121,7 +120,6 @@ void initTimeScale(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); - t->flag |= T_NULL_ONE; t->num.val_flag[0] |= NUM_NULL_ONE; /* Numeric-input has max of (n-1). */ @@ -138,3 +136,14 @@ void initTimeScale(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_timescale = { + /*flags*/ T_NULL_ONE, + /*init_fn*/ initTimeScale, + /*transform_fn*/ applyTimeScale, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_timeslide.c b/source/blender/editors/transform/transform_mode_timeslide.c index 762cff2f318..dde1bd2ad47 100644 --- a/source/blender/editors/transform/transform_mode_timeslide.c +++ b/source/blender/editors/transform/transform_mode_timeslide.c @@ -148,7 +148,7 @@ static void applyTimeSlide(TransInfo *t, const int mval[2]) ED_area_status_text(t->area, str); } -void initTimeSlide(TransInfo *t) +static void initTimeSlide(TransInfo *t, struct wmOperator *UNUSED(op)) { /* this tool is only really available in the Action Editor... */ if (t->spacetype == SPACE_ACTION) { @@ -162,7 +162,6 @@ void initTimeSlide(TransInfo *t) } t->mode = TFM_TIME_SLIDE; - t->transform = applyTimeSlide; initMouseInputMode(t, &t->mouse, INPUT_NONE); @@ -219,3 +218,14 @@ void initTimeSlide(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_timeslide = { + /*flags*/ T_NULL_ONE, + /*init_fn*/ initTimeSlide, + /*transform_fn*/ applyTimeSlide, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_timetranslate.c b/source/blender/editors/transform/transform_mode_timetranslate.c index 87f284faff3..1fa0d6811b9 100644 --- a/source/blender/editors/transform/transform_mode_timetranslate.c +++ b/source/blender/editors/transform/transform_mode_timetranslate.c @@ -119,15 +119,13 @@ static void applyTimeTranslate(TransInfo *t, const int mval[2]) ED_area_status_text(t->area, str); } -void initTimeTranslate(TransInfo *t) +static void initTimeTranslate(TransInfo *t, struct wmOperator *UNUSED(op)) { /* this tool is only really available in the Action Editor... */ if (!ELEM(t->spacetype, SPACE_ACTION, SPACE_SEQ)) { t->state = TRANS_CANCEL; } - t->transform = applyTimeTranslate; - initMouseInputMode(t, &t->mouse, INPUT_NONE); /* Numeric-input has max of (n-1). */ @@ -145,3 +143,14 @@ void initTimeTranslate(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_timetranslate = { + /*flags*/ 0, + /*init_fn*/ initTimeTranslate, + /*transform_fn*/ applyTimeTranslate, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_tosphere.c b/source/blender/editors/transform/transform_mode_tosphere.c index 2166a20e577..b589b354544 100644 --- a/source/blender/editors/transform/transform_mode_tosphere.c +++ b/source/blender/editors/transform/transform_mode_tosphere.c @@ -237,10 +237,9 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initToSphere(TransInfo *t) +static void initToSphere(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_TOSPHERE; - t->transform = applyToSphere; initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO); @@ -254,7 +253,6 @@ void initToSphere(TransInfo *t) t->num.unit_type[0] = B_UNIT_NONE; t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE; - t->flag |= T_NO_CONSTRAINT; struct ToSphereInfo *data = MEM_callocN(sizeof(*data), __func__); t->custom.mode.data = data; @@ -264,3 +262,14 @@ void initToSphere(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_tosphere = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initToSphere, + /*transform_fn*/ applyToSphere, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_trackball.c b/source/blender/editors/transform/transform_mode_trackball.c index 86741fd8d66..cc59a62a5a7 100644 --- a/source/blender/editors/transform/transform_mode_trackball.c +++ b/source/blender/editors/transform/transform_mode_trackball.c @@ -187,11 +187,9 @@ static void applyTrackballMatrix(TransInfo *t, float mat_xform[4][4]) mul_m4_m4m4(mat_xform, mat4, mat_xform); } -void initTrackball(TransInfo *t) +static void initTrackball(TransInfo *t, struct wmOperator *UNUSED(op)) { t->mode = TFM_TRACKBALL; - t->transform = applyTrackball; - t->transform_matrix = applyTrackballMatrix; initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL); @@ -205,8 +203,17 @@ void initTrackball(TransInfo *t) t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS); t->num.unit_type[0] = B_UNIT_ROTATION; t->num.unit_type[1] = B_UNIT_ROTATION; - - t->flag |= T_NO_CONSTRAINT; } /** \} */ + +TransModeInfo TransMode_trackball = { + /*flags*/ T_NO_CONSTRAINT, + /*init_fn*/ initTrackball, + /*transform_fn*/ applyTrackball, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ NULL, + /*snap_apply_fn*/ NULL, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index b9e0d0a5a50..88db72642eb 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -666,7 +666,7 @@ static void applyTranslationMatrix(TransInfo *t, float mat_xform[4][4]) add_v3_v3(mat_xform[3], delta); } -void initTranslation(TransInfo *t) +static void initTranslation(TransInfo *t, struct wmOperator *UNUSED(op)) { if (t->spacetype == SPACE_ACTION) { /* this space uses time translate */ @@ -675,13 +675,9 @@ void initTranslation(TransInfo *t) "Use 'Time_Translate' transform mode instead of 'Translation' mode " "for translating keyframes in Dope Sheet Editor"); t->state = TRANS_CANCEL; + return; } - t->transform = applyTranslation; - t->transform_matrix = applyTranslationMatrix; - t->tsnap.snap_mode_apply_fn = ApplySnapTranslation; - t->tsnap.snap_mode_distance_fn = transform_snap_distance_len_squared_fn; - initMouseInputMode(t, &t->mouse, INPUT_VECTOR); t->idx_max = (t->flag & T_2D_EDIT) ? 1 : 2; @@ -716,3 +712,14 @@ void initTranslation(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_translate = { + /*flags*/ 0, + /*init_fn*/ initTranslation, + /*transform_fn*/ applyTranslation, + /*transform_matrix_fn*/ applyTranslationMatrix, + /*handle_event_fn*/ NULL, + /*snap_distance_fn*/ transform_snap_distance_len_squared_fn, + /*snap_apply_fn*/ ApplySnapTranslation, + /*draw_fn*/ NULL, +}; diff --git a/source/blender/editors/transform/transform_mode_vert_slide.c b/source/blender/editors/transform/transform_mode_vert_slide.c index b0296e450e8..854599975e8 100644 --- a/source/blender/editors/transform/transform_mode_vert_slide.c +++ b/source/blender/editors/transform/transform_mode_vert_slide.c @@ -26,6 +26,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "RNA_access.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -304,55 +306,53 @@ static void freeVertSlideVerts(TransInfo *UNUSED(t), static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event) { - if (t->mode == TFM_VERT_SLIDE) { - VertSlideParams *slp = t->custom.mode.data; + VertSlideParams *slp = t->custom.mode.data; - if (slp) { - switch (event->type) { - case EVT_EKEY: - if (event->val == KM_PRESS) { - slp->use_even = !slp->use_even; - if (slp->flipped) { - calcVertSlideCustomPoints(t); - } - return TREDRAW_HARD; - } - break; - case EVT_FKEY: - if (event->val == KM_PRESS) { - slp->flipped = !slp->flipped; + if (slp) { + switch (event->type) { + case EVT_EKEY: + if (event->val == KM_PRESS) { + slp->use_even = !slp->use_even; + if (slp->flipped) { calcVertSlideCustomPoints(t); - return TREDRAW_HARD; } - break; - case EVT_CKEY: - /* use like a modifier key */ - if (event->val == KM_PRESS) { - t->flag ^= T_ALT_TRANSFORM; - calcVertSlideCustomPoints(t); - return TREDRAW_HARD; - } - break; - case MOUSEMOVE: { - /* don't recalculate the best edge */ - const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); - if (is_clamp) { - calcVertSlideMouseActiveEdges(t, event->mval); - } - calcVertSlideCustomPoints(t); - break; + return TREDRAW_HARD; } - default: - break; + break; + case EVT_FKEY: + if (event->val == KM_PRESS) { + slp->flipped = !slp->flipped; + calcVertSlideCustomPoints(t); + return TREDRAW_HARD; + } + break; + case EVT_CKEY: + /* use like a modifier key */ + if (event->val == KM_PRESS) { + t->flag ^= T_ALT_TRANSFORM; + calcVertSlideCustomPoints(t); + return TREDRAW_HARD; + } + break; + case MOUSEMOVE: { + /* don't recalculate the best edge */ + const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); + if (is_clamp) { + calcVertSlideMouseActiveEdges(t, event->mval); + } + calcVertSlideCustomPoints(t); + break; } + default: + break; } } return TREDRAW_NOTHING; } -void drawVertSlide(TransInfo *t) +static void drawVertSlide(TransInfo *t) { - if ((t->mode == TFM_VERT_SLIDE) && TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) { + if (TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) { const VertSlideParams *slp = t->custom.mode.data; VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); @@ -610,15 +610,10 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) +static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) { t->mode = TFM_VERT_SLIDE; - t->transform = applyVertSlide; - t->handleEvent = handleEventVertSlide; - t->transform_matrix = NULL; - t->tsnap.snap_mode_apply_fn = vert_slide_snap_apply; - t->tsnap.snap_mode_distance_fn = transform_snap_distance_len_squared_fn; { VertSlideParams *slp = MEM_callocN(sizeof(*slp), __func__); @@ -664,13 +659,19 @@ void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) copy_v3_fl(t->num.val_inc, t->snap[0]); t->num.unit_sys = t->scene->unit.system; t->num.unit_type[0] = B_UNIT_NONE; - - t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } -void initVertSlide(TransInfo *t) +static void initVertSlide(TransInfo *t, wmOperator *op) { - initVertSlide_ex(t, false, false, true); + bool use_even = false; + bool flipped = false; + bool use_clamp = true; + if (op) { + use_even = RNA_boolean_get(op->ptr, "use_even"); + flipped = RNA_boolean_get(op->ptr, "flipped"); + use_clamp = RNA_boolean_get(op->ptr, "use_clamp"); + } + initVertSlide_ex(t, use_even, flipped, use_clamp); } /** \} */ @@ -693,3 +694,14 @@ void transform_mode_vert_slide_reproject_input(TransInfo *t) } /** \} */ + +TransModeInfo TransMode_vertslide = { + /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT, + /*init_fn*/ initVertSlide, + /*transform_fn*/ applyVertSlide, + /*transform_matrix_fn*/ NULL, + /*handle_event_fn*/ handleEventVertSlide, + /*snap_distance_fn*/ transform_snap_distance_len_squared_fn, + /*snap_apply_fn*/ vert_slide_snap_apply, + /*draw_fn*/ drawVertSlide, +}; diff --git a/source/blender/editors/transform/transform_snap.cc b/source/blender/editors/transform/transform_snap.cc index 4be68cd9946..930b996b910 100644 --- a/source/blender/editors/transform/transform_snap.cc +++ b/source/blender/editors/transform/transform_snap.cc @@ -50,6 +50,7 @@ #include "transform.h" #include "transform_convert.h" +#include "transform_mode.h" #include "transform_snap.h" /* use half of flt-max so we can scale up without an exception */ @@ -546,7 +547,7 @@ void transform_snap_mixed_apply(TransInfo *t, float *vec) } if (validSnap(t)) { - t->tsnap.snap_mode_apply_fn(t, vec); + t->mode_info->snap_apply_fn(t, vec); } } } @@ -1317,7 +1318,7 @@ static void snap_source_closest_fn(TransInfo *t) copy_v3_v3(loc, bb->vec[j]); mul_m4_v3(td->ext->obmat, loc); - dist = t->tsnap.snap_mode_distance_fn(t, loc, t->tsnap.snap_target); + dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target); if ((dist != TRANSFORM_DIST_INVALID) && (closest == nullptr || fabsf(dist) < fabsf(dist_closest))) { @@ -1334,7 +1335,7 @@ static void snap_source_closest_fn(TransInfo *t) copy_v3_v3(loc, td->center); - dist = t->tsnap.snap_mode_distance_fn(t, loc, t->tsnap.snap_target); + dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target); if ((dist != TRANSFORM_DIST_INVALID) && (closest == nullptr || fabsf(dist) < fabsf(dist_closest))) { @@ -1359,7 +1360,7 @@ static void snap_source_closest_fn(TransInfo *t) mul_m4_v3(tc->mat, loc); } - dist = t->tsnap.snap_mode_distance_fn(t, loc, t->tsnap.snap_target); + dist = t->mode_info->snap_distance_fn(t, loc, t->tsnap.snap_target); if ((dist != TRANSFORM_DIST_INVALID) && (closest == nullptr || fabsf(dist) < fabsf(dist_closest))) {