Blender V5.3
cage2d_gizmo.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#include "MEM_guardedalloc.h"
17
18#include "BLI_dial_2d.hh"
19#include "BLI_math_base_safe.hh"
20#include "BLI_math_matrix_c.hh"
22#include "BLI_math_vector_c.hh"
24#include "BLI_rect.hh"
25
26#include "BKE_context.hh"
27
28#include "GPU_immediate.hh"
29#include "GPU_immediate_util.hh"
30#include "GPU_matrix.hh"
31#include "GPU_select.hh"
32#include "GPU_state.hh"
33
34#include "RNA_access.hh"
35#include "RNA_define.hh"
36
37#include "WM_api.hh"
38#include "WM_types.hh"
39
40#include "ED_gizmo_library.hh"
41#include "ED_screen.hh"
42
43/* own includes */
45
46namespace blender {
47
48#define GIZMO_MARGIN_OFFSET_SCALE 1.5f
49/* The same as in `draw_cache.cc`. */
50#define CIRCLE_RESOL 32
51
52static int gizmo_cage2d_transform_flag_get(const wmGizmo *gz);
53
54static void gizmo_calc_rect_view_scale(const wmGizmo *gz, float scale[2])
55{
56 float matrix_final_no_offset[4][4];
57 float x_axis[3], y_axis[3];
58 WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
59 mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, gz->matrix_offset[0]);
60 mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, gz->matrix_offset[1]);
61
62 float len_x_axis = len_v3(x_axis);
63 float len_y_axis = len_v3(y_axis);
64
65 /* Set scale to zero if axis length is zero. */
66 scale[0] = safe_divide(1.0f, len_x_axis);
67 scale[1] = safe_divide(1.0f, len_y_axis);
68}
69
70static void gizmo_calc_rect_view_margin(const wmGizmo *gz, float margin[2])
71{
72 float handle_size;
73 handle_size = 0.15f;
74 handle_size *= gz->scale_final;
75 float scale_xy[2];
76 gizmo_calc_rect_view_scale(gz, scale_xy);
77
78 margin[0] = (handle_size * scale_xy[0]);
79 margin[1] = (handle_size * scale_xy[1]);
80}
81
82/* -------------------------------------------------------------------- */
87
88static void cage2d_draw_box_corners(const rctf *r,
89 const float margin[2],
90 const float color[3],
91 const float line_width)
92{
93 /* NOTE(Metal): Prefer using 3D coordinates with 3D shader, even if rendering 2D gizmo's. */
94 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
95
98
99 float viewport[4];
100 GPU_viewport_size_get_f(viewport);
101 immUniform2fv("viewportSize", &viewport[2]);
102
103 immUniform1f("lineWidth", line_width * U.pixelsize);
104
106
107 immVertex3f(pos, r->xmin, r->ymin + margin[1], 0.0f);
108 immVertex3f(pos, r->xmin, r->ymin, 0.0f);
109 immVertex3f(pos, r->xmin, r->ymin, 0.0f);
110 immVertex3f(pos, r->xmin + margin[0], r->ymin, 0.0f);
111
112 immVertex3f(pos, r->xmax, r->ymin + margin[1], 0.0f);
113 immVertex3f(pos, r->xmax, r->ymin, 0.0f);
114 immVertex3f(pos, r->xmax, r->ymin, 0.0f);
115 immVertex3f(pos, r->xmax - margin[0], r->ymin, 0.0f);
116
117 immVertex3f(pos, r->xmax, r->ymax - margin[1], 0.0f);
118 immVertex3f(pos, r->xmax, r->ymax, 0.0f);
119 immVertex3f(pos, r->xmax, r->ymax, 0.0f);
120 immVertex3f(pos, r->xmax - margin[0], r->ymax, 0.0f);
121
122 immVertex3f(pos, r->xmin, r->ymax - margin[1], 0.0f);
123 immVertex3f(pos, r->xmin, r->ymax, 0.0f);
124 immVertex3f(pos, r->xmin, r->ymax, 0.0f);
125 immVertex3f(pos, r->xmin + margin[0], r->ymax, 0.0f);
126
127 immEnd();
128
130}
131
132static void cage2d_draw_box_interaction(const float color[4],
133 const int highlighted,
134 const float size[2],
135 const float margin[2],
136 const float line_width,
137 const bool is_solid,
138 const int draw_options)
139{
140 /* 4 verts for translate, otherwise only 3 are used. */
141 float verts[4][2];
142 uint verts_len = 0;
143 GPUPrimType prim_type = GPU_PRIM_NONE;
144
145 switch (highlighted) {
147 rctf r;
148 r.xmin = -size[0];
149 r.xmax = -size[0] + margin[0];
150 r.ymin = -size[1] + margin[1];
151 r.ymax = size[1] - margin[1];
152
153 ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
154 ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
155 verts_len = 2;
156 if (is_solid) {
157 ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
158 ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
159 verts_len += 2;
160 prim_type = GPU_PRIM_TRI_FAN;
161 }
162 else {
163 prim_type = GPU_PRIM_LINE_STRIP;
164 }
165 break;
166 }
168 rctf r;
169 r.xmin = size[0] - margin[0];
170 r.xmax = size[0];
171 r.ymin = -size[1] + margin[1];
172 r.ymax = size[1] - margin[1];
173
174 ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
175 ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
176 verts_len = 2;
177 if (is_solid) {
178 ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
179 ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
180 verts_len += 2;
181 prim_type = GPU_PRIM_TRI_FAN;
182 }
183 else {
184 prim_type = GPU_PRIM_LINE_STRIP;
185 }
186 break;
187 }
189 rctf r;
190 r.xmin = -size[0] + margin[0];
191 r.xmax = size[0] - margin[0];
192 r.ymin = -size[1];
193 r.ymax = -size[1] + margin[1];
194
195 ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
196 ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
197 verts_len = 2;
198 if (is_solid) {
199 ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
200 ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
201 verts_len += 2;
202 prim_type = GPU_PRIM_TRI_FAN;
203 }
204 else {
205 prim_type = GPU_PRIM_LINE_STRIP;
206 }
207 break;
208 }
210 rctf r;
211 r.xmin = -size[0] + margin[0];
212 r.xmax = size[0] - margin[0];
213 r.ymin = size[1] - margin[1];
214 r.ymax = size[1];
215
216 ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
217 ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
218 verts_len = 2;
219 if (is_solid) {
220 ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
221 ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
222 verts_len += 2;
223 prim_type = GPU_PRIM_TRI_FAN;
224 }
225 else {
226 prim_type = GPU_PRIM_LINE_STRIP;
227 }
228 break;
229 }
231 rctf r;
232 r.xmin = -size[0];
233 r.xmax = -size[0] + margin[0];
234 r.ymin = -size[1];
235 r.ymax = -size[1] + margin[1];
236
237 ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
238 ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
239 ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
240 verts_len = 3;
241 if (is_solid) {
242 ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
243 verts_len += 1;
244 prim_type = GPU_PRIM_TRI_FAN;
245 }
246 else {
247 prim_type = GPU_PRIM_LINE_STRIP;
248 }
249 break;
250 }
252 rctf r;
253 r.xmin = -size[0];
254 r.xmax = -size[0] + margin[0];
255 r.ymin = size[1] - margin[1];
256 r.ymax = size[1];
257
258 ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymax);
259 ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
260 ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymin);
261 verts_len = 3;
262 if (is_solid) {
263 ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
264 verts_len += 1;
265 prim_type = GPU_PRIM_TRI_FAN;
266 }
267 else {
268 prim_type = GPU_PRIM_LINE_STRIP;
269 }
270 break;
271 }
273 rctf r;
274 r.xmin = size[0] - margin[0];
275 r.xmax = size[0];
276 r.ymin = -size[1];
277 r.ymax = -size[1] + margin[1];
278
279 ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
280 ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
281 ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
282 verts_len = 3;
283 if (is_solid) {
284 ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
285 verts_len += 1;
286 prim_type = GPU_PRIM_TRI_FAN;
287 }
288 else {
289 prim_type = GPU_PRIM_LINE_STRIP;
290 }
291 break;
292 }
294 rctf r;
295 r.xmin = size[0] - margin[0];
296 r.xmax = size[0];
297 r.ymin = size[1] - margin[1];
298 r.ymax = size[1];
299
300 ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
301 ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymin);
302 ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
303 verts_len = 3;
304 if (is_solid) {
305 ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymax);
306 verts_len += 1;
307 prim_type = GPU_PRIM_TRI_FAN;
308 }
309 else {
310 prim_type = GPU_PRIM_LINE_STRIP;
311 }
312 break;
313 }
315 const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
316 rctf r_rotate{};
317 r_rotate.xmin = rotate_pt[0] - margin[0] / 2.0f;
318 r_rotate.xmax = rotate_pt[0] + margin[0] / 2.0f;
319 r_rotate.ymin = rotate_pt[1] - margin[1] / 2.0f;
320 r_rotate.ymax = rotate_pt[1] + margin[1] / 2.0f;
321
322 ARRAY_SET_ITEMS(verts[0], r_rotate.xmin, r_rotate.ymin);
323 ARRAY_SET_ITEMS(verts[1], r_rotate.xmin, r_rotate.ymax);
324 ARRAY_SET_ITEMS(verts[2], r_rotate.xmax, r_rotate.ymax);
325 ARRAY_SET_ITEMS(verts[3], r_rotate.xmax, r_rotate.ymin);
326
327 verts_len = 4;
328 if (is_solid) {
329 prim_type = GPU_PRIM_TRI_FAN;
330 }
331 else {
332 prim_type = GPU_PRIM_LINE_STRIP;
333 }
334 break;
335 }
336
339 ARRAY_SET_ITEMS(verts[0], -margin[0] / 2, -margin[1] / 2);
340 ARRAY_SET_ITEMS(verts[1], margin[0] / 2, margin[1] / 2);
341 ARRAY_SET_ITEMS(verts[2], -margin[0] / 2, margin[1] / 2);
342 ARRAY_SET_ITEMS(verts[3], margin[0] / 2, -margin[1] / 2);
343 verts_len = 4;
344 if (is_solid) {
345 prim_type = GPU_PRIM_TRI_FAN;
346 }
347 else {
348 prim_type = GPU_PRIM_LINES;
349 }
350 }
351 else {
352 /* Only used for 3D view selection, never displayed to the user. */
353 ARRAY_SET_ITEMS(verts[0], -size[0], -size[1]);
354 ARRAY_SET_ITEMS(verts[1], -size[0], size[1]);
355 ARRAY_SET_ITEMS(verts[2], size[0], size[1]);
356 ARRAY_SET_ITEMS(verts[3], size[0], -size[1]);
357 verts_len = 4;
358 if (is_solid) {
359 prim_type = GPU_PRIM_TRI_FAN;
360 }
361 else {
362 /* unreachable */
363 BLI_assert(0);
364 prim_type = GPU_PRIM_LINE_STRIP;
365 }
366 }
367 break;
368 default:
369 return;
370 }
371
372 BLI_assert(prim_type != GPU_PRIM_NONE);
373
374 GPUVertFormat *format = immVertexFormat();
375 struct {
376 uint pos, col;
377 } attr_id{};
378
379 attr_id.pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
380 attr_id.col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32);
381
382 {
383 if (is_solid) {
384
385 if (margin[0] == 0.0f && margin[1] == 0.0) {
386 prim_type = GPU_PRIM_POINTS;
388 }
389 else if (margin[0] == 0.0f || margin[1] == 0.0) {
390 prim_type = GPU_PRIM_LINE_STRIP;
392 }
393 else {
394 BLI_assert(ELEM(prim_type, GPU_PRIM_TRI_FAN));
396 }
397
398 immBegin(prim_type, verts_len);
399 immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
400 for (uint i = 0; i < verts_len; i++) {
401 immVertex2fv(attr_id.pos, verts[i]);
402 }
403 immEnd();
404 }
405 else {
407
409
410 float viewport[4];
411 GPU_viewport_size_get_f(viewport);
412 immUniform2fv("viewportSize", &viewport[2]);
413
414 immUniform1f("lineWidth", (line_width * 3.0f) * U.pixelsize);
415
416 immBegin(prim_type, verts_len);
417 immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
418 for (uint i = 0; i < verts_len; i++) {
419 immVertex2fv(attr_id.pos, verts[i]);
420 }
421 immEnd();
422
423 immUniform1f("lineWidth", line_width * U.pixelsize);
424
425 immBegin(prim_type, verts_len);
426 immAttr3fv(attr_id.col, color);
427 for (uint i = 0; i < verts_len; i++) {
428 immVertex2fv(attr_id.pos, verts[i]);
429 }
430 immEnd();
431 }
432 }
433
435}
436
438
439/* -------------------------------------------------------------------- */
444
446 uint pos, float x, float y, float rad_x, float rad_y, bool solid)
447{
448 if (rad_x == 0 && rad_y == 0) {
450 immVertex2f(pos, x, y);
451 immEnd();
452 return;
453 }
454
455 if (rad_x == 0 || rad_y == 0) {
456 /* Do not draw anything if only on of the radii is zero. */
457 return;
458 }
459
460 if (solid) {
461 /* NOTE(Metal/AMD): Small Triangle-list primitives more optimal for GPU HW than Triangle-strip.
462 */
464 immVertex2f(pos, x - rad_x, y - rad_y);
465 immVertex2f(pos, x - rad_x, y + rad_y);
466 immVertex2f(pos, x + rad_x, y + rad_y);
467
468 immVertex2f(pos, x - rad_x, y - rad_y);
469 immVertex2f(pos, x + rad_x, y + rad_y);
470 immVertex2f(pos, x + rad_x, y - rad_y);
471 immEnd();
472 }
473 else {
474 /* NOTE(Metal/AMD): Small Line-list primitives more optimal for GPU HW than Line-strip. */
476 immVertex2f(pos, x - rad_x, y - rad_y);
477 immVertex2f(pos, x - rad_x, y + rad_y);
478
479 immVertex2f(pos, x - rad_x, y + rad_y);
480 immVertex2f(pos, x + rad_x, y + rad_y);
481
482 immVertex2f(pos, x + rad_x, y + rad_y);
483 immVertex2f(pos, x + rad_x, y - rad_y);
484
485 immVertex2f(pos, x + rad_x, y - rad_y);
486 immVertex2f(pos, x - rad_x, y - rad_y);
487 immEnd();
488 }
489}
490
491static void cage2d_draw_rect_wire(const rctf *r,
492 const float margin[2],
493 const float color[3],
494 const int transform_flag,
495 const int draw_options,
496 const float line_width)
497{
498 /* NOTE(Metal): Prefer using 3D coordinates with 3D shader input, even if rendering 2D gizmo's.
499 */
500 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
501
504
505 float viewport[4];
506 GPU_viewport_size_get_f(viewport);
507 immUniform2fv("viewportSize", &viewport[2]);
508 immUniform1f("lineWidth", line_width * U.pixelsize);
509
510 /* Small 'lines' primitives more efficient for hardware processing than line-strip. */
512 immVertex3f(pos, r->xmin, r->ymin, 0.0f);
513 immVertex3f(pos, r->xmax, r->ymin, 0.0f);
514
515 immVertex3f(pos, r->xmax, r->ymin, 0.0f);
516 immVertex3f(pos, r->xmax, r->ymax, 0.0f);
517
518 immVertex3f(pos, r->xmax, r->ymax, 0.0f);
519 immVertex3f(pos, r->xmin, r->ymax, 0.0f);
520
521 immVertex3f(pos, r->xmin, r->ymax, 0.0f);
522 immVertex3f(pos, r->xmin, r->ymin, 0.0f);
523 immEnd();
524
525 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
527 immVertex3f(pos, BLI_rctf_cent_x(r), r->ymax, 0.0f);
528 immVertex3f(pos, BLI_rctf_cent_x(r), r->ymax + margin[1], 0.0f);
529
530 immVertex3f(pos, BLI_rctf_cent_x(r), r->ymax + margin[1], 0.0f);
531 immVertex3f(pos, BLI_rctf_cent_x(r), r->ymax, 0.0f);
532 immEnd();
533 }
534
535 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
537 const float rad[2] = {margin[0] / 2, margin[1] / 2};
538 const float center[2] = {BLI_rctf_cent_x(r), BLI_rctf_cent_y(r)};
539
541 immVertex3f(pos, center[0] - rad[0], center[1] - rad[1], 0.0f);
542 immVertex3f(pos, center[0] + rad[0], center[1] + rad[1], 0.0f);
543 immVertex3f(pos, center[0] + rad[0], center[1] - rad[1], 0.0f);
544 immVertex3f(pos, center[0] - rad[0], center[1] + rad[1], 0.0f);
545 immEnd();
546 }
547 }
548
550}
551
552static void cage2d_draw_circle_wire(const float color[3],
553 const float size[2],
554 const float margin[2],
555 const int transform_flag,
556 const int draw_options,
557 const float line_width)
558{
559 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
560
561 const bool use_points = is_zero_v2(margin);
565
566 if (use_points) {
567 /* Draw a central point. */
568 immUniform1f("size", 1.0 * U.pixelsize);
570 immVertex3f(pos, 0.0f, 0.0f, 0.0f);
571 immEnd();
572 }
573 else {
574 float viewport[4];
575 GPU_viewport_size_get_f(viewport);
576 immUniform2fv("viewportSize", &viewport[2]);
577 immUniform1f("lineWidth", line_width * U.pixelsize);
578 imm_draw_circle_wire_aspect_3d(pos, 0.0f, 0.0f, size[0], size[1], CIRCLE_RESOL);
579 }
580
581 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
583 immVertex3f(pos, 0.0f, size[1], 0.0f);
584 immVertex3f(pos, 0.0f, size[1] + margin[1], 0.0f);
585
586 immVertex3f(pos, 0.0f, size[1] + margin[1], 0.0f);
587 immVertex3f(pos, 0.0f, size[1], 0.0f);
588 immEnd();
589 }
590
591 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
593 const float rad[2] = {margin[0] / 2, margin[1] / 2};
594 const float center[2] = {0.0f, 0.0f};
595
597 immVertex3f(pos, center[0] - rad[0], center[1] - rad[1], 0.0f);
598 immVertex3f(pos, center[0] + rad[0], center[1] + rad[1], 0.0f);
599 immVertex3f(pos, center[0] + rad[0], center[1] - rad[1], 0.0f);
600 immVertex3f(pos, center[0] - rad[0], center[1] + rad[1], 0.0f);
601 immEnd();
602 }
603 }
604
606}
607
616
618 const float margin[2],
619 const float color[3],
620 bool solid)
621{
622 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
623 void (*circle_fn)(uint, float, float, float, float, int) = (solid) ?
626 const int resolu = 12;
627 const float rad[2] = {margin[0] / 3, margin[1] / 3};
628
631
632 const float handle[2] = {
634 r->ymax + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE),
635 };
636 circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu);
637
639}
640
642 const float margin[2],
643 const float color[3],
644 bool solid)
645{
646 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
647 const float rad[2] = {margin[0] / 3, margin[1] / 3};
648
651
652 /* Should really divide by two, but looks too bulky. */
653 {
654 imm_draw_point_aspect_2d(pos, r->xmin, r->ymin, rad[0], rad[1], solid);
655 imm_draw_point_aspect_2d(pos, r->xmax, r->ymin, rad[0], rad[1], solid);
656 imm_draw_point_aspect_2d(pos, r->xmax, r->ymax, rad[0], rad[1], solid);
657 imm_draw_point_aspect_2d(pos, r->xmin, r->ymax, rad[0], rad[1], solid);
658 }
659
661}
662
664 const int highlighted,
665 const float size[2],
666 const float margin[2],
667 const float color[3],
668 bool solid)
669{
670 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
671
674
675 switch (highlighted) {
678 const float rad[2] = {0.2f * margin[0], 0.4f * size[1]};
679 imm_draw_point_aspect_2d(pos, r->xmin, 0.0f, rad[0], rad[1], solid);
680 imm_draw_point_aspect_2d(pos, r->xmax, 0.0f, rad[0], rad[1], solid);
681 break;
682 }
685 const float rad[2] = {0.4f * size[0], 0.2f * margin[1]};
686 imm_draw_point_aspect_2d(pos, 0.0f, r->ymin, rad[0], rad[1], solid);
687 imm_draw_point_aspect_2d(pos, 0.0f, r->ymax, rad[0], rad[1], solid);
688 break;
689 }
690 }
691
693}
694
696
698 const bool select,
699 const bool highlight,
700 const int select_id)
701{
702 // const bool use_clamp = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0;
703 float dims[2];
704 RNA_float_get_array(gz->ptr, "dimensions", dims);
705 float matrix_final[4][4];
706
707 const int transform_flag = gizmo_cage2d_transform_flag_get(gz);
708 const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
709 const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
710
711 const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
712
713 WM_gizmo_calc_matrix_final(gz, matrix_final);
714
716 GPU_matrix_mul(matrix_final);
717
718 float margin[2];
719 gizmo_calc_rect_view_margin(gz, margin);
720
721 /* Handy for quick testing draw (if it's outside bounds). */
722 if (false) {
724 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
726 immUniformColor4f(1, 1, 1, 0.5f);
727 float s = 0.5f;
728 immRectf(pos, -s, -s, s, s);
731 }
732
733 if (select) {
734 /* Expand for hot-spot. */
735 const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
736 if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
737 /* Only scaling is needed for now. */
739
740 cage2d_draw_circle_wire(gz->color, size_real, margin, 0, draw_options, gz->line_width);
741 }
742 else {
743 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE) {
744 int scale_parts[] = {
749
754 };
755 for (int i = 0; i < ARRAY_SIZE(scale_parts); i++) {
756 GPU_select_load_id(select_id | scale_parts[i]);
758 gz->color, scale_parts[i], size, margin, gz->line_width, true, draw_options);
759 }
760 }
761 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
762 const int transform_part = ED_GIZMO_CAGE2D_PART_TRANSLATE;
763 GPU_select_load_id(select_id | transform_part);
765 gz->color, transform_part, size, margin, gz->line_width, true, draw_options);
766 }
767 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
770 size_real,
771 margin,
772 gz->line_width,
773 true,
774 draw_options);
775 }
776 }
777 }
778 else {
779 rctf r;
780 r.xmin = -size_real[0];
781 r.ymin = -size_real[1];
782 r.xmax = size_real[0];
783 r.ymax = size_real[1];
784
785 if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
786 float color[4], black[3] = {0, 0, 0};
787 gizmo_color_get(gz, highlight, color);
788
789 /* corner gizmos */
790 cage2d_draw_box_corners(&r, margin, black, gz->line_width + 3.0f);
791
792 /* corner gizmos */
793 cage2d_draw_box_corners(&r, margin, color, gz->line_width);
794
795 bool show = false;
797 /* Only show if we're drawing the center handle
798 * otherwise the entire rectangle is the hot-spot. */
800 show = true;
801 }
802 }
803 else {
804 show = true;
805 }
806
807 if (show) {
809 gz->color, gz->highlight_part, size_real, margin, gz->line_width, false, draw_options);
810 }
811
812 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
815 size_real,
816 margin,
817 gz->line_width,
818 false,
819 draw_options);
820 }
821 }
822 else {
823 float color[4], black[3] = {0, 0, 0};
824 gizmo_color_get(gz, highlight, color);
825
827
828 float outline_line_width = gz->line_width + 3.0f;
829
830 if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX_TRANSFORM) {
831 cage2d_draw_rect_wire(&r, margin, black, transform_flag, draw_options, outline_line_width);
832 cage2d_draw_rect_wire(&r, margin, color, transform_flag, draw_options, gz->line_width);
833
834 /* Edge handles. */
835 cage2d_draw_rect_edge_handles(&r, gz->highlight_part, size_real, margin, color, true);
836 cage2d_draw_rect_edge_handles(&r, gz->highlight_part, size_real, margin, black, false);
837
838 /* Only draw corner handles when hovering over the corners. */
840 cage2d_draw_rect_corner_handles(&r, margin, color, true);
841 cage2d_draw_rect_corner_handles(&r, margin, black, false);
842 }
843
844 /* Rotate handles. */
845 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
846 cage2d_draw_rect_rotate_handle(&r, margin, color, true);
847 cage2d_draw_rect_rotate_handle(&r, margin, black, false);
848 }
849 }
850 else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
852 black, size_real, margin, transform_flag, draw_options, outline_line_width);
854 color, size_real, margin, transform_flag, draw_options, gz->line_width);
855
856 /* Edge handles. */
857 cage2d_draw_rect_edge_handles(&r, gz->highlight_part, size_real, margin, color, true);
858 cage2d_draw_rect_edge_handles(&r, gz->highlight_part, size_real, margin, black, false);
859
860 /* Draw corner handles. */
861 if (draw_options & ED_GIZMO_CAGE_DRAW_FLAG_CORNER_HANDLES) {
862 cage2d_draw_rect_corner_handles(&r, margin, color, true);
863 cage2d_draw_rect_corner_handles(&r, margin, black, false);
864 }
865
866 /* Rotation handles. */
867 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
868 cage2d_draw_rect_rotate_handle(&r, margin, color, true);
869 cage2d_draw_rect_rotate_handle(&r, margin, black, false);
870 }
871 }
872 else {
873 BLI_assert(0);
874 }
876 }
877 }
878
880}
881
885static void gizmo_cage2d_draw_select(const bContext * /*C*/, wmGizmo *gz, int select_id)
886{
887 gizmo_cage2d_draw_intern(gz, true, false, select_id);
888}
889
890static void gizmo_cage2d_draw(const bContext * /*C*/, wmGizmo *gz)
891{
892 const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
893 gizmo_cage2d_draw_intern(gz, false, is_highlight, -1);
894}
895
897{
898 int highlight_part = gz->highlight_part;
899
902 }
903
904 switch (highlight_part) {
913
914 /* TODO: diagonal cursor. */
922 return WM_CURSOR_CROSS;
923 default:
924 return WM_CURSOR_DEFAULT;
925 }
926}
927
928static int gizmo_cage2d_test_select(bContext *C, wmGizmo *gz, const int mval[2])
929{
930 float point_local[2];
931 float dims[2];
932 RNA_float_get_array(gz->ptr, "dimensions", dims);
933 const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
934
935 if (gizmo_window_project_2d(C, gz, float2(int2(mval)), 2, true, point_local) == false) {
936 return -1;
937 }
938
939 float margin[2];
940 gizmo_calc_rect_view_margin(gz, margin);
941
942 /* Expand for hots-pot. */
943 const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
944
945 const int transform_flag = gizmo_cage2d_transform_flag_get(gz);
946 const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
947
948 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
949 rctf r;
951 r.xmin = -margin[0] / 2;
952 r.ymin = -margin[1] / 2;
953 r.xmax = margin[0] / 2;
954 r.ymax = margin[1] / 2;
955 }
956 else {
957 r.xmin = -size[0] + margin[0];
958 r.ymin = -size[1] + margin[1];
959 r.xmax = size[0] - margin[0];
960 r.ymax = size[1] - margin[1];
961 if (!BLI_rctf_is_valid(&r)) {
962 /* Typically happens when gizmo width or height is very small. */
964 }
965 }
966 bool isect = BLI_rctf_isect_pt_v(&r, point_local);
967 if (isect) {
969 }
970 }
971
972 /* if gizmo does not have a scale intersection, don't do it */
974 rctf r_xmin{};
975 r_xmin.xmin = -size[0];
976 r_xmin.ymin = -size[1];
977 r_xmin.xmax = -size[0] + margin[0];
978 r_xmin.ymax = size[1];
979
980 rctf r_xmax{};
981 r_xmax.xmin = size[0] - margin[0];
982 r_xmax.ymin = -size[1];
983 r_xmax.xmax = size[0];
984 r_xmax.ymax = size[1];
985
986 rctf r_ymin{};
987 r_ymin.xmin = -size[0];
988 r_ymin.ymin = -size[1];
989 r_ymin.xmax = size[0];
990 r_ymin.ymax = -size[1] + margin[1];
991
992 rctf r_ymax{};
993 r_ymax.xmin = -size[0];
994 r_ymax.ymin = size[1] - margin[1];
995 r_ymax.xmax = size[0];
996 r_ymax.ymax = size[1];
997
998 const bool draw_corners = draw_options & ED_GIZMO_CAGE_DRAW_FLAG_CORNER_HANDLES;
999
1000 if (BLI_rctf_isect_pt_v(&r_xmin, point_local)) {
1001 if (draw_corners) {
1002 if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
1004 }
1005 if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
1007 }
1008 }
1010 }
1011 if (BLI_rctf_isect_pt_v(&r_xmax, point_local)) {
1012 if (draw_corners) {
1013 if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
1015 }
1016 if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
1018 }
1019 }
1021 }
1022 if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
1024 }
1025 if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
1027 }
1028 }
1029
1030 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
1031 /* Rotate:
1032 * (*) <-- hot spot is here!
1033 * +---+
1034 * | |
1035 * +---+ */
1036 const float r_rotate_pt[2] = {0.0f, size_real[1] + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)};
1037 rctf r_rotate{};
1038 r_rotate.xmin = r_rotate_pt[0] - margin[0] / 2.0f;
1039 r_rotate.xmax = r_rotate_pt[0] + margin[0] / 2.0f;
1040 r_rotate.ymin = r_rotate_pt[1] - margin[1] / 2.0f;
1041 r_rotate.ymax = r_rotate_pt[1] + margin[1] / 2.0f;
1042
1043 if (BLI_rctf_isect_pt_v(&r_rotate, point_local)) {
1045 }
1046 }
1047
1048 return -1;
1049}
1050
1051namespace {
1052
1053struct RectTransformInteraction {
1054 float orig_mouse[2];
1055 float orig_matrix_offset[4][4];
1056 float orig_matrix_final_no_offset[4][4];
1057 Dial *dial;
1058 bool use_temp_uniform;
1059};
1060
1061} // namespace
1062
1064{
1065 RectTransformInteraction *data = static_cast<RectTransformInteraction *>(gz->interaction_data);
1066 int transform_flag = RNA_enum_get(gz->ptr, "transform");
1067 if (data) {
1068 if (data->use_temp_uniform) {
1070 }
1071 }
1072 return transform_flag;
1073}
1074
1079
1081{
1082 RectTransformInteraction *data = MEM_new_zeroed<RectTransformInteraction>("cage_interaction");
1083
1084 copy_m4_m4(data->orig_matrix_offset, gz->matrix_offset);
1085 WM_gizmo_calc_matrix_final_no_offset(gz, data->orig_matrix_final_no_offset);
1086
1087 if (gizmo_window_project_2d(C, gz, float2(int2(event->mval)), 2, false, data->orig_mouse) == 0) {
1088 zero_v2(data->orig_mouse);
1089 }
1090
1091 gz->interaction_data = data;
1092
1094}
1095
1096static void gizmo_constrain_from_scale_part(int part, bool r_constrain_axis[2])
1097{
1098 r_constrain_axis[0] = (part > ED_GIZMO_CAGE2D_PART_SCALE_MAX_X &&
1100 true :
1101 false;
1102 r_constrain_axis[1] = (part > ED_GIZMO_CAGE2D_PART_SCALE &&
1104 true :
1105 false;
1106}
1107
1108static void gizmo_pivot_from_scale_part(int part, float r_pt[2])
1109{
1110 switch (part) {
1112 ARRAY_SET_ITEMS(r_pt, 0.0, 0.0);
1113 break;
1114 }
1116 ARRAY_SET_ITEMS(r_pt, 0.5, 0.0);
1117 break;
1118 }
1120 ARRAY_SET_ITEMS(r_pt, -0.5, 0.0);
1121 break;
1122 }
1124 ARRAY_SET_ITEMS(r_pt, 0.0, 0.5);
1125 break;
1126 }
1128 ARRAY_SET_ITEMS(r_pt, 0.0, -0.5);
1129 break;
1130 }
1132 ARRAY_SET_ITEMS(r_pt, 0.5, 0.5);
1133 break;
1134 }
1136 ARRAY_SET_ITEMS(r_pt, 0.5, -0.5);
1137 break;
1138 }
1140 ARRAY_SET_ITEMS(r_pt, -0.5, 0.5);
1141 break;
1142 }
1144 ARRAY_SET_ITEMS(r_pt, -0.5, -0.5);
1145 break;
1146 }
1147 default:
1148 BLI_assert(0);
1149 }
1150}
1151
1153 wmGizmo *gz,
1154 const wmEvent *event,
1155 eWM_GizmoFlagTweak /*tweak_flag*/)
1156{
1157 RectTransformInteraction *data = static_cast<RectTransformInteraction *>(gz->interaction_data);
1158 int transform_flag = RNA_enum_get(gz->ptr, "transform");
1159 if ((transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM) == 0) {
1160 /* WARNING: Checking the events modifier only makes sense as long as `tweak_flag`
1161 * remains unused (this controls #WM_GIZMO_TWEAK_PRECISE by default). */
1162 const bool use_temp_uniform = (event->modifier & KM_SHIFT) != 0;
1163 const bool changed = data->use_temp_uniform != use_temp_uniform;
1164 data->use_temp_uniform = use_temp_uniform;
1165 if (use_temp_uniform) {
1167 }
1168
1169 if (changed) {
1170 /* Always refresh. */
1171 }
1172 else if (event->type != MOUSEMOVE) {
1174 }
1175 }
1176
1177 float point_local[2];
1178
1179 float dims[2];
1180 RNA_float_get_array(gz->ptr, "dimensions", dims);
1181
1182 {
1183 float matrix_back[4][4];
1184 copy_m4_m4(matrix_back, gz->matrix_offset);
1185 copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
1186
1187 /* The mouse coords are projected into the matrix so we don't need to worry about axis
1188 * alignment. */
1189 bool ok = gizmo_window_project_2d(C, gz, float2(int2(event->mval)), 2, false, point_local);
1190 copy_m4_m4(gz->matrix_offset, matrix_back);
1191 if (!ok) {
1193 }
1194 }
1195
1196 wmGizmoProperty *gz_prop;
1197
1198 gz_prop = WM_gizmo_target_property_find(gz, "matrix");
1199 if (gz_prop->type != nullptr) {
1201 }
1202
1204 /* do this to prevent clamping from changing size */
1205 copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
1206 gz->matrix_offset[3][0] = data->orig_matrix_offset[3][0] +
1207 (point_local[0] - data->orig_mouse[0]);
1208 gz->matrix_offset[3][1] = data->orig_matrix_offset[3][1] +
1209 (point_local[1] - data->orig_mouse[1]);
1210 }
1212
1213#define MUL_V2_V3_M4_FINAL(test_co, mouse_co) \
1214 mul_v3_m4v3(test_co, data->orig_matrix_final_no_offset, float3{UNPACK2(mouse_co), 0.0})
1215
1216 float test_co[3];
1217
1218 if (data->dial == nullptr) {
1219 MUL_V2_V3_M4_FINAL(test_co, data->orig_matrix_offset[3]);
1220
1221 data->dial = BLI_dial_init(test_co, FLT_EPSILON);
1222
1223 MUL_V2_V3_M4_FINAL(test_co, data->orig_mouse);
1224 BLI_dial_angle(data->dial, test_co);
1225 }
1226
1227 /* rotate */
1228 MUL_V2_V3_M4_FINAL(test_co, point_local);
1229 const float angle = BLI_dial_angle(data->dial, test_co);
1230
1231 float matrix_space_inv[4][4];
1232 float matrix_rotate[4][4];
1233 float pivot[3];
1234
1235 copy_v3_v3(pivot, data->orig_matrix_offset[3]);
1236
1237 invert_m4_m4(matrix_space_inv, gz->matrix_space);
1238
1239 unit_m4(matrix_rotate);
1240 mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
1241 rotate_m4(matrix_rotate, 'Z', -angle);
1242 mul_m4_m4m4(matrix_rotate, matrix_rotate, gz->matrix_space);
1243
1244 zero_v3(matrix_rotate[3]);
1245 transform_pivot_set_m4(matrix_rotate, pivot);
1246
1247 mul_m4_m4m4(gz->matrix_offset, matrix_rotate, data->orig_matrix_offset);
1248
1249#undef MUL_V2_V3_M4_FINAL
1250 }
1251 else {
1252 /* scale */
1253 copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
1254 const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
1255
1256 float pivot[2];
1257 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
1259 mul_v2_v2(pivot, dims);
1260 }
1261 else {
1262 RNA_float_get_array(gz->ptr, "pivot", pivot);
1263 }
1264
1265 float curr_mouse[2];
1266 copy_v2_v2(curr_mouse, data->orig_mouse);
1267
1268 /* Rotate current and original mouse coordinates around gizmo center. */
1269 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_ROTATE) {
1270 float rot[3][3];
1271 float loc[3];
1272 float size[3];
1273 mat4_to_loc_rot_size(loc, rot, size, gz->matrix_offset);
1274
1275 invert_m3(rot);
1276 sub_v2_v2(point_local, loc);
1277 mul_m3_v2(rot, point_local);
1278 add_v2_v2(point_local, loc);
1279
1280 sub_v2_v2(curr_mouse, loc);
1281 mul_m3_v2(rot, curr_mouse);
1282 add_v2_v2(curr_mouse, loc);
1283 }
1284
1285 bool constrain_axis[2] = {false};
1287
1288 float size_new[2], size_orig[2];
1289 for (int i = 0; i < 2; i++) {
1290 size_orig[i] = len_v3(data->orig_matrix_offset[i]);
1291 size_new[i] = size_orig[i];
1292 if (constrain_axis[i] == false) {
1293 /* Original cursor position relative to pivot. */
1294 const float delta_orig = curr_mouse[i] - data->orig_matrix_offset[3][i] -
1295 pivot[i] * size_orig[i];
1296 const float delta_curr = point_local[i] - data->orig_matrix_offset[3][i] -
1297 pivot[i] * size_orig[i];
1298
1299 if ((transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_SIGNED) == 0) {
1300 if (signum_i(delta_orig) != signum_i(delta_curr)) {
1301 size_new[i] = 0.0f;
1302 continue;
1303 }
1304 }
1305 if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
1306 /* Use the half-dimension as a fixed reference for circle gizmos,
1307 * since the circle registers as a single `PART_SCALE` (both axes free)
1308 * and `delta_orig` can be near-zero on one axis. */
1309 size_new[i] = delta_curr / (signf(delta_orig) * 0.5f * dims[i] - pivot[i]);
1310 }
1311 else {
1312 /* Ratio of cursor-to-pivot distances (current / original). */
1313 size_new[i] = size_orig[i] * (delta_curr / delta_orig);
1314 }
1315 }
1316 }
1317
1318 float scale[2] = {1.0f, 1.0f};
1319 for (int i = 0; i < 2; i++) {
1320 if (size_orig[i] == 0) {
1321 size_orig[i] = 1.0f;
1322 gz->matrix_offset[i][i] = 1.0f;
1323 }
1324 scale[i] = size_new[i] / size_orig[i];
1325 }
1326
1327 if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM) {
1328 if (constrain_axis[0] == false && constrain_axis[1] == false) {
1329 if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE &&
1331 {
1332 /* So that the cursor lies on the circle. */
1333 scale[1] = scale[0] = len_v2(scale);
1334 }
1335 else {
1336 scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
1337 }
1338 }
1339 else if (constrain_axis[0] == false) {
1340 scale[1] = scale[0];
1341 }
1342 else if (constrain_axis[1] == false) {
1343 scale[0] = scale[1];
1344 }
1345 else {
1346 BLI_assert(0);
1347 }
1348 }
1349
1350 /* Scale around pivot. */
1351 float matrix_scale[4][4];
1352 unit_m4(matrix_scale);
1353
1354 mul_v3_fl(matrix_scale[0], scale[0]);
1355 mul_v3_fl(matrix_scale[1], scale[1]);
1356
1357 transform_pivot_set_m4(matrix_scale, float3(UNPACK2(pivot), 0.0f));
1358 mul_m4_m4_post(gz->matrix_offset, matrix_scale);
1359 }
1360
1361 if (gz_prop->type != nullptr) {
1363 }
1364
1365 /* tag the region for redraw */
1367
1369}
1370
1372{
1373 if (STREQ(gz_prop->type->idname, "matrix")) {
1374 if (WM_gizmo_target_property_array_length(gz, gz_prop) == 16) {
1376 }
1377 else {
1378 BLI_assert(0);
1379 }
1380 }
1381 else {
1382 BLI_assert(0);
1383 }
1384}
1385
1386static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel)
1387{
1388 RectTransformInteraction *data = static_cast<RectTransformInteraction *>(gz->interaction_data);
1389
1390 if (data->dial) {
1391 BLI_dial_free(data->dial);
1392 data->dial = nullptr;
1393 }
1394
1395 wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "matrix");
1396
1397 if (!cancel) {
1398 if (WM_gizmo_target_property_is_valid(gz_prop)) {
1400 }
1401 return;
1402 }
1403
1404 /* reset properties */
1405 if (gz_prop->type != nullptr) {
1406 WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &data->orig_matrix_offset[0][0]);
1407 }
1408
1409 copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
1410}
1411
1412/* -------------------------------------------------------------------- */
1415
1417{
1418 /* identifiers */
1419 gzt->idname = "GIZMO_GT_cage_2d";
1420
1421 /* API callbacks. */
1422 gzt->draw = gizmo_cage2d_draw;
1429 gzt->exit = gizmo_cage2d_exit;
1431
1432 gzt->struct_size = sizeof(wmGizmo);
1433
1434 /* rna */
1435 static const EnumPropertyItem rna_enum_draw_style[] = {
1436 {ED_GIZMO_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
1437 {ED_GIZMO_CAGE2D_STYLE_BOX_TRANSFORM, "BOX_TRANSFORM", 0, "Box Transform", ""},
1438 {ED_GIZMO_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
1439 {0, nullptr, 0, nullptr, nullptr},
1440 };
1441 static const EnumPropertyItem rna_enum_transform[] = {
1442 {ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Move", ""},
1443 {ED_GIZMO_CAGE_XFORM_FLAG_ROTATE, "ROTATE", 0, "Rotate", ""},
1444 {ED_GIZMO_CAGE_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
1445 {ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
1446 {0, nullptr, 0, nullptr, nullptr},
1447 };
1448 static const EnumPropertyItem rna_enum_draw_options[] = {
1449 {ED_GIZMO_CAGE_DRAW_FLAG_XFORM_CENTER_HANDLE, "XFORM_CENTER_HANDLE", 0, "Center Handle", ""},
1450 {ED_GIZMO_CAGE_DRAW_FLAG_CORNER_HANDLES, "CORNER_HANDLES", 0, "Corner Handles", ""},
1451 {0, nullptr, 0, nullptr, nullptr},
1452 };
1453 static const float unit_v2[2] = {1.0f, 1.0f};
1454 static const float zero_v2[2] = {0.0f, 0.0f};
1456 gzt->srna, "dimensions", 2, unit_v2, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
1458 gzt->srna, "pivot", 2, zero_v2, FLT_MIN, FLT_MAX, "Pivot", "", FLT_MIN, FLT_MAX);
1459 RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
1460 RNA_def_enum(gzt->srna,
1461 "draw_style",
1462 rna_enum_draw_style,
1464 "Draw Style",
1465 "");
1467 "draw_options",
1468 rna_enum_draw_options,
1470 "Draw Options",
1471 "");
1472
1473 WM_gizmotype_target_property_def(gzt, "matrix", PROP_FLOAT, 16);
1474}
1475
1480
1482
1483} // namespace blender
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UNPACK2(a)
#define ARRAY_SET_ITEMS(...)
#define ELEM(...)
#define STREQ(a, b)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define GIZMO_MARGIN_OFFSET_SCALE
#define CIRCLE_RESOL
#define MUL_V2_V3_M4_FINAL(test_co, mouse_co)
#define rot(x, k)
#define FLT_MAX
#define FLT_MIN
#define FLT_EPSILON
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
static void gizmo_calc_rect_view_margin(const wmGizmo *gz, float margin[2])
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void cage2d_draw_rect_rotate_handle(const rctf *r, const float margin[2], const float color[3], bool solid)
MINLINE bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
int RNA_enum_get(PointerRNA *ptr, const char *name)
void immAttr3f(uint attr_id, float x, float y, float z)
void immEnd()
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
bool GPU_select_load_id(unsigned int id)
void imm_draw_circle_wire_aspect_3d(uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
void WM_gizmotype_append(void(*gtfunc)(wmGizmoType *))
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
static void cage2d_draw_box_interaction(const float color[4], const int highlighted, const float size[2], const float margin[2], const float line_width, const bool is_solid, const int draw_options)
static void gizmo_constrain_from_scale_part(int part, bool r_constrain_axis[2])
static int gizmo_cage2d_get_cursor(wmGizmo *gz)
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
void WM_gizmo_target_property_anim_autokey(bContext *C, const wmGizmo *, wmGizmoProperty *gz_prop)
void ED_gizmotypes_cage_2d()
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void immBegin(GPUPrimType, uint vertex_len)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void WM_gizmo_calc_matrix_final_no_offset(const wmGizmo *gz, float r_mat[4][4])
Definition wm_gizmo.cc:556
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
@ GPU_PRIM_LINE_STRIP
static int gizmo_cage2d_test_select(bContext *C, wmGizmo *gz, const int mval[2])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void WM_gizmo_calc_matrix_final(const wmGizmo *gz, float r_mat[4][4])
Definition wm_gizmo.cc:569
void mul_m3_v2(const float m[3][3], float r[2])
static void cage2d_draw_circle_wire(const float color[3], const float size[2], const float margin[2], const int transform_flag, const int draw_options, const float line_width)
void WM_gizmotype_target_property_def(wmGizmoType *gzt, const char *idname, int data_type, int array_length)
void BLI_rctf_sanitize(struct rctf *rect)
Definition rct.cc:448
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE
@ ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE_SIGNED
@ ED_GIZMO_CAGE_XFORM_FLAG_ROTATE
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:745
static void imm_draw_point_aspect_2d(uint pos, float x, float y, float rad_x, float rad_y, bool solid)
void immUnbindProgram()
void GPU_matrix_mul(const float m[4][4])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void mul_v2_v2(float r[2], const float a[2])
static void gizmo_cage2d_setup(wmGizmo *gz)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ ED_GIZMO_CAGE2D_STYLE_CIRCLE
@ ED_GIZMO_CAGE2D_STYLE_BOX_TRANSFORM
@ ED_GIZMO_CAGE2D_STYLE_BOX
static wmOperatorStatus gizmo_cage2d_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
static void cage2d_draw_rect_corner_handles(const rctf *r, const float margin[2], const float color[3], bool solid)
void immAttr3fv(uint attr_id, const float data[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
bool BLI_rctf_is_valid(const struct rctf *rect)
void WM_gizmo_target_property_float_set_array(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float *value)
static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
static void gizmo_calc_rect_view_scale(const wmGizmo *gz, float scale[2])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
MINLINE void add_v2_v2(float r[2], const float a[2])
eWM_GizmoFlagTweak
Gizmo tweak flag. Bit-flag passed to gizmo while tweaking.
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
MINLINE int signum_i(float a)
BMesh const char void * data
static void GIZMO_GT_cage_2d(wmGizmoType *gzt)
MINLINE float signf(float f)
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_POINT_FLAT_COLOR
static void cage2d_draw_rect_wire(const rctf *r, const float margin[2], const float color[3], const int transform_flag, const int draw_options, const float line_width)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
static bool is_corner_highlighted(const int highlighted)
void immUniformColor4f(float r, float g, float b, float a)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
void unit_m4(float m[4][4])
static void gizmo_cage2d_draw_intern(wmGizmo *gz, const bool select, const bool highlight, const int select_id)
void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void gizmo_color_get(const wmGizmo *gz, bool highlight, float r_color[4])
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
bool invert_m3(float mat[3][3])
@ WM_GIZMO_DRAW_NO_SCALE
@ WM_GIZMO_DRAW_MODAL
void imm_draw_circle_wire_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
@ WM_CURSOR_CROSS
Definition wm_cursors.hh:28
void rotate_m4(float mat[4][4], char axis, float angle)
@ WM_GIZMO_STATE_HIGHLIGHT
void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void BLI_dial_free(Dial *dial)
static void gizmo_cage2d_draw_select(const bContext *, wmGizmo *gz, int select_id)
bool gizmo_window_project_2d(bContext *C, const wmGizmo *gz, const float mval[2], int axis, bool use_offset, float r_co[2])
void mul_m4_m4_post(float R[4][4], const float B[4][4])
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
Dial * BLI_dial_init(const float start_position[2], float threshold)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void cage2d_draw_box_corners(const rctf *r, const float margin[2], const float color[3], const float line_width)
static int gizmo_cage2d_transform_flag_get(const wmGizmo *gz)
void immUniform2fv(const char *name, const float data[2])
@ ED_GIZMO_CAGE_DRAW_FLAG_XFORM_CENTER_HANDLE
@ ED_GIZMO_CAGE_DRAW_FLAG_CORNER_HANDLES
static void cage2d_draw_rect_edge_handles(const rctf *r, const int highlighted, const float size[2], const float margin[2], const float color[3], bool solid)
MINLINE void sub_v2_v2(float r[2], const float a[2])
void immUniformColor3fv(const float rgb[3])
void immVertex3f(uint attr_id, float x, float y, float z)
float BLI_dial_angle(Dial *dial, const float current_position[2])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void copy_m4_m4(float m1[4][4], const float m2[4][4])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
VecBase< float, 3 > float3
void immVertex2fv(uint attr_id, const float data[2])
void GPU_matrix_pop()
MINLINE float safe_divide(float a, float b)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
MINLINE void zero_v2(float r[2])
ARegion * CTX_wm_region(const bContext *C)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
static wmOperatorStatus gizmo_cage2d_modal(bContext *C, wmGizmo *gz, const wmEvent *event, eWM_GizmoFlagTweak)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
static void gizmo_cage2d_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
void GPU_matrix_push()
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
static void gizmo_cage2d_draw(const bContext *, wmGizmo *gz)
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X
@ ED_GIZMO_CAGE2D_PART_ROTATE
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y
@ ED_GIZMO_CAGE2D_PART_TRANSLATE
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y
@ ED_GIZMO_CAGE2D_PART_SCALE
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y
static void gizmo_pivot_from_scale_part(int part, float r_pt[2])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
wmEventType type
Definition WM_types.hh:817
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupType * type
const wmGizmoPropertyType * type
wmGizmoFnInvoke invoke
wmGizmoFnDrawSelect draw_select
wmGizmoFnCursorGet cursor_get
wmGizmoFnPropertyUpdate property_update
wmGizmoFnTestSelect test_select
float matrix_space[4][4]
float matrix_offset[4][4]
wmGizmoGroup * parent_gzgroup
eWM_GizmoFlag flag
eWM_GizmoFlagState state