Blender V5.0
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
8
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string_utf8.h"
13
14#include "BKE_unit.hh"
15
16#include "ED_screen.hh"
17
18#include "UI_interface_types.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
29namespace blender::ed::transform {
30
31/* -------------------------------------------------------------------- */
34
36{
37 char tvec[NUM_STR_REP_LEN * 3];
38 int ofs = 0;
39
40 /* If numeric input is active, use results from that, otherwise apply snapping to result. */
41 if (hasNumInput(&t->num)) {
42 outputNumInput(&(t->num), tvec, t->scene->unit);
43 }
44 else {
45 eSnapMode snap_mode = t->tsnap.mode;
46 float ival = TRANS_DATA_CONTAINER_FIRST_OK(t)->data->ival;
47 float val = ival + t->values_final[0];
48
49 snapFrameTransform(t, snap_mode, ival, val, &val);
50 float delta_x = val - ival;
51
52 if (snap_mode == SCE_SNAP_TO_SECOND) {
53 /* Convert to seconds. */
54 const Scene *scene = t->scene;
55 delta_x /= scene->frames_per_second();
56 val /= scene->frames_per_second();
57 }
58
59 if (snap_mode == SCE_SNAP_TO_FRAME) {
60 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.2f (%.4f)", delta_x, val);
61 }
62 else if (snap_mode == SCE_SNAP_TO_SECOND) {
63 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.2f sec (%.4f)", delta_x, val);
64 }
65 else {
66 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.4f", delta_x);
67 }
68 }
69
70 ofs += BLI_snprintf_utf8_rlen(str, UI_MAX_DRAW_STR, IFACE_("DeltaX: %s"), &tvec[0]);
71
72 if (t->flag & T_PROP_EDIT_ALL) {
74 str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
75 }
76}
77
78static void applyTimeTranslateValue(TransInfo *t, const float deltax)
79{
81 /* It doesn't matter whether we apply to t->data. */
82 TransData *td = tc->data;
83 for (int i = 0; i < tc->data_len; i++, td++) {
84 float *dst, ival;
85 if (td->val) {
86 dst = td->val;
87 ival = td->ival;
88 }
89 else {
90 dst = &td->loc[0];
91 ival = td->iloc[0];
92 }
93
94 *dst = ival + deltax * td->factor;
95 }
96 }
97}
98
100{
101 View2D *v2d = (View2D *)t->view;
102 char str[UI_MAX_DRAW_STR];
103
104 /* Calculate translation amount from mouse movement - in 'time-grid space'. */
105 if (t->flag & T_MODAL) {
106 float cval[2], sval[2];
107 UI_view2d_region_to_view(v2d, t->mval[0], t->mval[0], &cval[0], &cval[1]);
108 UI_view2d_region_to_view(v2d, t->mouse.imval[0], t->mouse.imval[0], &sval[0], &sval[1]);
109
110 /* We only need to calculate effect for time (#applyTimeTranslate only needs that). */
111 t->values[0] = cval[0] - sval[0];
112 }
113
114 /* Handle numeric-input stuff. */
115 t->vec[0] = t->values[0];
116 applyNumInput(&t->num, &t->vec[0]);
117 t->values_final[0] = t->vec[0];
119
121
122 recalc_data(t);
123
125}
126
127static void initTimeTranslate(TransInfo *t, wmOperator * /*op*/)
128{
129 /* This tool is only really available in the Action Editor. */
131 t->state = TRANS_CANCEL;
132 }
133
135
136 /* Numeric-input has max of (n-1). */
137 t->idx_max = 0;
138 t->num.flag = 0;
139 t->num.idx_max = t->idx_max;
140
141 /* Initialize snap like for everything else. */
142 t->increment[0] = 1.0f;
143 t->increment_precision = 1.0f;
144
145 copy_v3_fl(t->num.val_inc, t->increment[0]);
146 t->num.unit_sys = t->scene->unit.system;
147 /* No time unit supporting frames currently. */
148 t->num.unit_type[0] = B_UNIT_NONE;
149}
150
152
154 /*flags*/ 0,
155 /*init_fn*/ initTimeTranslate,
156 /*transform_fn*/ applyTimeTranslate,
157 /*transform_matrix_fn*/ nullptr,
158 /*handle_event_fn*/ nullptr,
159 /*snap_distance_fn*/ nullptr,
160 /*snap_apply_fn*/ nullptr,
161 /*draw_fn*/ nullptr,
162};
163
164} // namespace blender::ed::transform
@ 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
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define ELEM(...)
#define IFACE_(msgid)
@ SCE_SNAP_TO_FRAME
@ SCE_SNAP_TO_SECOND
@ SPACE_ACTION
@ SPACE_SEQ
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
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
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:1668
#define str(s)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeTranslate(TransInfo *t)
void snapFrameTransform(TransInfo *t, eSnapMode snap_mode, float val_initial, float val_final, float *r_val_final)
static void initTimeTranslate(TransInfo *t, wmOperator *)
static void applyTimeTranslateValue(TransInfo *t, const float deltax)
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
short flag
struct UnitSettings unit
i
Definition text_draw.cc:230
#define TRANS_DATA_CONTAINER_FIRST_OK(t)
Definition transform.hh:37
#define T_PROP_EDIT_ALL
Definition transform.hh:28
#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.