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);
154 WM_event_add_mousemove(C);
157 if(vpd->sa->spacetype==SPACE_OUTLINER) {
158 SpaceOops *soops= vpd->sa->spacedata.first;
159 soops->storeflag |= SO_TREESTORE_REDRAW;
163 /* cleanup temp customdata */
164 static void view_pan_exit(bContext *C, wmOperator *op)
166 if (op->customdata) {
167 MEM_freeN(op->customdata);
168 op->customdata= NULL;
172 /* ------------------ Modal Drag Version (1) ---------------------- */
174 /* for 'redo' only, with no user input */
175 static int view_pan_exec(bContext *C, wmOperator *op)
177 if (!view_pan_init(C, op))
178 return OPERATOR_CANCELLED;
180 view_pan_apply(C, op);
181 view_pan_exit(C, op);
182 return OPERATOR_FINISHED;
185 /* set up modal operator and relevant settings */
186 static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
188 wmWindow *window= CTX_wm_window(C);
192 /* set up customdata */
193 if (!view_pan_init(C, op))
194 return OPERATOR_PASS_THROUGH;
199 /* set initial settings */
200 vpd->startx= vpd->lastx= event->x;
201 vpd->starty= vpd->lasty= event->y;
202 RNA_int_set(op->ptr, "deltax", 0);
203 RNA_int_set(op->ptr, "deltay", 0);
205 if (v2d->keepofs & V2D_LOCKOFS_X)
206 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
207 else if (v2d->keepofs & V2D_LOCKOFS_Y)
208 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
210 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
212 /* add temp handler */
213 WM_event_add_modal_handler(C, &window->handlers, op);
215 return OPERATOR_RUNNING_MODAL;
218 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
219 static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
221 v2dViewPanData *vpd= op->customdata;
223 /* execute the events */
224 switch (event->type) {
227 /* calculate new delta transform, then store mouse-coordinates for next-time */
228 RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
229 RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
231 vpd->lastx= event->x;
232 vpd->lasty= event->y;
234 view_pan_apply(C, op);
240 /* calculate overall delta mouse-movement for redo */
241 RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
242 RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
244 view_pan_exit(C, op);
245 WM_cursor_restore(CTX_wm_window(C));
247 return OPERATOR_FINISHED;
252 return OPERATOR_RUNNING_MODAL;
255 void VIEW2D_OT_pan(wmOperatorType *ot)
258 ot->name= "Pan View";
259 ot->idname= "VIEW2D_OT_pan";
262 ot->exec= view_pan_exec;
263 ot->invoke= view_pan_invoke;
264 ot->modal= view_pan_modal;
266 /* operator is repeatable */
267 ot->flag= OPTYPE_BLOCKING;
269 /* rna - must keep these in sync with the other operators */
270 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
271 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
274 /* ------------------ Scrollwheel Versions (2) ---------------------- */
276 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
277 static int view_scrollright_exec(bContext *C, wmOperator *op)
281 /* initialise default settings (and validate if ok to run) */
282 if (!view_pan_init(C, op))
283 return OPERATOR_PASS_THROUGH;
285 /* also, check if can pan in horizontal axis */
287 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
288 view_pan_exit(C, op);
289 return OPERATOR_PASS_THROUGH;
292 /* set RNA-Props - only movement in positive x-direction */
293 RNA_int_set(op->ptr, "deltax", 20);
294 RNA_int_set(op->ptr, "deltay", 0);
296 /* apply movement, then we're done */
297 view_pan_apply(C, op);
298 view_pan_exit(C, op);
300 return OPERATOR_FINISHED;
303 void VIEW2D_OT_scroll_right(wmOperatorType *ot)
306 ot->name= "Scroll Right";
307 ot->idname= "VIEW2D_OT_scroll_right";
310 ot->exec= view_scrollright_exec;
312 /* operator is repeatable */
313 // ot->flag= OPTYPE_REGISTER;
315 /* rna - must keep these in sync with the other operators */
316 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
317 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
322 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
323 static int view_scrollleft_exec(bContext *C, wmOperator *op)
327 /* initialise default settings (and validate if ok to run) */
328 if (!view_pan_init(C, op))
329 return OPERATOR_PASS_THROUGH;
331 /* also, check if can pan in horizontal axis */
333 if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
334 view_pan_exit(C, op);
335 return OPERATOR_PASS_THROUGH;
338 /* set RNA-Props - only movement in negative x-direction */
339 RNA_int_set(op->ptr, "deltax", -20);
340 RNA_int_set(op->ptr, "deltay", 0);
342 /* apply movement, then we're done */
343 view_pan_apply(C, op);
344 view_pan_exit(C, op);
346 return OPERATOR_FINISHED;
349 void VIEW2D_OT_scroll_left(wmOperatorType *ot)
352 ot->name= "Scroll Left";
353 ot->idname= "VIEW2D_OT_scroll_left";
356 ot->exec= view_scrollleft_exec;
358 /* operator is repeatable */
359 // ot->flag= OPTYPE_REGISTER;
361 /* rna - must keep these in sync with the other operators */
362 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
363 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
367 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
368 static int view_scrolldown_exec(bContext *C, wmOperator *op)
372 /* initialise default settings (and validate if ok to run) */
373 if (!view_pan_init(C, op))
374 return OPERATOR_PASS_THROUGH;
376 /* also, check if can pan in vertical axis */
378 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
379 view_pan_exit(C, op);
380 return OPERATOR_PASS_THROUGH;
384 RNA_int_set(op->ptr, "deltax", 0);
385 RNA_int_set(op->ptr, "deltay", -20);
387 /* apply movement, then we're done */
388 view_pan_apply(C, op);
389 view_pan_exit(C, op);
391 return OPERATOR_FINISHED;
394 void VIEW2D_OT_scroll_down(wmOperatorType *ot)
397 ot->name= "Scroll Down";
398 ot->idname= "VIEW2D_OT_scroll_down";
401 ot->exec= view_scrolldown_exec;
403 /* operator is repeatable */
404 // ot->flag= OPTYPE_REGISTER;
406 /* rna - must keep these in sync with the other operators */
407 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
408 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
413 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
414 static int view_scrollup_exec(bContext *C, wmOperator *op)
418 /* initialise default settings (and validate if ok to run) */
419 if (!view_pan_init(C, op))
420 return OPERATOR_PASS_THROUGH;
422 /* also, check if can pan in vertical axis */
424 if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
425 view_pan_exit(C, op);
426 return OPERATOR_PASS_THROUGH;
430 RNA_int_set(op->ptr, "deltax", 0);
431 RNA_int_set(op->ptr, "deltay", 20);
433 /* apply movement, then we're done */
434 view_pan_apply(C, op);
435 view_pan_exit(C, op);
437 return OPERATOR_FINISHED;
440 void VIEW2D_OT_scroll_up(wmOperatorType *ot)
443 ot->name= "Scroll Up";
444 ot->idname= "VIEW2D_OT_scroll_up";
447 ot->exec= view_scrollup_exec;
449 /* operator is repeatable */
450 // ot->flag= OPTYPE_REGISTER;
452 /* rna - must keep these in sync with the other operators */
453 RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
454 RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
457 /* ********************************************************* */
458 /* SINGLE-STEP VIEW ZOOMING OPERATOR */
460 /* This group of operators come in several forms:
461 * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
462 * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented...
463 * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
465 * In order to make sure this works, each operator must define the following RNA-Operator Props:
466 * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling.
467 * It is safe to scale by 0, as these factors are used to determine
468 * amount to enlarge 'cur' by
471 /* ------------------ 'Shared' stuff ------------------------ */
473 /* check if step-zoom can be applied */
474 static int view_zoom_poll(bContext *C)
476 ARegion *ar= CTX_wm_region(C);
479 /* check if there's a region in context to work with */
484 /* check that 2d-view is zoomable */
485 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
488 /* view is zoomable */
492 /* apply transform to view (i.e. adjust 'cur' rect) */
493 static void view_zoomstep_apply(bContext *C, wmOperator *op)
495 ARegion *ar= CTX_wm_region(C);
496 View2D *v2d= &ar->v2d;
497 float dx, dy, facx, facy;
499 /* calculate amount to move view by, ensuring symmetry so the
500 * old zoom level is restored after zooming back the same amount */
501 facx= RNA_float_get(op->ptr, "zoomfacx");
502 facy= RNA_float_get(op->ptr, "zoomfacy");
505 dx= (v2d->cur.xmax - v2d->cur.xmin) * facx;
506 dy= (v2d->cur.ymax - v2d->cur.ymin) * facy;
509 dx= ((v2d->cur.xmax - v2d->cur.xmin)/(1.0f + 2.0f*facx)) * facx;
510 dy= ((v2d->cur.ymax - v2d->cur.ymin)/(1.0f + 2.0f*facy)) * facy;
513 /* only resize view on an axis if change is allowed */
514 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
515 if (v2d->keepofs & V2D_LOCKOFS_X) {
516 v2d->cur.xmax -= 2*dx;
518 else if (v2d->keepofs & V2D_KEEPOFS_X) {
519 if(v2d->align & V2D_ALIGN_NO_POS_X)
520 v2d->cur.xmin += 2*dx;
522 v2d->cur.xmax -= 2*dx;
529 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
530 if (v2d->keepofs & V2D_LOCKOFS_Y) {
531 v2d->cur.ymax -= 2*dy;
533 else if (v2d->keepofs & V2D_KEEPOFS_Y) {
534 if(v2d->align & V2D_ALIGN_NO_POS_Y)
535 v2d->cur.ymin += 2*dy;
537 v2d->cur.ymax -= 2*dy;
545 /* validate that view is in valid configuration after this operation */
546 UI_view2d_curRect_validate(v2d);
548 /* request updates to be done... */
549 ED_area_tag_redraw(CTX_wm_area(C));
550 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
551 WM_event_add_mousemove(C);
554 /* --------------- Individual Operators ------------------- */
556 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
557 static int view_zoomin_exec(bContext *C, wmOperator *op)
559 /* check that there's an active region, as View2D data resides there */
560 if (!view_zoom_poll(C))
561 return OPERATOR_PASS_THROUGH;
563 /* set RNA-Props - zooming in by uniform factor */
564 RNA_float_set(op->ptr, "zoomfacx", 0.0375f);
565 RNA_float_set(op->ptr, "zoomfacy", 0.0375f);
567 /* apply movement, then we're done */
568 view_zoomstep_apply(C, op);
570 return OPERATOR_FINISHED;
573 void VIEW2D_OT_zoom_in(wmOperatorType *ot)
577 ot->idname= "VIEW2D_OT_zoom_in";
580 ot->exec= view_zoomin_exec;
582 /* operator is repeatable */
583 // ot->flag= OPTYPE_REGISTER;
585 /* rna - must keep these in sync with the other operators */
586 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
587 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
592 /* this operator only needs this single callback, where it callsthe view_zoom_*() methods */
593 static int view_zoomout_exec(bContext *C, wmOperator *op)
595 /* check that there's an active region, as View2D data resides there */
596 if (!view_zoom_poll(C))
597 return OPERATOR_PASS_THROUGH;
599 /* set RNA-Props - zooming in by uniform factor */
600 RNA_float_set(op->ptr, "zoomfacx", -0.0375f);
601 RNA_float_set(op->ptr, "zoomfacy", -0.0375f);
603 /* apply movement, then we're done */
604 view_zoomstep_apply(C, op);
606 return OPERATOR_FINISHED;
609 void VIEW2D_OT_zoom_out(wmOperatorType *ot)
612 ot->name= "Zoom Out";
613 ot->idname= "VIEW2D_OT_zoom_out";
616 ot->exec= view_zoomout_exec;
618 /* operator is repeatable */
619 // ot->flag= OPTYPE_REGISTER;
621 /* rna - must keep these in sync with the other operators */
622 RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
623 RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
626 /* ********************************************************* */
627 /* DRAG-ZOOM OPERATOR */
629 /* MMB Drag - allows non-uniform scaling by dragging mouse
631 * In order to make sure this works, each operator must define the following RNA-Operator Props:
632 * deltax, deltay - amounts to add to each side of the 'cur' rect
635 /* ------------------ Shared 'core' stuff ---------------------- */
637 /* temp customdata for operator */
638 typedef struct v2dViewZoomData {
639 View2D *v2d; /* view2d we're operating in */
641 int lastx, lasty; /* previous x/y values of mouse in window */
642 float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
645 /* initialise panning customdata */
646 static int view_zoomdrag_init(bContext *C, wmOperator *op)
648 ARegion *ar= CTX_wm_region(C);
649 v2dViewZoomData *vzd;
652 /* regions now have v2d-data by default, so check for region */
657 /* check that 2d-view is zoomable */
658 if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
661 /* set custom-data for operator */
662 vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
665 /* set pointers to owners */
671 /* apply transform to view (i.e. adjust 'cur' rect) */
672 static void view_zoomdrag_apply(bContext *C, wmOperator *op)
674 v2dViewZoomData *vzd= op->customdata;
675 View2D *v2d= vzd->v2d;
678 /* get amount to move view by */
679 dx= RNA_float_get(op->ptr, "deltax");
680 dy= RNA_float_get(op->ptr, "deltay");
682 /* only move view on an axis if change is allowed */
683 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
684 if (v2d->keepofs & V2D_LOCKOFS_X) {
685 v2d->cur.xmax -= 2*dx;
692 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
693 if (v2d->keepofs & V2D_LOCKOFS_Y) {
694 v2d->cur.ymax -= 2*dy;
702 /* validate that view is in valid configuration after this operation */
703 UI_view2d_curRect_validate(v2d);
705 /* request updates to be done... */
706 ED_area_tag_redraw(CTX_wm_area(C));
707 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
708 WM_event_add_mousemove(C);
711 /* cleanup temp customdata */
712 static void view_zoomdrag_exit(bContext *C, wmOperator *op)
714 if (op->customdata) {
715 MEM_freeN(op->customdata);
716 op->customdata= NULL;
720 /* for 'redo' only, with no user input */
721 static int view_zoomdrag_exec(bContext *C, wmOperator *op)
723 if (!view_zoomdrag_init(C, op))
724 return OPERATOR_PASS_THROUGH;
726 view_zoomdrag_apply(C, op);
727 view_zoomdrag_exit(C, op);
728 return OPERATOR_FINISHED;
731 /* set up modal operator and relevant settings */
732 static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
734 wmWindow *window= CTX_wm_window(C);
735 v2dViewZoomData *vzd;
738 /* set up customdata */
739 if (!view_zoomdrag_init(C, op))
740 return OPERATOR_PASS_THROUGH;
745 /* set initial settings */
746 vzd->lastx= event->x;
747 vzd->lasty= event->y;
748 RNA_float_set(op->ptr, "deltax", 0);
749 RNA_float_set(op->ptr, "deltay", 0);
751 if (v2d->keepofs & V2D_LOCKOFS_X)
752 WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
753 else if (v2d->keepofs & V2D_LOCKOFS_Y)
754 WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
756 WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
758 /* add temp handler */
759 WM_event_add_modal_handler(C, &window->handlers, op);
761 return OPERATOR_RUNNING_MODAL;
764 /* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
765 static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
767 v2dViewZoomData *vzd= op->customdata;
768 View2D *v2d= vzd->v2d;
770 /* execute the events */
771 switch (event->type) {
776 /* calculate new delta transform, based on zooming mode */
777 if (U.viewzoom == USER_ZOOM_SCALE) {
778 /* 'scale' zooming */
781 /* x-axis transform */
782 dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
783 dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
784 dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
786 /* y-axis transform */
787 dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
788 dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
789 dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
792 /* 'continuous' or 'dolly' */
795 /* x-axis transform */
796 fac= 0.01f * (event->x - vzd->lastx);
797 dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
799 /* y-axis transform */
800 fac= 0.01f * (event->y - vzd->lasty);
801 dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
803 /* continous zoom shouldn't move that fast... */
804 if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
810 /* set transform amount, and add current deltas to stored total delta (for redo) */
811 RNA_float_set(op->ptr, "deltax", dx);
812 RNA_float_set(op->ptr, "deltay", dy);
816 /* store mouse coordinates for next time, if not doing continuous zoom
817 * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
819 if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
820 vzd->lastx= event->x;
821 vzd->lasty= event->y;
825 view_zoomdrag_apply(C, op);
831 /* for redo, store the overall deltas - need to respect zoom-locks here... */
832 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
833 RNA_float_set(op->ptr, "deltax", vzd->dx);
835 RNA_float_set(op->ptr, "deltax", 0);
837 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
838 RNA_float_set(op->ptr, "deltay", vzd->dy);
840 RNA_float_set(op->ptr, "deltay", 0);
842 /* free customdata */
843 view_zoomdrag_exit(C, op);
844 WM_cursor_restore(CTX_wm_window(C));
846 return OPERATOR_FINISHED;
851 return OPERATOR_RUNNING_MODAL;
854 void VIEW2D_OT_zoom(wmOperatorType *ot)
857 ot->name= "Zoom View";
858 ot->idname= "VIEW2D_OT_zoom";
861 ot->exec= view_zoomdrag_exec;
862 ot->invoke= view_zoomdrag_invoke;
863 ot->modal= view_zoomdrag_modal;
865 ot->poll= view_zoom_poll;
867 /* operator is repeatable */
868 // ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
870 /* rna - must keep these in sync with the other operators */
871 RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
872 RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
875 /* ********************************************************* */
878 /* The user defines a rect using standard borderselect tools, and we use this rect to
879 * define the new zoom-level of the view in the following ways:
880 * 1) LEFTMOUSE - zoom in to view
881 * 2) RIGHTMOUSE - zoom out of view
883 * Currently, these key mappings are hardcoded, but it shouldn't be too important to
884 * have custom keymappings for this...
887 static int view_borderzoom_exec(bContext *C, wmOperator *op)
889 ARegion *ar= CTX_wm_region(C);
890 View2D *v2d= &ar->v2d;
894 /* convert coordinates of rect to 'tot' rect coordinates */
895 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
896 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
898 /* check if zooming in/out view */
899 // XXX hardcoded for now!
900 event_type= RNA_int_get(op->ptr, "event_type");
902 if (event_type == LEFTMOUSE) {
904 * - 'cur' rect will be defined by the coordinates of the border region
905 * - just set the 'cur' rect to have the same coordinates as the border region
906 * if zoom is allowed to be changed
908 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
909 v2d->cur.xmin= rect.xmin;
910 v2d->cur.xmax= rect.xmax;
912 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
913 v2d->cur.ymin= rect.ymin;
914 v2d->cur.ymax= rect.ymax;
919 * - the current 'cur' rect coordinates are going to end upwhere the 'rect' ones are,
920 * but the 'cur' rect coordinates will need to be adjusted to take in more of the view
921 * - calculate zoom factor, and adjust using center-point
923 float zoom, center, size;
925 // TODO: is this zoom factor calculation valid? It seems to produce same results everytime...
926 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
927 size= (v2d->cur.xmax - v2d->cur.xmin);
928 zoom= size / (rect.xmax - rect.xmin);
929 center= (v2d->cur.xmax + v2d->cur.xmin) * 0.5f;
931 v2d->cur.xmin= center - (size * zoom);
932 v2d->cur.xmax= center + (size * zoom);
934 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
935 size= (v2d->cur.ymax - v2d->cur.ymin);
936 zoom= size / (rect.ymax - rect.ymin);
937 center= (v2d->cur.ymax + v2d->cur.ymin) * 0.5f;
939 v2d->cur.ymin= center - (size * zoom);
940 v2d->cur.ymax= center + (size * zoom);
944 /* validate that view is in valid configuration after this operation */
945 UI_view2d_curRect_validate(v2d);
947 /* request updates to be done... */
948 ED_area_tag_redraw(CTX_wm_area(C));
949 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
950 WM_event_add_mousemove(C);
952 return OPERATOR_FINISHED;
955 void VIEW2D_OT_zoom_border(wmOperatorType *ot)
958 ot->name= "Zoom to Border";
959 ot->idname= "VIEW2D_OT_zoom_border";
962 ot->invoke= WM_border_select_invoke;
963 ot->exec= view_borderzoom_exec;
964 ot->modal= WM_border_select_modal;
966 ot->poll= view_zoom_poll;
969 RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
970 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
971 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
972 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
973 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
976 /* ********************************************************* */
979 /* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
980 * 1) 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable,
981 * enlarge 'cur' rect on the relevant side
982 * 2) 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite)
984 * In order to make sure this works, each operator must define the following RNA-Operator Props:
985 * deltax, deltay - define how much to move view by (relative to zoom-correction factor)
988 /* customdata for scroller-invoke data */
989 typedef struct v2dScrollerMove {
990 View2D *v2d; /* View2D data that this operation affects */
992 short scroller; /* scroller that mouse is in ('h' or 'v') */
993 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?)
995 float fac; /* view adjustment factor, based on size of region */
996 float delta; /* amount moved by mouse on axis of interest */
998 int lastx, lasty; /* previous mouse coordinates (in screen coordinates) for determining movement */
1002 /* View2DScrollers is typedef'd in UI_view2d.h
1003 * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info
1004 * WARNING: the start of this struct must not change, so that it stays in sync with the 'real' version
1005 * For now, we don't need to have a separate (internal) header for structs like this...
1007 struct View2DScrollers {
1009 int vert_min, vert_max; /* vertical scrollbar */
1010 int hor_min, hor_max; /* horizontal scrollbar */
1013 /* quick enum for vsm->zone (scroller handles) */
1015 SCROLLHANDLE_MIN= -1,
1018 } eV2DScrollerHandle_Zone;
1020 /* ------------------------ */
1022 /* check if mouse is within scroller handle
1023 * - mouse = relevant mouse coordinate in region space
1024 * - sc_min, sc_max = extents of scroller
1025 * - sh_min, sh_max = positions of scroller handles
1027 static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
1029 short in_min, in_max, in_view=1;
1031 /* firstly, check if
1032 * - 'bubble' fills entire scroller
1033 * - 'bubble' completely out of view on either side
1035 if ((sh_min <= sc_min) && (sh_max >= sc_max)) in_view= 0;
1036 if (sh_min == sh_max) {
1037 if (sh_min <= sc_min) in_view= 0;
1038 if (sh_max >= sc_max) in_view= 0;
1041 if (sh_max <= sc_min) in_view= 0;
1042 if (sh_min >= sc_max) in_view= 0;
1047 return SCROLLHANDLE_BAR;
1050 /* check if mouse is in or past either handle */
1051 in_max= ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
1052 in_min= ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
1054 /* check if overlap --> which means user clicked on bar, as bar is within handles region */
1055 if (in_max && in_min)
1056 return SCROLLHANDLE_BAR;
1058 return SCROLLHANDLE_MAX;
1060 return SCROLLHANDLE_MIN;
1062 /* unlikely to happen, though we just cover it in case */
1063 return SCROLLHANDLE_BAR;
1066 /* initialise customdata for scroller manipulation operator */
1067 static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event, short in_scroller)
1069 v2dScrollerMove *vsm;
1070 View2DScrollers *scrollers;
1071 ARegion *ar= CTX_wm_region(C);
1072 View2D *v2d= &ar->v2d;
1076 /* set custom-data for operator */
1077 vsm= MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove");
1078 op->customdata= vsm;
1080 /* set general data */
1082 vsm->scroller= in_scroller;
1084 /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
1085 vsm->lastx = event->x;
1086 vsm->lasty = event->y;
1087 x= event->x - ar->winrct.xmin;
1088 y= event->y - ar->winrct.ymin;
1090 /* 'zone' depends on where mouse is relative to bubble
1091 * - zooming must be allowed on this axis, otherwise, default to pan
1093 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1094 if (in_scroller == 'h') {
1095 /* horizontal scroller - calculate adjustment factor first */
1096 mask_size= (float)(v2d->hor.xmax - v2d->hor.xmin);
1097 vsm->fac= (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
1099 /* get 'zone' (i.e. which part of scroller is activated) */
1100 if (v2d->keepzoom & V2D_LOCKZOOM_X) {
1101 /* default to scroll, as handles not usable */
1102 vsm->zone= SCROLLHANDLE_BAR;
1105 /* check which handle we're in */
1106 vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
1110 /* vertical scroller - calculate adjustment factor first */
1111 mask_size= (float)(v2d->vert.ymax - v2d->vert.ymin);
1112 vsm->fac= (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
1114 /* get 'zone' (i.e. which part of scroller is activated) */
1115 if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
1116 /* default to scroll, as handles not usable */
1117 vsm->zone= SCROLLHANDLE_BAR;
1120 /* check which handle we're in */
1121 vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max);
1125 UI_view2d_scrollers_free(scrollers);
1126 ED_region_tag_redraw(ar);
1129 /* cleanup temp customdata */
1130 static void scroller_activate_exit(bContext *C, wmOperator *op)
1132 if (op->customdata) {
1133 v2dScrollerMove *vsm= op->customdata;
1135 vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE|V2D_SCROLL_V_ACTIVE);
1137 MEM_freeN(op->customdata);
1138 op->customdata= NULL;
1140 ED_region_tag_redraw(CTX_wm_region(C));
1144 /* apply transform to view (i.e. adjust 'cur' rect) */
1145 static void scroller_activate_apply(bContext *C, wmOperator *op)
1147 v2dScrollerMove *vsm= op->customdata;
1148 View2D *v2d= vsm->v2d;
1151 /* calculate amount to move view by */
1152 temp= vsm->fac * vsm->delta;
1154 /* type of movement */
1155 switch (vsm->zone) {
1156 case SCROLLHANDLE_MIN:
1157 case SCROLLHANDLE_MAX:
1159 /* only expand view on axis if zoom is allowed */
1160 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1161 v2d->cur.xmin -= temp;
1162 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1163 v2d->cur.ymin -= temp;
1165 /* only expand view on axis if zoom is allowed */
1166 if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
1167 v2d->cur.xmax += temp;
1168 if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
1169 v2d->cur.ymax += temp;
1172 default: /* SCROLLHANDLE_BAR */
1173 /* only move view on an axis if panning is allowed */
1174 if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
1175 v2d->cur.xmin += temp;
1176 v2d->cur.xmax += temp;
1178 if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
1179 v2d->cur.ymin += temp;
1180 v2d->cur.ymax += temp;
1185 /* validate that view is in valid configuration after this operation */
1186 UI_view2d_curRect_validate(v2d);
1188 /* request updates to be done... */
1189 ED_area_tag_redraw(CTX_wm_area(C));
1190 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1191 WM_event_add_mousemove(C);
1194 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
1195 static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
1197 v2dScrollerMove *vsm= op->customdata;
1199 /* execute the events */
1200 switch (event->type) {
1203 /* calculate new delta transform, then store mouse-coordinates for next-time */
1204 if (vsm->zone != SCROLLHANDLE_MIN) {
1205 /* if using bar (i.e. 'panning') or 'max' zoom widget */
1206 switch (vsm->scroller) {
1207 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
1208 vsm->delta= (float)(event->x - vsm->lastx);
1210 case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
1211 vsm->delta= (float)(event->y - vsm->lasty);
1216 /* using 'min' zoom widget */
1217 switch (vsm->scroller) {
1218 case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
1219 vsm->delta= (float)(vsm->lastx - event->x);
1221 case 'v': /* vertical scroller - so only vertical movement ('cur' moves with to mouse) */
1222 vsm->delta= (float)(vsm->lasty - event->y);
1227 /* store previous coordinates */
1228 vsm->lastx= event->x;
1229 vsm->lasty= event->y;
1231 scroller_activate_apply(C, op);
1236 if (event->val==0) {
1237 scroller_activate_exit(C, op);
1238 return OPERATOR_FINISHED;
1243 return OPERATOR_RUNNING_MODAL;
1247 /* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
1248 static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
1250 ARegion *ar= CTX_wm_region(C);
1251 View2D *v2d= &ar->v2d;
1252 short in_scroller= 0;
1254 /* check if mouse in scrollbars, if they're enabled */
1255 in_scroller= UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
1257 /* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
1259 v2dScrollerMove *vsm;
1261 /* initialise customdata */
1262 scroller_activate_init(C, op, event, in_scroller);
1263 vsm= (v2dScrollerMove *)op->customdata;
1265 /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
1266 if (vsm->zone == SCROLLHANDLE_BAR) {
1267 if ( ((vsm->scroller=='h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
1268 ((vsm->scroller=='v') && (v2d->keepofs & V2D_LOCKOFS_Y)) )
1270 /* free customdata initialised */
1271 scroller_activate_exit(C, op);
1273 /* can't catch this event for ourselves, so let it go to someone else? */
1274 return OPERATOR_PASS_THROUGH;
1278 if(vsm->scroller=='h')
1279 v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE;
1281 v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE;
1283 /* still ok, so can add */
1284 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1285 return OPERATOR_RUNNING_MODAL;
1288 /* not in scroller, so nothing happened... (pass through let's something else catch event) */
1289 return OPERATOR_PASS_THROUGH;
1293 /* LMB-Drag in Scrollers - not repeatable operator! */
1294 void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
1297 ot->name= "Scroller Activate";
1298 ot->idname= "VIEW2D_OT_scroller_activate";
1301 ot->flag= OPTYPE_BLOCKING;
1304 ot->invoke= scroller_activate_invoke;
1305 ot->modal= scroller_activate_modal;
1306 ot->poll= view2d_poll;
1309 /* ********************************************************* */
1312 static int reset_exec(bContext *C, wmOperator *op)
1314 uiStyle *style= U.uistyles.first;
1315 ARegion *ar= CTX_wm_region(C);
1316 View2D *v2d= &ar->v2d;
1320 winx= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
1321 winy= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
1323 v2d->cur.xmax= v2d->cur.xmin + winx;
1324 v2d->cur.ymax= v2d->cur.ymin + winy;
1328 /* posx and negx flags are mutually exclusive, so watch out */
1329 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
1330 v2d->cur.xmax= 0.0f;
1331 v2d->cur.xmin= -winx*style->panelzoom;
1333 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
1334 v2d->cur.xmax= winx*style->panelzoom;
1335 v2d->cur.xmin= 0.0f;
1338 /* - posx and negx flags are mutually exclusive, so watch out */
1339 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1340 v2d->cur.ymax= 0.0f;
1341 v2d->cur.ymin= -winy*style->panelzoom;
1343 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
1344 v2d->cur.ymax= winy*style->panelzoom;
1345 v2d->cur.ymin= 0.0f;
1349 /* validate that view is in valid configuration after this operation */
1350 UI_view2d_curRect_validate(v2d);
1352 /* request updates to be done... */
1353 ED_area_tag_redraw(CTX_wm_area(C));
1354 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
1355 WM_event_add_mousemove(C);
1357 return OPERATOR_FINISHED;
1360 void VIEW2D_OT_reset(wmOperatorType *ot)
1363 ot->name= "Reset View";
1364 ot->idname= "VIEW2D_OT_reset";
1367 ot->exec= reset_exec;
1368 ot->poll= view2d_poll;
1371 // ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1374 /* ********************************************************* */
1377 void ui_view2d_operatortypes(void)
1379 WM_operatortype_append(VIEW2D_OT_pan);
1381 WM_operatortype_append(VIEW2D_OT_scroll_left);
1382 WM_operatortype_append(VIEW2D_OT_scroll_right);
1383 WM_operatortype_append(VIEW2D_OT_scroll_up);
1384 WM_operatortype_append(VIEW2D_OT_scroll_down);
1386 WM_operatortype_append(VIEW2D_OT_zoom_in);
1387 WM_operatortype_append(VIEW2D_OT_zoom_out);
1389 WM_operatortype_append(VIEW2D_OT_zoom);
1390 WM_operatortype_append(VIEW2D_OT_zoom_border);
1392 WM_operatortype_append(VIEW2D_OT_scroller_activate);
1394 WM_operatortype_append(VIEW2D_OT_reset);
1397 void UI_view2d_keymap(wmWindowManager *wm)
1399 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
1402 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1403 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
1405 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
1406 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
1408 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
1409 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
1411 /* zoom - single step */
1412 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
1413 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
1414 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1415 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1417 /* scroll up/down - no modifiers, only when zoom fails */
1418 /* these may fail if zoom is disallowed, in which case they should pass on event */
1419 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1420 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1421 /* these may be necessary if vertical scroll is disallowed */
1422 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1423 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, 0, 0);
1426 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1428 /* borderzoom - drag */
1429 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
1432 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
1434 /* Alternative keymap for buttons listview */
1435 keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
1436 WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
1437 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
1438 WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
1439 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
1440 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
1441 WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
1442 WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);
1443 WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);