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 if(vpd->sa->spacetype==SPACE_OUTLINER) {
157 SpaceOops *soops= vpd->sa->spacedata.first;
158 soops->storeflag |= SO_TREESTORE_REDRAW;
162 /* cleanup temp customdata */
163 static void view_pan_exit(bContext *C, wmOperator *op)
165 if (op->customdata) {
166 MEM_freeN(op->customdata);
167 op->customdata= NULL;
171 /* ------------------ Modal Drag Version (1) ---------------------- */
173 /* for 'redo' only, with no user input */
174 static int view_pan_exec(bContext *C, wmOperator *op)
176 if (!view_pan_init(C, op))
177 return OPERATOR_CANCELLED;
179 view_pan_apply(C, op);
180 view_pan_exit(C, op);
181 return OPERATOR_FINISHED;
184 /* set up modal operator and relevant settings */
185 static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
187 wmWindow *window= CTX_wm_window(C);
191 /* set up customdata */
192 if (!view_pan_init(C, op))
193 return OPERATOR_PASS_THROUGH;
198 /* set initial settings */
199 vpd->startx= vpd->lastx= event->x;
200 vpd->starty= vpd->lasty= event->y;
201 RNA_int_set(op->ptr, "deltax", 0);
202 RNA_int_set(op->ptr, "deltay", 0);
204 if (v2d->keepofs & V2D_LOCKOFS_X)
205 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
206 else if (v2d->keepofs & V2D_LOCKOFS_Y)
207 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
209 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
211 /* add temp handler */
212 WM_event_add_modal_handler(C, &window->handlers, op);
214 return OPERATOR_RUNNING_MODAL;
217 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
218 static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
220 v2dViewPanData *vpd= op->customdata;
222 /* execute the events */
223 switch (event->type) {
226 /* calculate new delta transform, then store mouse-coordinates for next-time */
227 RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
228 RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
230 vpd->lastx= event->x;
231 vpd->lasty= event->y;
233 view_pan_apply(C, op);
239 /* calculate overall delta mouse-movement for redo */
240 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
241 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
243 view_pan_exit(C, op);
244 WM_cursor_restore(CTX_wm_window(C));
246 return OPERATOR_FINISHED;
251 return OPERATOR_RUNNING_MODAL;
254 void VIEW2D_OT_pan(wmOperatorType *ot)
257 ot->name= "Pan View";
258 ot->idname= "VIEW2D_OT_pan";
261 ot->exec= view_pan_exec;
262 ot->invoke= view_pan_invoke;
263 ot->modal= view_pan_modal;
265 /* operator is repeatable */
266 ot->flag= OPTYPE_BLOCKING;
268 /* rna - must keep these in sync with the other operators */
269 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
270 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
273 /* ------------------ Scrollwheel Versions (2) ---------------------- */
275 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
276 static int view_scrollright_exec(bContext *C, wmOperator *op)
280 /* initialise default settings (and validate if ok to run) */
281 if (!view_pan_init(C, op))
282 return OPERATOR_PASS_THROUGH;
284 /* also, check if can pan in horizontal axis */
286 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
287 view_pan_exit(C, op);
288 return OPERATOR_PASS_THROUGH;
291 /* set RNA-Props - only movement in positive x-direction */
292 RNA_int_set(op->ptr, "deltax", 20);
293 RNA_int_set(op->ptr, "deltay", 0);
295 /* apply movement, then we're done */
296 view_pan_apply(C, op);
297 view_pan_exit(C, op);
299 return OPERATOR_FINISHED;
302 void VIEW2D_OT_scroll_right(wmOperatorType *ot)
305 ot->name= "Scroll Right";
306 ot->idname= "VIEW2D_OT_scroll_right";
309 ot->exec= view_scrollright_exec;
311 /* operator is repeatable */
312 // ot->flag= OPTYPE_REGISTER;
314 /* rna - must keep these in sync with the other operators */
315 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
316 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
321 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
322 static int view_scrollleft_exec(bContext *C, wmOperator *op)
326 /* initialise default settings (and validate if ok to run) */
327 if (!view_pan_init(C, op))
328 return OPERATOR_PASS_THROUGH;
330 /* also, check if can pan in horizontal axis */
332 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
333 view_pan_exit(C, op);
334 return OPERATOR_PASS_THROUGH;
337 /* set RNA-Props - only movement in negative x-direction */
338 RNA_int_set(op->ptr, "deltax", -20);
339 RNA_int_set(op->ptr, "deltay", 0);
341 /* apply movement, then we're done */
342 view_pan_apply(C, op);
343 view_pan_exit(C, op);
345 return OPERATOR_FINISHED;
348 void VIEW2D_OT_scroll_left(wmOperatorType *ot)
351 ot->name= "Scroll Left";
352 ot->idname= "VIEW2D_OT_scroll_left";
355 ot->exec= view_scrollleft_exec;
357 /* operator is repeatable */
358 // ot->flag= OPTYPE_REGISTER;
360 /* rna - must keep these in sync with the other operators */
361 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
362 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
366 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
367 static int view_scrolldown_exec(bContext *C, wmOperator *op)
371 /* initialise default settings (and validate if ok to run) */
372 if (!view_pan_init(C, op))
373 return OPERATOR_PASS_THROUGH;
375 /* also, check if can pan in vertical axis */
377 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
378 view_pan_exit(C, op);
379 return OPERATOR_PASS_THROUGH;
383 RNA_int_set(op->ptr, "deltax", 0);
384 RNA_int_set(op->ptr, "deltay", -20);
386 /* apply movement, then we're done */
387 view_pan_apply(C, op);
388 view_pan_exit(C, op);
390 return OPERATOR_FINISHED;
393 void VIEW2D_OT_scroll_down(wmOperatorType *ot)
396 ot->name= "Scroll Down";
397 ot->idname= "VIEW2D_OT_scroll_down";
400 ot->exec= view_scrolldown_exec;
402 /* operator is repeatable */
403 // ot->flag= OPTYPE_REGISTER;
405 /* rna - must keep these in sync with the other operators */
406 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
407 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
412 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
413 static int view_scrollup_exec(bContext *C, wmOperator *op)
417 /* initialise default settings (and validate if ok to run) */
418 if (!view_pan_init(C, op))
419 return OPERATOR_PASS_THROUGH;
421 /* also, check if can pan in vertical axis */
423 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
424 view_pan_exit(C, op);
425 return OPERATOR_PASS_THROUGH;
429 RNA_int_set(op->ptr, "deltax", 0);
430 RNA_int_set(op->ptr, "deltay", 20);
432 /* apply movement, then we're done */
433 view_pan_apply(C, op);
434 view_pan_exit(C, op);
436 return OPERATOR_FINISHED;
439 void VIEW2D_OT_scroll_up(wmOperatorType *ot)
442 ot->name= "Scroll Up";
443 ot->idname= "VIEW2D_OT_scroll_up";
446 ot->exec= view_scrollup_exec;
448 /* operator is repeatable */
449 // ot->flag= OPTYPE_REGISTER;
451 /* rna - must keep these in sync with the other operators */
452 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
453 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
456 /* ********************************************************* */
457 /* SINGLE-STEP VIEW ZOOMING OPERATOR */
459 /* This group of operators come in several forms:
460 * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
461 * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented...
462 * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
464 * In order to make sure this works, each operator must define the following RNA-Operator Props:
465 * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling.
466 * It is safe to scale by 0, as these factors are used to determine
467 * amount to enlarge 'cur' by
470 /* ------------------ 'Shared' stuff ------------------------ */
472 /* check if step-zoom can be applied */
473 static int view_zoom_poll(bContext *C)
475 ARegion *ar= CTX_wm_region(C);
478 /* check if there's a region in context to work with */
483 /* check that 2d-view is zoomable */
484 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
487 /* view is zoomable */
491 /* apply transform to view (i.e. adjust 'cur' rect) */
492 static void view_zoomstep_apply(bContext *C, wmOperator *op)
494 ARegion *ar= CTX_wm_region(C);
495 View2D *v2d= &ar->v2d;
498 /* calculate amount to move view by */
499 dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx");
500 dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
502 /* only resize view on an axis if change is allowed */
503 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
504 if (v2d->keepofs & V2D_LOCKOFS_X) {
505 v2d->cur.xmax -= 2*dx;
512 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
513 if (v2d->keepofs & V2D_LOCKOFS_Y) {
514 v2d->cur.ymax -= 2*dy;
522 /* validate that view is in valid configuration after this operation */
523 UI_view2d_curRect_validate(v2d);
525 /* request updates to be done... */
526 ED_area_tag_redraw(CTX_wm_area(C));
527 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
530 /* --------------- Individual Operators ------------------- */
532 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
533 static int view_zoomin_exec(bContext *C, wmOperator *op)
535 /* check that there's an active region, as View2D data resides there */
536 if (!view_zoom_poll(C))
537 return OPERATOR_PASS_THROUGH;
539 /* set RNA-Props - zooming in by uniform factor */
540 RNA_float_set(op->ptr, "zoomfacx", 0.0375f);
541 RNA_float_set(op->ptr, "zoomfacy", 0.0375f);
543 /* apply movement, then we're done */
544 view_zoomstep_apply(C, op);
546 return OPERATOR_FINISHED;
549 void VIEW2D_OT_zoom_in(wmOperatorType *ot)
553 ot->idname= "VIEW2D_OT_zoom_in";
556 ot->exec= view_zoomin_exec;
558 /* operator is repeatable */
559 // ot->flag= OPTYPE_REGISTER;
561 /* rna - must keep these in sync with the other operators */
562 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
563 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
568 /* this operator only needs this single callback, where it callsthe view_zoom_*() methods */
569 static int view_zoomout_exec(bContext *C, wmOperator *op)
571 /* check that there's an active region, as View2D data resides there */
572 if (!view_zoom_poll(C))
573 return OPERATOR_PASS_THROUGH;
575 /* set RNA-Props - zooming in by uniform factor */
576 RNA_float_set(op->ptr, "zoomfacx", -0.0375f);
577 RNA_float_set(op->ptr, "zoomfacy", -0.0375f);
579 /* apply movement, then we're done */
580 view_zoomstep_apply(C, op);
582 return OPERATOR_FINISHED;
585 void VIEW2D_OT_zoom_out(wmOperatorType *ot)
588 ot->name= "Zoom Out";
589 ot->idname= "VIEW2D_OT_zoom_out";
592 ot->exec= view_zoomout_exec;
594 /* operator is repeatable */
595 // ot->flag= OPTYPE_REGISTER;
597 /* rna - must keep these in sync with the other operators */
598 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
599 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
602 /* ********************************************************* */
603 /* DRAG-ZOOM OPERATOR */
605 /* MMB Drag - allows non-uniform scaling by dragging mouse
607 * In order to make sure this works, each operator must define the following RNA-Operator Props:
608 * deltax, deltay - amounts to add to each side of the 'cur' rect
611 /* ------------------ Shared 'core' stuff ---------------------- */
613 /* temp customdata for operator */
614 typedef struct v2dViewZoomData {
615 View2D *v2d; /* view2d we're operating in */
617 int lastx, lasty; /* previous x/y values of mouse in window */
618 float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
621 /* initialise panning customdata */
622 static int view_zoomdrag_init(bContext *C, wmOperator *op)
624 ARegion *ar= CTX_wm_region(C);
625 v2dViewZoomData *vzd;
628 /* regions now have v2d-data by default, so check for region */
633 /* check that 2d-view is zoomable */
634 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
637 /* set custom-data for operator */
638 vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
641 /* set pointers to owners */
647 /* apply transform to view (i.e. adjust 'cur' rect) */
648 static void view_zoomdrag_apply(bContext *C, wmOperator *op)
650 v2dViewZoomData *vzd= op->customdata;
651 View2D *v2d= vzd->v2d;
654 /* get amount to move view by */
655 dx= RNA_float_get(op->ptr, "deltax");
656 dy= RNA_float_get(op->ptr, "deltay");
658 /* only move view on an axis if change is allowed */
659 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
660 if (v2d->keepofs & V2D_LOCKOFS_X) {
661 v2d->cur.xmax -= 2*dx;
668 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
669 if (v2d->keepofs & V2D_LOCKOFS_Y) {
670 v2d->cur.ymax -= 2*dy;
678 /* validate that view is in valid configuration after this operation */
679 UI_view2d_curRect_validate(v2d);
681 /* request updates to be done... */
682 ED_area_tag_redraw(CTX_wm_area(C));
683 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
686 /* cleanup temp customdata */
687 static void view_zoomdrag_exit(bContext *C, wmOperator *op)
689 if (op->customdata) {
690 MEM_freeN(op->customdata);
691 op->customdata= NULL;
695 /* for 'redo' only, with no user input */
696 static int view_zoomdrag_exec(bContext *C, wmOperator *op)
698 if (!view_zoomdrag_init(C, op))
699 return OPERATOR_PASS_THROUGH;
701 view_zoomdrag_apply(C, op);
702 view_zoomdrag_exit(C, op);
703 return OPERATOR_FINISHED;
706 /* set up modal operator and relevant settings */
707 static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
709 wmWindow *window= CTX_wm_window(C);
710 v2dViewZoomData *vzd;
713 /* set up customdata */
714 if (!view_zoomdrag_init(C, op))
715 return OPERATOR_PASS_THROUGH;
720 /* set initial settings */
721 vzd->lastx= event->x;
722 vzd->lasty= event->y;
723 RNA_float_set(op->ptr, "deltax", 0);
724 RNA_float_set(op->ptr, "deltay", 0);
726 if (v2d->keepofs & V2D_LOCKOFS_X)
727 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
728 else if (v2d->keepofs & V2D_LOCKOFS_Y)
729 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
731 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
733 /* add temp handler */
734 WM_event_add_modal_handler(C, &window->handlers, op);
736 return OPERATOR_RUNNING_MODAL;
739 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
740 static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
742 v2dViewZoomData *vzd= op->customdata;
743 View2D *v2d= vzd->v2d;
745 /* execute the events */
746 switch (event->type) {
751 /* calculate new delta transform, based on zooming mode */
752 if (U.viewzoom == USER_ZOOM_SCALE) {
753 /* 'scale' zooming */
756 /* x-axis transform */
757 dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
758 dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
759 dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
761 /* y-axis transform */
762 dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
763 dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
764 dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
767 /* 'continuous' or 'dolly' */
770 /* x-axis transform */
771 fac= 0.01f * (event->x - vzd->lastx);
772 dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
774 /* y-axis transform */
775 fac= 0.01f * (event->y - vzd->lasty);
776 dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
778 /* continous zoom shouldn't move that fast... */
779 if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
785 /* set transform amount, and add current deltas to stored total delta (for redo) */
786 RNA_float_set(op->ptr, "deltax", dx);
787 RNA_float_set(op->ptr, "deltay", dy);
791 /* store mouse coordinates for next time, if not doing continuous zoom
792 * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
794 if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
795 vzd->lastx= event->x;
796 vzd->lasty= event->y;
800 view_zoomdrag_apply(C, op);
806 /* for redo, store the overall deltas - need to respect zoom-locks here... */
807 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
808 RNA_float_set(op->ptr, "deltax", vzd->dx);
810 RNA_float_set(op->ptr, "deltax", 0);
812 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
813 RNA_float_set(op->ptr, "deltay", vzd->dy);
815 RNA_float_set(op->ptr, "deltay", 0);
817 /* free customdata */
818 view_zoomdrag_exit(C, op);
819 WM_cursor_restore(CTX_wm_window(C));
821 return OPERATOR_FINISHED;
826 return OPERATOR_RUNNING_MODAL;
829 void VIEW2D_OT_zoom(wmOperatorType *ot)
832 ot->name= "Zoom View";
833 ot->idname= "VIEW2D_OT_zoom";
836 ot->exec= view_zoomdrag_exec;
837 ot->invoke= view_zoomdrag_invoke;
838 ot->modal= view_zoomdrag_modal;
840 ot->poll= view_zoom_poll;
842 /* operator is repeatable */
843 // ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
845 /* rna - must keep these in sync with the other operators */
846 RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
847 RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
850 /* ********************************************************* */
853 /* The user defines a rect using standard borderselect tools, and we use this rect to
854 * define the new zoom-level of the view in the following ways:
855 * 1) LEFTMOUSE - zoom in to view
856 * 2) RIGHTMOUSE - zoom out of view
858 * Currently, these key mappings are hardcoded, but it shouldn't be too important to
859 * have custom keymappings for this...
862 static int view_borderzoom_exec(bContext *C, wmOperator *op)
864 ARegion *ar= CTX_wm_region(C);
865 View2D *v2d= &ar->v2d;
869 /* convert coordinates of rect to 'tot' rect coordinates */
870 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
871 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
873 /* check if zooming in/out view */
874 // XXX hardcoded for now!
875 event_type= RNA_int_get(op->ptr, "event_type");
877 if (event_type == LEFTMOUSE) {
879 * - 'cur' rect will be defined by the coordinates of the border region
880 * - just set the 'cur' rect to have the same coordinates as the border region
881 * if zoom is allowed to be changed
883 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
884 v2d->cur.xmin= rect.xmin;
885 v2d->cur.xmax= rect.xmax;
887 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
888 v2d->cur.ymin= rect.ymin;
889 v2d->cur.ymax= rect.ymax;
894 * - the current 'cur' rect coordinates are going to end upwhere the 'rect' ones are,
895 * but the 'cur' rect coordinates will need to be adjusted to take in more of the view
896 * - calculate zoom factor, and adjust using center-point
898 float zoom, center, size;
900 // TODO: is this zoom factor calculation valid? It seems to produce same results everytime...
901 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
902 size= (v2d->cur.xmax - v2d->cur.xmin);
903 zoom= size / (rect.xmax - rect.xmin);
904 center= (v2d->cur.xmax + v2d->cur.xmin) * 0.5f;
906 v2d->cur.xmin= center - (size * zoom);
907 v2d->cur.xmax= center + (size * zoom);
909 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
910 size= (v2d->cur.ymax - v2d->cur.ymin);
911 zoom= size / (rect.ymax - rect.ymin);
912 center= (v2d->cur.ymax + v2d->cur.ymin) * 0.5f;
914 v2d->cur.ymin= center - (size * zoom);
915 v2d->cur.ymax= center + (size * zoom);
919 /* validate that view is in valid configuration after this operation */
920 UI_view2d_curRect_validate(v2d);
922 /* request updates to be done... */
923 ED_area_tag_redraw(CTX_wm_area(C));
924 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
926 return OPERATOR_FINISHED;
929 void VIEW2D_OT_zoom_border(wmOperatorType *ot)
932 ot->name= "Zoom to Border";
933 ot->idname= "VIEW2D_OT_zoom_border";
936 ot->invoke= WM_border_select_invoke;
937 ot->exec= view_borderzoom_exec;
938 ot->modal= WM_border_select_modal;
940 ot->poll= view_zoom_poll;
943 RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
944 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
945 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
946 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
947 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
950 /* ********************************************************* */
953 /* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
954 * 1) 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable,
955 * enlarge 'cur' rect on the relevant side
956 * 2) 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite)
958 * In order to make sure this works, each operator must define the following RNA-Operator Props:
959 * deltax, deltay - define how much to move view by (relative to zoom-correction factor)
962 /* customdata for scroller-invoke data */
963 typedef struct v2dScrollerMove {
964 View2D *v2d; /* View2D data that this operation affects */
966 short scroller; /* scroller that mouse is in ('h' or 'v') */
967 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?)
969 float fac; /* view adjustment factor, based on size of region */
970 float delta; /* amount moved by mouse on axis of interest */
972 int lastx, lasty; /* previous mouse coordinates (in screen coordinates) for determining movement */
976 /* View2DScrollers is typedef'd in UI_view2d.h
977 * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info
978 * WARNING: the start of this struct must not change, so that it stays in sync with the 'real' version
979 * For now, we don't need to have a separate (internal) header for structs like this...
981 struct View2DScrollers {
983 int vert_min, vert_max; /* vertical scrollbar */
984 int hor_min, hor_max; /* horizontal scrollbar */
987 /* quick enum for vsm->zone (scroller handles) */
989 SCROLLHANDLE_MIN= -1,
992 } eV2DScrollerHandle_Zone;
994 /* ------------------------ */
996 /* check if mouse is within scroller handle
997 * - mouse = relevant mouse coordinate in region space
998 * - sc_min, sc_max = extents of scroller
999 * - sh_min, sh_max = positions of scroller handles
1001 static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
1003 short in_min, in_max, in_view=1;
1005 /* firstly, check if
1006 * - 'bubble' fills entire scroller
1007 * - 'bubble' completely out of view on either side
1009 if ((sh_min <= sc_min) && (sh_max >= sc_max)) in_view= 0;
1010 if (sh_min == sh_max) {
1011 if (sh_min <= sc_min) in_view= 0;
1012 if (sh_max >= sc_max) in_view= 0;
1015 if (sh_max <= sc_min) in_view= 0;
1016 if (sh_min >= sc_max) in_view= 0;
1021 return SCROLLHANDLE_BAR;
1024 /* check if mouse is in or past either handle */
1025 in_max= ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
1026 in_min= ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
1028 /* check if overlap --> which means user clicked on bar, as bar is within handles region */
1029 if (in_max && in_min)
1030 return SCROLLHANDLE_BAR;
1032 return SCROLLHANDLE_MAX;
1034 return SCROLLHANDLE_MIN;
1036 /* unlikely to happen, though we just cover it in case */
1037 return SCROLLHANDLE_BAR;
1040 /* initialise customdata for scroller manipulation operator */
1041 static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event, short in_scroller)
1043 v2dScrollerMove *vsm;
1044 View2DScrollers *scrollers;
1045 ARegion *ar= CTX_wm_region(C);
1046 View2D *v2d= &ar->v2d;
1050 /* set custom-data for operator */
1051 vsm= MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove");
1052 op->customdata= vsm;
1054 /* set general data */
1056 vsm->scroller= in_scroller;
1058 /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
1059 vsm->lastx = event->x;
1060 vsm->lasty = event->y;
1061 x= event->x - ar->winrct.xmin;
1062 y= event->y - ar->winrct.ymin;
1064 /* 'zone' depends on where mouse is relative to bubble
1065 * - zooming must be allowed on this axis, otherwise, default to pan
1067 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1068 if (in_scroller == 'h') {
1069 /* horizontal scroller - calculate adjustment factor first */
1070 mask_size= (float)(v2d->hor.xmax - v2d->hor.xmin);
1071 vsm->fac= (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
1073 /* get 'zone' (i.e. which part of scroller is activated) */
1074 if (v2d->keepzoom & V2D_LOCKZOOM_X) {
1075 /* default to scroll, as handles not usable */
1076 vsm->zone= SCROLLHANDLE_BAR;
1079 /* check which handle we're in */
1080 vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
1084 /* vertical scroller - calculate adjustment factor first */
1085 mask_size= (float)(v2d->vert.ymax - v2d->vert.ymin);
1086 vsm->fac= (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
1088 /* get 'zone' (i.e. which part of scroller is activated) */
1089 if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
1090 /* default to scroll, as handles not usable */
1091 vsm->zone= SCROLLHANDLE_BAR;
1094 /* check which handle we're in */
1095 vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max);
1099 UI_view2d_scrollers_free(scrollers);
1100 ED_region_tag_redraw(ar);
1103 /* cleanup temp customdata */
1104 static void scroller_activate_exit(bContext *C, wmOperator *op)
1106 if (op->customdata) {
1107 v2dScrollerMove *vsm= op->customdata;
1109 vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE|V2D_SCROLL_V_ACTIVE);
1111 MEM_freeN(op->customdata);
1112 op->customdata= NULL;
1114 ED_region_tag_redraw(CTX_wm_region(C));
1118 /* apply transform to view (i.e. adjust 'cur' rect) */
1119 static void scroller_activate_apply(bContext *C, wmOperator *op)
1121 v2dScrollerMove *vsm= op->customdata;
1122 View2D *v2d= vsm->v2d;
1125 /* calculate amount to move view by */
1126 temp= vsm->fac * vsm->delta;
1128 /* type of movement */
1129 switch (vsm->zone) {
1130 case SCROLLHANDLE_MIN:
1131 case SCROLLHANDLE_MAX:
1133 /* only expand view on axis if zoom is allowed */
1134 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1135 v2d->cur.xmin -= temp;
1136 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1137 v2d->cur.ymin -= temp;
1139 /* only expand view on axis if zoom is allowed */
1140 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1141 v2d->cur.xmax += temp;
1142 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1143 v2d->cur.ymax += temp;
1146 default: /* SCROLLHANDLE_BAR */
1147 /* only move view on an axis if panning is allowed */
1148 if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
1149 v2d->cur.xmin += temp;
1150 v2d->cur.xmax += temp;
1152 if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
1153 v2d->cur.ymin += temp;
1154 v2d->cur.ymax += temp;
1159 /* validate that view is in valid configuration after this operation */
1160 UI_view2d_curRect_validate(v2d);
1162 /* request updates to be done... */
1163 ED_area_tag_redraw(CTX_wm_area(C));
1164 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1167 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
1168 static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
1170 v2dScrollerMove *vsm= op->customdata;
1172 /* execute the events */
1173 switch (event->type) {
1176 /* calculate new delta transform, then store mouse-coordinates for next-time */
1177 if (vsm->zone != SCROLLHANDLE_MIN) {
1178 /* if using bar (i.e. 'panning') or 'max' zoom widget */
1179 switch (vsm->scroller) {
1180 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
1181 vsm->delta= (float)(event->x - vsm->lastx);
1183 case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
1184 vsm->delta= (float)(event->y - vsm->lasty);
1189 /* using 'min' zoom widget */
1190 switch (vsm->scroller) {
1191 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
1192 vsm->delta= (float)(vsm->lastx - event->x);
1194 case 'v': /* vertical scroller - so only vertical movement ('cur' moves with to mouse) */
1195 vsm->delta= (float)(vsm->lasty - event->y);
1200 /* store previous coordinates */
1201 vsm->lastx= event->x;
1202 vsm->lasty= event->y;
1204 scroller_activate_apply(C, op);
1209 if (event->val==0) {
1210 scroller_activate_exit(C, op);
1211 return OPERATOR_FINISHED;
1216 return OPERATOR_RUNNING_MODAL;
1220 /* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
1221 static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
1223 ARegion *ar= CTX_wm_region(C);
1224 View2D *v2d= &ar->v2d;
1225 short in_scroller= 0;
1227 /* check if mouse in scrollbars, if they're enabled */
1228 in_scroller= UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
1230 /* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
1232 v2dScrollerMove *vsm;
1234 /* initialise customdata */
1235 scroller_activate_init(C, op, event, in_scroller);
1236 vsm= (v2dScrollerMove *)op->customdata;
1238 /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
1239 if (vsm->zone == SCROLLHANDLE_BAR) {
1240 if ( ((vsm->scroller=='h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
1241 ((vsm->scroller=='v') && (v2d->keepofs & V2D_LOCKOFS_Y)) )
1243 /* free customdata initialised */
1244 scroller_activate_exit(C, op);
1246 /* can't catch this event for ourselves, so let it go to someone else? */
1247 return OPERATOR_PASS_THROUGH;
1251 if(vsm->scroller=='h')
1252 v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE;
1254 v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE;
1256 /* still ok, so can add */
1257 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1258 return OPERATOR_RUNNING_MODAL;
1261 /* not in scroller, so nothing happened... (pass through let's something else catch event) */
1262 return OPERATOR_PASS_THROUGH;
1266 /* LMB-Drag in Scrollers - not repeatable operator! */
1267 void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
1270 ot->name= "Scroller Activate";
1271 ot->idname= "VIEW2D_OT_scroller_activate";
1274 ot->flag= OPTYPE_BLOCKING;
1277 ot->invoke= scroller_activate_invoke;
1278 ot->modal= scroller_activate_modal;
1279 ot->poll= view2d_poll;
1282 /* ********************************************************* */
1285 static int reset_exec(bContext *C, wmOperator *op)
1287 uiStyle *style= U.uistyles.first;
1288 ARegion *ar= CTX_wm_region(C);
1289 View2D *v2d= &ar->v2d;
1293 winx= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
1294 winy= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
1296 v2d->cur.xmax= v2d->cur.xmin + winx;
1297 v2d->cur.ymax= v2d->cur.ymin + winy;
1301 /* posx and negx flags are mutually exclusive, so watch out */
1302 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
1303 v2d->cur.xmax= 0.0f;
1304 v2d->cur.xmin= v2d->winx*style->panelzoom;
1306 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
1307 v2d->cur.xmax= (v2d->cur.xmax - v2d->cur.xmin)*style->panelzoom;
1308 v2d->cur.xmin= 0.0f;
1311 /* - posx and negx flags are mutually exclusive, so watch out */
1312 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1313 v2d->cur.ymax= 0.0f;
1314 v2d->cur.ymin= -v2d->winy*style->panelzoom;
1316 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
1317 v2d->cur.ymax= (v2d->cur.ymax - v2d->cur.ymin)*style->panelzoom;
1318 v2d->cur.ymin= 0.0f;
1322 /* validate that view is in valid configuration after this operation */
1323 UI_view2d_curRect_validate(v2d);
1325 /* request updates to be done... */
1326 ED_area_tag_redraw(CTX_wm_area(C));
1327 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1329 return OPERATOR_FINISHED;
1332 void VIEW2D_OT_reset(wmOperatorType *ot)
1335 ot->name= "Reset View";
1336 ot->idname= "VIEW2D_OT_reset";
1339 ot->exec= reset_exec;
1340 ot->poll= view2d_poll;
1343 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1346 /* ********************************************************* */
1349 void ui_view2d_operatortypes(void)
1351 WM_operatortype_append(VIEW2D_OT_pan);
1353 WM_operatortype_append(VIEW2D_OT_scroll_left);
1354 WM_operatortype_append(VIEW2D_OT_scroll_right);
1355 WM_operatortype_append(VIEW2D_OT_scroll_up);
1356 WM_operatortype_append(VIEW2D_OT_scroll_down);
1358 WM_operatortype_append(VIEW2D_OT_zoom_in);
1359 WM_operatortype_append(VIEW2D_OT_zoom_out);
1361 WM_operatortype_append(VIEW2D_OT_zoom);
1362 WM_operatortype_append(VIEW2D_OT_zoom_border);
1364 WM_operatortype_append(VIEW2D_OT_scroller_activate);
1366 WM_operatortype_append(VIEW2D_OT_reset);
1369 void UI_view2d_keymap(wmWindowManager *wm)
1371 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
1374 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1375 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
1377 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
1378 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
1380 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
1381 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
1383 /* zoom - single step */
1384 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
1385 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
1386 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1387 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1389 /* scroll up/down - no modifiers, only when zoom fails */
1390 /* these may fail if zoom is disallowed, in which case they should pass on event */
1391 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1392 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1393 /* these may be necessary if vertical scroll is disallowed */
1394 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1395 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, 0, 0);
1398 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1400 /* borderzoom - drag */
1401 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
1404 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
1406 /* Alternative keymap for buttons listview */
1407 keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
1408 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1409 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1410 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1411 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1412 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1413 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1414 WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);
1415 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);