Blender V5.3
transform_mode_edge_seq_slide.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 "MEM_guardedalloc.h"
12
13#include "BLI_math_vector_c.hh"
14#include "BLI_string_utf8.hh"
15
16#include "BKE_context.hh"
17#include "BKE_unit.hh"
18
19#include "ED_screen.hh"
20
21#include "RNA_access.hh"
22
23#include "WM_api.hh"
24#include "WM_types.hh"
25
26#include "UI_interface_types.hh"
27
28#include "BLT_translation.hh"
29
30#include "ED_sequencer.hh"
31
32#include "SEQ_sequencer.hh"
33
34#include "transform.hh"
35#include "transform_convert.hh"
36#include "transform_mode.hh"
37#include "transform_snap.hh"
38
39namespace blender::ed::transform {
40
41/* -------------------------------------------------------------------- */
44
49
50static const char *seq_slide_overlap_mode_name(const eSeqOverlapMode overlap_mode)
51{
52 switch (overlap_mode) {
54 return IFACE_("Ripple");
56 return IFACE_("Overwrite");
58 return IFACE_("Shuffle");
59 }
60 return "";
61}
62
63static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRAW_STR])
64{
66 char tvec[NUM_STR_REP_LEN * 3];
67 size_t ofs = 0;
68
69 if (hasNumInput(&t->num)) {
70 outputNumInput(&(t->num), tvec, scene->unit);
71 }
72 else {
73 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
74 }
75
76 const eSeqOverlapMode overlap_mode = seq::tool_settings_overlap_mode_get(scene);
77 ofs += BLI_snprintf_utf8_rlen(str + ofs,
78 UI_MAX_DRAW_STR - ofs,
79 IFACE_("Sequence Slide: %s%s | Overlap: %s"),
80 &tvec[0],
81 t->con.text,
82 seq_slide_overlap_mode_name(overlap_mode));
83
84 if (overlap_mode == SEQ_OVERLAP_RIPPLE) {
85 const eSeqRippleFlag ripple_flag = seq::tool_settings_ripple_flag_get(scene);
86 ofs += BLI_snprintf_utf8_rlen(str + ofs,
87 UI_MAX_DRAW_STR - ofs,
88 IFACE_(" | Insert: %s"),
89 WM_bool_as_string((ripple_flag & SEQ_RIPPLE_INSERT) != 0));
90 }
91}
92
93static void applySeqSlideValue(TransInfo *t, const float val[2])
94{
95 int i;
96
98 TransData *td = tc->data;
99 for (i = 0; i < tc->data_len; i++, td++) {
100 if (td->flag & TD_SKIP) {
101 continue;
102 }
103
104 madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor);
105 }
106 }
107}
108
110{
111 char str[UI_MAX_DRAW_STR];
112 float values_final[3] = {0.0f}, values_clamped[3] = {0.0f};
113
114 if (applyNumInput(&t->num, values_final)) {
115 if (t->con.mode & CON_APPLY) {
116 if (t->con.mode & CON_AXIS0) {
117 mul_v2_v2fl(values_final, t->spacemtx[0], values_final[0]);
118 }
119 else {
120 mul_v2_v2fl(values_final, t->spacemtx[1], values_final[0]);
121 }
122 }
123 }
124 else {
125 copy_v2_v2(values_final, t->values);
126 transform_snap_mixed_apply(t, values_final);
127
128 if (t->con.mode & CON_APPLY) {
129 t->con.applyVec(t, nullptr, nullptr, values_final, values_final);
130 }
131 }
132
133 values_final[0] = round_fl_to_int(values_final[0]);
134 values_final[1] = round_fl_to_int(values_final[1]);
135
136 copy_v2_v2(values_clamped, values_final);
137 transform_convert_sequencer_clamp(t, values_clamped);
138 headerSeqSlide(t, values_clamped, str);
139
140 copy_v2_v2(t->values_final, values_final);
142
143 recalc_data(t);
144
146}
147
149{
150 if (t->keymap == nullptr || t->data_container_len == 0) {
151 return;
152 }
153
155 const wmKeyMap &keymap = *t->keymap;
156 const TransSeq *ts = static_cast<const TransSeq *>(
157 TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data);
158
159 WorkspaceStatus status(t->context);
160 status.modal_keymap(IFACE_("Confirm"), keymap, TFM_MODAL_CONFIRM);
161 status.modal_keymap(IFACE_("Cancel"), keymap, TFM_MODAL_CANCEL);
162 status.modal_keymap(IFACE_("Snap"), keymap, TFM_MODAL_SNAP_TOGGLE, t->modifiers & MOD_SNAP);
163 status.modal_keymap(
164 IFACE_("Snap Invert"), keymap, TFM_MODAL_SNAP_INV_ON, t->modifiers & MOD_SNAP_INVERT);
165 status.modal_keymap(
166 IFACE_("Precision"), keymap, TFM_MODAL_PRECISION, t->modifiers & MOD_PRECISION);
167
168 const bool has_constraint = (t->con.mode & CON_APPLY) != 0;
169 if ((t->flag & T_NO_CONSTRAINT) == 0) {
170 status.modal_keymap({}, keymap, TFM_MODAL_AXIS_X, has_constraint && (t->con.mode & CON_AXIS0));
171 status.modal_keymap(
172 IFACE_("Axis"), keymap, TFM_MODAL_AXIS_Y, has_constraint && (t->con.mode & CON_AXIS1));
173 }
174
175 const bool y_locked = ts->offset_clamp.ymin == 0 && ts->offset_clamp.ymax == 0;
176 const bool handles_selected = y_locked && t->data_type == &TransConvertType_Sequencer;
177 if (has_constraint) {
178 status.modal_keymap(IFACE_("Clear Constraints"), keymap, TFM_MODAL_CONS_OFF);
179 }
180 else if (handles_selected) {
181 status.modal_keymap(IFACE_("Clamp Handles"),
182 keymap,
185 }
186
187 const eSeqOverlapMode overlap_mode = seq::tool_settings_overlap_mode_get(scene);
188 status.modal_keymap(IFACE_("Ripple"),
189 keymap,
191 overlap_mode == SEQ_OVERLAP_RIPPLE);
192 status.modal_keymap(IFACE_("Overwrite"),
193 keymap,
195 overlap_mode == SEQ_OVERLAP_OVERWRITE);
196 status.modal_keymap(IFACE_("Shuffle"),
197 keymap,
199 overlap_mode == SEQ_OVERLAP_SHUFFLE);
200
201 if (overlap_mode == SEQ_OVERLAP_RIPPLE) {
202 const eSeqRippleFlag ripple_flag = seq::tool_settings_ripple_flag_get(scene);
203 status.modal_keymap(IFACE_("Insert"),
204 keymap,
206 (ripple_flag & SEQ_RIPPLE_INSERT) != 0);
207 }
208}
209
211{
213 t->custom.mode.data = ssp;
214 t->custom.mode.use_free = true;
215 ssp->op = op;
216 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_restore_handle_selection");
217 if (op != nullptr && prop != nullptr) {
219 }
220
222
224
225 t->idx_max = 1;
226 t->num.flag = 0;
227 t->num.idx_max = t->idx_max;
228
229 t->increment = float3(floorf(scene->r.frs_sec / scene->r.frs_sec_base));
230 t->increment_precision = 10.0f / t->increment[0];
231
232 copy_v3_fl(t->num.val_inc, t->increment[0]);
233 t->num.unit_sys = scene->unit.system;
234 /* Would be nice to have a time handling in units as well
235 * (supporting frames in addition to "natural" time...). */
236 t->num.unit_type[0] = B_UNIT_NONE;
237 t->num.unit_type[1] = B_UNIT_NONE;
238}
239
241{
242 SeqSlideParams *ssp = static_cast<SeqSlideParams *>(t->custom.mode.data);
243 if (ssp == nullptr) {
244 return false;
245 }
247}
248
250{
251 if (t->mode != TFM_SEQ_SLIDE) {
252 return nullptr;
253 }
254 SeqSlideParams *ssp = static_cast<SeqSlideParams *>(t->custom.mode.data);
255 if (ssp == nullptr) {
256 return nullptr;
257 }
258 return ssp->op;
259}
260
262
264 /*flags*/ 0,
265 /*init_fn*/ initSeqSlide,
266 /*transform_fn*/ applySeqSlide,
267 /*transform_matrix_fn*/ nullptr,
268 /*handle_event_fn*/ nullptr,
269 /*snap_distance_fn*/ nullptr,
270 /*snap_apply_fn*/ snap_sequencer_apply_seqslide,
271 /*draw_fn*/ nullptr,
272 /*status_fn*/ seq_slide_status,
273};
274
275} // namespace blender::ed::transform
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
Read Blender memory allocation and freeing.
#define UI_MAX_DRAW_STR
void modal_keymap(std::string text, const wmKeyMap &keymap, int propvalue, bool inverted=false)
Definition area.cc:1119
#define str(s)
static void applySeqSlide(TransInfo *t)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
TransConvertTypeInfo TransConvertType_Sequencer
void recalc_data(TransInfo *t)
static void initSeqSlide(TransInfo *t, wmOperator *op)
void transform_snap_mixed_apply(TransInfo *t, float *vec)
static void applySeqSlideValue(TransInfo *t, const float val[2])
static const char * seq_slide_overlap_mode_name(const eSeqOverlapMode overlap_mode)
void snap_sequencer_apply_seqslide(TransInfo *t, float *vec)
bool transform_mode_edge_seq_slide_use_restore_handle_selection(const TransInfo *t)
static void seq_slide_status(TransInfo *t)
wmOperator * transform_mode_edge_seq_slide_operator_get(const TransInfo *t)
bool transform_convert_sequencer_clamp(const TransInfo *t, float r_val[2])
static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRAW_STR])
eSeqRippleFlag tool_settings_ripple_flag_get(Scene *scene)
Definition sequencer.cc:451
eSeqOverlapMode tool_settings_overlap_mode_get(Scene *scene)
Definition sequencer.cc:445
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
Scene * CTX_data_sequencer_scene(const bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
MINLINE int round_fl_to_int(float a)
MINLINE void copy_v2_v2(float r[2], const float a[2])
const char * WM_bool_as_string(bool test)
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
MINLINE void copy_v3_fl(float r[3], float f)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
VecBase< float, 3 > float3
@ B_UNIT_NONE
Definition BKE_unit.hh:165
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
#define floorf
int unit_type[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
struct UnitSettings unit
struct RenderData r
void(*) applyVec(const TransInfo *t, const TransDataContainer *tc, const TransData *td, const float in[3], float r_out[3])
Definition transform.hh:606
TransConvertTypeInfo * data_type
Definition transform.hh:836
TransCustomDataContainer custom
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
Definition transform.hh:45
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.