Blender V4.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.h"
12#include "BLI_string.h"
13
14#include "BKE_nla.hh"
15#include "BKE_unit.hh"
16
17#include "ED_screen.hh"
18
19#include "UI_interface.hh"
20
21#include "BLT_translation.hh"
22
23#include "transform.hh"
24#include "transform_convert.hh"
25#include "transform_snap.hh"
26
27#include "transform_mode.hh"
28
29/* -------------------------------------------------------------------- */
32
33static void timescale_snap_apply_fn(TransInfo *t, float vec[3])
34{
35 float point[3];
37 const float fac = (point[0] - t->center_global[0]) /
38 (t->tsnap.snap_source[0] - t->center_global[0]);
39 vec[0] = fac;
40}
41
43{
44 char tvec[NUM_STR_REP_LEN * 3];
45
46 if (hasNumInput(&t->num)) {
47 outputNumInput(&(t->num), tvec, &t->scene->unit);
48 }
49 else {
50 BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values_final[0]);
51 }
52
53 BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleX: %s"), &tvec[0]);
54}
55
56static void applyTimeScaleValue(TransInfo *t, float value)
57{
58 Scene *scene = t->scene;
59
61 TransData *td = tc->data;
62 TransData2D *td2d = tc->data_2d;
63 for (int i = 0; i < tc->data_len; i++, td++, td2d++) {
64 /* It is assumed that td->extra is a pointer to the AnimData,
65 * whose active action is where this keyframe comes from
66 * (this is only valid when not in NLA). */
67 AnimData *adt = static_cast<AnimData *>((t->spacetype != SPACE_NLA) ? td->extra : nullptr);
68 float startx = scene->r.cfra;
69 float fac = value;
70
71 /* Take proportional editing into account. */
72 fac = ((fac - 1.0f) * td->factor) + 1;
73
74 /* Check if any need to apply nla-mapping. */
75 if (adt) {
77 }
78
79 /* Now, calculate the new value. */
80 td->loc[0] = ((td->iloc[0] - startx) * fac) + startx;
81 }
82 }
83}
84
86{
87 char str[UI_MAX_DRAW_STR];
88
89 /* Handle numeric-input stuff. */
90 t->vec[0] = t->values[0];
91 applyNumInput(&t->num, &t->vec[0]);
92
94
95 t->values_final[0] = t->vec[0];
97
99
100 recalc_data(t);
101
103}
104
105static void timescale_transform_matrix_fn(TransInfo *t, float mat_xform[4][4])
106{
107 const float i_loc = mat_xform[3][0];
108 const float startx = t->center_global[0];
109 const float fac = t->values_final[0];
110 const float loc = ((i_loc - startx) * fac) + startx;
111 mat_xform[3][0] = loc;
112}
113
114static void initTimeScale(TransInfo *t, wmOperator * /*op*/)
115{
116 float center[2];
117
118 /* This tool is only really available in the Action Editor
119 * AND NLA Editor (for strip scaling). */
120 if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA) == 0) {
121 t->state = TRANS_CANCEL;
122 }
123
124 t->mode = TFM_TIME_SCALE;
125
126 /* Recalculate center2d to use scene->r.cfra and mouse Y, since that's
127 * what is used in time scale. */
128 if ((t->flag & T_OVERRIDE_CENTER) == 0) {
129 t->center_global[0] = t->scene->r.cfra;
130 projectFloatView(t, t->center_global, center);
131 center[1] = t->mouse.imval[1];
132 }
133
134 /* Force a reinitialize with the center2d used here. */
135 initMouseInput(t, &t->mouse, center, t->mouse.imval, false);
136
138
139 t->num.val_flag[0] |= NUM_NULL_ONE;
140
141 /* Numeric-input has max of (n-1). */
142 t->idx_max = 0;
143 t->num.flag = 0;
144 t->num.idx_max = t->idx_max;
145
146 /* Initialize snap like for everything else. */
147 t->snap[0] = t->snap[1] = 1.0f;
148
149 copy_v3_fl(t->num.val_inc, t->snap[0]);
150 t->num.unit_sys = t->scene->unit.system;
151 t->num.unit_type[0] = B_UNIT_NONE;
152}
153
155
157 /*flags*/ T_NULL_ONE,
158 /*init_fn*/ initTimeScale,
159 /*transform_fn*/ applyTimeScale,
160 /*transform_matrix_fn*/ timescale_transform_matrix_fn,
161 /*handle_event_fn*/ nullptr,
162 /*snap_distance_fn*/ nullptr,
163 /*snap_apply_fn*/ timescale_snap_apply_fn,
164 /*draw_fn*/ nullptr,
165};
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, short mode)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:513
@ B_UNIT_NONE
Definition BKE_unit.hh:106
MINLINE void copy_v3_fl(float r[3], float f)
size_t BLI_snprintf(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
@ NUM_NULL_ONE
void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings)
Definition numinput.cc:88
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:803
@ TFM_TIME_SCALE
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
#define UI_MAX_DRAW_STR
void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
#define str(s)
blender::float2 imval
Definition transform.hh:383
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
eTfmMode mode
Definition transform.hh:517
char spacetype
Definition transform.hh:582
float snap[2]
Definition transform.hh:561
float values[4]
Definition transform.hh:624
TransSnap tsnap
Definition transform.hh:537
short idx_max
Definition transform.hh:559
eTState state
Definition transform.hh:527
NumInput num
Definition transform.hh:540
Scene * scene
Definition transform.hh:654
float vec[3]
Definition transform.hh:587
eTFlag flag
Definition transform.hh:523
MouseInput mouse
Definition transform.hh:543
float values_final[4]
Definition transform.hh:632
float center_global[3]
Definition transform.hh:555
ScrArea * area
Definition transform.hh:651
float snap_source[3]
Definition transform.hh:325
@ INPUT_SPRING_FLIP
Definition transform.hh:744
void initMouseInput(TransInfo *t, MouseInput *mi, const blender::float2 &center, const blender::float2 &mval, bool precision)
@ T_OVERRIDE_CENTER
Definition transform.hh:129
@ T_NULL_ONE
Definition transform.hh:96
@ TRANS_CANCEL
Definition transform.hh:210
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:854
void recalc_data(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.
TransModeInfo TransMode_timescale
static void initTimeScale(TransInfo *t, wmOperator *)
static void applyTimeScaleValue(TransInfo *t, float value)
static void timescale_snap_apply_fn(TransInfo *t, float vec[3])
static void timescale_transform_matrix_fn(TransInfo *t, float mat_xform[4][4])
static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeScale(TransInfo *t)
void transform_snap_mixed_apply(TransInfo *t, float *vec)
void getSnapPoint(const TransInfo *t, float vec[3])