Blender V5.3
view2d_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_userdef_types.h"
15
16#include "BLI_math_base_c.hh"
17#include "BLI_math_vector_c.hh"
18#include "BLI_time.hh" /* USER_ZOOM_CONTINUE */
19#include "BLI_utildefines.hh"
20
21#include "BKE_context.hh"
22
23#include "RNA_access.hh"
24#include "RNA_define.hh"
25
26#include "WM_api.hh"
27#include "WM_types.hh"
28
29#include "ED_screen.hh"
30
31#include "UI_interface.hh"
32#include "UI_view2d.hh"
33
34#include "view2d_intern.hh"
35
36namespace blender::ui {
37
38/* -------------------------------------------------------------------- */
41
42static bool view2d_poll(bContext *C)
43{
44 ARegion *region = CTX_wm_region(C);
45
46 return (region != nullptr) && (region->v2d.flag & V2D_IS_INIT);
47}
48
54static float view2d_scroll_delta_y_snap_page_size(const View2D &v2d, const float delta_y)
55{
56 const float page_size = view2d_page_size_y(v2d);
57 const int delta_pages = int(delta_y / (page_size * 0.5f));
58
59 /* Apply no change, don't update last coordinates. */
60 if (abs(delta_pages) < 1) {
61 return 0.0f;
62 }
63
64 /* Snap the delta to a multiple of a page size. */
65 return delta_pages * page_size;
66}
67
69
70/* -------------------------------------------------------------------- */
73
82
95
97 float facx, facy;
98
99 /* options for version 1 */
106
110
113
114 /* View2D Edge Panning */
117};
118
120{
121 ARegion *region = CTX_wm_region(C);
122
123 /* check if there's a region in context to work with */
124 if (region == nullptr) {
125 return false;
126 }
127
128 View2D *v2d = &region->v2d;
129
130 /* check that 2d-view can pan */
131 if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y)) {
132 return false;
133 }
134
135 /* view can pan */
136 return true;
137}
138
139/* initialize panning customdata */
141{
142 /* Should've been checked before. */
144
145 /* set custom-data for operator */
147 op->customdata = vpd;
148
149 /* set pointers to owners */
150 vpd->screen = CTX_wm_screen(C);
151 vpd->area = CTX_wm_area(C);
152 vpd->region = CTX_wm_region(C);
153 vpd->v2d = &vpd->region->v2d;
154
155 /* calculate translation factor - based on size of view */
156 const float winx = float(BLI_rcti_size_x(&vpd->region->winrct) + 1);
157 const float winy = float(BLI_rcti_size_y(&vpd->region->winrct) + 1);
158 vpd->facx = BLI_rctf_size_x(&vpd->v2d->cur) / winx;
159 vpd->facy = BLI_rctf_size_y(&vpd->v2d->cur) / winy;
160
161 vpd->v2d->flag |= V2D_IS_NAVIGATING;
162
163 vpd->do_category_scroll = false;
164}
165
166/* apply transform to view (i.e. adjust 'cur' rect) */
167static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float dy)
168{
169 View2D *v2d = vpd->v2d;
170
171 /* calculate amount to move view by */
172 dx *= vpd->facx;
173 dy *= vpd->facy;
174
175 if (!vpd->do_category_scroll) {
176 /* only move view on an axis if change is allowed */
177 if ((v2d->keepofs & V2D_LOCKOFS_X) == 0) {
178 v2d->cur.xmin += dx;
179 v2d->cur.xmax += dx;
180 }
181 if ((v2d->keepofs & V2D_LOCKOFS_Y) == 0) {
182 v2d->cur.ymin += dy;
183 v2d->cur.ymax += dy;
184 }
185 }
186 else {
187 vpd->region->category_scroll -= dy;
188 }
189
190 /* Inform v2d about changes after this operation. */
192
193 /* don't rebuild full tree in outliner, since we're just changing our view */
195
196 /* request updates to be done... */
198
199 view2d_sync(vpd->screen, vpd->area, v2d, V2D_LOCK_COPY);
200}
201
203{
204 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
205
206 view_pan_apply_ex(C, vpd, RNA_int_get(op->ptr, "deltax"), RNA_int_get(op->ptr, "deltay"));
207}
208
209/* Cleanup temp custom-data. */
210static void view_pan_exit(wmOperator *op)
211{
212 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
213 vpd->v2d->flag &= ~V2D_IS_NAVIGATING;
214 MEM_delete(vpd);
215 op->customdata = nullptr;
216}
217
219
220/* -------------------------------------------------------------------- */
223
224/* for 'redo' only, with no user input */
226{
227 view_pan_init(C, op);
228 view_pan_apply(C, op);
229 view_pan_exit(op);
230 return OPERATOR_FINISHED;
231}
232
233/* set up modal operator and relevant settings */
235{
236 wmWindow *window = CTX_wm_window(C);
237
238 /* set up customdata */
239 view_pan_init(C, op);
240
241 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
242 View2D *v2d = vpd->v2d;
243
244 /* set initial settings */
245 vpd->startx = vpd->lastx = event->xy[0];
246 vpd->starty = vpd->lasty = event->xy[1];
247 vpd->invoke_event = event->type;
248
250
251 if (event->type == MOUSEPAN) {
252 RNA_int_set(op->ptr, "deltax", event->prev_xy[0] - event->xy[0]);
253 RNA_int_set(op->ptr, "deltay", event->prev_xy[1] - event->xy[1]);
254
255 view_pan_apply(C, op);
256 view_pan_exit(op);
257 return OPERATOR_FINISHED;
258 }
259
260 RNA_int_set(op->ptr, "deltax", 0);
261 RNA_int_set(op->ptr, "deltay", 0);
262
263 if (WM_cursor_modal_is_set_ok(window)) {
264 if (v2d->keepofs & V2D_LOCKOFS_X) {
266 }
267 else if (v2d->keepofs & V2D_LOCKOFS_Y) {
269 }
270 else {
272 }
273 vpd->own_cursor = true;
274 }
275
276 /* add temp handler */
278
280}
281
282/* handle user input - calculations of mouse-movement
283 * need to be done here, not in the apply callback! */
285{
286 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
287 View2D *v2d = vpd->v2d;
288
289 /* execute the events */
290 switch (event->type) {
291 case MOUSEMOVE: {
292 /* calculate new delta transform, then store mouse-coordinates for next-time */
293 int deltax = vpd->lastx - event->xy[0];
294 int deltay = vpd->lasty - event->xy[1];
295
296 /* Page snapping: When panning for more than half a page size, snap to the next page. */
297 if (v2d->flag & V2D_SNAP_TO_PAGESIZE_Y) {
298 deltay = view2d_scroll_delta_y_snap_page_size(*v2d, deltay);
299 }
300
301 if (deltax != 0) {
302 vpd->lastx = event->xy[0];
303 }
304 if (deltay != 0) {
305 vpd->lasty = event->xy[1];
306 }
307
308 if (deltax || deltay) {
309 RNA_int_set(op->ptr, "deltax", deltax);
310 RNA_int_set(op->ptr, "deltay", deltay);
311 view_pan_apply(C, op);
312 }
313 break;
314 }
315 /* XXX: Mode switching isn't implemented. See comments in 36818.
316 * switch to zoom */
317#if 0
318 case LEFTMOUSE:
319 if (event->val == KM_PRESS) {
320 /* calculate overall delta mouse-movement for redo */
321 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
322 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
323
324 const bool own_cursor = vpd->own_cursor;
325 view_pan_exit(op);
326 if (own_cursor) {
328 }
330 C, "VIEW2D_OT_zoom", wm::OpCallContext::InvokeDefault, nullptr, event);
331 return OPERATOR_FINISHED;
332 }
333#endif
334 default:
335 if (ELEM(event->type, vpd->invoke_event, EVT_ESCKEY)) {
336 if (event->val == KM_RELEASE) {
337 /* calculate overall delta mouse-movement for redo */
338 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
339 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
340
341 const bool own_cursor = vpd->own_cursor;
342 view_pan_exit(op);
343 if (own_cursor) {
345 }
346 return OPERATOR_FINISHED;
347 }
348 }
349 break;
350 }
351
353}
354
355static void view_pan_cancel(bContext * /*C*/, wmOperator *op)
356{
357 view_pan_exit(op);
358}
359
361{
362 /* identifiers */
363 ot->name = "Pan View";
364 ot->description = "Pan the view";
365 ot->idname = "VIEW2D_OT_pan";
366
367 /* API callbacks. */
368 ot->exec = view_pan_exec;
370 ot->modal = view_pan_modal;
372 ot->poll = view_pan_poll;
373
374 /* operator is modal */
376
377 /* rna - must keep these in sync with the other operators */
378 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
379 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
380}
381
383
384/* -------------------------------------------------------------------- */
390
391/* set up modal operator and relevant settings */
393 wmOperator *op,
394 const wmEvent * /*event*/)
395{
396 op->customdata = MEM_new_zeroed<View2DEdgePanData>("View2DEdgePanData");
397 View2DEdgePanData *vpd = static_cast<View2DEdgePanData *>(op->customdata);
399
401
403}
404
406{
407 View2DEdgePanData *vpd = static_cast<View2DEdgePanData *>(op->customdata);
408
409 wmWindow *source_win = CTX_wm_window(C);
410 int event_xy_target[2];
411 wmWindow *target_win = WM_window_find_under_cursor(source_win, event->xy, &event_xy_target[0]);
412
413 /* Exit if we release the mouse button, hit escape, or enter a different window. */
414 if (event->val == KM_RELEASE || event->type == EVT_ESCKEY || source_win != target_win) {
415 vpd->v2d->flag &= ~V2D_IS_NAVIGATING;
416 MEM_SAFE_DELETE(vpd);
417 op->customdata = nullptr;
419 }
420
421 view2d_edge_pan_apply_event(C, vpd, event);
422
423 /* This operator is supposed to run together with some drag action.
424 * On successful handling, always pass events on to other handlers. */
426}
427
428static void view_edge_pan_cancel(bContext * /*C*/, wmOperator *op)
429{
430 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
431 vpd->v2d->flag &= ~V2D_IS_NAVIGATING;
432 MEM_SAFE_DELETE(vpd);
433 op->customdata = nullptr;
434}
435
437{
438 /* identifiers */
439 ot->name = "View Edge Pan";
440 ot->description = "Pan the view when the mouse is held at an edge";
441 ot->idname = "VIEW2D_OT_edge_pan";
442
443 /* API callbacks. */
448
449 /* operator is modal */
450 ot->flag = OPTYPE_INTERNAL;
452}
453
455
456/* -------------------------------------------------------------------- */
459
460/* this operator only needs this single callback, where it calls the view_pan_*() methods */
462{
463 /* initialize default settings (and validate if ok to run) */
464 view_pan_init(C, op);
465
466 /* also, check if can pan in horizontal axis */
467 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
468 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
469 view_pan_exit(op);
471 }
472
473 /* set RNA-Props - only movement in positive x-direction */
474 RNA_int_set(op->ptr, "deltax", 40 * UI_SCALE_FAC);
475 RNA_int_set(op->ptr, "deltay", 0);
476
477 /* apply movement, then we're done */
478 view_pan_apply(C, op);
479 view_pan_exit(op);
480
481 return OPERATOR_FINISHED;
482}
483
485{
486 /* identifiers */
487 ot->name = "Scroll Right";
488 ot->description = "Scroll the view right";
489 ot->idname = "VIEW2D_OT_scroll_right";
490
491 /* API callbacks. */
493 ot->poll = view_pan_poll;
494
495 /* rna - must keep these in sync with the other operators */
496 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
497 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
498}
499
500/* this operator only needs this single callback, where it calls the view_pan_*() methods */
502{
503 /* initialize default settings (and validate if ok to run) */
504 view_pan_init(C, op);
505
506 /* also, check if can pan in horizontal axis */
507 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
508 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
509 view_pan_exit(op);
511 }
512
513 /* set RNA-Props - only movement in negative x-direction */
514 RNA_int_set(op->ptr, "deltax", -40 * UI_SCALE_FAC);
515 RNA_int_set(op->ptr, "deltay", 0);
516
517 /* apply movement, then we're done */
518 view_pan_apply(C, op);
519 view_pan_exit(op);
520
521 return OPERATOR_FINISHED;
522}
523
525{
526 /* identifiers */
527 ot->name = "Scroll Left";
528 ot->description = "Scroll the view left";
529 ot->idname = "VIEW2D_OT_scroll_left";
530
531 /* API callbacks. */
533 ot->poll = view_pan_poll;
534
535 /* rna - must keep these in sync with the other operators */
536 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
537 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
538}
539
540/* this operator only needs this single callback, where it calls the view_pan_*() methods */
542{
543 /* initialize default settings (and validate if ok to run) */
544 view_pan_init(C, op);
545
546 /* also, check if can pan in vertical axis */
547 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
548 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
549 view_pan_exit(op);
551 }
552
553 const wmWindow *win = CTX_wm_window(C);
555 win->runtime->eventstate->xy);
556
557 /* set RNA-Props */
558 RNA_int_set(op->ptr, "deltax", 0);
559 RNA_int_set(op->ptr, "deltay", -40 * UI_SCALE_FAC);
560
561 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page");
562 const bool use_page_size = (vpd->v2d->flag & V2D_SNAP_TO_PAGESIZE_Y) ||
563 (RNA_property_is_set(op->ptr, prop) &&
564 RNA_property_boolean_get(op->ptr, prop));
565 if (use_page_size) {
566 const ARegion *region = CTX_wm_region(C);
567 const int page_size = view2d_page_size_y(region->v2d);
568 RNA_int_set(op->ptr, "deltay", -page_size);
569 }
570
571 /* apply movement, then we're done */
572 view_pan_apply(C, op);
573 view_pan_exit(op);
574
575 return OPERATOR_FINISHED;
576}
577
579{
580 /* identifiers */
581 ot->name = "Scroll Down";
582 ot->description = "Scroll the view down";
583 ot->idname = "VIEW2D_OT_scroll_down";
584
585 /* API callbacks. */
587 ot->poll = view_pan_poll;
588
589 /* rna - must keep these in sync with the other operators */
590 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
591 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
592 RNA_def_boolean(ot->srna, "page", false, "Page", "Scroll down one page");
593}
594
595/* this operator only needs this single callback, where it calls the view_pan_*() methods */
597{
598 /* initialize default settings (and validate if ok to run) */
599 view_pan_init(C, op);
600
601 /* also, check if can pan in vertical axis */
602 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
603 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
604 view_pan_exit(op);
606 }
607
608 const wmWindow *win = CTX_wm_window(C);
610 win->runtime->eventstate->xy);
611
612 /* set RNA-Props */
613 RNA_int_set(op->ptr, "deltax", 0);
614 RNA_int_set(op->ptr, "deltay", 40 * UI_SCALE_FAC);
615
616 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page");
617 const bool use_page_size = (vpd->v2d->flag & V2D_SNAP_TO_PAGESIZE_Y) ||
618 (RNA_property_is_set(op->ptr, prop) &&
619 RNA_property_boolean_get(op->ptr, prop));
620 if (use_page_size) {
621 const ARegion *region = CTX_wm_region(C);
622 const int page_size = view2d_page_size_y(region->v2d);
623 RNA_int_set(op->ptr, "deltay", page_size);
624 }
625
626 /* apply movement, then we're done */
627 view_pan_apply(C, op);
628 view_pan_exit(op);
629
630 return OPERATOR_FINISHED;
631}
632
634{
635 /* identifiers */
636 ot->name = "Scroll Up";
637 ot->description = "Scroll the view up";
638 ot->idname = "VIEW2D_OT_scroll_up";
639
640 /* API callbacks. */
642 ot->poll = view_pan_poll;
643
644 /* rna - must keep these in sync with the other operators */
645 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
646 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
647 RNA_def_boolean(ot->srna, "page", false, "Page", "Scroll up one page");
648}
649
651
652/* -------------------------------------------------------------------- */
655
669
674 View2D *v2d; /* view2d we're operating in */
676
677 /* needed for continuous zoom */
680
681 int lastx, lasty; /* previous x/y values of mouse in window */
682 int invoke_event; /* event type that invoked, for modal exits */
683 float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
684 float mx_2d, my_2d; /* initial mouse location in v2d coords */
687};
688
693static void view_zoom_axis_lock_defaults(bContext *C, bool r_do_zoom_xy[2])
694{
695 ScrArea *area = CTX_wm_area(C);
696
697 r_do_zoom_xy[0] = true;
698 r_do_zoom_xy[1] = true;
699
700 /* default not to zoom the sequencer vertically */
701 if (area && area->spacetype == SPACE_SEQ) {
702 ARegion *region = CTX_wm_region(C);
703
704 if (region && region->regiontype == RGN_TYPE_WINDOW) {
705 r_do_zoom_xy[1] = false;
706 }
707 }
708}
709
710/* check if step-zoom can be applied */
712{
713 ARegion *region = CTX_wm_region(C);
714
715 /* check if there's a region in context to work with */
716 if (region == nullptr) {
717 return false;
718 }
719
720 /* Do not show that in 3DView context. */
721 if (CTX_wm_region_view3d(C)) {
722 return false;
723 }
724
725 View2D *v2d = &region->v2d;
726
727 /* check that 2d-view is zoomable */
728 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y)) {
729 return false;
730 }
731
732 /* view is zoomable */
733 return true;
734}
735
736/* initialize panning customdata */
738{
739 /* Should've been checked before. */
741
742 /* set custom-data for operator */
744 op->customdata = vzd;
745
746 /* set pointers to owners */
747 vzd->region = CTX_wm_region(C);
748 vzd->v2d = &vzd->region->v2d;
749 /* False by default. Interactive callbacks (ie invoke()) can set it to true. */
750 vzd->zoom_to_mouse_pos = false;
751
752 vzd->v2d->flag |= V2D_IS_NAVIGATING;
753}
754
755/* apply transform to view (i.e. adjust 'cur' rect) */
757 v2dViewZoomData *vzd,
758 const float facx,
759 const float facy)
760{
761 ARegion *region = CTX_wm_region(C);
762 View2D *v2d = &region->v2d;
763 const rctf cur_old = v2d->cur;
764 const int snap_test = ED_region_snap_size_test(region);
765 const bool do_keepofs = !(v2d->flag & V2D_ZOOM_IGNORE_KEEPOFS);
766
767 /* calculate amount to move view by, ensuring symmetry so the
768 * old zoom level is restored after zooming back the same amount
769 */
770 float dx, dy;
771 if (facx >= 0.0f) {
772 dx = BLI_rctf_size_x(&v2d->cur) * facx;
773 dy = BLI_rctf_size_y(&v2d->cur) * facy;
774 }
775 else {
776 dx = (BLI_rctf_size_x(&v2d->cur) / (1.0f + 2.0f * facx)) * facx;
777 dy = (BLI_rctf_size_y(&v2d->cur) / (1.0f + 2.0f * facy)) * facy;
778 }
779
780 /* Only resize view on an axis if change is allowed. */
781 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
782 if ((v2d->keepofs & V2D_LOCKOFS_X) && do_keepofs) {
783 v2d->cur.xmax -= 2 * dx;
784 }
785 else if ((v2d->keepofs & V2D_KEEPOFS_X) && do_keepofs) {
786 if (v2d->align & V2D_ALIGN_NO_POS_X) {
787 v2d->cur.xmin += 2 * dx;
788 }
789 else {
790 v2d->cur.xmax -= 2 * dx;
791 }
792 }
793 else {
794
795 v2d->cur.xmin += dx;
796 v2d->cur.xmax -= dx;
797
798 if (vzd->zoom_to_mouse_pos) {
799 /* get zoom fac the same way as in
800 * ui_view2d_curRect_validate_resize - better keep in sync! */
801 const float zoomx = float(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur);
802
803 /* only move view to mouse if zoom fac is inside minzoom/maxzoom */
804 if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) ||
805 IN_RANGE_INCL(zoomx, v2d->minzoom, v2d->maxzoom))
806 {
807 const float mval_fac = (vzd->mx_2d - cur_old.xmin) / BLI_rctf_size_x(&cur_old);
808 const float mval_faci = 1.0f - mval_fac;
809 const float ofs = (mval_fac * dx) - (mval_faci * dx);
810
811 v2d->cur.xmin += ofs;
812 v2d->cur.xmax += ofs;
813 }
814 }
815 }
816 }
817 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
818 if ((v2d->keepofs & V2D_LOCKOFS_Y) && do_keepofs) {
819 v2d->cur.ymax -= 2 * dy;
820 }
821 else if ((v2d->keepofs & V2D_KEEPOFS_Y) && do_keepofs) {
822 if (v2d->align & V2D_ALIGN_NO_POS_Y) {
823 v2d->cur.ymin += 2 * dy;
824 }
825 else {
826 v2d->cur.ymax -= 2 * dy;
827 }
828 }
829 else {
830
831 v2d->cur.ymin += dy;
832 v2d->cur.ymax -= dy;
833
834 if (vzd->zoom_to_mouse_pos) {
835 /* get zoom fac the same way as in
836 * ui_view2d_curRect_validate_resize - better keep in sync! */
837 const float zoomy = float(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur);
838
839 /* only move view to mouse if zoom fac is inside minzoom/maxzoom */
840 if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) ||
841 IN_RANGE_INCL(zoomy, v2d->minzoom, v2d->maxzoom))
842 {
843 const float mval_fac = (vzd->my_2d - cur_old.ymin) / BLI_rctf_size_y(&cur_old);
844 const float mval_faci = 1.0f - mval_fac;
845 const float ofs = (mval_fac * dy) - (mval_faci * dy);
846
847 v2d->cur.ymin += ofs;
848 v2d->cur.ymax += ofs;
849 }
850 }
851 }
852 }
853
854 /* Inform v2d about changes after this operation. */
856
857 if (ED_region_snap_size_apply(region, snap_test)) {
858 ScrArea *area = CTX_wm_area(C);
859 ED_area_tag_redraw(area);
861 }
862
863 /* request updates to be done... */
866}
867
869{
870 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
872 C, vzd, RNA_float_get(op->ptr, "zoomfacx"), RNA_float_get(op->ptr, "zoomfacy"));
873}
874
876
877/* -------------------------------------------------------------------- */
880
884static constexpr float view_zoomfac_default = 0.0375f;
885
886static void view_zoomstep_props_init(bContext *C, wmOperator *op, const float zoomfac_default)
887{
888 bool do_zoom_xy[2];
889 view_zoom_axis_lock_defaults(C, do_zoom_xy);
890
891 /* Set RNA-Props - zooming in by uniform factor. */
892 const char *props_zoomfac[2] = {"zoomfacx", "zoomfacy"};
893 for (int i = 0; i < 2; i++) {
894 PropertyRNA *prop = RNA_struct_find_property(op->ptr, props_zoomfac[i]);
895 /* If we can zoom on this value *and* the value is set (likely by the key-map),
896 * then respect the value the user set. */
897 if (do_zoom_xy[i] && RNA_property_is_set(op->ptr, prop)) {
898 continue;
899 }
900 RNA_property_float_set(op->ptr, prop, do_zoom_xy[i] ? zoomfac_default : 0.0f);
901 }
902}
903
904static void view_zoomstep_props_def(StructRNA *srna, const float zoomfac_default)
905{
906 const char *props_id[2] = {"zoomfacx", "zoomfacy"};
907 const char *props_name[2] = {"Zoom Factor X", "Zoom Factor Y"};
908 for (int i = 0; i < 2; i++) {
909 PropertyRNA *prop = RNA_def_float(srna,
910 props_id[i],
911 zoomfac_default,
912 -FLT_MAX,
913 FLT_MAX,
914 props_name[i],
915 "",
916 -FLT_MAX,
917 FLT_MAX);
919 }
920}
921
922/* Cleanup temp custom-data. */
924{
925 ScrArea *area = CTX_wm_area(C);
926 /* Some areas change font sizes when zooming, so clear glyph cache. */
927 if (area && !ELEM(area->spacetype, SPACE_GRAPH, SPACE_ACTION)) {
929 }
930
931 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
932 vzd->v2d->flag &= ~V2D_IS_NAVIGATING;
933 MEM_SAFE_DELETE(vzd);
934 op->customdata = nullptr;
935}
936
937/* this operator only needs this single callback, where it calls the view_zoom_*() methods */
939{
940 if (op->customdata == nullptr) { /* Might have been setup in _invoke() already. */
942 }
943
944 /* Apply movement, then we're done. */
947
949
950 return OPERATOR_FINISHED;
951}
952
954{
956
957 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
958
959 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
960 ARegion *region = CTX_wm_region(C);
961
962 /* store initial mouse position (in view space) */
963 view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d);
964 vzd->zoom_to_mouse_pos = true;
965 }
966
967 return view_zoomin_exec(C, op);
968}
969
971{
972 /* identifiers */
973 ot->name = "Zoom In";
974 ot->description = "Zoom in the view";
975 ot->idname = "VIEW2D_OT_zoom_in";
976
977 /* API callbacks. */
980 ot->poll = view_zoom_poll;
981
983}
984
985/* this operator only needs this single callback, where it calls the view_zoom_*() methods */
987{
988 if (op->customdata == nullptr) { /* Might have been setup in _invoke() already. */
990 }
991
992 /* Apply movement, then we're done. */
995
997
998 return OPERATOR_FINISHED;
999}
1000
1002{
1003 view_zoomdrag_init(C, op);
1004
1005 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1006
1007 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
1008 ARegion *region = CTX_wm_region(C);
1009
1010 /* store initial mouse position (in view space) */
1011 view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d);
1012 vzd->zoom_to_mouse_pos = true;
1013 }
1014
1015 return view_zoomout_exec(C, op);
1016}
1017
1019{
1020 /* identifiers */
1021 ot->name = "Zoom Out";
1022 ot->description = "Zoom out the view";
1023 ot->idname = "VIEW2D_OT_zoom_out";
1024
1025 /* API callbacks. */
1027 ot->exec = view_zoomout_exec;
1028
1029 ot->poll = view_zoom_poll;
1030
1032}
1033
1035
1036/* -------------------------------------------------------------------- */
1039
1046
1047/* apply transform to view (i.e. adjust 'cur' rect) */
1049{
1050 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1051 View2D *v2d = vzd->v2d;
1052 const int snap_test = ED_region_snap_size_test(vzd->region);
1053
1054 const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
1055 const bool zoom_to_pos = use_cursor_init && vzd->zoom_to_mouse_pos;
1056
1057 /* get amount to move view by */
1058 float dx = RNA_float_get(op->ptr, "deltax") / UI_SCALE_FAC;
1059 float dy = RNA_float_get(op->ptr, "deltay") / UI_SCALE_FAC;
1060
1061 /* Check if the 'timer' is initialized, as zooming with the trackpad
1062 * never uses the "Continuous" zoom method, and the 'timer' is not initialized. */
1063 if ((U.viewzoom == USER_ZOOM_CONTINUE) && vzd->timer) { /* XXX store this setting as RNA prop? */
1064 const double time = BLI_time_now_seconds();
1065 const float time_step = float(time - vzd->timer_lastdraw);
1066
1067 dx *= time_step * 5.0f;
1068 dy *= time_step * 5.0f;
1069
1070 vzd->timer_lastdraw = time;
1071 }
1072
1073 /* only move view on an axis if change is allowed */
1074 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1075 if (v2d->keepofs & V2D_LOCKOFS_X) {
1076 v2d->cur.xmax -= 2 * dx;
1077 }
1078 else {
1079 if (zoom_to_pos) {
1080 const float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
1081 const float mval_faci = 1.0f - mval_fac;
1082 const float ofs = (mval_fac * dx) - (mval_faci * dx);
1083
1084 v2d->cur.xmin += ofs + dx;
1085 v2d->cur.xmax += ofs - dx;
1086 }
1087 else {
1088 v2d->cur.xmin += dx;
1089 v2d->cur.xmax -= dx;
1090 }
1091 }
1092 }
1093 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1094 if (v2d->keepofs & V2D_LOCKOFS_Y) {
1095 v2d->cur.ymax -= 2 * dy;
1096 }
1097 else {
1098 if (zoom_to_pos) {
1099 const float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
1100 const float mval_faci = 1.0f - mval_fac;
1101 const float ofs = (mval_fac * dy) - (mval_faci * dy);
1102
1103 v2d->cur.ymin += ofs + dy;
1104 v2d->cur.ymax += ofs - dy;
1105 }
1106 else {
1107 v2d->cur.ymin += dy;
1108 v2d->cur.ymax -= dy;
1109 }
1110 }
1111 }
1112
1113 /* Inform v2d about changes after this operation. */
1115
1116 if (ED_region_snap_size_apply(vzd->region, snap_test)) {
1117 ScrArea *area = CTX_wm_area(C);
1118 ED_area_tag_redraw(area);
1120 }
1121
1122 /* request updates to be done... */
1125}
1126
1127/* Cleanup temp custom-data. */
1129{
1131
1132 if (op->customdata) {
1133 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1134 vzd->v2d->flag &= ~V2D_IS_NAVIGATING;
1135
1136 if (vzd->timer) {
1138 }
1139
1140 MEM_delete(vzd);
1141 op->customdata = nullptr;
1142 }
1143}
1144
1146{
1147 view_zoomdrag_exit(C, op);
1148}
1149
1150/* for 'redo' only, with no user input */
1158
1159/* set up modal operator and relevant settings */
1161{
1162 wmWindow *window = CTX_wm_window(C);
1163
1164 /* set up customdata */
1165 view_zoomdrag_init(C, op);
1166
1167 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1168 View2D *v2d = vzd->v2d;
1169
1170 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
1171 ARegion *region = CTX_wm_region(C);
1172
1173 /* Store initial mouse position (in view space). */
1174 view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d);
1175 vzd->zoom_to_mouse_pos = true;
1176 }
1177
1178 if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) {
1179 vzd->lastx = event->prev_xy[0];
1180 vzd->lasty = event->prev_xy[1];
1181
1182 float facx, facy;
1183 float zoomfac = 0.01f;
1184
1185 /* Some view2d's (graph) don't have min/max zoom, or extreme ones. */
1186 if (v2d->maxzoom > 0.0f) {
1187 zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f);
1188 }
1189
1190 if (event->type == MOUSEPAN) {
1191 facx = zoomfac * WM_event_absolute_delta_x(event);
1192 facy = zoomfac * WM_event_absolute_delta_y(event);
1193
1194 if (U.uiflag & USER_ZOOM_INVERT) {
1195 facx *= -1.0f;
1196 facy *= -1.0f;
1197 }
1198 }
1199 else { /* MOUSEZOOM */
1200 facx = facy = zoomfac * WM_event_absolute_delta_x(event);
1201 }
1202
1203 /* Only respect user setting zoom axis if the view does not have any zoom restrictions
1204 * any will be scaled uniformly. */
1205 if (((v2d->keepzoom & (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y)) == 0) &&
1206 (v2d->keepzoom & V2D_KEEPASPECT))
1207 {
1208 if (U.uiflag & USER_ZOOM_HORIZ) {
1209 facy = 0.0f;
1210 }
1211 else {
1212 facx = 0.0f;
1213 }
1214 }
1215
1216 /* support trackpad zoom to always zoom entirely - the v2d code uses portrait or
1217 * landscape exceptions */
1218 if (v2d->keepzoom & V2D_KEEPASPECT) {
1219 if (fabsf(facx) > fabsf(facy)) {
1220 facy = facx;
1221 }
1222 else {
1223 facx = facy;
1224 }
1225 }
1226
1227 const float dx = facx * BLI_rctf_size_x(&v2d->cur);
1228 const float dy = facy * BLI_rctf_size_y(&v2d->cur);
1229
1230 RNA_float_set(op->ptr, "deltax", dx);
1231 RNA_float_set(op->ptr, "deltay", dy);
1232
1234 view_zoomdrag_exit(C, op);
1235 return OPERATOR_FINISHED;
1236 }
1237
1238 /* set initial settings */
1239 vzd->lastx = event->xy[0];
1240 vzd->lasty = event->xy[1];
1241 RNA_float_set(op->ptr, "deltax", 0);
1242 RNA_float_set(op->ptr, "deltay", 0);
1243
1244 /* for modal exit test */
1245 vzd->invoke_event = event->type;
1246
1247 if (WM_cursor_modal_is_set_ok(window)) {
1248 if (v2d->keepofs & V2D_LOCKOFS_X) {
1250 }
1251 else if (v2d->keepofs & V2D_LOCKOFS_Y) {
1253 }
1254 else {
1256 }
1257 vzd->own_cursor = true;
1258 }
1259
1260 /* add temp handler */
1262
1263 if (U.viewzoom == USER_ZOOM_CONTINUE) {
1264 /* needs a timer to continue redrawing */
1265 vzd->timer = WM_event_timer_add(CTX_wm_manager(C), window, TIMER, 0.01f);
1267 }
1268
1270}
1271
1272/* handle user input - calculations of mouse-movement need to be done here,
1273 * not in the apply callback! */
1275{
1276 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1277 View2D *v2d = vzd->v2d;
1278
1279 /* execute the events */
1280 if (event->type == TIMER && event->customdata == vzd->timer) {
1282 }
1283 else if (event->type == MOUSEMOVE) {
1284 float dx, dy;
1285 float zoomfac = 0.01f;
1286
1287 /* some view2d's (graph) don't have min/max zoom, or extreme ones */
1288 if (v2d->maxzoom > 0.0f) {
1289 zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f);
1290 }
1291
1292 /* calculate new delta transform, based on zooming mode */
1293 if (U.viewzoom == USER_ZOOM_SCALE) {
1294 /* 'scale' zooming */
1295 float dist;
1296 float len_old[2];
1297 float len_new[2];
1298
1299 /* x-axis transform */
1300 dist = BLI_rcti_size_x(&v2d->mask) / 2.0f;
1301 len_old[0] = zoomfac * fabsf(vzd->lastx - vzd->region->winrct.xmin - dist);
1302 len_new[0] = zoomfac * fabsf(event->xy[0] - vzd->region->winrct.xmin - dist);
1303
1304 /* y-axis transform */
1305 dist = BLI_rcti_size_y(&v2d->mask) / 2.0f;
1306 len_old[1] = zoomfac * fabsf(vzd->lasty - vzd->region->winrct.ymin - dist);
1307 len_new[1] = zoomfac * fabsf(event->xy[1] - vzd->region->winrct.ymin - dist);
1308
1309 /* Calculate distance */
1310 if (v2d->keepzoom & V2D_KEEPASPECT) {
1311 dist = len_v2(len_new) - len_v2(len_old);
1312 dx = dy = dist;
1313 }
1314 else {
1315 dx = len_new[0] - len_old[0];
1316 dy = len_new[1] - len_old[1];
1317 }
1318
1319 dx *= BLI_rctf_size_x(&v2d->cur);
1320 dy *= BLI_rctf_size_y(&v2d->cur);
1321 }
1322 else { /* USER_ZOOM_CONTINUE or USER_ZOOM_DOLLY */
1323 float facx = zoomfac * (event->xy[0] - vzd->lastx);
1324 float facy = zoomfac * (event->xy[1] - vzd->lasty);
1325
1326 /* Only respect user setting zoom axis if the view does not have any zoom restrictions
1327 * any will be scaled uniformly */
1328 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 &&
1329 (v2d->keepzoom & V2D_KEEPASPECT))
1330 {
1331 if (U.uiflag & USER_ZOOM_HORIZ) {
1332 facy = 0.0f;
1333 }
1334 else {
1335 facx = 0.0f;
1336 }
1337 }
1338
1339 /* support zoom to always zoom entirely - the v2d code uses portrait or
1340 * landscape exceptions */
1341 if (v2d->keepzoom & V2D_KEEPASPECT) {
1342 if (fabsf(facx) > fabsf(facy)) {
1343 facy = facx;
1344 }
1345 else {
1346 facx = facy;
1347 }
1348 }
1349
1350 dx = facx * BLI_rctf_size_x(&v2d->cur);
1351 dy = facy * BLI_rctf_size_y(&v2d->cur);
1352 }
1353
1354 if (U.uiflag & USER_ZOOM_INVERT) {
1355 dx *= -1.0f;
1356 dy *= -1.0f;
1357 }
1358
1359 /* set transform amount, and add current deltas to stored total delta (for redo) */
1360 RNA_float_set(op->ptr, "deltax", dx);
1361 RNA_float_set(op->ptr, "deltay", dy);
1362
1363 vzd->dx += dx;
1364 vzd->dy += dy;
1365
1366 /* Store mouse coordinates for next time, if not doing continuous zoom:
1367 * - Continuous zoom only depends on distance of mouse
1368 * to starting point to determine rate of change.
1369 */
1370 if (U.viewzoom != USER_ZOOM_CONTINUE) { /* XXX store this setting as RNA prop? */
1371 vzd->lastx = event->xy[0];
1372 vzd->lasty = event->xy[1];
1373 }
1374
1375 /* apply zooming */
1377 }
1378 else if (ELEM(event->type, vzd->invoke_event, EVT_ESCKEY)) {
1379 if (event->val == KM_RELEASE) {
1380
1381 /* for redo, store the overall deltas - need to respect zoom-locks here... */
1382 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1383 RNA_float_set(op->ptr, "deltax", vzd->dx);
1384 }
1385 else {
1386 RNA_float_set(op->ptr, "deltax", 0);
1387 }
1388
1389 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1390 RNA_float_set(op->ptr, "deltay", vzd->dy);
1391 }
1392 else {
1393 RNA_float_set(op->ptr, "deltay", 0);
1394 }
1395
1396 /* free customdata */
1397 const bool own_cursor = vzd->own_cursor;
1398 view_zoomdrag_exit(C, op);
1399 if (own_cursor) {
1401 }
1402
1403 return OPERATOR_FINISHED;
1404 }
1405 }
1406
1408}
1409
1411{
1412 PropertyRNA *prop;
1413 /* identifiers */
1414 ot->name = "Zoom 2D View";
1415 ot->description = "Zoom in/out the view";
1416 ot->idname = "VIEW2D_OT_zoom";
1417
1418 /* API callbacks. */
1423
1424 ot->poll = view_zoom_poll;
1425
1426 /* operator is repeatable */
1428
1429 /* rna - must keep these in sync with the other operators */
1430 prop = RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
1432 prop = RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
1434
1436}
1437
1439
1440/* -------------------------------------------------------------------- */
1452
1454{
1455 ARegion *region = CTX_wm_region(C);
1456 View2D *v2d = &region->v2d;
1457 rctf cur_new = v2d->cur;
1458 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
1459
1460 /* convert coordinates of rect to `tot` rect coordinates */
1461 rctf rect;
1463 view2d_region_to_view_rctf(v2d, &rect, &rect);
1464
1465 /* check if zooming in/out view */
1466 const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
1467
1468 if (zoom_in) {
1469 /* zoom in:
1470 * - `cur` rect will be defined by the coordinates of the border region
1471 * - just set the `cur` rect to have the same coordinates as the border region
1472 * if zoom is allowed to be changed
1473 */
1474 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1475 cur_new.xmin = rect.xmin;
1476 cur_new.xmax = rect.xmax;
1477 }
1478 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1479 cur_new.ymin = rect.ymin;
1480 cur_new.ymax = rect.ymax;
1481 }
1482 }
1483 else {
1484 /* zoom out:
1485 * - the current `cur` rect coordinates are going to end up where the `rect` ones are,
1486 * but the `cur` rect coordinates will need to be adjusted to take in more of the view
1487 * - calculate zoom factor, and adjust using center-point
1488 */
1489 float zoom, center, size;
1490
1491 /* TODO: is this zoom factor calculation valid?
1492 * It seems to produce same results every time... */
1493 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1494 size = BLI_rctf_size_x(&cur_new);
1495 zoom = size / BLI_rctf_size_x(&rect);
1496 center = BLI_rctf_cent_x(&cur_new);
1497
1498 cur_new.xmin = center - (size * zoom);
1499 cur_new.xmax = center + (size * zoom);
1500 }
1501 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1502 size = BLI_rctf_size_y(&cur_new);
1503 zoom = size / BLI_rctf_size_y(&rect);
1504 center = BLI_rctf_cent_y(&cur_new);
1505
1506 cur_new.ymin = center - (size * zoom);
1507 cur_new.ymax = center + (size * zoom);
1508 }
1509 }
1510
1511 view2d_smooth_view(C, region, &cur_new, smooth_viewtx);
1512
1513 return OPERATOR_FINISHED;
1514}
1515
1517{
1518 /* identifiers */
1519 ot->name = "Zoom to Border";
1520 ot->description = "Zoom in the view to the nearest item contained in the border";
1521 ot->idname = "VIEW2D_OT_zoom_border";
1522
1523 /* API callbacks. */
1528
1529 ot->poll = view_zoom_poll;
1530
1531 /* rna */
1533}
1534
1536
1537/* -------------------------------------------------------------------- */
1540
1541#ifdef WITH_INPUT_NDOF
1542static wmOperatorStatus view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1543{
1544 if (event->type != NDOF_MOTION) {
1545 return OPERATOR_CANCELLED;
1546 }
1547
1548 const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
1549
1550 /* tune these until it feels right */
1551 const float zoom_sensitivity = 0.5f;
1552 const float pan_speed = NDOF_PIXELS_PER_SECOND;
1553 float3 pan_vec = WM_event_ndof_translation_get_for_navigation(ndof);
1554 const bool has_translate = !is_zero_v2(pan_vec) && view_pan_poll(C);
1555 const bool has_zoom = (pan_vec[2] != 0.0f) && view_zoom_poll(C);
1556
1557 if (has_translate) {
1558 mul_v2_fl(pan_vec, ndof.time_delta * pan_speed);
1559
1560 view_pan_init(C, op);
1561
1562 v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata);
1563 view_pan_apply_ex(C, vpd, pan_vec[0], pan_vec[1]);
1564
1565 view_pan_exit(op);
1566 }
1567
1568 if (has_zoom) {
1569 float zoom_factor = zoom_sensitivity * ndof.time_delta * -pan_vec[2];
1570
1571 bool do_zoom_xy[2];
1572 view_zoom_axis_lock_defaults(C, do_zoom_xy);
1573
1574 view_zoomdrag_init(C, op);
1575
1576 v2dViewZoomData *vzd = static_cast<v2dViewZoomData *>(op->customdata);
1578 C, vzd, do_zoom_xy[0] ? zoom_factor : 0.0f, do_zoom_xy[1] ? zoom_factor : 0.0f);
1579
1580 view_zoomstep_exit(C, op);
1581 }
1582
1583 return OPERATOR_FINISHED;
1584}
1585
1586static void VIEW2D_OT_ndof(wmOperatorType *ot)
1587{
1588 /* identifiers */
1589 ot->name = "NDOF Pan/Zoom";
1590 ot->idname = "VIEW2D_OT_ndof";
1591 ot->description = "Use a 3D mouse device to pan/zoom the view";
1592
1593 /* API callbacks. */
1594 ot->invoke = view2d_ndof_invoke;
1595 ot->poll = view2d_poll;
1596
1597 /* flags */
1598 ot->flag = OPTYPE_LOCK_BYPASS;
1599}
1600#endif /* WITH_INPUT_NDOF */
1601
1603
1604/* -------------------------------------------------------------------- */
1607
1613
1622static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b)
1623{
1624 const float size_a[2] = {BLI_rctf_size_x(rect_a), BLI_rctf_size_y(rect_a)};
1625 const float size_b[2] = {BLI_rctf_size_x(rect_b), BLI_rctf_size_y(rect_b)};
1626 const float cent_a[2] = {BLI_rctf_cent_x(rect_a), BLI_rctf_cent_y(rect_a)};
1627 const float cent_b[2] = {BLI_rctf_cent_x(rect_b), BLI_rctf_cent_y(rect_b)};
1628
1629 float fac_max = 0.0f;
1630
1631 for (int i = 0; i < 2; i++) {
1632 /* axis translation normalized to scale */
1633 float tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]);
1634 fac_max = max_ff(fac_max, tfac);
1635 if (fac_max >= 1.0f) {
1636 break;
1637 }
1638
1639 /* axis scale difference, x2 so doubling or half gives 1.0f */
1640 tfac = (1.0f - (min_ff(size_a[i], size_b[i]) / max_ff(size_a[i], size_b[i]))) * 2.0f;
1641 fac_max = max_ff(fac_max, tfac);
1642 if (fac_max >= 1.0f) {
1643 break;
1644 }
1645 }
1646 return min_ff(fac_max, 1.0f);
1647}
1648
1650 ARegion *region,
1651 const rctf *cur,
1652 const int smooth_viewtx)
1653{
1655 wmWindow *win = CTX_wm_window(C);
1656
1657 View2D *v2d = &region->v2d;
1658 SmoothView2DStore sms = {{0}};
1659 bool ok = false;
1660 float fac = 1.0f;
1661
1662 /* initialize sms */
1663 sms.new_cur = v2d->cur;
1664
1665 /* store the options we want to end with */
1666 if (cur) {
1667 sms.new_cur = *cur;
1668 }
1669
1670 if (cur) {
1671 fac = smooth_view_rect_to_fac(&v2d->cur, cur);
1672 }
1673
1674 if (smooth_viewtx && fac > FLT_EPSILON) {
1675 bool changed = false;
1676
1677 if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == false) {
1678 changed = true;
1679 }
1680
1681 /* The new view is different from the old one
1682 * so animate the view */
1683 if (changed) {
1684 sms.orig_cur = v2d->cur;
1685
1686 sms.time_allowed = double(smooth_viewtx) / 1000.0;
1687
1688 /* scale the time allowed the change in view */
1689 sms.time_allowed *= double(fac);
1690
1691 /* keep track of running timer! */
1692 if (v2d->sms == nullptr) {
1693 v2d->sms = MEM_new<SmoothView2DStore>(__func__);
1694 }
1695 *v2d->sms = sms;
1696 if (v2d->smooth_timer) {
1698 }
1699 /* TIMER1 is hard-coded in key-map. */
1700 v2d->smooth_timer = WM_event_timer_add(wm, win, TIMER1, 1.0 / 100.0);
1701
1702 ok = true;
1703 }
1704 }
1705
1706 /* if we get here nothing happens */
1707 if (ok == false) {
1708 v2d->cur = sms.new_cur;
1709
1713 }
1714}
1715
1716/* only meant for timer usage */
1718 wmOperator * /*op*/,
1719 const wmEvent *event)
1720{
1721 wmWindow *win = CTX_wm_window(C);
1722 ARegion *region = CTX_wm_region(C);
1723 View2D *v2d = &region->v2d;
1724 SmoothView2DStore *sms = v2d->sms;
1725
1726 /* escape if not our timer */
1727 if (v2d->smooth_timer == nullptr || v2d->smooth_timer != event->customdata) {
1728 return OPERATOR_PASS_THROUGH;
1729 }
1730
1731 float step;
1732 if (sms->time_allowed != 0.0) {
1734 }
1735 else {
1736 step = 1.0f;
1737 }
1738
1739 /* end timer */
1740 if (step >= 1.0f) {
1741 v2d->cur = sms->new_cur;
1742
1743 MEM_delete(v2d->sms);
1744 v2d->sms = nullptr;
1745
1747 v2d->smooth_timer = nullptr;
1748
1749 /* Event handling won't know if a UI item has been moved under the pointer. */
1751 }
1752 else {
1753 /* ease in/out */
1754 step = (3.0f * step * step - 2.0f * step * step * step);
1755
1756 BLI_rctf_interp(&v2d->cur, &sms->orig_cur, &sms->new_cur, step);
1757 }
1758
1762
1763 if (v2d->sms == nullptr) {
1765 }
1766
1767 return OPERATOR_FINISHED;
1768}
1769
1771{
1772 /* identifiers */
1773 ot->name = "Smooth View 2D";
1774 ot->idname = "VIEW2D_OT_smoothview";
1775
1776 /* API callbacks. */
1778 ot->poll = view2d_poll;
1779
1780 /* flags */
1781 ot->flag = OPTYPE_INTERNAL;
1782
1783 /* rna */
1785}
1786
1788
1789/* -------------------------------------------------------------------- */
1792
1802
1803/* customdata for scroller-invoke data */
1809
1812
1813 /* XXX find some way to provide visual feedback of this (active color?) */
1815 short zone;
1816
1818 float fac;
1822 float delta;
1823
1828
1831};
1832
1833/* quick enum for vsm->zone (scroller handles) */
1834enum {
1840} /*eV2DScrollerHandle_Zone*/;
1841
1848static short scrollbar_zone_get(int mouse, int sh_min, int sh_max)
1849{
1850 /* Check if mouse is in either zoom handle. */
1851 bool in_max = ((mouse >= (sh_max - V2D_SCROLL_HANDLE_SIZE_HOTSPOT)) &&
1852 (mouse <= (sh_max + V2D_SCROLL_HANDLE_SIZE_HOTSPOT)));
1853 bool in_min = ((mouse <= (sh_min + V2D_SCROLL_HANDLE_SIZE_HOTSPOT)) &&
1854 (mouse >= (sh_min - V2D_SCROLL_HANDLE_SIZE_HOTSPOT)));
1855
1856 /* Check if mouse is in scrollbar or outside, on the scrollbar track. */
1857 bool in_bar = ((mouse < (sh_max - V2D_SCROLL_HANDLE_SIZE_HOTSPOT)) &&
1858 (mouse > (sh_min + V2D_SCROLL_HANDLE_SIZE_HOTSPOT)));
1859 const bool out_min = mouse < (sh_min - V2D_SCROLL_HANDLE_SIZE_HOTSPOT);
1860 const bool out_max = mouse > (sh_max + V2D_SCROLL_HANDLE_SIZE_HOTSPOT);
1861
1862 if (in_bar) {
1863 return SCROLLHANDLE_BAR;
1864 }
1865 if (in_max) {
1866 return SCROLLHANDLE_MAX;
1867 }
1868 if (in_min) {
1869 return SCROLLHANDLE_MIN;
1870 }
1871 if (out_min) {
1873 }
1874 if (out_max) {
1876 }
1877
1878 /* unlikely to happen, though we just cover it in case */
1879 return SCROLLHANDLE_BAR;
1880}
1881
1883{
1884 const wmWindow *win = CTX_wm_window(C);
1885 if (!(win && win->runtime->eventstate)) {
1886 return false;
1887 }
1888 if (!view2d_poll(C)) {
1889 return false;
1890 }
1891 ARegion *region = CTX_wm_region(C);
1892 View2D *v2d = &region->v2d;
1893 /* Check if mouse in scroll-bars, if they're enabled. */
1894 return (view2d_mouse_in_scrollers(region, v2d, win->runtime->eventstate->xy) != 0);
1895}
1896
1897/* Initialize #wmOperator.customdata for scroller manipulation operator. */
1899 wmOperator *op,
1900 const wmEvent *event,
1901 const char in_scroller)
1902{
1903 ARegion *region = CTX_wm_region(C);
1904 View2D *v2d = &region->v2d;
1905
1906 /* set custom-data for operator */
1908 op->customdata = vsm;
1909
1910 /* set general data */
1911 vsm->v2d = v2d;
1912 vsm->region = region;
1913 vsm->scroller = in_scroller;
1914
1915 /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
1916 vsm->lastx = event->xy[0];
1917 vsm->lasty = event->xy[1];
1918 /* `zone` depends on where mouse is relative to bubble
1919 * - zooming must be allowed on this axis, otherwise, default to pan.
1920 */
1921 View2DScrollers scrollers;
1922 /* Reconstruct the custom scroller mask passed to #view2d_scrollers_draw().
1923 *
1924 * Some editors like the File Browser, Spreadsheet or scrubbing UI already set up custom masks
1925 * for scroll-bars (they don't cover the whole region width or height), these need to be
1926 * considered, otherwise coords for `scrollbar_zone_get` later are not compatible. This
1927 * should be a reliable way to do it. Otherwise the custom scroller mask could also be stored in
1928 * #View2D.
1929 */
1930 rcti scroller_mask = v2d->hor;
1931 BLI_rcti_union(&scroller_mask, &v2d->vert);
1932
1933 view2d_scrollers_calc(v2d, &scroller_mask, &scrollers);
1934
1935 /* Use a union of 'cur' & 'tot' in case the current view is far outside 'tot'. In this cases
1936 * moving the scroll bars has far too little effect and the view can get stuck #31476. */
1937 rctf tot_cur_union = v2d->tot;
1938 BLI_rctf_union(&tot_cur_union, &v2d->cur);
1939
1940 if (in_scroller == 'h') {
1941 /* horizontal scroller - calculate adjustment factor first */
1942 const float mask_size = float(BLI_rcti_size_x(&v2d->hor));
1943 vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size;
1944
1945 /* pixel rounding */
1946 vsm->fac_round = BLI_rctf_size_x(&v2d->cur) / float(BLI_rcti_size_x(&region->winrct) + 1);
1947
1948 /* get 'zone' (i.e. which part of scroller is activated) */
1949 vsm->zone = scrollbar_zone_get(event->mval[0], scrollers.hor_min, scrollers.hor_max);
1950
1952 /* default to scroll, as handles not usable */
1953 vsm->zone = SCROLLHANDLE_BAR;
1954 }
1955
1956 vsm->scrollbarwidth = scrollers.hor_max - scrollers.hor_min;
1957 vsm->scrollbar_orig = ((scrollers.hor_max + scrollers.hor_min) / 2) + region->winrct.xmin;
1958 }
1959 else {
1960 /* vertical scroller - calculate adjustment factor first */
1961 const float mask_size = float(BLI_rcti_size_y(&v2d->vert));
1962 vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size;
1963
1964 /* pixel rounding */
1965 vsm->fac_round = BLI_rctf_size_y(&v2d->cur) / float(BLI_rcti_size_y(&region->winrct) + 1);
1966
1967 /* Get `zone` (i.e. which part of scroller is activated). */
1968 vsm->zone = scrollbar_zone_get(event->mval[1], scrollers.vert_min, scrollers.vert_max);
1969
1971 /* default to scroll, as handles not usable */
1972 vsm->zone = SCROLLHANDLE_BAR;
1973 }
1974
1975 vsm->scrollbarwidth = scrollers.vert_max - scrollers.vert_min;
1976 vsm->scrollbar_orig = ((scrollers.vert_max + scrollers.vert_min) / 2) + region->winrct.ymin;
1977 }
1978
1979 vsm->v2d->flag |= V2D_IS_NAVIGATING;
1980
1982}
1983
1984/* Cleanup temp custom-data. */
1986{
1987 if (op->customdata) {
1988 v2dScrollerMove *vsm = static_cast<v2dScrollerMove *>(op->customdata);
1989
1991 vsm->v2d->flag &= ~V2D_IS_NAVIGATING;
1992
1993 MEM_delete(vsm);
1994 op->customdata = nullptr;
1995
1997 }
1998}
1999
2001{
2003}
2004
2005/* apply transform to view (i.e. adjust 'cur' rect) */
2007{
2008 v2dScrollerMove *vsm = static_cast<v2dScrollerMove *>(op->customdata);
2009 View2D *v2d = vsm->v2d;
2010
2011 /* calculate amount to move view by */
2012 float temp = vsm->fac * vsm->delta;
2013
2014 /* round to pixel */
2015 temp = roundf(temp / vsm->fac_round) * vsm->fac_round;
2016
2017 /* type of movement */
2018 switch (vsm->zone) {
2019 case SCROLLHANDLE_MIN:
2020 /* only expand view on axis if zoom is allowed */
2021 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X)) {
2022 v2d->cur.xmin -= temp;
2023 }
2024 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y)) {
2025 v2d->cur.ymin -= temp;
2026 }
2027 break;
2028
2029 case SCROLLHANDLE_MAX:
2030
2031 /* only expand view on axis if zoom is allowed */
2032 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X)) {
2033 v2d->cur.xmax += temp;
2034 }
2035 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y)) {
2036 v2d->cur.ymax += temp;
2037 }
2038 break;
2039
2042 case SCROLLHANDLE_BAR:
2043 default:
2044 /* only move view on an axis if panning is allowed */
2045 if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
2046 v2d->cur.xmin += temp;
2047 v2d->cur.xmax += temp;
2048 }
2049 if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
2050 v2d->cur.ymin += temp;
2051 v2d->cur.ymax += temp;
2052 }
2053 break;
2054 }
2055
2056 /* Inform v2d about changes after this operation. */
2058
2059 /* request updates to be done... */
2062}
2063
2069{
2070 v2dScrollerMove *vsm = static_cast<v2dScrollerMove *>(op->customdata);
2071 const bool use_page_size_y = vsm->v2d->flag & V2D_SNAP_TO_PAGESIZE_Y;
2072
2073 /* execute the events */
2074 switch (event->type) {
2075 case MOUSEMOVE: {
2076 float delta = 0.0f;
2077
2078 /* calculate new delta transform, then store mouse-coordinates for next-time */
2080 /* if using bar (i.e. 'panning') or 'max' zoom widget */
2081 switch (vsm->scroller) {
2082 case 'h': /* horizontal scroller - so only horizontal movement
2083 * ('cur' moves opposite to mouse) */
2084 delta = float(event->xy[0] - vsm->lastx);
2085 break;
2086 case 'v': /* vertical scroller - so only vertical movement
2087 * ('cur' moves opposite to mouse) */
2088 delta = float(event->xy[1] - vsm->lasty);
2089 break;
2090 }
2091 }
2092 else if (vsm->zone == SCROLLHANDLE_MIN) {
2093 /* using 'min' zoom widget */
2094 switch (vsm->scroller) {
2095 case 'h': /* horizontal scroller - so only horizontal movement
2096 * ('cur' moves with mouse) */
2097 delta = float(vsm->lastx - event->xy[0]);
2098 break;
2099 case 'v': /* vertical scroller - so only vertical movement
2100 * ('cur' moves with to mouse) */
2101 delta = float(vsm->lasty - event->xy[1]);
2102 break;
2103 }
2104 }
2105
2106 /* Page snapping: When panning for more than half a page size, snap to the next page. */
2107 if (use_page_size_y && (vsm->scroller == 'v')) {
2108 delta = view2d_scroll_delta_y_snap_page_size(*vsm->v2d, delta * vsm->fac) / vsm->fac;
2109 }
2110
2111 if (IS_EQF(delta, 0.0f)) {
2112 break;
2113 }
2114
2115 vsm->delta = delta;
2116 /* store previous coordinates */
2117 vsm->lastx = event->xy[0];
2118 vsm->lasty = event->xy[1];
2119
2121 break;
2122 }
2123 case LEFTMOUSE:
2124 case MIDDLEMOUSE:
2125 if (event->val == KM_RELEASE) {
2126 /* single-click was in empty space outside bubble, so scroll by 1 'page' */
2128 if (vsm->zone == SCROLLHANDLE_MIN_OUTSIDE) {
2129 vsm->delta = -vsm->scrollbarwidth * 0.8f;
2130 }
2131 else if (vsm->zone == SCROLLHANDLE_MAX_OUTSIDE) {
2132 vsm->delta = vsm->scrollbarwidth * 0.8f;
2133 }
2134
2137 return OPERATOR_FINISHED;
2138 }
2139
2140 /* Otherwise, end the drag action. */
2141 if (vsm->lastx || vsm->lasty) {
2143 return OPERATOR_FINISHED;
2144 }
2145 }
2146 break;
2147 default: {
2148 break;
2149 }
2150 }
2151
2153}
2154
2155/* a click (or click drag in progress)
2156 * should have occurred, so check if it happened in scrollbar */
2158{
2159 ARegion *region = CTX_wm_region(C);
2160 View2D *v2d = &region->v2d;
2161
2162 /* check if mouse in scroll-bars, if they're enabled */
2163 const char in_scroller = view2d_mouse_in_scrollers(region, v2d, event->xy);
2164
2165 /* if in a scroller, init customdata then set modal handler which will
2166 * catch mouse-down to start doing useful stuff */
2167 if (in_scroller) {
2168 /* initialize customdata */
2169 scroller_activate_init(C, op, event, in_scroller);
2170 v2dScrollerMove *vsm = static_cast<v2dScrollerMove *>(op->customdata);
2171
2172 /* Support for quick jump to location - GTK and QT do this on Linux. */
2173 if (event->type == MIDDLEMOUSE) {
2174 switch (vsm->scroller) {
2175 case 'h': /* horizontal scroller - so only horizontal movement
2176 * ('cur' moves opposite to mouse) */
2177 vsm->delta = float(event->xy[0] - vsm->scrollbar_orig);
2178 break;
2179 case 'v': /* vertical scroller - so only vertical movement
2180 * ('cur' moves opposite to mouse) */
2181 vsm->delta = float(event->xy[1] - vsm->scrollbar_orig);
2182 break;
2183 }
2185
2186 vsm->zone = SCROLLHANDLE_BAR;
2187 }
2188
2189 /* Check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue
2190 * NOTE: see `view2d.cc` for latest conditions, and keep this in sync with that. */
2192 if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_HORIZONTAL_HANDLES) == 0) ||
2193 ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_VERTICAL_HANDLES) == 0))
2194 {
2195 /* switch to bar (i.e. no scaling gets handled) */
2196 vsm->zone = SCROLLHANDLE_BAR;
2197 }
2198 }
2199
2200 /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
2201 if (vsm->zone == SCROLLHANDLE_BAR) {
2202 if (((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
2203 ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y)))
2204 {
2205 /* free customdata initialized */
2207
2208 /* can't catch this event for ourselves, so let it go to someone else? */
2209 return OPERATOR_PASS_THROUGH;
2210 }
2211 }
2212
2213 /* zone is also inappropriate if scroller is not visible... */
2214 if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_HORIZONTAL_FULLR)) ||
2215 ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_VERTICAL_FULLR)))
2216 {
2217 /* free customdata initialized */
2219
2220 /* can't catch this event for ourselves, so let it go to someone else? */
2221 /* XXX NOTE: if handlers use mask rect to clip input, input will fail for this case. */
2222 return OPERATOR_PASS_THROUGH;
2223 }
2224
2225 /* activate the scroller */
2226 if (vsm->scroller == 'h') {
2228 }
2229 else {
2231 }
2232
2233 /* still ok, so can add */
2236 }
2237
2238 /* not in scroller, so nothing happened...
2239 * (pass through let's something else catch event) */
2240 return OPERATOR_PASS_THROUGH;
2241}
2242
2243/* LMB-Drag in Scrollers - not repeatable operator! */
2245{
2246 /* identifiers */
2247 ot->name = "Scroller Activate";
2248 ot->description = "Scroll view by mouse click and drag";
2249 ot->idname = "VIEW2D_OT_scroller_activate";
2250
2251 /* flags */
2252 ot->flag = OPTYPE_BLOCKING;
2253
2254 /* API callbacks. */
2258
2260}
2261
2263
2264/* -------------------------------------------------------------------- */
2267
2269{
2270 const uiStyle *style = style_get();
2271 ARegion *region = CTX_wm_region(C);
2272 View2D *v2d = &region->v2d;
2273 const int snap_test = ED_region_snap_size_test(region);
2274
2275 region->category_scroll = 0;
2276
2277 /* zoom 1.0 */
2278 const int winx = float(BLI_rcti_size_x(&v2d->mask) + 1);
2279 const int winy = float(BLI_rcti_size_y(&v2d->mask) + 1);
2280
2281 v2d->cur.xmax = v2d->cur.xmin + winx;
2282 v2d->cur.ymax = v2d->cur.ymin + winy;
2283
2284 /* align */
2285 if (v2d->align) {
2286 /* posx and negx flags are mutually exclusive, so watch out */
2287 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
2288 v2d->cur.xmax = 0.0f;
2289 v2d->cur.xmin = -winx * style->panelzoom;
2290 }
2291 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
2292 v2d->cur.xmax = winx * style->panelzoom;
2293 v2d->cur.xmin = 0.0f;
2294 }
2295
2296 /* - posx and negx flags are mutually exclusive, so watch out */
2297 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
2298 v2d->cur.ymax = 0.0f;
2299 v2d->cur.ymin = -winy * style->panelzoom;
2300 }
2301 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
2302 v2d->cur.ymax = winy * style->panelzoom;
2303 v2d->cur.ymin = 0.0f;
2304 }
2305 }
2306
2307 /* Inform v2d about changes after this operation. */
2309
2310 if (ED_region_snap_size_apply(region, snap_test)) {
2311 ScrArea *area = CTX_wm_area(C);
2312 ED_area_tag_redraw(area);
2314 }
2315
2316 /* request updates to be done... */
2317 ED_region_tag_redraw(region);
2319
2321
2322 return OPERATOR_FINISHED;
2323}
2324
2326{
2327 /* identifiers */
2328 ot->name = "Reset View";
2329 ot->description = "Reset the view";
2330 ot->idname = "VIEW2D_OT_reset";
2331
2332 /* API callbacks. */
2333 ot->exec = reset_exec;
2334 ot->poll = view2d_poll;
2335}
2336
2338
2339/* -------------------------------------------------------------------- */
2342
2369
2371{
2372 WM_keymap_ensure(keyconf, "View2D", SPACE_EMPTY, RGN_TYPE_WINDOW);
2373}
2374
2376
2377} // namespace blender::ui
Platform independent time functions.
#define UI_SCALE_FAC
#define NDOF_PIXELS_PER_SECOND
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define V2D_LOCK_COPY
Definition UI_view2d.hh:110
#define V2D_SCROLL_HANDLE_SIZE_HOTSPOT
Definition UI_view2d.hh:96
#define NC_SCREEN
Definition WM_types.hh:390
#define NA_EDITED
Definition WM_types.hh:634
#define ELEM(...)
#define IS_EQF(a, b)
#define IN_RANGE_INCL(a, b, c)
#define roundf(x)
#define FLT_MAX
#define INT_MAX
#define FLT_EPSILON
#define abs
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
static wmOperatorStatus reset_exec(bContext *C, wmOperator *)
static void VIEW2D_OT_edge_pan(wmOperatorType *ot)
static void view_zoomstep_props_init(bContext *C, wmOperator *op, const float zoomfac_default)
static wmOperatorStatus view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void view_edge_pan_cancel(bContext *, wmOperator *op)
static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b)
static wmOperatorStatus scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void scroller_activate_exit(bContext *C, wmOperator *op)
static wmOperatorStatus view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus view_scrollright_exec(bContext *C, wmOperator *op)
static void VIEW2D_OT_scroll_right(wmOperatorType *ot)
const uiStyle * style_get()
static wmOperatorStatus view_zoomin_exec(bContext *C, wmOperator *op)
void ED_keymap_view2d(wmKeyConfig *keyconf)
static void VIEW2D_OT_smoothview(wmOperatorType *ot)
static wmOperatorStatus view_zoomdrag_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_edge_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float dy)
static void scroller_activate_init(bContext *C, wmOperator *op, const wmEvent *event, const char in_scroller)
static void VIEW2D_OT_zoom_border(wmOperatorType *ot)
void view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom, View2DScrollers *r_scrollers)
Definition view2d.cc:1374
static void VIEW2D_OT_scroll_left(wmOperatorType *ot)
static wmOperatorStatus view2d_smoothview_invoke(bContext *C, wmOperator *, const wmEvent *event)
static void VIEW2D_OT_reset(wmOperatorType *ot)
char char view2d_mouse_in_scrollers(const ARegion *region, const View2D *v2d, const int xy[2]) ATTR_NONNULL(1
Definition view2d.cc:2044
static float view2d_scroll_delta_y_snap_page_size(const View2D &v2d, const float delta_y)
Definition view2d_ops.cc:54
void view2d_edge_pan_operator_init(bContext *C, View2DEdgePanData *vpd, wmOperator *op)
static void view_zoomstep_props_def(StructRNA *srna, const float zoomfac_default)
static wmOperatorStatus scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void view_zoomdrag_apply(bContext *C, wmOperator *op)
void ED_operatortypes_view2d()
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
static void view_pan_exit(wmOperator *op)
static wmOperatorStatus view_zoomout_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static constexpr float view_zoomfac_default
static void VIEW2D_OT_pan(wmOperatorType *ot)
static void VIEW2D_OT_scroll_up(wmOperatorType *ot)
static wmOperatorStatus view_borderzoom_exec(bContext *C, wmOperator *op)
static void view_pan_cancel(bContext *, wmOperator *op)
static void VIEW2D_OT_zoom(wmOperatorType *ot)
void view2d_smooth_view(const bContext *C, ARegion *region, const rctf *cur, int smooth_viewtx)
static wmOperatorStatus view_edge_pan_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void view_zoomstep_apply(bContext *C, wmOperator *op)
static void view_zoomdrag_cancel(bContext *C, wmOperator *op)
static void view_pan_init(bContext *C, wmOperator *op)
static void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
static void view_zoomdrag_init(bContext *C, wmOperator *op)
static void view_zoom_axis_lock_defaults(bContext *C, bool r_do_zoom_xy[2])
@ SCROLLHANDLE_MAX_OUTSIDE
@ SCROLLHANDLE_MIN_OUTSIDE
static wmOperatorStatus view_scrollup_exec(bContext *C, wmOperator *op)
void view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:850
static void scroller_activate_apply(bContext *C, wmOperator *op)
static wmOperatorStatus view_zoomdrag_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void view2d_curRect_changed(const bContext *C, View2D *v2d)
Definition view2d.cc:815
float view2d_page_size_y(const View2D &v2d)
Definition view2d.cc:79
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
static void scroller_activate_cancel(bContext *C, wmOperator *op)
static void VIEW2D_OT_zoom_in(wmOperatorType *ot)
static wmOperatorStatus view_pan_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_zoomin_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool scroller_activate_poll(bContext *C)
void void view2d_edge_pan_apply_event(bContext *C, View2DEdgePanData *vpd, const wmEvent *event)
static wmOperatorStatus view_scrolldown_exec(bContext *C, wmOperator *op)
static bool view_pan_poll(bContext *C)
static wmOperatorStatus view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void view_zoomstep_apply_ex(bContext *C, v2dViewZoomData *vzd, const float facx, const float facy)
static short scrollbar_zone_get(int mouse, int sh_min, int sh_max)
static bool view_zoom_poll(bContext *C)
static void VIEW2D_OT_scroll_down(wmOperatorType *ot)
void view2d_edge_pan_operator_properties(wmOperatorType *ot)
static wmOperatorStatus view_scrollleft_exec(bContext *C, wmOperator *op)
static void VIEW2D_OT_zoom_out(wmOperatorType *ot)
static wmOperatorStatus view_zoomout_exec(bContext *C, wmOperator *op)
void view2d_zoom_cache_reset()
Definition view2d.cc:1026
static void view_zoomdrag_exit(bContext *C, wmOperator *op)
bool view2d_edge_pan_poll(bContext *C)
static void view_pan_apply(bContext *C, wmOperator *op)
static bool view2d_poll(bContext *C)
Definition view2d_ops.cc:42
static void view_zoomstep_exit(bContext *C, wmOperator *op)
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
int WM_event_absolute_delta_x(const wmEvent *event)
ScrArea * CTX_wm_area(const bContext *C)
MINLINE bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ V2D_ZOOM_IGNORE_KEEPOFS
@ V2D_SNAP_TO_PAGESIZE_Y
MINLINE void mul_v2_fl(float r[2], float f)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void WM_cursor_modal_set(wmWindow *win, int val)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmWindow * CTX_wm_window(const bContext *C)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bool ED_region_panel_category_gutter_isect_xy(const ARegion *region, const int event_xy[2])
Definition area_query.cc:95
bool ED_region_snap_size_apply(ARegion *region, int snap_flag)
Definition area.cc:4922
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void WM_operator_properties_use_cursor_init(wmOperatorType *ot)
void WM_operator_properties_border_to_rctf(wmOperator *op, rctf *r_rect)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, float limit)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
void WM_cursor_modal_restore(wmWindow *win)
void WM_operator_properties_gesture_box_zoom(wmOperatorType *ot)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
void WM_operator_properties_gesture_box(wmOperatorType *ot)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
@ V2D_SCROLL_VERTICAL_FULLR
@ V2D_SCROLL_HORIZONTAL_HANDLES
@ V2D_SCROLL_VERTICAL_HANDLES
@ V2D_SCROLL_HORIZONTAL_FULLR
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
@ WM_CURSOR_NS_SCROLL
Definition wm_cursors.hh:55
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:56
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, float fac)
MINLINE float max_ff(float a, float b)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
@ PROP_HIDDEN
Definition RNA_types.hh:408
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
int WM_event_absolute_delta_y(const wmEvent *event)
@ KM_RELEASE
Definition WM_types.hh:325
double BLI_time_now_seconds()
Definition time.cc:30
bScreen * CTX_wm_screen(const bContext *C)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
@ OPTYPE_LOCK_BYPASS
Definition WM_types.hh:213
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
bool WM_cursor_modal_is_set_ok(const wmWindow *win)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void WM_event_add_mousemove(wmWindow *win)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
ARegion * CTX_wm_region(const bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
int ED_region_snap_size_test(const ARegion *region)
Definition area.cc:4909
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
MINLINE float clamp_f(float value, float min, float max)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eRegion_Type regiontype
ui::SmoothView2DStore * sms
struct wmTimer * smooth_timer
eView2D_KeepOfs keepofs
eView2D_KeepZoom keepzoom
eView2D_Scroll scroll
eView2D_ScrollUI scroll_ui
eView2D_Align align
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
bke::WindowRuntime * runtime
float panelzoom