4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, Joshua Leung
25 * ***** END GPL LICENSE BLOCK *****
30 #include "MEM_guardedalloc.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_screen_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_userdef_types.h"
36 #include "DNA_vec_types.h"
37 #include "DNA_view2d_types.h"
39 #include "BLI_blenlib.h"
41 #include "BKE_context.h"
42 #include "BKE_utildefines.h"
44 #include "RNA_access.h"
45 #include "RNA_define.h"
52 #include "ED_screen.h"
54 #include "UI_resources.h"
55 #include "UI_view2d.h"
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 View2D *v2d; /* view2d we're operating in */
83 float facx, facy; /* amount to move view relative to zoom */
85 /* options for version 1 */
86 int startx, starty; /* mouse x/y values in window when operator was initiated */
87 int lastx, lasty; /* previous x/y values of mouse in window */
89 short in_scroller; /* for MMB in scrollers (old feature in past, but now not that useful) */
92 /* initialise panning customdata */
93 static int view_pan_init(bContext *C, wmOperator *op)
95 ARegion *ar= CTX_wm_region(C);
100 /* regions now have v2d-data by default, so check for region */
104 /* check if panning is allowed at all */
106 if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y))
109 /* set custom-data for operator */
110 vpd= MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData");
113 /* set pointers to owners */
114 vpd->sc= CTX_wm_screen(C);
115 vpd->sa= CTX_wm_area(C);
118 /* calculate translation factor - based on size of view */
119 winx= (float)(ar->winrct.xmax - ar->winrct.xmin + 1);
120 winy= (float)(ar->winrct.ymax - ar->winrct.ymin + 1);
121 vpd->facx= (v2d->cur.xmax - v2d->cur.xmin) / winx;
122 vpd->facy= (v2d->cur.ymax - v2d->cur.ymin) / winy;
127 /* apply transform to view (i.e. adjust 'cur' rect) */
128 static void view_pan_apply(bContext *C, wmOperator *op)
130 v2dViewPanData *vpd= op->customdata;
131 View2D *v2d= vpd->v2d;
134 /* calculate amount to move view by */
135 dx= vpd->facx * (float)RNA_int_get(op->ptr, "deltax");
136 dy= vpd->facy * (float)RNA_int_get(op->ptr, "deltay");
138 /* only move view on an axis if change is allowed */
139 if ((v2d->keepofs & V2D_LOCKOFS_X)==0) {
143 if ((v2d->keepofs & V2D_LOCKOFS_Y)==0) {
148 /* validate that view is in valid configuration after this operation */
149 UI_view2d_curRect_validate(v2d);
151 /* request updates to be done... */
152 ED_area_tag_redraw(vpd->sa);
153 UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY);
156 /* cleanup temp customdata */
157 static void view_pan_exit(bContext *C, wmOperator *op)
159 if (op->customdata) {
160 MEM_freeN(op->customdata);
161 op->customdata= NULL;
165 /* ------------------ Modal Drag Version (1) ---------------------- */
167 /* for 'redo' only, with no user input */
168 static int view_pan_exec(bContext *C, wmOperator *op)
170 if (!view_pan_init(C, op))
171 return OPERATOR_CANCELLED;
173 view_pan_apply(C, op);
174 view_pan_exit(C, op);
175 return OPERATOR_FINISHED;
178 /* set up modal operator and relevant settings */
179 static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
181 wmWindow *window= CTX_wm_window(C);
185 /* set up customdata */
186 if (!view_pan_init(C, op))
187 return OPERATOR_PASS_THROUGH;
192 /* set initial settings */
193 vpd->startx= vpd->lastx= event->x;
194 vpd->starty= vpd->lasty= event->y;
195 RNA_int_set(op->ptr, "deltax", 0);
196 RNA_int_set(op->ptr, "deltay", 0);
198 if (v2d->keepofs & V2D_LOCKOFS_X)
199 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
200 else if (v2d->keepofs & V2D_LOCKOFS_Y)
201 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
203 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
205 /* add temp handler */
206 WM_event_add_modal_handler(C, &window->handlers, op);
208 return OPERATOR_RUNNING_MODAL;
211 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
212 static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
214 v2dViewPanData *vpd= op->customdata;
216 /* execute the events */
217 switch (event->type) {
220 /* calculate new delta transform, then store mouse-coordinates for next-time */
221 RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
222 RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
224 vpd->lastx= event->x;
225 vpd->lasty= event->y;
227 view_pan_apply(C, op);
233 /* calculate overall delta mouse-movement for redo */
234 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
235 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
237 view_pan_exit(C, op);
238 WM_cursor_restore(CTX_wm_window(C));
240 return OPERATOR_FINISHED;
245 return OPERATOR_RUNNING_MODAL;
248 void VIEW2D_OT_pan(wmOperatorType *ot)
251 ot->name= "Pan View";
252 ot->idname= "VIEW2D_OT_pan";
255 ot->exec= view_pan_exec;
256 ot->invoke= view_pan_invoke;
257 ot->modal= view_pan_modal;
259 /* operator is repeatable */
260 ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
262 /* rna - must keep these in sync with the other operators */
263 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
264 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
267 /* ------------------ Scrollwheel Versions (2) ---------------------- */
269 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
270 static int view_scrollright_exec(bContext *C, wmOperator *op)
274 /* initialise default settings (and validate if ok to run) */
275 if (!view_pan_init(C, op))
276 return OPERATOR_PASS_THROUGH;
278 /* also, check if can pan in horizontal axis */
280 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
281 view_pan_exit(C, op);
282 return OPERATOR_PASS_THROUGH;
285 /* set RNA-Props - only movement in positive x-direction */
286 RNA_int_set(op->ptr, "deltax", 20);
287 RNA_int_set(op->ptr, "deltay", 0);
289 /* apply movement, then we're done */
290 view_pan_apply(C, op);
291 view_pan_exit(C, op);
293 return OPERATOR_FINISHED;
296 void VIEW2D_OT_scroll_right(wmOperatorType *ot)
299 ot->name= "Scroll Right";
300 ot->idname= "VIEW2D_OT_scroll_right";
303 ot->exec= view_scrollright_exec;
305 /* operator is repeatable */
306 ot->flag= OPTYPE_REGISTER;
308 /* rna - must keep these in sync with the other operators */
309 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
310 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
315 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
316 static int view_scrollleft_exec(bContext *C, wmOperator *op)
320 /* initialise default settings (and validate if ok to run) */
321 if (!view_pan_init(C, op))
322 return OPERATOR_PASS_THROUGH;
324 /* also, check if can pan in horizontal axis */
326 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
327 view_pan_exit(C, op);
328 return OPERATOR_PASS_THROUGH;
331 /* set RNA-Props - only movement in negative x-direction */
332 RNA_int_set(op->ptr, "deltax", -20);
333 RNA_int_set(op->ptr, "deltay", 0);
335 /* apply movement, then we're done */
336 view_pan_apply(C, op);
337 view_pan_exit(C, op);
339 return OPERATOR_FINISHED;
342 void VIEW2D_OT_scroll_left(wmOperatorType *ot)
345 ot->name= "Scroll Left";
346 ot->idname= "VIEW2D_OT_scroll_left";
349 ot->exec= view_scrollleft_exec;
351 /* operator is repeatable */
352 ot->flag= OPTYPE_REGISTER;
354 /* rna - must keep these in sync with the other operators */
355 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
356 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 callsthe view_pan_*() methods */
361 static int view_scrolldown_exec(bContext *C, wmOperator *op)
365 /* initialise 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 vertical axis */
371 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
372 view_pan_exit(C, op);
373 return OPERATOR_PASS_THROUGH;
377 RNA_int_set(op->ptr, "deltax", 0);
378 RNA_int_set(op->ptr, "deltay", -20);
380 /* apply movement, then we're done */
381 view_pan_apply(C, op);
382 view_pan_exit(C, op);
384 return OPERATOR_FINISHED;
387 void VIEW2D_OT_scroll_down(wmOperatorType *ot)
390 ot->name= "Scroll Down";
391 ot->idname= "VIEW2D_OT_scroll_down";
394 ot->exec= view_scrolldown_exec;
396 /* operator is repeatable */
397 ot->flag= OPTYPE_REGISTER;
399 /* rna - must keep these in sync with the other operators */
400 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
401 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
406 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
407 static int view_scrollup_exec(bContext *C, wmOperator *op)
411 /* initialise default settings (and validate if ok to run) */
412 if (!view_pan_init(C, op))
413 return OPERATOR_PASS_THROUGH;
415 /* also, check if can pan in vertical axis */
417 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
418 view_pan_exit(C, op);
419 return OPERATOR_PASS_THROUGH;
423 RNA_int_set(op->ptr, "deltax", 0);
424 RNA_int_set(op->ptr, "deltay", 20);
426 /* apply movement, then we're done */
427 view_pan_apply(C, op);
428 view_pan_exit(C, op);
430 return OPERATOR_FINISHED;
433 void VIEW2D_OT_scroll_up(wmOperatorType *ot)
436 ot->name= "Scroll Up";
437 ot->idname= "VIEW2D_OT_scroll_up";
440 ot->exec= view_scrollup_exec;
442 /* operator is repeatable */
443 ot->flag= OPTYPE_REGISTER;
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);
450 /* ********************************************************* */
451 /* SINGLE-STEP VIEW ZOOMING OPERATOR */
453 /* This group of operators come in several forms:
454 * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
455 * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented...
456 * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
458 * In order to make sure this works, each operator must define the following RNA-Operator Props:
459 * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling.
460 * It is safe to scale by 0, as these factors are used to determine
461 * amount to enlarge 'cur' by
464 /* ------------------ 'Shared' stuff ------------------------ */
466 /* check if step-zoom can be applied */
467 static short view_zoomstep_ok(bContext *C)
469 ARegion *ar= CTX_wm_region(C);
472 /* check if there's a region in context to work with */
477 /* check that 2d-view is zoomable */
478 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
481 /* view is zoomable */
485 /* apply transform to view (i.e. adjust 'cur' rect) */
486 static void view_zoomstep_apply(bContext *C, wmOperator *op)
488 ARegion *ar= CTX_wm_region(C);
489 View2D *v2d= &ar->v2d;
492 /* calculate amount to move view by */
493 dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx");
494 dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
496 /* only resize view on an axis if change is allowed */
497 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
498 if (v2d->keepofs & V2D_LOCKOFS_X) {
499 v2d->cur.xmax -= 2*dx;
506 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
507 if (v2d->keepofs & V2D_LOCKOFS_Y) {
508 v2d->cur.ymax -= 2*dy;
516 /* validate that view is in valid configuration after this operation */
517 UI_view2d_curRect_validate(v2d);
519 /* request updates to be done... */
520 ED_area_tag_redraw(CTX_wm_area(C));
521 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
524 /* --------------- Individual Operators ------------------- */
526 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
527 static int view_zoomin_exec(bContext *C, wmOperator *op)
529 /* check that there's an active region, as View2D data resides there */
530 if (!view_zoomstep_ok(C))
531 return OPERATOR_PASS_THROUGH;
533 /* set RNA-Props - zooming in by uniform factor */
534 RNA_float_set(op->ptr, "zoomfacx", 0.0375f);
535 RNA_float_set(op->ptr, "zoomfacy", 0.0375f);
537 /* apply movement, then we're done */
538 view_zoomstep_apply(C, op);
540 return OPERATOR_FINISHED;
543 void VIEW2D_OT_zoom_in(wmOperatorType *ot)
547 ot->idname= "VIEW2D_OT_zoom_in";
550 ot->exec= view_zoomin_exec;
552 /* operator is repeatable */
553 ot->flag= OPTYPE_REGISTER;
555 /* rna - must keep these in sync with the other operators */
556 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
557 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
562 /* this operator only needs this single callback, where it callsthe view_zoom_*() methods */
563 static int view_zoomout_exec(bContext *C, wmOperator *op)
565 /* check that there's an active region, as View2D data resides there */
566 if (!view_zoomstep_ok(C))
567 return OPERATOR_PASS_THROUGH;
569 /* set RNA-Props - zooming in by uniform factor */
570 RNA_float_set(op->ptr, "zoomfacx", -0.0375f);
571 RNA_float_set(op->ptr, "zoomfacy", -0.0375f);
573 /* apply movement, then we're done */
574 view_zoomstep_apply(C, op);
576 return OPERATOR_FINISHED;
579 void VIEW2D_OT_zoom_out(wmOperatorType *ot)
582 ot->name= "Zoom Out";
583 ot->idname= "VIEW2D_OT_zoom_out";
586 ot->exec= view_zoomout_exec;
588 /* operator is repeatable */
589 ot->flag= OPTYPE_REGISTER;
591 /* rna - must keep these in sync with the other operators */
592 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
593 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
596 /* ********************************************************* */
597 /* DRAG-ZOOM OPERATOR */
599 /* MMB Drag - allows non-uniform scaling by dragging mouse
601 * In order to make sure this works, each operator must define the following RNA-Operator Props:
602 * deltax, deltay - amounts to add to each side of the 'cur' rect
605 /* ------------------ Shared 'core' stuff ---------------------- */
607 /* temp customdata for operator */
608 typedef struct v2dViewZoomData {
609 View2D *v2d; /* view2d we're operating in */
611 int lastx, lasty; /* previous x/y values of mouse in window */
612 float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
615 /* initialise panning customdata */
616 static int view_zoomdrag_init(bContext *C, wmOperator *op)
618 ARegion *ar= CTX_wm_region(C);
619 v2dViewZoomData *vzd;
622 /* regions now have v2d-data by default, so check for region */
627 /* check that 2d-view is zoomable */
628 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
631 /* set custom-data for operator */
632 vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
635 /* set pointers to owners */
641 /* apply transform to view (i.e. adjust 'cur' rect) */
642 static void view_zoomdrag_apply(bContext *C, wmOperator *op)
644 v2dViewZoomData *vzd= op->customdata;
645 View2D *v2d= vzd->v2d;
648 /* get amount to move view by */
649 dx= RNA_float_get(op->ptr, "deltax");
650 dy= RNA_float_get(op->ptr, "deltay");
652 /* only move view on an axis if change is allowed */
653 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
654 if (v2d->keepofs & V2D_LOCKOFS_X) {
655 v2d->cur.xmax -= 2*dx;
662 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
663 if (v2d->keepofs & V2D_LOCKOFS_Y) {
664 v2d->cur.ymax -= 2*dy;
672 /* validate that view is in valid configuration after this operation */
673 UI_view2d_curRect_validate(v2d);
675 /* request updates to be done... */
676 ED_area_tag_redraw(CTX_wm_area(C));
677 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
680 /* cleanup temp customdata */
681 static void view_zoomdrag_exit(bContext *C, wmOperator *op)
683 if (op->customdata) {
684 MEM_freeN(op->customdata);
685 op->customdata= NULL;
689 /* for 'redo' only, with no user input */
690 static int view_zoomdrag_exec(bContext *C, wmOperator *op)
692 if (!view_zoomdrag_init(C, op))
693 return OPERATOR_PASS_THROUGH;
695 view_zoomdrag_apply(C, op);
696 view_zoomdrag_exit(C, op);
697 return OPERATOR_FINISHED;
700 /* set up modal operator and relevant settings */
701 static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
703 wmWindow *window= CTX_wm_window(C);
704 v2dViewZoomData *vzd;
707 /* set up customdata */
708 if (!view_zoomdrag_init(C, op))
709 return OPERATOR_PASS_THROUGH;
714 /* set initial settings */
715 vzd->lastx= event->x;
716 vzd->lasty= event->y;
717 RNA_float_set(op->ptr, "deltax", 0);
718 RNA_float_set(op->ptr, "deltay", 0);
720 if (v2d->keepofs & V2D_LOCKOFS_X)
721 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
722 else if (v2d->keepofs & V2D_LOCKOFS_Y)
723 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
725 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
727 /* add temp handler */
728 WM_event_add_modal_handler(C, &window->handlers, op);
730 return OPERATOR_RUNNING_MODAL;
733 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
734 static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
736 v2dViewZoomData *vzd= op->customdata;
737 View2D *v2d= vzd->v2d;
739 /* execute the events */
740 switch (event->type) {
745 /* calculate new delta transform, based on zooming mode */
746 if (U.viewzoom == USER_ZOOM_SCALE) {
747 /* 'scale' zooming */
750 /* x-axis transform */
751 dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
752 dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
753 dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
755 /* y-axis transform */
756 dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
757 dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
758 dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
761 /* 'continuous' or 'dolly' */
764 /* x-axis transform */
765 fac= 0.01f * (event->x - vzd->lastx);
766 dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
768 /* y-axis transform */
769 fac= 0.01f * (event->y - vzd->lasty);
770 dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
772 /* continous zoom shouldn't move that fast... */
773 if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
779 /* set transform amount, and add current deltas to stored total delta (for redo) */
780 RNA_float_set(op->ptr, "deltax", dx);
781 RNA_float_set(op->ptr, "deltay", dy);
785 /* store mouse coordinates for next time, if not doing continuous zoom
786 * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
788 if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
789 vzd->lastx= event->x;
790 vzd->lasty= event->y;
794 view_zoomdrag_apply(C, op);
800 /* for redo, store the overall deltas - need to respect zoom-locks here... */
801 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
802 RNA_float_set(op->ptr, "deltax", vzd->dx);
804 RNA_float_set(op->ptr, "deltax", 0);
806 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
807 RNA_float_set(op->ptr, "deltay", vzd->dy);
809 RNA_float_set(op->ptr, "deltay", 0);
811 /* free customdata */
812 view_zoomdrag_exit(C, op);
813 WM_cursor_restore(CTX_wm_window(C));
815 return OPERATOR_FINISHED;
820 return OPERATOR_RUNNING_MODAL;
823 void VIEW2D_OT_zoom(wmOperatorType *ot)
826 ot->name= "Zoom View";
827 ot->idname= "VIEW2D_OT_zoom";
830 ot->exec= view_zoomdrag_exec;
831 ot->invoke= view_zoomdrag_invoke;
832 ot->modal= view_zoomdrag_modal;
834 /* operator is repeatable */
835 ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
837 /* rna - must keep these in sync with the other operators */
838 RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
839 RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
842 /* ********************************************************* */
845 /* The user defines a rect using standard borderselect tools, and we use this rect to
846 * define the new zoom-level of the view in the following ways:
847 * 1) LEFTMOUSE - zoom in to view
848 * 2) RIGHTMOUSE - zoom out of view
850 * Currently, these key mappings are hardcoded, but it shouldn't be too important to
851 * have custom keymappings for this...
854 static int view_borderzoom_exec(bContext *C, wmOperator *op)
856 ARegion *ar= CTX_wm_region(C);
857 View2D *v2d= &ar->v2d;
861 /* convert coordinates of rect to 'tot' rect coordinates */
862 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
863 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
865 /* check if zooming in/out view */
866 // XXX hardcoded for now!
867 event_type= RNA_int_get(op->ptr, "event_type");
869 if (event_type == LEFTMOUSE) {
871 * - 'cur' rect will be defined by the coordinates of the border region
872 * - just set the 'cur' rect to have the same coordinates as the border region
873 * if zoom is allowed to be changed
875 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
876 v2d->cur.xmin= rect.xmin;
877 v2d->cur.xmax= rect.xmax;
879 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
880 v2d->cur.ymin= rect.ymin;
881 v2d->cur.ymax= rect.ymax;
886 * - the current 'cur' rect coordinates are going to end upwhere the 'rect' ones are,
887 * but the 'cur' rect coordinates will need to be adjusted to take in more of the view
888 * - calculate zoom factor, and adjust using center-point
890 float zoom, center, size;
892 // TODO: is this zoom factor calculation valid? It seems to produce same results everytime...
893 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
894 size= (v2d->cur.xmax - v2d->cur.xmin);
895 zoom= size / (rect.xmax - rect.xmin);
896 center= (v2d->cur.xmax + v2d->cur.xmin) * 0.5f;
898 v2d->cur.xmin= center - (size * zoom);
899 v2d->cur.xmax= center + (size * zoom);
901 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
902 size= (v2d->cur.ymax - v2d->cur.ymin);
903 zoom= size / (rect.ymax - rect.ymin);
904 center= (v2d->cur.ymax + v2d->cur.ymin) * 0.5f;
906 v2d->cur.ymin= center - (size * zoom);
907 v2d->cur.ymax= center + (size * zoom);
911 /* validate that view is in valid configuration after this operation */
912 UI_view2d_curRect_validate(v2d);
914 /* request updates to be done... */
915 ED_area_tag_redraw(CTX_wm_area(C));
916 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
918 return OPERATOR_FINISHED;
921 void VIEW2D_OT_zoom_border(wmOperatorType *ot)
924 ot->name= "Zoom to Border";
925 ot->idname= "VIEW2D_OT_zoom_border";
928 ot->invoke= WM_border_select_invoke;
929 ot->exec= view_borderzoom_exec;
930 ot->modal= WM_border_select_modal;
932 ot->poll= ED_operator_areaactive;
935 RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
936 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
937 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
938 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
939 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
942 /* ********************************************************* */
945 /* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
946 * 1) 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable,
947 * enlarge 'cur' rect on the relevant side
948 * 2) 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite)
950 * In order to make sure this works, each operator must define the following RNA-Operator Props:
951 * deltax, deltay - define how much to move view by (relative to zoom-correction factor)
954 /* customdata for scroller-invoke data */
955 typedef struct v2dScrollerMove {
956 View2D *v2d; /* View2D data that this operation affects */
958 short scroller; /* scroller that mouse is in ('h' or 'v') */
959 short zone; /* -1 is min zoomer, 0 is bar, 1 is max zoomer */ // XXX find some way to provide visual feedback of this (active colour?)
961 float fac; /* view adjustment factor, based on size of region */
962 float delta; /* amount moved by mouse on axis of interest */
964 int lastx, lasty; /* previous mouse coordinates (in screen coordinates) for determining movement */
968 /* View2DScrollers is typedef'd in UI_view2d.h
969 * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info
970 * WARNING: the start of this struct must not change, so that it stays in sync with the 'real' version
971 * For now, we don't need to have a separate (internal) header for structs like this...
973 struct View2DScrollers {
975 int vert_min, vert_max; /* vertical scrollbar */
976 int hor_min, hor_max; /* horizontal scrollbar */
979 /* quick enum for vsm->zone (scroller handles) */
981 SCROLLHANDLE_MIN= -1,
984 } eV2DScrollerHandle_Zone;
986 /* ------------------------ */
988 /* check if mouse is within scroller handle
989 * - mouse = relevant mouse coordinate in region space
990 * - sc_min, sc_max = extents of scroller
991 * - sh_min, sh_max = positions of scroller handles
993 static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
995 short in_min, in_max, in_view=1;
998 * - 'bubble' fills entire scroller
999 * - 'bubble' completely out of view on either side
1001 if ((sh_min <= sc_min) && (sh_max >= sc_max)) in_view= 0;
1002 if (sh_min == sh_max) {
1003 if (sh_min <= sc_min) in_view= 0;
1004 if (sh_max >= sc_max) in_view= 0;
1007 if (sh_max <= sc_min) in_view= 0;
1008 if (sh_min >= sc_max) in_view= 0;
1013 return SCROLLHANDLE_BAR;
1016 /* check if mouse is in or past either handle */
1017 in_max= ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
1018 in_min= ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
1020 /* check if overlap --> which means user clicked on bar, as bar is within handles region */
1021 if (in_max && in_min)
1022 return SCROLLHANDLE_BAR;
1024 return SCROLLHANDLE_MAX;
1026 return SCROLLHANDLE_MIN;
1028 /* unlikely to happen, though we just cover it in case */
1029 return SCROLLHANDLE_BAR;
1032 /* initialise customdata for scroller manipulation operator */
1033 static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event, short in_scroller)
1035 v2dScrollerMove *vsm;
1036 View2DScrollers *scrollers;
1037 ARegion *ar= CTX_wm_region(C);
1038 View2D *v2d= &ar->v2d;
1042 /* set custom-data for operator */
1043 vsm= MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove");
1044 op->customdata= vsm;
1046 /* set general data */
1048 vsm->scroller= in_scroller;
1050 /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
1051 vsm->lastx = event->x;
1052 vsm->lasty = event->y;
1053 x= event->x - ar->winrct.xmin;
1054 y= event->y - ar->winrct.ymin;
1056 /* 'zone' depends on where mouse is relative to bubble
1057 * - zooming must be allowed on this axis, otherwise, default to pan
1059 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1060 if (in_scroller == 'h') {
1061 /* horizontal scroller - calculate adjustment factor first */
1062 mask_size= (float)(v2d->hor.xmax - v2d->hor.xmin);
1063 vsm->fac= (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
1065 /* get 'zone' (i.e. which part of scroller is activated) */
1066 if (v2d->keepzoom & V2D_LOCKZOOM_X) {
1067 /* default to scroll, as handles not usable */
1068 vsm->zone= SCROLLHANDLE_BAR;
1071 /* check which handle we're in */
1072 vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
1076 /* vertical scroller - calculate adjustment factor first */
1077 mask_size= (float)(v2d->vert.ymax - v2d->vert.ymin);
1078 vsm->fac= (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
1080 /* get 'zone' (i.e. which part of scroller is activated) */
1081 if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
1082 /* default to scroll, as handles not usable */
1083 vsm->zone= SCROLLHANDLE_BAR;
1086 /* check which handle we're in */
1087 vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max);
1091 UI_view2d_scrollers_free(scrollers);
1092 ED_region_tag_redraw(ar);
1095 /* cleanup temp customdata */
1096 static void scroller_activate_exit(bContext *C, wmOperator *op)
1098 if (op->customdata) {
1099 v2dScrollerMove *vsm= op->customdata;
1101 vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE|V2D_SCROLL_V_ACTIVE);
1103 MEM_freeN(op->customdata);
1104 op->customdata= NULL;
1106 ED_region_tag_redraw(CTX_wm_region(C));
1110 /* apply transform to view (i.e. adjust 'cur' rect) */
1111 static void scroller_activate_apply(bContext *C, wmOperator *op)
1113 v2dScrollerMove *vsm= op->customdata;
1114 View2D *v2d= vsm->v2d;
1117 /* calculate amount to move view by */
1118 temp= vsm->fac * vsm->delta;
1120 /* type of movement */
1121 switch (vsm->zone) {
1122 case SCROLLHANDLE_MIN:
1123 case SCROLLHANDLE_MAX:
1125 /* only expand view on axis if zoom is allowed */
1126 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1127 v2d->cur.xmin -= temp;
1128 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1129 v2d->cur.ymin -= temp;
1131 /* only expand view on axis if zoom is allowed */
1132 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1133 v2d->cur.xmax += temp;
1134 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1135 v2d->cur.ymax += temp;
1138 default: /* SCROLLHANDLE_BAR */
1139 /* only move view on an axis if panning is allowed */
1140 if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
1141 v2d->cur.xmin += temp;
1142 v2d->cur.xmax += temp;
1144 if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
1145 v2d->cur.ymin += temp;
1146 v2d->cur.ymax += temp;
1151 /* validate that view is in valid configuration after this operation */
1152 UI_view2d_curRect_validate(v2d);
1154 /* request updates to be done... */
1155 ED_area_tag_redraw(CTX_wm_area(C));
1156 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1159 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
1160 static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
1162 v2dScrollerMove *vsm= op->customdata;
1164 /* execute the events */
1165 switch (event->type) {
1168 /* calculate new delta transform, then store mouse-coordinates for next-time */
1169 if (vsm->zone != SCROLLHANDLE_MIN) {
1170 /* if using bar (i.e. 'panning') or 'max' zoom widget */
1171 switch (vsm->scroller) {
1172 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
1173 vsm->delta= (float)(event->x - vsm->lastx);
1175 case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
1176 vsm->delta= (float)(event->y - vsm->lasty);
1181 /* using 'min' zoom widget */
1182 switch (vsm->scroller) {
1183 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
1184 vsm->delta= (float)(vsm->lastx - event->x);
1186 case 'v': /* vertical scroller - so only vertical movement ('cur' moves with to mouse) */
1187 vsm->delta= (float)(vsm->lasty - event->y);
1192 /* store previous coordinates */
1193 vsm->lastx= event->x;
1194 vsm->lasty= event->y;
1196 scroller_activate_apply(C, op);
1201 if (event->val==0) {
1202 scroller_activate_exit(C, op);
1203 return OPERATOR_FINISHED;
1208 return OPERATOR_RUNNING_MODAL;
1212 /* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
1213 static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
1215 ARegion *ar= CTX_wm_region(C);
1216 View2D *v2d= &ar->v2d;
1217 short in_scroller= 0;
1219 /* check if mouse in scrollbars, if they're enabled */
1220 in_scroller= UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
1222 /* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
1224 v2dScrollerMove *vsm;
1226 /* initialise customdata */
1227 scroller_activate_init(C, op, event, in_scroller);
1228 vsm= (v2dScrollerMove *)op->customdata;
1230 /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
1231 if (vsm->zone == SCROLLHANDLE_BAR) {
1232 if ( ((vsm->scroller=='h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
1233 ((vsm->scroller=='v') && (v2d->keepofs & V2D_LOCKOFS_Y)) )
1235 /* free customdata initialised */
1236 scroller_activate_exit(C, op);
1238 /* can't catch this event for ourselves, so let it go to someone else? */
1239 return OPERATOR_PASS_THROUGH;
1243 if(vsm->scroller=='h')
1244 v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE;
1246 v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE;
1248 /* still ok, so can add */
1249 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1250 return OPERATOR_RUNNING_MODAL;
1253 /* not in scroller, so nothing happened... (pass through let's something else catch event) */
1254 return OPERATOR_PASS_THROUGH;
1258 /* LMB-Drag in Scrollers - not repeatable operator! */
1259 void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
1262 ot->name= "Scroller Activate";
1263 ot->idname= "VIEW2D_OT_scroller_activate";
1266 ot->flag= OPTYPE_BLOCKING;
1269 ot->invoke= scroller_activate_invoke;
1270 ot->modal= scroller_activate_modal;
1271 ot->poll= view2d_poll;
1274 /* ********************************************************* */
1277 static int reset_exec(bContext *C, wmOperator *op)
1279 uiStyle *style= U.uistyles.first;
1280 ARegion *ar= CTX_wm_region(C);
1281 View2D *v2d= &ar->v2d;
1285 winx= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
1286 winy= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
1288 v2d->cur.xmax= v2d->cur.xmin + winx;
1289 v2d->cur.ymax= v2d->cur.ymin + winy;
1293 /* posx and negx flags are mutually exclusive, so watch out */
1294 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
1295 v2d->cur.xmax= 0.0f;
1296 v2d->cur.xmin= v2d->winx*style->panelzoom;
1298 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
1299 v2d->cur.xmax= (v2d->cur.xmax - v2d->cur.xmin)*style->panelzoom;
1300 v2d->cur.xmin= 0.0f;
1303 /* - posx and negx flags are mutually exclusive, so watch out */
1304 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1305 v2d->cur.ymax= 0.0f;
1306 v2d->cur.ymin= -v2d->winy*style->panelzoom;
1308 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
1309 v2d->cur.ymax= (v2d->cur.ymax - v2d->cur.ymin)*style->panelzoom;
1310 v2d->cur.ymin= 0.0f;
1314 /* validate that view is in valid configuration after this operation */
1315 UI_view2d_curRect_validate(v2d);
1317 /* request updates to be done... */
1318 ED_area_tag_redraw(CTX_wm_area(C));
1319 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1321 return OPERATOR_FINISHED;
1324 void VIEW2D_OT_reset(wmOperatorType *ot)
1327 ot->name= "Reset View";
1328 ot->idname= "VIEW2D_OT_reset";
1331 ot->exec= reset_exec;
1332 ot->poll= view2d_poll;
1335 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1338 /* ********************************************************* */
1341 void ui_view2d_operatortypes(void)
1343 WM_operatortype_append(VIEW2D_OT_pan);
1345 WM_operatortype_append(VIEW2D_OT_scroll_left);
1346 WM_operatortype_append(VIEW2D_OT_scroll_right);
1347 WM_operatortype_append(VIEW2D_OT_scroll_up);
1348 WM_operatortype_append(VIEW2D_OT_scroll_down);
1350 WM_operatortype_append(VIEW2D_OT_zoom_in);
1351 WM_operatortype_append(VIEW2D_OT_zoom_out);
1353 WM_operatortype_append(VIEW2D_OT_zoom);
1354 WM_operatortype_append(VIEW2D_OT_zoom_border);
1356 WM_operatortype_append(VIEW2D_OT_scroller_activate);
1358 WM_operatortype_append(VIEW2D_OT_reset);
1361 void UI_view2d_keymap(wmWindowManager *wm)
1363 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
1366 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1367 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
1369 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
1370 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
1372 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
1373 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
1375 /* zoom - single step */
1376 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
1377 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
1378 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1379 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1381 /* scroll up/down - no modifiers, only when zoom fails */
1382 /* these may fail if zoom is disallowed, in which case they should pass on event */
1383 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1384 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1385 /* these may be necessary if vertical scroll is disallowed */
1386 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1387 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, 0, 0);
1390 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1392 /* borderzoom - drag */
1393 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
1396 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
1398 /* Alternative keymap for buttons listview */
1399 keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
1400 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1401 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1402 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1403 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1404 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1405 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1406 WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);
1407 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);