Blender V5.3
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_c.hh"
12#include "BLI_string_utf8.hh"
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 for (int i = 0; i < tc->data_len; i++, td++) {
65 /* It is assumed that td->extra is a pointer to the AnimData,
66 * whose active action is where this keyframe comes from
67 * (this is only valid when not in NLA). */
68 AnimData *adt = static_cast<AnimData *>((t->spacetype != SPACE_NLA) ? td->extra : nullptr);
69 float startx = scene->r.cfra;
70 float fac = value;
71
72 /* Take proportional editing into account. */
73 fac = ((fac - 1.0f) * td->factor) + 1;
74
75 /* Check if any need to apply nla-mapping. */
76 if (adt) {
78 }
79
80 /* Now, calculate the new value. */
81 td->loc[0] = ((td->iloc[0] - startx) * fac) + startx;
82 }
83 }
84}
85
87{
88 char str[UI_MAX_DRAW_STR];
89
90 /* Handle numeric-input stuff. */
91 t->vec[0] = t->values[0];
92 applyNumInput(&t->num, &t->vec[0]);
93
95
96 t->values_final[0] = t->vec[0];
98
100
101 recalc_data(t);
102
104}
105
106static void timescale_transform_matrix_fn(TransInfo *t, float mat_xform[4][4])
107{
108 const float i_loc = mat_xform[3][0];
109 const float startx = t->center_global[0];
110 const float fac = t->values_final[0];
111 const float loc = ((i_loc - startx) * fac) + startx;
112 mat_xform[3][0] = loc;
113}
114
115static void initTimeScale(TransInfo *t, wmOperator * /*op*/)
116{
117 float center[2];
118
119 /* This tool is only really available in the Action Editor
120 * AND NLA Editor (for strip scaling). */
121 if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA) == 0) {
122 t->state = TRANS_CANCEL;
123 }
124
125 t->mode = TFM_TIME_SCALE;
126
127 /* Recalculate center2d to use scene->r.cfra and mouse Y, since that's
128 * what is used in time scale. */
129 if ((t->flag & T_OVERRIDE_CENTER) == 0) {
130 t->center_global[0] = t->scene->r.cfra;
131 projectFloatView(t, t->center_global, center);
132 center[1] = t->mouse.imval[1];
133 }
134
135 /* Force a reinitialize with the center2d used here. */
136 initMouseInput(t, &t->mouse, center, t->mouse.imval, false);
137
139
140 t->num.val_flag[0] |= NUM_NULL_ONE;
141
142 /* Numeric-input has max of (n-1). */
143 t->idx_max = 0;
144 t->num.flag = 0;
145 t->num.idx_max = t->idx_max;
146
147 /* Initialize snap like for everything else. */
148 t->increment[0] = 1.0f;
149 t->increment_precision = 1.0f;
150
151 copy_v3_fl(t->num.val_inc, t->increment[0]);
152 t->num.unit_sys = t->scene->unit.system;
153 t->num.unit_type[0] = B_UNIT_NONE;
154}
155
157
159 /*flags*/ T_NULL_ONE,
160 /*init_fn*/ initTimeScale,
161 /*transform_fn*/ applyTimeScale,
162 /*transform_matrix_fn*/ timescale_transform_matrix_fn,
163 /*handle_event_fn*/ nullptr,
164 /*snap_distance_fn*/ nullptr,
165 /*snap_apply_fn*/ timescale_snap_apply_fn,
166 /*draw_fn*/ nullptr,
167 /*status_fn*/ nullptr,
168};
169
170} // namespace blender::ed::transform
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
#define UI_MAX_DRAW_STR
#define ELEM(...)
#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)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
MINLINE void copy_v3_fl(float r[3], float f)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
@ B_UNIT_NONE
Definition BKE_unit.hh:165
int unit_type[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
short val_flag[NUM_MAX_ELEMENTS]
struct UnitSettings unit
struct RenderData r
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.