Blender V4.5
transform_mode_baketime.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_unit.hh"
15
16#include "ED_screen.hh"
17
18#include "UI_interface.hh"
19
20#include "BLT_translation.hh"
21
22#include "transform.hh"
23#include "transform_convert.hh"
24#include "transform_snap.hh"
25
26#include "transform_mode.hh"
27
28namespace blender::ed::transform {
29
30/* -------------------------------------------------------------------- */
33
34static void applyBakeTime(TransInfo *t)
35{
36 float time;
37 int i;
38 char str[UI_MAX_DRAW_STR];
39
40 float fac = 0.1f;
41
42/* XXX, disable precision for now,
43 * this isn't even accessible by the user. */
44#if 0
45 if (t->mouse.precision) {
46 /* Calculate ratio for shift-key position, and for total, and blend these for precision. */
47 time = float(t->center2d[0] - t->mouse.precision_mval[0]) * fac;
48 time += 0.1f * (float(t->center2d[0] * fac - mval[0]) - time);
49 }
50 else
51#endif
52 {
53 time = (t->center2d[0] - t->mval[0]) * fac;
54 }
55
57
58 applyNumInput(&t->num, &time);
59
60 /* Header print for NumInput. */
61 if (hasNumInput(&t->num)) {
62 char c[NUM_STR_REP_LEN];
63
64 outputNumInput(&(t->num), c, t->scene->unit);
65
66 if (time >= 0.0f) {
67 SNPRINTF(str, IFACE_("Time: +%s %s"), c, t->proptext);
68 }
69 else {
70 SNPRINTF(str, IFACE_("Time: %s %s"), c, t->proptext);
71 }
72 }
73 else {
74 /* Default header print. */
75 if (time >= 0.0f) {
76 SNPRINTF(str, IFACE_("Time: +%.3f %s"), time, t->proptext);
77 }
78 else {
79 SNPRINTF(str, IFACE_("Time: %.3f %s"), time, t->proptext);
80 }
81 }
82
84 TransData *td = tc->data;
85 for (i = 0; i < tc->data_len; i++, td++) {
86 if (td->flag & TD_SKIP) {
87 continue;
88 }
89
90 float *dst, ival;
91 if (td->val) {
92 dst = td->val;
93 ival = td->ival;
94 }
95 else {
96 dst = &td->loc[0];
97 ival = td->iloc[0];
98 }
99
100 *dst = ival + time * td->factor;
101 if (td->ext->scale && *dst < *td->ext->scale) {
102 *dst = *td->ext->scale;
103 }
104 if (td->ext->quat && *dst > *td->ext->quat) {
105 *dst = *td->ext->quat;
106 }
107 }
108 }
109
110 recalc_data(t);
111
113}
114
115static void initBakeTime(TransInfo *t, wmOperator * /*op*/)
116{
118
119 t->idx_max = 0;
120 t->num.idx_max = 0;
121 t->snap[0] = 1.0f;
122 t->snap[1] = t->snap[0] * 0.1f;
123
124 copy_v3_fl(t->num.val_inc, t->snap[0]);
125 t->num.unit_sys = t->scene->unit.system;
126 t->num.unit_type[0] = B_UNIT_NONE; /* Don't think this uses units? */
127}
128
130
132 /*flags*/ 0,
133 /*init_fn*/ initBakeTime,
134 /*transform_fn*/ applyBakeTime,
135 /*transform_matrix_fn*/ nullptr,
136 /*handle_event_fn*/ nullptr,
137 /*snap_distance_fn*/ nullptr,
138 /*snap_apply_fn*/ nullptr,
139 /*draw_fn*/ nullptr,
140};
141
142} // namespace blender::ed::transform
@ B_UNIT_NONE
Definition BKE_unit.hh:123
MINLINE void copy_v3_fl(float r[3], float f)
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:189
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:87
bool hasNumInput(const NumInput *n)
Definition numinput.cc:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:872
#define UI_MAX_DRAW_STR
#define str(s)
static void initBakeTime(TransInfo *t, wmOperator *)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)
static void applyBakeTime(TransInfo *t)
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
struct UnitSettings unit
i
Definition text_draw.cc:230
#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.