Blender V5.0
transform_mode_timescale.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string_utf8.h"
13
14#include "BKE_nla.hh"
15#include "BKE_unit.hh"
16
17#include "ED_screen.hh"
18
19#include "BLT_translation.hh"
20
21#include "UI_interface_types.hh"
22
23#include "transform.hh"
24#include "transform_convert.hh"
25#include "transform_snap.hh"
26
27#include "transform_mode.hh"
28
29namespace blender::ed::transform {
30
31/* -------------------------------------------------------------------- */
34
35static void timescale_snap_apply_fn(TransInfo *t, float vec[3])
36{
37 float point[3];
38 getSnapPoint(t, point);
39 const float fac = (point[0] - t->center_global[0]) /
40 (t->tsnap.snap_source[0] - t->center_global[0]);
41 vec[0] = fac;
42}
43
45{
46 char tvec[NUM_STR_REP_LEN * 3];
47
48 if (hasNumInput(&t->num)) {
49 outputNumInput(&(t->num), tvec, t->scene->unit);
50 }
51 else {
52 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values_final[0]);
53 }
54
55 BLI_snprintf_utf8(str, UI_MAX_DRAW_STR, IFACE_("ScaleX: %s"), &tvec[0]);
56}
57
58static void applyTimeScaleValue(TransInfo *t, float value)
59{
60 Scene *scene = t->scene;
61
63 TransData *td = tc->data;
64 TransData2D *td2d = tc->data_2d;
65 for (int i = 0; i < tc->data_len; i++, td++, td2d++) {
66 /* It is assumed that td->extra is a pointer to the AnimData,
67 * whose active action is where this keyframe comes from
68 * (this is only valid when not in NLA). */
69 AnimData *adt = static_cast<AnimData *>((t->spacetype != SPACE_NLA) ? td->extra : nullptr);
70 float startx = scene->r.cfra;
71 float fac = value;
72
73 /* Take proportional editing into account. */
74 fac = ((fac - 1.0f) * td->factor) + 1;
75
76 /* Check if any need to apply nla-mapping. */
77 if (adt) {
79 }
80
81 /* Now, calculate the new value. */
82 td->loc[0] = ((td->iloc[0] - startx) * fac) + startx;
83 }
84 }
85}
86
88{
89 char str[UI_MAX_DRAW_STR];
90
91 /* Handle numeric-input stuff. */
92 t->vec[0] = t->values[0];
93 applyNumInput(&t->num, &t->vec[0]);
94
96
97 t->values_final[0] = t->vec[0];
99
101
102 recalc_data(t);
103
105}
106
107static void timescale_transform_matrix_fn(TransInfo *t, float mat_xform[4][4])
108{
109 const float i_loc = mat_xform[3][0];
110 const float startx = t->center_global[0];
111 const float fac = t->values_final[0];
112 const float loc = ((i_loc - startx) * fac) + startx;
113 mat_xform[3][0] = loc;
114}
115
116static void initTimeScale(TransInfo *t, wmOperator * /*op*/)
117{
118 float center[2];
119
120 /* This tool is only really available in the Action Editor
121 * AND NLA Editor (for strip scaling). */
122 if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA) == 0) {
123 t->state = TRANS_CANCEL;
124 }
125
126 t->mode = TFM_TIME_SCALE;
127
128 /* Recalculate center2d to use scene->r.cfra and mouse Y, since that's
129 * what is used in time scale. */
130 if ((t->flag & T_OVERRIDE_CENTER) == 0) {
131 t->center_global[0] = t->scene->r.cfra;
132 projectFloatView(t, t->center_global, center);
133 center[1] = t->mouse.imval[1];
134 }
135
136 /* Force a reinitialize with the center2d used here. */
137 initMouseInput(t, &t->mouse, center, t->mouse.imval, false);
138
140
141 t->num.val_flag[0] |= NUM_NULL_ONE;
142
143 /* Numeric-input has max of (n-1). */
144 t->idx_max = 0;
145 t->num.flag = 0;
146 t->num.idx_max = t->idx_max;
147
148 /* Initialize snap like for everything else. */
149 t->increment[0] = 1.0f;
150 t->increment_precision = 1.0f;
151
152 copy_v3_fl(t->num.val_inc, t->increment[0]);
153 t->num.unit_sys = t->scene->unit.system;
154 t->num.unit_type[0] = B_UNIT_NONE;
155}
156
158
160 /*flags*/ T_NULL_ONE,
161 /*init_fn*/ initTimeScale,
162 /*transform_fn*/ applyTimeScale,
163 /*transform_matrix_fn*/ timescale_transform_matrix_fn,
164 /*handle_event_fn*/ nullptr,
165 /*snap_distance_fn*/ nullptr,
166 /*snap_apply_fn*/ timescale_snap_apply_fn,
167 /*draw_fn*/ nullptr,
168};
169
170} // namespace blender::ed::transform
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:549
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
@ B_UNIT_NONE
Definition BKE_unit.hh:136
MINLINE void copy_v3_fl(float r[3], float f)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define ELEM(...)
#define IFACE_(msgid)
@ SPACE_ACTION
@ SPACE_NLA
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
@ NUM_NULL_ONE
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:88
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:851
#define UI_MAX_DRAW_STR
#define str(s)
static void timescale_snap_apply_fn(TransInfo *t, float vec[3])
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
static void timescale_transform_matrix_fn(TransInfo *t, float mat_xform[4][4])
void recalc_data(TransInfo *t)
void getSnapPoint(const TransInfo *t, float vec[3])
static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])
void transform_snap_mixed_apply(TransInfo *t, float *vec)
static void initTimeScale(TransInfo *t, wmOperator *)
void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
void initMouseInput(TransInfo *t, MouseInput *mi, const float2 &center, const float2 &mval, bool precision)
static void applyTimeScaleValue(TransInfo *t, float value)
static void applyTimeScale(TransInfo *t)
short idx_max
short val_flag[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
short flag
struct RenderData r
struct UnitSettings unit
i
Definition text_draw.cc:230
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.