Blender  V3.3
transform_mode_timescale.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdlib.h>
9 
10 #include "DNA_anim_types.h"
11 
12 #include "BLI_math.h"
13 #include "BLI_string.h"
14 
15 #include "BKE_context.h"
16 #include "BKE_nla.h"
17 #include "BKE_unit.h"
18 
19 #include "ED_screen.h"
20 
21 #include "UI_interface.h"
22 
23 #include "BLT_translation.h"
24 
25 #include "transform.h"
26 #include "transform_convert.h"
27 #include "transform_snap.h"
28 
29 #include "transform_mode.h"
30 
31 /* -------------------------------------------------------------------- */
36 {
37  char tvec[NUM_STR_REP_LEN * 3];
38 
39  if (hasNumInput(&t->num)) {
40  outputNumInput(&(t->num), tvec, &t->scene->unit);
41  }
42  else {
43  BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values_final[0]);
44  }
45 
46  BLI_snprintf(str, UI_MAX_DRAW_STR, TIP_("ScaleX: %s"), &tvec[0]);
47 }
48 
49 static void applyTimeScaleValue(TransInfo *t, float value)
50 {
51  Scene *scene = t->scene;
52 
54  TransData *td = tc->data;
55  TransData2D *td2d = tc->data_2d;
56  for (int i = 0; i < tc->data_len; i++, td++, td2d++) {
57  /* it is assumed that td->extra is a pointer to the AnimData,
58  * whose active action is where this keyframe comes from
59  * (this is only valid when not in NLA)
60  */
61  AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
62  float startx = scene->r.cfra;
63  float fac = value;
64 
65  /* take proportional editing into account */
66  fac = ((fac - 1.0f) * td->factor) + 1;
67 
68  /* check if any need to apply nla-mapping */
69  if (adt) {
70  startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP);
71  }
72 
73  /* now, calculate the new value */
74  td->loc[0] = ((td->iloc[0] - startx) * fac) + startx;
75  }
76  }
77 }
78 
79 static void applyTimeScale(TransInfo *t, const int UNUSED(mval[2]))
80 {
81  char str[UI_MAX_DRAW_STR];
82 
83  /* handle numeric-input stuff */
84  t->vec[0] = t->values[0];
85  applyNumInput(&t->num, &t->vec[0]);
86  t->values_final[0] = t->vec[0];
88 
89  applyTimeScaleValue(t, t->values_final[0]);
90 
91  recalcData(t);
92 
93  ED_area_status_text(t->area, str);
94 }
95 
97 {
98  float center[2];
99 
100  /* this tool is only really available in the Action Editor
101  * AND NLA Editor (for strip scaling)
102  */
103  if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA) == 0) {
104  t->state = TRANS_CANCEL;
105  }
106 
107  t->mode = TFM_TIME_SCALE;
108  t->transform = applyTimeScale;
109 
110  /* recalculate center2d to use scene->r.cfra and mouse Y, since that's
111  * what is used in time scale */
112  if ((t->flag & T_OVERRIDE_CENTER) == 0) {
113  t->center_global[0] = t->scene->r.cfra;
114  projectFloatView(t, t->center_global, center);
115  center[1] = t->mouse.imval[1];
116  }
117 
118  /* force a reinit with the center2d used here */
119  initMouseInput(t, &t->mouse, center, t->mouse.imval, false);
120 
122 
123  t->flag |= T_NULL_ONE;
124  t->num.val_flag[0] |= NUM_NULL_ONE;
125 
126  /* Numeric-input has max of (n-1). */
127  t->idx_max = 0;
128  t->num.flag = 0;
129  t->num.idx_max = t->idx_max;
130 
131  /* Initialize snap like for everything else. */
132  t->snap[0] = t->snap[1] = 1.0f;
133 
134  copy_v3_fl(t->num.val_inc, t->snap[0]);
135  t->num.unit_sys = t->scene->unit.system;
136  t->num.unit_type[0] = B_UNIT_NONE;
137 }
138 
@ NLATIME_CONVERT_UNMAP
Definition: BKE_nla.h:357
float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short mode)
Definition: nla.c:642
@ B_UNIT_NONE
Definition: BKE_unit.h:100
MINLINE void copy_v3_fl(float r[3], float f)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
@ SPACE_ACTION
@ SPACE_NLA
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:87
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:13
@ NUM_NULL_ONE
Definition: ED_numinput.h:55
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:189
bool hasNumInput(const NumInput *n)
Definition: numinput.c:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:792
@ TFM_TIME_SCALE
Definition: ED_transform.h:52
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:91
Scene scene
#define str(s)
void initMouseInput(TransInfo *t, MouseInput *mi, const float center[2], const int mval[2], bool precision)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
struct RenderData r
void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
Definition: transform.c:366
void recalcData(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.
void initTimeScale(TransInfo *t)
static void applyTimeScaleValue(TransInfo *t, float value)
static void applyTimeScale(TransInfo *t, const int UNUSED(mval[2]))
static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])