Blender  V2.93
transform_mode_edge_seq_slide.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdlib.h>
25 
26 #include "BLI_math.h"
27 #include "BLI_string.h"
28 
29 #include "BKE_context.h"
30 #include "BKE_unit.h"
31 
32 #include "ED_screen.h"
33 
34 #include "WM_api.h"
35 #include "WM_types.h"
36 
37 #include "UI_interface.h"
38 #include "UI_view2d.h"
39 
40 #include "BLT_translation.h"
41 
42 #include "transform.h"
43 #include "transform_convert.h"
44 #include "transform_mode.h"
45 #include "transform_snap.h"
46 
47 /* -------------------------------------------------------------------- */
51 static eRedrawFlag seq_slide_handleEvent(struct TransInfo *t, const wmEvent *event)
52 {
53  BLI_assert(t->mode == TFM_SEQ_SLIDE);
54  const wmKeyMapItem *kmi = t->custom.mode.data;
55  if (kmi && event->type == kmi->type && event->val == kmi->val) {
56  /* Allows the "Expand to Fit" effect to be enabled as a toggle. */
57  t->flag ^= T_ALT_TRANSFORM;
58  return TREDRAW_HARD;
59  }
60  return TREDRAW_NOTHING;
61 }
62 
63 static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRAW_STR])
64 {
65  char tvec[NUM_STR_REP_LEN * 3];
66  size_t ofs = 0;
67 
68  if (hasNumInput(&t->num)) {
69  outputNumInput(&(t->num), tvec, &t->scene->unit);
70  }
71  else {
72  BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
73  }
74 
75  ofs += BLI_snprintf(
76  str + ofs, UI_MAX_DRAW_STR - ofs, TIP_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text);
77 
78  const wmKeyMapItem *kmi = t->custom.mode.data;
79  if (kmi) {
80  ofs += WM_keymap_item_to_string(kmi, false, str + ofs, UI_MAX_DRAW_STR - ofs);
81  }
82 
83  ofs += BLI_snprintf(str + ofs,
84  UI_MAX_DRAW_STR - ofs,
85  TIP_(" or Alt) Expand to fit %s"),
86  WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
87 }
88 
89 static void applySeqSlideValue(TransInfo *t, const float val[2])
90 {
91  int i;
92 
94  TransData *td = tc->data;
95  for (i = 0; i < tc->data_len; i++, td++) {
96  if (td->flag & TD_SKIP) {
97  continue;
98  }
99 
100  madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor);
101  }
102  }
103 }
104 
105 static void applySeqSlide(TransInfo *t, const int mval[2])
106 {
107  char str[UI_MAX_DRAW_STR];
108  float values_final[3] = {0.0f};
109 
110  snapSequenceBounds(t, mval);
112  if (applyNumInput(&t->num, values_final)) {
113  if (t->con.mode & CON_APPLY) {
114  if (t->con.mode & CON_AXIS0) {
115  mul_v2_v2fl(values_final, t->spacemtx[0], values_final[0]);
116  }
117  else {
118  mul_v2_v2fl(values_final, t->spacemtx[1], values_final[0]);
119  }
120  }
121  }
122  else if (t->con.mode & CON_APPLY) {
123  t->con.applyVec(t, NULL, NULL, t->values, values_final);
124  }
125  else {
126  copy_v2_v2(values_final, t->values);
127  }
128 
129  values_final[0] = floorf(values_final[0] + 0.5f);
130  values_final[1] = floorf(values_final[1] + 0.5f);
131  copy_v2_v2(t->values_final, values_final);
132 
133  headerSeqSlide(t, t->values_final, str);
134  applySeqSlideValue(t, t->values_final);
135 
136  recalcData(t);
137 
138  ED_area_status_text(t->area, str);
139 }
140 
142 {
143  t->transform = applySeqSlide;
144  t->handleEvent = seq_slide_handleEvent;
145 
146  initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
147 
148  t->idx_max = 1;
149  t->num.flag = 0;
150  t->num.idx_max = t->idx_max;
151 
152  t->snap[0] = floorf(t->scene->r.frs_sec / t->scene->r.frs_sec_base);
153  t->snap[1] = 10.0f;
154 
155  copy_v3_fl(t->num.val_inc, t->snap[0]);
156  t->num.unit_sys = t->scene->unit.system;
157  /* Would be nice to have a time handling in units as well
158  * (supporting frames in addition to "natural" time...). */
159  t->num.unit_type[0] = B_UNIT_NONE;
160  t->num.unit_type[1] = B_UNIT_NONE;
161 
162  if (t->keymap) {
163  /* Workaround to use the same key as the modal keymap. */
164  t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE);
165  }
166 }
@ B_UNIT_NONE
Definition: BKE_unit.h:78
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define TIP_(msgid)
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:102
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:27
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:207
bool hasNumInput(const NumInput *n)
Definition: numinput.c:185
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:815
@ TFM_SEQ_SLIDE
Definition: ED_transform.h:76
_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:90
#define str(s)
#define floorf(x)
short val
Definition: WM_types.h:579
short type
Definition: WM_types.h:577
@ INPUT_VECTOR
Definition: transform.h:728
@ CON_APPLY
Definition: transform.h:177
@ CON_AXIS0
Definition: transform.h:179
void recalcData(TransInfo *t)
eRedrawFlag
Definition: transform.h:197
@ TREDRAW_NOTHING
Definition: transform.h:198
@ TREDRAW_HARD
Definition: transform.h:199
@ T_ALT_TRANSFORM
Definition: transform.h:140
@ TFM_MODAL_TRANSLATE
Definition: transform.h:253
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
conversion and adaptation of different datablocks to a common struct.
void transform_convert_sequencer_channel_clamp(TransInfo *t)
@ TD_SKIP
transform modes used by different operators.
static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRAW_STR])
void initSeqSlide(TransInfo *t)
static eRedrawFlag seq_slide_handleEvent(struct TransInfo *t, const wmEvent *event)
static void applySeqSlide(TransInfo *t, const int mval[2])
static void applySeqSlideValue(TransInfo *t, const float val[2])
void snapSequenceBounds(TransInfo *t, const int mval[2])
const char * WM_bool_as_string(bool test)
Definition: wm_keymap.c:2003
int WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact, char *result, const int result_len)
Definition: wm_keymap.c:1213
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
Definition: wm_keymap.c:980