2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation, Joshua Leung
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/editors/interface/view2d_ops.c
27 * \ingroup edinterface
33 #include "MEM_guardedalloc.h"
35 #include "DNA_userdef_types.h"
37 #include "BLI_blenlib.h"
38 #include "BLI_utildefines.h"
39 #include "BLI_math_base.h"
41 #include "BKE_context.h"
43 #include "RNA_access.h"
44 #include "RNA_define.h"
50 #include "ED_screen.h"
52 #include "UI_view2d.h"
53 #include "UI_interface.h"
55 #include "PIL_time.h" /* USER_ZOOM_CONT */
57 static int view2d_poll(bContext *C)
59 ARegion *ar = CTX_wm_region(C);
61 return (ar != NULL) && (ar->v2d.flag & V2D_IS_INITIALISED);
64 /* ********************************************************* */
65 /* VIEW PANNING OPERATOR */
67 /* This group of operators come in several forms:
68 * 1) Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by
69 * 2) Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount
71 * In order to make sure this works, each operator must define the following RNA-Operator Props:
72 * deltax, deltay - define how much to move view by (relative to zoom-correction factor)
75 /* ------------------ Shared 'core' stuff ---------------------- */
77 /* temp customdata for operator */
78 typedef struct v2dViewPanData {
79 bScreen *sc; /* screen where view pan was initiated */
80 ScrArea *sa; /* area where view pan was initiated */
81 ARegion *ar; /* region where view pan was initiated */
82 View2D *v2d; /* view2d we're operating in */
84 float facx, facy; /* amount to move view relative to zoom */
86 /* options for version 1 */
87 int startx, starty; /* mouse x/y values in window when operator was initiated */
88 int lastx, lasty; /* previous x/y values of mouse in window */
89 int invoke_event; /* event starting pan, for modal exit */
91 short in_scroller; /* for MMB in scrollers (old feature in past, but now not that useful) */
94 /* initialize panning customdata */
95 static int view_pan_init(bContext *C, wmOperator *op)
97 ARegion *ar = CTX_wm_region(C);
102 /* regions now have v2d-data by default, so check for region */
106 /* check if panning is allowed at all */
108 if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y))
111 /* set custom-data for operator */
112 vpd = MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData");
113 op->customdata = vpd;
115 /* set pointers to owners */
116 vpd->sc = CTX_wm_screen(C);
117 vpd->sa = CTX_wm_area(C);
121 /* calculate translation factor - based on size of view */
122 winx = (float)(BLI_rcti_size_x(&ar->winrct) + 1);
123 winy = (float)(BLI_rcti_size_y(&ar->winrct) + 1);
124 vpd->facx = (BLI_rctf_size_x(&v2d->cur)) / winx;
125 vpd->facy = (BLI_rctf_size_y(&v2d->cur)) / winy;
130 /* apply transform to view (i.e. adjust 'cur' rect) */
131 static void view_pan_apply(bContext *C, wmOperator *op)
133 v2dViewPanData *vpd = op->customdata;
134 View2D *v2d = vpd->v2d;
137 /* calculate amount to move view by */
138 dx = vpd->facx * (float)RNA_int_get(op->ptr, "deltax");
139 dy = vpd->facy * (float)RNA_int_get(op->ptr, "deltay");
141 /* only move view on an axis if change is allowed */
142 if ((v2d->keepofs & V2D_LOCKOFS_X) == 0) {
146 if ((v2d->keepofs & V2D_LOCKOFS_Y) == 0) {
151 /* validate that view is in valid configuration after this operation */
152 UI_view2d_curRect_validate(v2d);
154 /* request updates to be done... */
155 ED_region_tag_redraw(vpd->ar);
156 WM_event_add_mousemove(C);
158 UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY);
161 if (vpd->sa->spacetype == SPACE_OUTLINER) {
162 /* don't rebuild full tree, since we're just changing our view */
163 SpaceOops *soops = vpd->sa->spacedata.first;
164 soops->storeflag |= SO_TREESTORE_REDRAW;
168 /* cleanup temp customdata */
169 static void view_pan_exit(wmOperator *op)
171 if (op->customdata) {
172 MEM_freeN(op->customdata);
173 op->customdata = NULL;
177 /* ------------------ Modal Drag Version (1) ---------------------- */
179 /* for 'redo' only, with no user input */
180 static int view_pan_exec(bContext *C, wmOperator *op)
182 if (!view_pan_init(C, op))
183 return OPERATOR_CANCELLED;
185 view_pan_apply(C, op);
187 return OPERATOR_FINISHED;
190 /* set up modal operator and relevant settings */
191 static int view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
193 wmWindow *window = CTX_wm_window(C);
197 /* set up customdata */
198 if (!view_pan_init(C, op))
199 return OPERATOR_PASS_THROUGH;
201 vpd = op->customdata;
204 /* set initial settings */
205 vpd->startx = vpd->lastx = event->x;
206 vpd->starty = vpd->lasty = event->y;
207 vpd->invoke_event = event->type;
209 if (event->type == MOUSEPAN) {
210 RNA_int_set(op->ptr, "deltax", event->prevx - event->x);
211 RNA_int_set(op->ptr, "deltay", event->prevy - event->y);
213 view_pan_apply(C, op);
215 return OPERATOR_FINISHED;
218 RNA_int_set(op->ptr, "deltax", 0);
219 RNA_int_set(op->ptr, "deltay", 0);
221 if (v2d->keepofs & V2D_LOCKOFS_X)
222 WM_cursor_modal_set(window, BC_NS_SCROLLCURSOR);
223 else if (v2d->keepofs & V2D_LOCKOFS_Y)
224 WM_cursor_modal_set(window, BC_EW_SCROLLCURSOR);
226 WM_cursor_modal_set(window, BC_NSEW_SCROLLCURSOR);
228 /* add temp handler */
229 WM_event_add_modal_handler(C, op);
231 return OPERATOR_RUNNING_MODAL;
234 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
235 static int view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
237 v2dViewPanData *vpd = op->customdata;
239 /* execute the events */
240 switch (event->type) {
243 /* calculate new delta transform, then store mouse-coordinates for next-time */
244 RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
245 RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
247 vpd->lastx = event->x;
248 vpd->lasty = event->y;
250 view_pan_apply(C, op);
253 /* XXX - Mode switching isn't implemented. See comments in 36818.
257 if (event->val == KM_PRESS) {
258 /* calculate overall delta mouse-movement for redo */
259 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
260 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
263 WM_cursor_modal_restore(CTX_wm_window(C));
264 WM_operator_name_call(C, "VIEW2D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
265 return OPERATOR_FINISHED;
269 if (event->type == vpd->invoke_event || event->type == ESCKEY) {
270 if (event->val == KM_RELEASE) {
271 /* calculate overall delta mouse-movement for redo */
272 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
273 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
276 WM_cursor_modal_restore(CTX_wm_window(C));
278 return OPERATOR_FINISHED;
284 return OPERATOR_RUNNING_MODAL;
287 static int view_pan_cancel(bContext *UNUSED(C), wmOperator *op)
290 return OPERATOR_CANCELLED;
293 static void VIEW2D_OT_pan(wmOperatorType *ot)
296 ot->name = "Pan View";
297 ot->description = "Pan the view";
298 ot->idname = "VIEW2D_OT_pan";
301 ot->exec = view_pan_exec;
302 ot->invoke = view_pan_invoke;
303 ot->modal = view_pan_modal;
304 ot->cancel = view_pan_cancel;
306 /* operator is modal */
307 ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
309 /* rna - must keep these in sync with the other operators */
310 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
311 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
314 /* ------------------ Scrollwheel Versions (2) ---------------------- */
316 /* this operator only needs this single callback, where it calls the view_pan_*() methods */
317 static int view_scrollright_exec(bContext *C, wmOperator *op)
321 /* initialize default settings (and validate if ok to run) */
322 if (!view_pan_init(C, op))
323 return OPERATOR_PASS_THROUGH;
325 /* also, check if can pan in horizontal axis */
326 vpd = op->customdata;
327 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
329 return OPERATOR_PASS_THROUGH;
332 /* set RNA-Props - only movement in positive x-direction */
333 RNA_int_set(op->ptr, "deltax", 20);
334 RNA_int_set(op->ptr, "deltay", 0);
336 /* apply movement, then we're done */
337 view_pan_apply(C, op);
340 return OPERATOR_FINISHED;
343 static void VIEW2D_OT_scroll_right(wmOperatorType *ot)
346 ot->name = "Scroll Right";
347 ot->description = "Scroll the view right";
348 ot->idname = "VIEW2D_OT_scroll_right";
351 ot->exec = view_scrollright_exec;
353 /* rna - must keep these in sync with the other operators */
354 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
355 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
360 /* this operator only needs this single callback, where it calls the view_pan_*() methods */
361 static int view_scrollleft_exec(bContext *C, wmOperator *op)
365 /* initialize default settings (and validate if ok to run) */
366 if (!view_pan_init(C, op))
367 return OPERATOR_PASS_THROUGH;
369 /* also, check if can pan in horizontal axis */
370 vpd = op->customdata;
371 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
373 return OPERATOR_PASS_THROUGH;
376 /* set RNA-Props - only movement in negative x-direction */
377 RNA_int_set(op->ptr, "deltax", -20);
378 RNA_int_set(op->ptr, "deltay", 0);
380 /* apply movement, then we're done */
381 view_pan_apply(C, op);
384 return OPERATOR_FINISHED;
387 static void VIEW2D_OT_scroll_left(wmOperatorType *ot)
390 ot->name = "Scroll Left";
391 ot->description = "Scroll the view left";
392 ot->idname = "VIEW2D_OT_scroll_left";
395 ot->exec = view_scrollleft_exec;
397 /* rna - must keep these in sync with the other operators */
398 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
399 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
403 /* this operator only needs this single callback, where it calls the view_pan_*() methods */
404 static int view_scrolldown_exec(bContext *C, wmOperator *op)
408 /* initialize default settings (and validate if ok to run) */
409 if (!view_pan_init(C, op))
410 return OPERATOR_PASS_THROUGH;
412 /* also, check if can pan in vertical axis */
413 vpd = op->customdata;
414 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
416 return OPERATOR_PASS_THROUGH;
420 RNA_int_set(op->ptr, "deltax", 0);
421 RNA_int_set(op->ptr, "deltay", -40);
423 if (RNA_boolean_get(op->ptr, "page")) {
424 ARegion *ar = CTX_wm_region(C);
425 RNA_int_set(op->ptr, "deltay", ar->v2d.mask.ymin - ar->v2d.mask.ymax);
428 /* apply movement, then we're done */
429 view_pan_apply(C, op);
432 return OPERATOR_FINISHED;
435 static void VIEW2D_OT_scroll_down(wmOperatorType *ot)
438 ot->name = "Scroll Down";
439 ot->description = "Scroll the view down";
440 ot->idname = "VIEW2D_OT_scroll_down";
443 ot->exec = view_scrolldown_exec;
445 /* rna - must keep these in sync with the other operators */
446 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
447 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
448 RNA_def_boolean(ot->srna, "page", 0, "Page", "Scroll down one page");
453 /* this operator only needs this single callback, where it calls the view_pan_*() methods */
454 static int view_scrollup_exec(bContext *C, wmOperator *op)
458 /* initialize default settings (and validate if ok to run) */
459 if (!view_pan_init(C, op))
460 return OPERATOR_PASS_THROUGH;
462 /* also, check if can pan in vertical axis */
463 vpd = op->customdata;
464 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
466 return OPERATOR_PASS_THROUGH;
470 RNA_int_set(op->ptr, "deltax", 0);
471 RNA_int_set(op->ptr, "deltay", 40);
473 if (RNA_boolean_get(op->ptr, "page")) {
474 ARegion *ar = CTX_wm_region(C);
475 RNA_int_set(op->ptr, "deltay", BLI_rcti_size_y(&ar->v2d.mask));
478 /* apply movement, then we're done */
479 view_pan_apply(C, op);
482 return OPERATOR_FINISHED;
485 static void VIEW2D_OT_scroll_up(wmOperatorType *ot)
488 ot->name = "Scroll Up";
489 ot->description = "Scroll the view up";
490 ot->idname = "VIEW2D_OT_scroll_up";
493 ot->exec = view_scrollup_exec;
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 RNA_def_boolean(ot->srna, "page", 0, "Page", "Scroll up one page");
501 /* ********************************************************* */
502 /* SINGLE-STEP VIEW ZOOMING OPERATOR */
504 /* This group of operators come in several forms:
505 * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
506 * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented...
507 * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
509 * In order to make sure this works, each operator must define the following RNA-Operator Props:
510 * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling.
511 * It is safe to scale by 0, as these factors are used to determine
512 * amount to enlarge 'cur' by
515 /* ------------------ 'Shared' stuff ------------------------ */
517 /* temp customdata for operator */
518 typedef struct v2dViewZoomData {
519 View2D *v2d; /* view2d we're operating in */
522 /* needed for continuous zoom */
524 double timer_lastdraw;
526 int lastx, lasty; /* previous x/y values of mouse in window */
527 int invoke_event; /* event type that invoked, for modal exits */
528 float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
529 float mx_2d, my_2d; /* initial mouse location in v2d coords */
533 /* initialize panning customdata */
534 static int view_zoomdrag_init(bContext *C, wmOperator *op)
536 ARegion *ar = CTX_wm_region(C);
537 v2dViewZoomData *vzd;
540 /* regions now have v2d-data by default, so check for region */
545 /* check that 2d-view is zoomable */
546 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
549 /* set custom-data for operator */
550 vzd = MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
551 op->customdata = vzd;
553 /* set pointers to owners */
560 /* check if step-zoom can be applied */
561 static int view_zoom_poll(bContext *C)
563 ARegion *ar = CTX_wm_region(C);
566 /* check if there's a region in context to work with */
571 /* check that 2d-view is zoomable */
572 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
575 /* view is zoomable */
579 /* apply transform to view (i.e. adjust 'cur' rect) */
580 static void view_zoomstep_apply(bContext *C, wmOperator *op)
582 v2dViewZoomData *vzd = op->customdata;
583 ARegion *ar = CTX_wm_region(C);
584 View2D *v2d = &ar->v2d;
585 float dx, dy, facx, facy;
587 /* calculate amount to move view by, ensuring symmetry so the
588 * old zoom level is restored after zooming back the same amount
590 facx = RNA_float_get(op->ptr, "zoomfacx");
591 facy = RNA_float_get(op->ptr, "zoomfacy");
594 dx = BLI_rctf_size_x(&v2d->cur) * facx;
595 dy = BLI_rctf_size_y(&v2d->cur) * facy;
598 dx = (BLI_rctf_size_x(&v2d->cur) / (1.0f + 2.0f * facx)) * facx;
599 dy = (BLI_rctf_size_y(&v2d->cur) / (1.0f + 2.0f * facy)) * facy;
602 /* only resize view on an axis if change is allowed */
603 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
604 if (v2d->keepofs & V2D_LOCKOFS_X) {
605 v2d->cur.xmax -= 2 * dx;
607 else if (v2d->keepofs & V2D_KEEPOFS_X) {
608 if (v2d->align & V2D_ALIGN_NO_POS_X)
609 v2d->cur.xmin += 2 * dx;
611 v2d->cur.xmax -= 2 * dx;
614 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
615 float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
616 float mval_faci = 1.0f - mval_fac;
617 float ofs = (mval_fac * dx) - (mval_faci * dx);
619 v2d->cur.xmin += ofs + dx;
620 v2d->cur.xmax += ofs - dx;
628 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
629 if (v2d->keepofs & V2D_LOCKOFS_Y) {
630 v2d->cur.ymax -= 2 * dy;
632 else if (v2d->keepofs & V2D_KEEPOFS_Y) {
633 if (v2d->align & V2D_ALIGN_NO_POS_Y)
634 v2d->cur.ymin += 2 * dy;
636 v2d->cur.ymax -= 2 * dy;
639 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
640 float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
641 float mval_faci = 1.0f - mval_fac;
642 float ofs = (mval_fac * dy) - (mval_faci * dy);
644 v2d->cur.ymin += ofs + dy;
645 v2d->cur.ymax += ofs - dy;
654 /* validate that view is in valid configuration after this operation */
655 UI_view2d_curRect_validate(v2d);
657 /* request updates to be done... */
658 ED_region_tag_redraw(vzd->ar);
659 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
662 /* --------------- Individual Operators ------------------- */
664 /* cleanup temp customdata */
665 static void view_zoomstep_exit(wmOperator *op)
667 if (op->customdata) {
668 MEM_freeN(op->customdata);
669 op->customdata = NULL;
673 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
674 static int view_zoomin_exec(bContext *C, wmOperator *op)
676 ScrArea *sa = CTX_wm_area(C);
677 short do_zoom_x = TRUE;
678 short do_zoom_y = TRUE;
680 /* check that there's an active region, as View2D data resides there */
681 if (!view_zoom_poll(C))
682 return OPERATOR_PASS_THROUGH;
684 /* default not to zoom the sequencer vertically */
685 if (sa && sa->spacetype == SPACE_SEQ) {
686 ARegion *ar = CTX_wm_region(C);
688 if (ar && ar->regiontype != RGN_TYPE_PREVIEW)
692 /* set RNA-Props - zooming in by uniform factor */
693 RNA_float_set(op->ptr, "zoomfacx", do_zoom_x ? 0.0375f : 0.0f);
694 RNA_float_set(op->ptr, "zoomfacy", do_zoom_y ? 0.0375f : 0.0f);
696 /* apply movement, then we're done */
697 view_zoomstep_apply(C, op);
699 view_zoomstep_exit(op);
701 return OPERATOR_FINISHED;
704 static int view_zoomin_invoke(bContext *C, wmOperator *op, const wmEvent *event)
706 v2dViewZoomData *vzd;
708 if (!view_zoomdrag_init(C, op))
709 return OPERATOR_PASS_THROUGH;
711 vzd = op->customdata;
713 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
714 ARegion *ar = CTX_wm_region(C);
716 /* store initial mouse position (in view space) */
717 UI_view2d_region_to_view(&ar->v2d,
718 event->mval[0], event->mval[1],
719 &vzd->mx_2d, &vzd->my_2d);
722 return view_zoomin_exec(C, op);
725 static void VIEW2D_OT_zoom_in(wmOperatorType *ot)
728 ot->name = "Zoom In";
729 ot->description = "Zoom in the view";
730 ot->idname = "VIEW2D_OT_zoom_in";
733 ot->invoke = view_zoomin_invoke;
734 ot->exec = view_zoomin_exec; // XXX, needs view_zoomdrag_init called first.
735 ot->poll = view_zoom_poll;
737 /* rna - must keep these in sync with the other operators */
738 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
739 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
742 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
743 static int view_zoomout_exec(bContext *C, wmOperator *op)
745 ScrArea *sa = CTX_wm_area(C);
746 short do_zoom_x = TRUE;
747 short do_zoom_y = TRUE;
749 /* check that there's an active region, as View2D data resides there */
750 if (!view_zoom_poll(C))
751 return OPERATOR_PASS_THROUGH;
753 /* default not to zoom the sequencer vertically */
754 if (sa && sa->spacetype == SPACE_SEQ) {
755 ARegion *ar = CTX_wm_region(C);
757 if (ar && ar->regiontype != RGN_TYPE_PREVIEW)
761 /* set RNA-Props - zooming in by uniform factor */
762 RNA_float_set(op->ptr, "zoomfacx", do_zoom_x ? -0.0375f : 0.0f);
763 RNA_float_set(op->ptr, "zoomfacy", do_zoom_y ? -0.0375f : 0.0f);
765 /* apply movement, then we're done */
766 view_zoomstep_apply(C, op);
768 view_zoomstep_exit(op);
770 return OPERATOR_FINISHED;
773 static int view_zoomout_invoke(bContext *C, wmOperator *op, const wmEvent *event)
775 v2dViewZoomData *vzd;
777 if (!view_zoomdrag_init(C, op))
778 return OPERATOR_PASS_THROUGH;
780 vzd = op->customdata;
782 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
783 ARegion *ar = CTX_wm_region(C);
785 /* store initial mouse position (in view space) */
786 UI_view2d_region_to_view(&ar->v2d,
787 event->mval[0], event->mval[1],
788 &vzd->mx_2d, &vzd->my_2d);
791 return view_zoomout_exec(C, op);
794 static void VIEW2D_OT_zoom_out(wmOperatorType *ot)
797 ot->name = "Zoom Out";
798 ot->description = "Zoom out the view";
799 ot->idname = "VIEW2D_OT_zoom_out";
802 ot->invoke = view_zoomout_invoke;
803 // ot->exec = view_zoomout_exec; // XXX, needs view_zoomdrag_init called first.
804 ot->poll = view_zoom_poll;
806 /* rna - must keep these in sync with the other operators */
807 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
808 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
811 /* ********************************************************* */
812 /* DRAG-ZOOM OPERATOR */
814 /* MMB Drag - allows non-uniform scaling by dragging mouse
816 * In order to make sure this works, each operator must define the following RNA-Operator Props:
817 * deltax, deltay - amounts to add to each side of the 'cur' rect
820 /* apply transform to view (i.e. adjust 'cur' rect) */
821 static void view_zoomdrag_apply(bContext *C, wmOperator *op)
823 v2dViewZoomData *vzd = op->customdata;
824 View2D *v2d = vzd->v2d;
827 /* get amount to move view by */
828 dx = RNA_float_get(op->ptr, "deltax");
829 dy = RNA_float_get(op->ptr, "deltay");
831 if (U.uiflag & USER_ZOOM_INVERT) {
836 /* continuous zoom shouldn't move that fast... */
837 if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
838 double time = PIL_check_seconds_timer();
839 float time_step = (float)(time - vzd->timer_lastdraw);
841 dx *= time_step * 0.5f;
842 dy *= time_step * 0.5f;
844 vzd->timer_lastdraw = time;
847 /* only move view on an axis if change is allowed */
848 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
849 if (v2d->keepofs & V2D_LOCKOFS_X) {
850 v2d->cur.xmax -= 2 * dx;
853 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
854 float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
855 float mval_faci = 1.0f - mval_fac;
856 float ofs = (mval_fac * dx) - (mval_faci * dx);
858 v2d->cur.xmin += ofs + dx;
859 v2d->cur.xmax += ofs - dx;
867 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
868 if (v2d->keepofs & V2D_LOCKOFS_Y) {
869 v2d->cur.ymax -= 2 * dy;
872 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
873 float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
874 float mval_faci = 1.0f - mval_fac;
875 float ofs = (mval_fac * dy) - (mval_faci * dy);
877 v2d->cur.ymin += ofs + dy;
878 v2d->cur.ymax += ofs - dy;
887 /* validate that view is in valid configuration after this operation */
888 UI_view2d_curRect_validate(v2d);
890 /* request updates to be done... */
891 ED_region_tag_redraw(vzd->ar);
892 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
895 /* cleanup temp customdata */
896 static void view_zoomdrag_exit(bContext *C, wmOperator *op)
898 if (op->customdata) {
899 v2dViewZoomData *vzd = op->customdata;
902 WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), vzd->timer);
904 MEM_freeN(op->customdata);
905 op->customdata = NULL;
909 static int view_zoomdrag_cancel(bContext *C, wmOperator *op)
911 view_zoomdrag_exit(C, op);
913 return OPERATOR_CANCELLED;
916 /* for 'redo' only, with no user input */
917 static int view_zoomdrag_exec(bContext *C, wmOperator *op)
919 if (!view_zoomdrag_init(C, op))
920 return OPERATOR_PASS_THROUGH;
922 view_zoomdrag_apply(C, op);
923 view_zoomdrag_exit(C, op);
924 return OPERATOR_FINISHED;
927 /* set up modal operator and relevant settings */
928 static int view_zoomdrag_invoke(bContext *C, wmOperator *op, const wmEvent *event)
930 wmWindow *window = CTX_wm_window(C);
931 v2dViewZoomData *vzd;
934 /* set up customdata */
935 if (!view_zoomdrag_init(C, op))
936 return OPERATOR_PASS_THROUGH;
938 vzd = op->customdata;
941 if (event->type == MOUSEZOOM || event->type == MOUSEPAN) {
944 vzd->lastx = event->prevx;
945 vzd->lasty = event->prevy;
947 /* As we have only 1D information (magnify value), feed both axes
948 * with magnify information that is stored in x axis
950 fac = 0.01f * (event->prevx - event->x);
951 dx = fac * BLI_rctf_size_x(&v2d->cur) / 10.0f;
952 if (event->type == MOUSEPAN)
953 fac = 0.01f * (event->prevy - event->y);
954 dy = fac * BLI_rctf_size_y(&v2d->cur) / 10.0f;
956 /* support trackpad zoom to always zoom entirely - the v2d code uses portrait or landscape exceptions */
957 if (v2d->keepzoom & V2D_KEEPASPECT) {
958 if (fabsf(dx) > fabsf(dy))
963 RNA_float_set(op->ptr, "deltax", dx);
964 RNA_float_set(op->ptr, "deltay", dy);
966 view_zoomdrag_apply(C, op);
967 view_zoomdrag_exit(C, op);
968 return OPERATOR_FINISHED;
971 /* set initial settings */
972 vzd->lastx = event->x;
973 vzd->lasty = event->y;
974 RNA_float_set(op->ptr, "deltax", 0);
975 RNA_float_set(op->ptr, "deltay", 0);
977 /* for modal exit test */
978 vzd->invoke_event = event->type;
980 if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
981 ARegion *ar = CTX_wm_region(C);
983 /* store initial mouse position (in view space) */
984 UI_view2d_region_to_view(&ar->v2d,
985 event->mval[0], event->mval[1],
986 &vzd->mx_2d, &vzd->my_2d);
989 if (v2d->keepofs & V2D_LOCKOFS_X)
990 WM_cursor_modal_set(window, BC_NS_SCROLLCURSOR);
991 else if (v2d->keepofs & V2D_LOCKOFS_Y)
992 WM_cursor_modal_set(window, BC_EW_SCROLLCURSOR);
994 WM_cursor_modal_set(window, BC_NSEW_SCROLLCURSOR);
996 /* add temp handler */
997 WM_event_add_modal_handler(C, op);
999 if (U.viewzoom == USER_ZOOM_CONT) {
1000 /* needs a timer to continue redrawing */
1001 vzd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
1002 vzd->timer_lastdraw = PIL_check_seconds_timer();
1005 return OPERATOR_RUNNING_MODAL;
1008 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
1009 static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event)
1011 v2dViewZoomData *vzd = op->customdata;
1012 View2D *v2d = vzd->v2d;
1014 /* execute the events */
1015 if (event->type == TIMER && event->customdata == vzd->timer) {
1016 view_zoomdrag_apply(C, op);
1018 else if (event->type == MOUSEMOVE) {
1021 /* calculate new delta transform, based on zooming mode */
1022 if (U.viewzoom == USER_ZOOM_SCALE) {
1023 /* 'scale' zooming */
1026 /* x-axis transform */
1027 dist = BLI_rcti_size_x(&v2d->mask) / 2.0f;
1028 dx = 1.0f - (fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist) + 2.0f) / (fabsf(event->mval[0] - dist) + 2.0f);
1029 dx *= 0.5f * BLI_rctf_size_x(&v2d->cur);
1031 /* y-axis transform */
1032 dist = BLI_rcti_size_y(&v2d->mask) / 2.0f;
1033 dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / (fabsf(event->mval[1] - dist) + 2.0f);
1034 dy *= 0.5f * BLI_rctf_size_y(&v2d->cur);
1037 /* 'continuous' or 'dolly' */
1038 float fac, zoomfac = 0.01f;
1040 /* some view2d's (graph) don't have min/max zoom, or extreme ones */
1041 if (v2d->maxzoom > 0.0f)
1042 zoomfac = CLAMPIS(0.001f * v2d->maxzoom, 0.001f, 0.01f);
1044 /* x-axis transform */
1045 fac = zoomfac * (event->x - vzd->lastx);
1046 dx = fac * BLI_rctf_size_x(&v2d->cur);
1048 /* y-axis transform */
1049 fac = zoomfac * (event->y - vzd->lasty);
1050 dy = fac * BLI_rctf_size_y(&v2d->cur);
1054 /* support zoom to always zoom entirely - the v2d code uses portrait or landscape exceptions */
1055 if (v2d->keepzoom & V2D_KEEPASPECT) {
1056 if (fabsf(dx) > fabsf(dy))
1062 /* set transform amount, and add current deltas to stored total delta (for redo) */
1063 RNA_float_set(op->ptr, "deltax", dx);
1064 RNA_float_set(op->ptr, "deltay", dy);
1069 /* store mouse coordinates for next time, if not doing continuous zoom
1070 * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
1072 if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
1073 vzd->lastx = event->x;
1074 vzd->lasty = event->y;
1078 view_zoomdrag_apply(C, op);
1080 else if (event->type == vzd->invoke_event || event->type == ESCKEY) {
1081 if (event->val == KM_RELEASE) {
1083 /* for redo, store the overall deltas - need to respect zoom-locks here... */
1084 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0)
1085 RNA_float_set(op->ptr, "deltax", vzd->dx);
1087 RNA_float_set(op->ptr, "deltax", 0);
1089 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0)
1090 RNA_float_set(op->ptr, "deltay", vzd->dy);
1092 RNA_float_set(op->ptr, "deltay", 0);
1094 /* free customdata */
1095 view_zoomdrag_exit(C, op);
1096 WM_cursor_modal_restore(CTX_wm_window(C));
1098 return OPERATOR_FINISHED;
1102 return OPERATOR_RUNNING_MODAL;
1105 static void VIEW2D_OT_zoom(wmOperatorType *ot)
1108 ot->name = "Zoom 2D View";
1109 ot->description = "Zoom in/out the view";
1110 ot->idname = "VIEW2D_OT_zoom";
1113 ot->exec = view_zoomdrag_exec;
1114 ot->invoke = view_zoomdrag_invoke;
1115 ot->modal = view_zoomdrag_modal;
1116 ot->cancel = view_zoomdrag_cancel;
1118 ot->poll = view_zoom_poll;
1120 /* operator is repeatable */
1121 ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
1123 /* rna - must keep these in sync with the other operators */
1124 RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
1125 RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
1128 /* ********************************************************* */
1131 /* The user defines a rect using standard borderselect tools, and we use this rect to
1132 * define the new zoom-level of the view in the following ways:
1133 * 1) LEFTMOUSE - zoom in to view
1134 * 2) RIGHTMOUSE - zoom out of view
1136 * Currently, these key mappings are hardcoded, but it shouldn't be too important to
1137 * have custom keymappings for this...
1140 static int view_borderzoom_exec(bContext *C, wmOperator *op)
1142 ARegion *ar = CTX_wm_region(C);
1143 View2D *v2d = &ar->v2d;
1145 rctf cur_new = v2d->cur;
1148 /* convert coordinates of rect to 'tot' rect coordinates */
1149 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
1150 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
1152 /* check if zooming in/out view */
1153 gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
1155 if (gesture_mode == GESTURE_MODAL_IN) {
1157 * - 'cur' rect will be defined by the coordinates of the border region
1158 * - just set the 'cur' rect to have the same coordinates as the border region
1159 * if zoom is allowed to be changed
1161 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1162 cur_new.xmin = rect.xmin;
1163 cur_new.xmax = rect.xmax;
1165 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1166 cur_new.ymin = rect.ymin;
1167 cur_new.ymax = rect.ymax;
1170 else { /* if (gesture_mode == GESTURE_MODAL_OUT) */
1173 * - the current 'cur' rect coordinates are going to end up where the 'rect' ones are,
1174 * but the 'cur' rect coordinates will need to be adjusted to take in more of the view
1175 * - calculate zoom factor, and adjust using center-point
1177 float zoom, center, size;
1179 /* TODO: is this zoom factor calculation valid? It seems to produce same results every time... */
1180 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
1181 size = BLI_rctf_size_x(&cur_new);
1182 zoom = size / BLI_rctf_size_x(&rect);
1183 center = BLI_rctf_cent_x(&cur_new);
1185 cur_new.xmin = center - (size * zoom);
1186 cur_new.xmax = center + (size * zoom);
1188 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
1189 size = BLI_rctf_size_y(&cur_new);
1190 zoom = size / BLI_rctf_size_y(&rect);
1191 center = BLI_rctf_cent_y(&cur_new);
1193 cur_new.ymin = center - (size * zoom);
1194 cur_new.ymax = center + (size * zoom);
1198 UI_view2d_smooth_view(C, ar, &cur_new);
1200 return OPERATOR_FINISHED;
1203 static void VIEW2D_OT_zoom_border(wmOperatorType *ot)
1206 ot->name = "Zoom to Border";
1207 ot->description = "Zoom in the view to the nearest item contained in the border";
1208 ot->idname = "VIEW2D_OT_zoom_border";
1211 ot->invoke = WM_border_select_invoke;
1212 ot->exec = view_borderzoom_exec;
1213 ot->modal = WM_border_select_modal;
1214 ot->cancel = WM_border_select_cancel;
1216 ot->poll = view_zoom_poll;
1219 WM_operator_properties_gesture_border(ot, FALSE);
1222 /* ********************************************************* */
1225 struct SmoothView2DStore {
1226 rctf orig_cur, new_cur;
1228 double time_allowed;
1232 * function to get a factor out of a rectangle
1234 * note: this doesn't always work as well as it might because the target size
1235 * may not be reached because of clamping the desired rect, we _could_
1236 * attempt to clamp the rect before working out the zoom factor but its
1237 * not really worthwhile for the few cases this happens.
1239 static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b)
1241 float size_a[2] = {BLI_rctf_size_x(rect_a),
1242 BLI_rctf_size_y(rect_a)};
1243 float size_b[2] = {BLI_rctf_size_x(rect_b),
1244 BLI_rctf_size_y(rect_b)};
1245 float cent_a[2] = {BLI_rctf_cent_x(rect_a),
1246 BLI_rctf_cent_y(rect_a)};
1247 float cent_b[2] = {BLI_rctf_cent_x(rect_b),
1248 BLI_rctf_cent_y(rect_b)};
1250 float fac_max = 0.0f;
1255 for (i = 0; i < 2; i++) {
1256 /* axis translation normalized to scale */
1257 tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]);
1258 fac_max = max_ff(fac_max, tfac);
1259 if (fac_max >= 1.0f) break;
1261 /* axis scale difference, x2 so doubling or half gives 1.0f */
1262 tfac = (1.0f - (min_ff(size_a[i], size_b[i]) / max_ff(size_a[i], size_b[i]))) * 2.0f;
1263 fac_max = max_ff(fac_max, tfac);
1264 if (fac_max >= 1.0f) break;
1266 return min_ff(fac_max, 1.0f);
1269 /* will start timer if appropriate */
1270 /* the arguments are the desired situation */
1271 void UI_view2d_smooth_view(bContext *C, ARegion *ar,
1274 wmWindowManager *wm = CTX_wm_manager(C);
1275 wmWindow *win = CTX_wm_window(C);
1277 View2D *v2d = &ar->v2d;
1278 struct SmoothView2DStore sms = {{0}};
1282 /* initialize sms */
1283 sms.new_cur = v2d->cur;
1285 /* store the options we want to end with */
1286 if (cur) sms.new_cur = *cur;
1289 fac = smooth_view_rect_to_fac(&v2d->cur, cur);
1292 if (U.smooth_viewtx && fac > FLT_EPSILON) {
1293 int changed = FALSE;
1295 if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == FALSE)
1298 /* The new view is different from the old one
1299 * so animate the view */
1301 sms.orig_cur = v2d->cur;
1303 sms.time_allowed = (double)U.smooth_viewtx / 1000.0;
1305 /* scale the time allowed the change in view */
1306 sms.time_allowed *= (double)fac;
1308 /* keep track of running timer! */
1309 if (v2d->sms == NULL)
1310 v2d->sms = MEM_mallocN(sizeof(struct SmoothView2DStore), "smoothview v2d");
1312 if (v2d->smooth_timer)
1313 WM_event_remove_timer(wm, win, v2d->smooth_timer);
1314 /* TIMER1 is hardcoded in keymap */
1315 v2d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); /* max 30 frs/sec */
1321 /* if we get here nothing happens */
1323 v2d->cur = sms.new_cur;
1325 UI_view2d_curRect_validate(v2d);
1326 ED_region_tag_redraw(ar);
1327 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1331 /* only meant for timer usage */
1332 static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
1334 ARegion *ar = CTX_wm_region(C);
1335 View2D *v2d = &ar->v2d;
1336 struct SmoothView2DStore *sms = v2d->sms;
1339 /* escape if not our timer */
1340 if (v2d->smooth_timer == NULL || v2d->smooth_timer != event->customdata)
1341 return OPERATOR_PASS_THROUGH;
1343 if (sms->time_allowed != 0.0)
1344 step = (float)((v2d->smooth_timer->duration) / sms->time_allowed);
1350 v2d->cur = sms->new_cur;
1352 MEM_freeN(v2d->sms);
1355 WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), v2d->smooth_timer);
1356 v2d->smooth_timer = NULL;
1360 step = (3.0f * step * step - 2.0f * step * step * step);
1362 BLI_rctf_interp(&v2d->cur, &sms->orig_cur, &sms->new_cur, step);
1365 UI_view2d_curRect_validate(v2d);
1366 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1367 ED_region_tag_redraw(ar);
1369 return OPERATOR_FINISHED;
1372 static void VIEW2D_OT_smoothview(wmOperatorType *ot)
1375 ot->name = "Smooth View 2D";
1376 ot->description = "Zoom in the view to the nearest item contained in the border";
1377 ot->idname = "VIEW2D_OT_smoothview";
1380 ot->invoke = view2d_smoothview_invoke;
1382 ot->poll = view2d_poll;
1385 WM_operator_properties_gesture_border(ot, FALSE);
1388 /* ********************************************************* */
1391 /* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
1392 * 1) 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable,
1393 * enlarge 'cur' rect on the relevant side
1394 * 2) 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite)
1396 * In order to make sure this works, each operator must define the following RNA-Operator Props:
1397 * deltax, deltay - define how much to move view by (relative to zoom-correction factor)
1400 /* customdata for scroller-invoke data */
1401 typedef struct v2dScrollerMove {
1402 View2D *v2d; /* View2D data that this operation affects */
1403 ARegion *ar; /* region that the scroller is in */
1405 short scroller; /* scroller that mouse is in ('h' or 'v') */
1406 short zone; /* -1 is min zoomer, 0 is bar, 1 is max zoomer */ // XXX find some way to provide visual feedback of this (active color?)
1408 float fac; /* view adjustment factor, based on size of region */
1409 float delta; /* amount moved by mouse on axis of interest */
1411 float scrollbarwidth; /* width of the scrollbar itself, used for page up/down clicks */
1412 int scrollbar_orig; /* initial location of scrollbar x/y, mouse relative */
1414 int lastx, lasty; /* previous mouse coordinates (in screen coordinates) for determining movement */
1418 /* View2DScrollers is typedef'd in UI_view2d.h
1419 * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info
1420 * WARNING: the start of this struct must not change, so that it stays in sync with the 'real' version
1421 * For now, we don't need to have a separate (internal) header for structs like this...
1423 struct View2DScrollers {
1425 int vert_min, vert_max; /* vertical scrollbar */
1426 int hor_min, hor_max; /* horizontal scrollbar */
1429 /* quick enum for vsm->zone (scroller handles) */
1431 SCROLLHANDLE_MIN = -1,
1434 SCROLLHANDLE_MIN_OUTSIDE,
1435 SCROLLHANDLE_MAX_OUTSIDE
1436 } /*eV2DScrollerHandle_Zone*/;
1438 /* ------------------------ */
1440 /* check if mouse is within scroller handle
1441 * - mouse = relevant mouse coordinate in region space
1442 * - sc_min, sc_max = extents of scroller 'groove' (potential available space for scroller)
1443 * - sh_min, sh_max = positions of scrollbar handles
1445 static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
1447 short in_min, in_max, in_bar, out_min, out_max, in_view = 1;
1449 /* firstly, check if
1450 * - 'bubble' fills entire scroller
1451 * - 'bubble' completely out of view on either side
1453 if ((sh_min <= sc_min) && (sh_max >= sc_max)) in_view = 0;
1454 if (sh_min == sh_max) {
1455 if (sh_min <= sc_min) in_view = 0;
1456 if (sh_max >= sc_max) in_view = 0;
1459 if (sh_max <= sc_min) in_view = 0;
1460 if (sh_min >= sc_max) in_view = 0;
1465 return SCROLLHANDLE_BAR;
1468 /* check if mouse is in or past either handle */
1469 /* TODO: check if these extents are still valid or not */
1470 in_max = ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
1471 in_min = ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
1472 in_bar = ( (mouse < (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse > (sh_min + V2D_SCROLLER_HANDLE_SIZE)) );
1473 out_min = mouse < (sh_min - V2D_SCROLLER_HANDLE_SIZE);
1474 out_max = mouse > (sh_max + V2D_SCROLLER_HANDLE_SIZE);
1477 return SCROLLHANDLE_BAR;
1479 return SCROLLHANDLE_MAX;
1481 return SCROLLHANDLE_MIN;
1483 return SCROLLHANDLE_MIN_OUTSIDE;
1485 return SCROLLHANDLE_MAX_OUTSIDE;
1487 /* unlikely to happen, though we just cover it in case */
1488 return SCROLLHANDLE_BAR;
1491 /* initialize customdata for scroller manipulation operator */
1492 static void scroller_activate_init(bContext *C, wmOperator *op, const wmEvent *event, short in_scroller)
1494 v2dScrollerMove *vsm;
1495 View2DScrollers *scrollers;
1496 ARegion *ar = CTX_wm_region(C);
1497 View2D *v2d = &ar->v2d;
1501 /* set custom-data for operator */
1502 vsm = MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove");
1503 op->customdata = vsm;
1505 /* set general data */
1508 vsm->scroller = in_scroller;
1510 /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
1511 vsm->lastx = event->x;
1512 vsm->lasty = event->y;
1513 /* 'zone' depends on where mouse is relative to bubble
1514 * - zooming must be allowed on this axis, otherwise, default to pan
1516 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1518 /* use a union of 'cur' & 'tot' incase the current view is far outside 'tot'.
1519 * In this cases moving the scroll bars has far too little effect and the view can get stuck [#31476] */
1520 tot_cur_union = v2d->tot;
1521 BLI_rctf_union(&tot_cur_union, &v2d->cur);
1523 if (in_scroller == 'h') {
1524 /* horizontal scroller - calculate adjustment factor first */
1525 mask_size = (float)BLI_rcti_size_x(&v2d->hor);
1526 vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size;
1528 /* get 'zone' (i.e. which part of scroller is activated) */
1529 vsm->zone = mouse_in_scroller_handle(event->mval[0],
1530 v2d->hor.xmin, v2d->hor.xmax,
1531 scrollers->hor_min, scrollers->hor_max);
1533 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
1534 /* default to scroll, as handles not usable */
1535 vsm->zone = SCROLLHANDLE_BAR;
1538 vsm->scrollbarwidth = scrollers->hor_max - scrollers->hor_min;
1539 vsm->scrollbar_orig = ((scrollers->hor_max + scrollers->hor_min) / 2) + ar->winrct.xmin;
1542 /* vertical scroller - calculate adjustment factor first */
1543 mask_size = (float)BLI_rcti_size_y(&v2d->vert);
1544 vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size;
1546 /* get 'zone' (i.e. which part of scroller is activated) */
1547 vsm->zone = mouse_in_scroller_handle(event->mval[1],
1548 v2d->vert.ymin, v2d->vert.ymax,
1549 scrollers->vert_min, scrollers->vert_max);
1551 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
1552 /* default to scroll, as handles not usable */
1553 vsm->zone = SCROLLHANDLE_BAR;
1556 vsm->scrollbarwidth = scrollers->vert_max - scrollers->vert_min;
1557 vsm->scrollbar_orig = ((scrollers->vert_max + scrollers->vert_min) / 2) + ar->winrct.ymin;
1560 UI_view2d_scrollers_free(scrollers);
1561 ED_region_tag_redraw(ar);
1564 /* cleanup temp customdata */
1565 static void scroller_activate_exit(bContext *C, wmOperator *op)
1567 if (op->customdata) {
1568 v2dScrollerMove *vsm = op->customdata;
1570 vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE | V2D_SCROLL_V_ACTIVE);
1572 MEM_freeN(op->customdata);
1573 op->customdata = NULL;
1575 ED_region_tag_redraw(CTX_wm_region(C));
1579 static int scroller_activate_cancel(bContext *C, wmOperator *op)
1581 scroller_activate_exit(C, op);
1583 return OPERATOR_CANCELLED;
1586 /* apply transform to view (i.e. adjust 'cur' rect) */
1587 static void scroller_activate_apply(bContext *C, wmOperator *op)
1589 v2dScrollerMove *vsm = op->customdata;
1590 View2D *v2d = vsm->v2d;
1593 /* calculate amount to move view by */
1594 temp = vsm->fac * vsm->delta;
1596 /* type of movement */
1597 switch (vsm->zone) {
1598 case SCROLLHANDLE_MIN:
1599 /* only expand view on axis if zoom is allowed */
1600 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1601 v2d->cur.xmin -= temp;
1602 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1603 v2d->cur.ymin -= temp;
1606 case SCROLLHANDLE_MAX:
1608 /* only expand view on axis if zoom is allowed */
1609 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1610 v2d->cur.xmax += temp;
1611 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1612 v2d->cur.ymax += temp;
1615 case SCROLLHANDLE_MIN_OUTSIDE:
1616 case SCROLLHANDLE_MAX_OUTSIDE:
1617 case SCROLLHANDLE_BAR:
1619 /* only move view on an axis if panning is allowed */
1620 if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
1621 v2d->cur.xmin += temp;
1622 v2d->cur.xmax += temp;
1624 if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
1625 v2d->cur.ymin += temp;
1626 v2d->cur.ymax += temp;
1632 /* validate that view is in valid configuration after this operation */
1633 UI_view2d_curRect_validate(v2d);
1635 /* request updates to be done... */
1636 ED_region_tag_redraw(vsm->ar);
1637 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1640 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
1641 static int scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *event)
1643 v2dScrollerMove *vsm = op->customdata;
1645 /* execute the events */
1646 switch (event->type) {
1649 /* calculate new delta transform, then store mouse-coordinates for next-time */
1650 if (ELEM(vsm->zone, SCROLLHANDLE_BAR, SCROLLHANDLE_MAX)) {
1651 /* if using bar (i.e. 'panning') or 'max' zoom widget */
1652 switch (vsm->scroller) {
1653 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
1654 vsm->delta = (float)(event->x - vsm->lastx);
1656 case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
1657 vsm->delta = (float)(event->y - vsm->lasty);
1661 else if (vsm->zone == SCROLLHANDLE_MIN) {
1662 /* using 'min' zoom widget */
1663 switch (vsm->scroller) {
1664 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
1665 vsm->delta = (float)(vsm->lastx - event->x);
1667 case 'v': /* vertical scroller - so only vertical movement ('cur' moves with to mouse) */
1668 vsm->delta = (float)(vsm->lasty - event->y);
1673 /* store previous coordinates */
1674 vsm->lastx = event->x;
1675 vsm->lasty = event->y;
1677 scroller_activate_apply(C, op);
1682 if (event->val == KM_RELEASE) {
1683 /* single-click was in empty space outside bubble, so scroll by 1 'page' */
1684 if (ELEM(vsm->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
1685 if (vsm->zone == SCROLLHANDLE_MIN_OUTSIDE)
1686 vsm->delta = -vsm->scrollbarwidth * 0.8f;
1687 else if (vsm->zone == SCROLLHANDLE_MAX_OUTSIDE)
1688 vsm->delta = vsm->scrollbarwidth * 0.8f;
1690 scroller_activate_apply(C, op);
1691 scroller_activate_exit(C, op);
1692 return OPERATOR_FINISHED;
1695 /* otherwise, end the drag action */
1696 if (vsm->lastx || vsm->lasty) {
1697 scroller_activate_exit(C, op);
1698 return OPERATOR_FINISHED;
1705 return OPERATOR_RUNNING_MODAL;
1709 /* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
1710 static int scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1712 ARegion *ar = CTX_wm_region(C);
1713 View2D *v2d = &ar->v2d;
1714 short in_scroller = 0;
1716 /* check if mouse in scrollbars, if they're enabled */
1717 in_scroller = UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
1719 /* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
1721 v2dScrollerMove *vsm;
1723 /* initialize customdata */
1724 scroller_activate_init(C, op, event, in_scroller);
1725 vsm = (v2dScrollerMove *)op->customdata;
1727 /* support for quick jump to location - gtk and qt do this on linux */
1728 if (event->type == MIDDLEMOUSE) {
1729 switch (vsm->scroller) {
1730 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
1731 vsm->delta = (float)(event->x - vsm->scrollbar_orig);
1733 case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
1734 vsm->delta = (float)(event->y - vsm->scrollbar_orig);
1737 scroller_activate_apply(C, op);
1739 vsm->zone = SCROLLHANDLE_BAR;
1742 /* check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue
1743 * NOTE: see view2d.c for latest conditions, and keep this in sync with that
1745 if (ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
1746 if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) ||
1747 ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0))
1749 /* switch to bar (i.e. no scaling gets handled) */
1750 vsm->zone = SCROLLHANDLE_BAR;
1754 /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
1755 if (vsm->zone == SCROLLHANDLE_BAR) {
1756 if (((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
1757 ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y)))
1759 /* free customdata initialized */
1760 scroller_activate_exit(C, op);
1762 /* can't catch this event for ourselves, so let it go to someone else? */
1763 return OPERATOR_PASS_THROUGH;
1767 /* zone is also inappropriate if scroller is not visible... */
1768 if (((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_FULLR))) ||
1769 ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_FULLR))) )
1771 /* free customdata initialized */
1772 scroller_activate_exit(C, op);
1774 /* can't catch this event for ourselves, so let it go to someone else? */
1775 /* XXX note: if handlers use mask rect to clip input, input will fail for this case */
1776 return OPERATOR_PASS_THROUGH;
1779 /* activate the scroller */
1780 if (vsm->scroller == 'h')
1781 v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE;
1783 v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE;
1785 /* still ok, so can add */
1786 WM_event_add_modal_handler(C, op);
1787 return OPERATOR_RUNNING_MODAL;
1790 /* not in scroller, so nothing happened... (pass through let's something else catch event) */
1791 return OPERATOR_PASS_THROUGH;
1795 /* LMB-Drag in Scrollers - not repeatable operator! */
1796 static void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
1799 ot->name = "Scroller Activate";
1800 ot->description = "Scroll view by mouse click and drag";
1801 ot->idname = "VIEW2D_OT_scroller_activate";
1804 ot->flag = OPTYPE_BLOCKING;
1807 ot->invoke = scroller_activate_invoke;
1808 ot->modal = scroller_activate_modal;
1809 ot->cancel = scroller_activate_cancel;
1811 ot->poll = view2d_poll;
1814 /* ********************************************************* */
1817 static int reset_exec(bContext *C, wmOperator *UNUSED(op))
1819 uiStyle *style = UI_GetStyle();
1820 ARegion *ar = CTX_wm_region(C);
1821 View2D *v2d = &ar->v2d;
1825 winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1);
1826 winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1);
1828 v2d->cur.xmax = v2d->cur.xmin + winx;
1829 v2d->cur.ymax = v2d->cur.ymin + winy;
1833 /* posx and negx flags are mutually exclusive, so watch out */
1834 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
1835 v2d->cur.xmax = 0.0f;
1836 v2d->cur.xmin = -winx * style->panelzoom;
1838 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
1839 v2d->cur.xmax = winx * style->panelzoom;
1840 v2d->cur.xmin = 0.0f;
1843 /* - posx and negx flags are mutually exclusive, so watch out */
1844 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1845 v2d->cur.ymax = 0.0f;
1846 v2d->cur.ymin = -winy * style->panelzoom;
1848 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
1849 v2d->cur.ymax = winy * style->panelzoom;
1850 v2d->cur.ymin = 0.0f;
1854 /* validate that view is in valid configuration after this operation */
1855 UI_view2d_curRect_validate(v2d);
1857 /* request updates to be done... */
1858 ED_region_tag_redraw(ar);
1859 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1861 return OPERATOR_FINISHED;
1864 static void VIEW2D_OT_reset(wmOperatorType *ot)
1867 ot->name = "Reset View";
1868 ot->description = "Reset the view";
1869 ot->idname = "VIEW2D_OT_reset";
1872 ot->exec = reset_exec;
1873 ot->poll = view2d_poll;
1876 /* ********************************************************* */
1879 void UI_view2d_operatortypes(void)
1881 WM_operatortype_append(VIEW2D_OT_pan);
1883 WM_operatortype_append(VIEW2D_OT_scroll_left);
1884 WM_operatortype_append(VIEW2D_OT_scroll_right);
1885 WM_operatortype_append(VIEW2D_OT_scroll_up);
1886 WM_operatortype_append(VIEW2D_OT_scroll_down);
1888 WM_operatortype_append(VIEW2D_OT_zoom_in);
1889 WM_operatortype_append(VIEW2D_OT_zoom_out);
1891 WM_operatortype_append(VIEW2D_OT_zoom);
1892 WM_operatortype_append(VIEW2D_OT_zoom_border);
1894 WM_operatortype_append(VIEW2D_OT_smoothview);
1896 WM_operatortype_append(VIEW2D_OT_scroller_activate);
1898 WM_operatortype_append(VIEW2D_OT_reset);
1901 void UI_view2d_keymap(wmKeyConfig *keyconf)
1903 wmKeyMap *keymap = WM_keymap_find(keyconf, "View2D", 0, 0);
1907 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
1908 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", MIDDLEMOUSE, KM_PRESS, 0, 0);
1911 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1912 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
1914 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MOUSEPAN, 0, 0, 0);
1916 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
1917 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
1919 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
1920 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
1922 /* zoom - single step */
1923 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
1924 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
1925 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1926 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1927 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEPAN, 0, KM_CTRL, 0);
1929 WM_keymap_verify_item(keymap, "VIEW2D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
1931 /* scroll up/down - no modifiers, only when zoom fails */
1932 /* these may fail if zoom is disallowed, in which case they should pass on event */
1933 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1934 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1935 /* these may be necessary if vertical scroll is disallowed */
1936 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1937 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, 0, 0);
1939 /* alternatives for page up/down to scroll */
1940 #if 0 // XXX disabled, since this causes conflicts with hotkeys in animation editors
1941 /* scroll up/down may fall through to left/right */
1942 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
1943 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
1944 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", PAGEDOWNKEY, KM_PRESS, 0, 0);
1945 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", PAGEUPKEY, KM_PRESS, 0, 0);
1946 /* shift for moving view left/right with page up/down */
1947 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0);
1948 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0);
1952 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1953 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
1955 /* borderzoom - drag */
1956 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
1958 /* Alternative keymap for buttons listview */
1959 keymap = WM_keymap_find(keyconf, "View2D Buttons List", 0, 0);
1961 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
1962 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", MIDDLEMOUSE, KM_PRESS, 0, 0);
1964 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1965 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MOUSEPAN, 0, 0, 0);
1966 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1967 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1969 kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
1970 RNA_boolean_set(kmi->ptr, "page", TRUE);
1971 kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
1972 RNA_boolean_set(kmi->ptr, "page", TRUE);
1974 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1975 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
1976 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEPAN, 0, KM_CTRL, 0);
1977 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1978 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1979 WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);