Blender V4.3
transform_mode_timetranslate.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
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string.h"
13
14#include "BKE_unit.hh"
15
16#include "ED_screen.hh"
17
18#include "UI_interface.hh"
19#include "UI_view2d.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/* -------------------------------------------------------------------- */
34{
35 char tvec[NUM_STR_REP_LEN * 3];
36 int ofs = 0;
37
38 /* If numeric input is active, use results from that, otherwise apply snapping to result. */
39 if (hasNumInput(&t->num)) {
40 outputNumInput(&(t->num), tvec, &t->scene->unit);
41 }
42 else {
43 eSnapMode snap_mode = t->tsnap.mode;
44 float ival = TRANS_DATA_CONTAINER_FIRST_OK(t)->data->ival;
45 float val = ival + t->values_final[0];
46
47 snapFrameTransform(t, snap_mode, ival, val, &val);
48 float delta_x = val - ival;
49
50 if (snap_mode == SCE_SNAP_TO_SECOND) {
51 /* Convert to seconds. */
52 const Scene *scene = t->scene;
53 delta_x /= FPS;
54 val /= FPS;
55 }
56
57 if (snap_mode == SCE_SNAP_TO_FRAME) {
58 BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.2f (%.4f)", delta_x, val);
59 }
60 else if (snap_mode == SCE_SNAP_TO_SECOND) {
61 BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.2f sec (%.4f)", delta_x, val);
62 }
63 else {
64 BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", delta_x);
65 }
66 }
67
68 ofs += BLI_snprintf_rlen(str, UI_MAX_DRAW_STR, IFACE_("DeltaX: %s"), &tvec[0]);
69
70 if (t->flag & T_PROP_EDIT_ALL) {
71 ofs += BLI_snprintf_rlen(
72 str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
73 }
74}
75
76static void applyTimeTranslateValue(TransInfo *t, const float deltax)
77{
79 /* It doesn't matter whether we apply to t->data. */
80 TransData *td = tc->data;
81 for (int i = 0; i < tc->data_len; i++, td++) {
82 float *dst, ival;
83 if (td->val) {
84 dst = td->val;
85 ival = td->ival;
86 }
87 else {
88 dst = &td->loc[0];
89 ival = td->iloc[0];
90 }
91
92 *dst = ival + deltax * td->factor;
93 }
94 }
95}
96
98{
99 View2D *v2d = (View2D *)t->view;
100 char str[UI_MAX_DRAW_STR];
101
102 /* Calculate translation amount from mouse movement - in 'time-grid space'. */
103 if (t->flag & T_MODAL) {
104 float cval[2], sval[2];
105 UI_view2d_region_to_view(v2d, t->mval[0], t->mval[0], &cval[0], &cval[1]);
106 UI_view2d_region_to_view(v2d, t->mouse.imval[0], t->mouse.imval[0], &sval[0], &sval[1]);
107
108 /* We only need to calculate effect for time (#applyTimeTranslate only needs that). */
109 t->values[0] = cval[0] - sval[0];
110 }
111
112 /* Handle numeric-input stuff. */
113 t->vec[0] = t->values[0];
114 applyNumInput(&t->num, &t->vec[0]);
115 t->values_final[0] = t->vec[0];
117
119
120 recalc_data(t);
121
123}
124
125static void initTimeTranslate(TransInfo *t, wmOperator * /*op*/)
126{
127 /* This tool is only really available in the Action Editor. */
129 t->state = TRANS_CANCEL;
130 }
131
133
134 /* Numeric-input has max of (n-1). */
135 t->idx_max = 0;
136 t->num.flag = 0;
137 t->num.idx_max = t->idx_max;
138
139 /* Initialize snap like for everything else. */
140 t->snap[0] = t->snap[1] = 1.0f;
141
142 copy_v3_fl(t->num.val_inc, t->snap[0]);
143 t->num.unit_sys = t->scene->unit.system;
144 /* No time unit supporting frames currently. */
145 t->num.unit_type[0] = B_UNIT_NONE;
146}
147
151 /*flags*/ 0,
152 /*init_fn*/ initTimeTranslate,
153 /*transform_fn*/ applyTimeTranslate,
154 /*transform_matrix_fn*/ nullptr,
155 /*handle_event_fn*/ nullptr,
156 /*snap_distance_fn*/ nullptr,
157 /*snap_apply_fn*/ nullptr,
158 /*draw_fn*/ nullptr,
159};
@ B_UNIT_NONE
Definition BKE_unit.hh:106
MINLINE void copy_v3_fl(float r[3], float f)
size_t BLI_snprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define ELEM(...)
#define IFACE_(msgid)
#define FPS
@ SCE_SNAP_TO_FRAME
@ SCE_SNAP_TO_SECOND
@ SPACE_ACTION
@ SPACE_SEQ
#define NUM_STR_REP_LEN
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
#define UI_MAX_DRAW_STR
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1663
#define str(s)
blender::float2 imval
Definition transform.hh:383
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
short flag
struct UnitSettings unit
void * view
Definition transform.hh:647
char spacetype
Definition transform.hh:582
float snap[2]
Definition transform.hh:561
float prop_size
Definition transform.hh:546
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
blender::float2 mval
Definition transform.hh:663
ScrArea * area
Definition transform.hh:651
eSnapMode mode
Definition transform.hh:312
@ INPUT_NONE
Definition transform.hh:741
#define TRANS_DATA_CONTAINER_FIRST_OK(t)
Definition transform.hh:849
@ T_MODAL
Definition transform.hh:118
@ TRANS_CANCEL
Definition transform.hh:210
#define T_PROP_EDIT_ALL
Definition transform.hh:157
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_timetranslate
static void applyTimeTranslateValue(TransInfo *t, const float deltax)
static void initTimeTranslate(TransInfo *t, wmOperator *)
static void applyTimeTranslate(TransInfo *t)
static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
void snapFrameTransform(TransInfo *t, eSnapMode autosnap, float val_initial, float val_final, float *r_val_final)