1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
|
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation, Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <math.h>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_vec_types.h"
#include "DNA_view2d_types.h"
#include "BLI_blenlib.h"
#include "BKE_context.h"
#include "BKE_utildefines.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
#include "BIF_gl.h"
#include "ED_screen.h"
#include "UI_resources.h"
#include "UI_view2d.h"
/* ********************************************************* */
/* VIEW PANNING OPERATOR */
/* This group of operators come in several forms:
* 1) Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by
* 2) Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount
*
* In order to make sure this works, each operator must define the following RNA-Operator Props:
* deltax, deltay - define how much to move view by (relative to zoom-correction factor)
*/
/* ------------------ Shared 'core' stuff ---------------------- */
/* temp customdata for operator */
typedef struct v2dViewPanData {
bScreen *sc; /* screen where view pan was initiated */
ScrArea *sa; /* area where view pan was initiated */
View2D *v2d; /* view2d we're operating in */
float facx, facy; /* amount to move view relative to zoom */
/* options for version 1 */
int startx, starty; /* mouse x/y values in window when operator was initiated */
int lastx, lasty; /* previous x/y values of mouse in window */
short in_scroller; /* for MMB in scrollers (old feature in past, but now not that useful) */
} v2dViewPanData;
/* initialise panning customdata */
static int view_pan_init(bContext *C, wmOperator *op)
{
ARegion *ar= CTX_wm_region(C);
v2dViewPanData *vpd;
View2D *v2d;
float winx, winy;
/* regions now have v2d-data by default, so check for region */
if (ar == NULL)
return 0;
/* check if panning is allowed at all */
v2d= &ar->v2d;
if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y))
return 0;
/* set custom-data for operator */
vpd= MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData");
op->customdata= vpd;
/* set pointers to owners */
vpd->sc= CTX_wm_screen(C);
vpd->sa= CTX_wm_area(C);
vpd->v2d= v2d;
/* calculate translation factor - based on size of view */
winx= (float)(ar->winrct.xmax - ar->winrct.xmin);
winy= (float)(ar->winrct.ymax - ar->winrct.ymin);
vpd->facx= (v2d->cur.xmax - v2d->cur.xmin) / winx;
vpd->facy= (v2d->cur.ymax - v2d->cur.ymin) / winy;
return 1;
}
/* apply transform to view (i.e. adjust 'cur' rect) */
static void view_pan_apply(bContext *C, wmOperator *op)
{
v2dViewPanData *vpd= op->customdata;
View2D *v2d= vpd->v2d;
float dx, dy;
/* calculate amount to move view by */
dx= vpd->facx * (float)RNA_int_get(op->ptr, "deltax");
dy= vpd->facy * (float)RNA_int_get(op->ptr, "deltay");
/* only move view on an axis if change is allowed */
if ((v2d->keepofs & V2D_LOCKOFS_X)==0) {
v2d->cur.xmin += dx;
v2d->cur.xmax += dx;
}
if ((v2d->keepofs & V2D_LOCKOFS_Y)==0) {
v2d->cur.ymin += dy;
v2d->cur.ymax += dy;
}
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
/* request updates to be done... */
ED_area_tag_redraw(vpd->sa);
UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY);
}
/* cleanup temp customdata */
static void view_pan_exit(bContext *C, wmOperator *op)
{
if (op->customdata) {
MEM_freeN(op->customdata);
op->customdata= NULL;
}
}
/* ------------------ Modal Drag Version (1) ---------------------- */
/* for 'redo' only, with no user input */
static int view_pan_exec(bContext *C, wmOperator *op)
{
if (!view_pan_init(C, op))
return OPERATOR_CANCELLED;
view_pan_apply(C, op);
view_pan_exit(C, op);
return OPERATOR_FINISHED;
}
/* set up modal operator and relevant settings */
static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
wmWindow *window= CTX_wm_window(C);
v2dViewPanData *vpd;
View2D *v2d;
/* set up customdata */
if (!view_pan_init(C, op))
return OPERATOR_PASS_THROUGH;
vpd= op->customdata;
v2d= vpd->v2d;
/* set initial settings */
vpd->startx= vpd->lastx= event->x;
vpd->starty= vpd->lasty= event->y;
RNA_int_set(op->ptr, "deltax", 0);
RNA_int_set(op->ptr, "deltay", 0);
if (v2d->keepofs & V2D_LOCKOFS_X)
WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
else if (v2d->keepofs & V2D_LOCKOFS_Y)
WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
else
WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
/* add temp handler */
WM_event_add_modal_handler(C, &window->handlers, op);
return OPERATOR_RUNNING_MODAL;
}
/* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
{
v2dViewPanData *vpd= op->customdata;
/* execute the events */
switch (event->type) {
case MOUSEMOVE:
{
/* calculate new delta transform, then store mouse-coordinates for next-time */
RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
vpd->lastx= event->x;
vpd->lasty= event->y;
view_pan_apply(C, op);
}
break;
case MIDDLEMOUSE:
if (event->val==0) {
/* calculate overall delta mouse-movement for redo */
RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
view_pan_exit(C, op);
WM_cursor_restore(CTX_wm_window(C));
return OPERATOR_FINISHED;
}
break;
}
return OPERATOR_RUNNING_MODAL;
}
void View2D_OT_view_pan(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Pan View";
ot->idname= "View2D_OT_view_pan";
/* api callbacks */
ot->exec= view_pan_exec;
ot->invoke= view_pan_invoke;
ot->modal= view_pan_modal;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
/* ------------------ Scrollwheel Versions (2) ---------------------- */
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrollright_exec(bContext *C, wmOperator *op)
{
v2dViewPanData *vpd;
/* initialise default settings (and validate if ok to run) */
if (!view_pan_init(C, op))
return OPERATOR_PASS_THROUGH;
/* also, check if can pan in horizontal axis */
vpd= op->customdata;
if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
view_pan_exit(C, op);
return OPERATOR_PASS_THROUGH;
}
/* set RNA-Props - only movement in positive x-direction */
RNA_int_set(op->ptr, "deltax", 20);
RNA_int_set(op->ptr, "deltay", 0);
/* apply movement, then we're done */
view_pan_apply(C, op);
view_pan_exit(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_scrollright(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Scroll Right";
ot->idname= "View2D_OT_view_rightscroll";
/* api callbacks */
ot->exec= view_scrollright_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrollleft_exec(bContext *C, wmOperator *op)
{
v2dViewPanData *vpd;
/* initialise default settings (and validate if ok to run) */
if (!view_pan_init(C, op))
return OPERATOR_PASS_THROUGH;
/* also, check if can pan in horizontal axis */
vpd= op->customdata;
if (vpd->v2d->keepofs & V2D_LOCKOFS_X) {
view_pan_exit(C, op);
return OPERATOR_PASS_THROUGH;
}
/* set RNA-Props - only movement in negative x-direction */
RNA_int_set(op->ptr, "deltax", -20);
RNA_int_set(op->ptr, "deltay", 0);
/* apply movement, then we're done */
view_pan_apply(C, op);
view_pan_exit(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_scrollleft(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Scroll Left";
ot->idname= "View2D_OT_view_leftscroll";
/* api callbacks */
ot->exec= view_scrollleft_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrolldown_exec(bContext *C, wmOperator *op)
{
v2dViewPanData *vpd;
/* initialise default settings (and validate if ok to run) */
if (!view_pan_init(C, op))
return OPERATOR_PASS_THROUGH;
/* also, check if can pan in vertical axis */
vpd= op->customdata;
if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
view_pan_exit(C, op);
return OPERATOR_PASS_THROUGH;
}
/* set RNA-Props - only movement in positive x-direction */
RNA_int_set(op->ptr, "deltax", 0);
RNA_int_set(op->ptr, "deltay", -20);
/* apply movement, then we're done */
view_pan_apply(C, op);
view_pan_exit(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_scrolldown(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Scroll Down";
ot->idname= "View2D_OT_view_downscroll";
/* api callbacks */
ot->exec= view_scrolldown_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrollup_exec(bContext *C, wmOperator *op)
{
v2dViewPanData *vpd;
/* initialise default settings (and validate if ok to run) */
if (!view_pan_init(C, op))
return OPERATOR_PASS_THROUGH;
/* also, check if can pan in vertical axis */
vpd= op->customdata;
if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) {
view_pan_exit(C, op);
return OPERATOR_PASS_THROUGH;
}
/* set RNA-Props - only movement in negative x-direction */
RNA_int_set(op->ptr, "deltax", 0);
RNA_int_set(op->ptr, "deltay", 20);
/* apply movement, then we're done */
view_pan_apply(C, op);
view_pan_exit(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_scrollup(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Scroll Up";
ot->idname= "View2D_OT_view_upscroll";
/* api callbacks */
ot->exec= view_scrollup_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
/* ********************************************************* */
/* SINGLE-STEP VIEW ZOOMING OPERATOR */
/* This group of operators come in several forms:
* 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
* 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented...
* 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
*
* In order to make sure this works, each operator must define the following RNA-Operator Props:
* zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling.
* It is safe to scale by 0, as these factors are used to determine
* amount to enlarge 'cur' by
*/
/* ------------------ 'Shared' stuff ------------------------ */
/* check if step-zoom can be applied */
static short view_zoomstep_ok(bContext *C)
{
ARegion *ar= CTX_wm_region(C);
View2D *v2d;
/* check if there's a region in context to work with */
if (ar == NULL)
return 0;
v2d= &ar->v2d;
/* check that 2d-view is zoomable */
if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
return 0;
/* view is zoomable */
return 1;
}
/* apply transform to view (i.e. adjust 'cur' rect) */
static void view_zoomstep_apply(bContext *C, wmOperator *op)
{
ARegion *ar= CTX_wm_region(C);
View2D *v2d= &ar->v2d;
float dx, dy;
/* calculate amount to move view by */
dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx");
dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
/* only move view on an axis if change is allowed */
if ((v2d->keepzoom & V2D_LOCKOFS_X)==0) {
v2d->cur.xmin += dx;
v2d->cur.xmax -= dx;
}
if ((v2d->keepzoom & V2D_LOCKOFS_Y)==0) {
v2d->cur.ymin += dy;
v2d->cur.ymax -= dy;
}
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
/* request updates to be done... */
ED_area_tag_redraw(CTX_wm_area(C));
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
}
/* --------------- Individual Operators ------------------- */
/* this operator only needs this single callback, where it calls the view_zoom_*() methods */
static int view_zoomin_exec(bContext *C, wmOperator *op)
{
/* check that there's an active region, as View2D data resides there */
if (!view_zoomstep_ok(C))
return OPERATOR_PASS_THROUGH;
/* set RNA-Props - zooming in by uniform factor */
RNA_float_set(op->ptr, "zoomfacx", 0.0375f);
RNA_float_set(op->ptr, "zoomfacy", 0.0375f);
/* apply movement, then we're done */
view_zoomstep_apply(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_zoomin(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Zoom In";
ot->idname= "View2D_OT_view_zoomin";
/* api callbacks */
ot->exec= view_zoomin_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "zoomfacx", PROP_FLOAT, PROP_NONE);
RNA_def_property(ot->srna, "zoomfacy", PROP_FLOAT, PROP_NONE);
}
/* this operator only needs this single callback, where it callsthe view_zoom_*() methods */
static int view_zoomout_exec(bContext *C, wmOperator *op)
{
/* check that there's an active region, as View2D data resides there */
if (!view_zoomstep_ok(C))
return OPERATOR_PASS_THROUGH;
/* set RNA-Props - zooming in by uniform factor */
RNA_float_set(op->ptr, "zoomfacx", -0.0375f);
RNA_float_set(op->ptr, "zoomfacy", -0.0375f);
/* apply movement, then we're done */
view_zoomstep_apply(C, op);
return OPERATOR_FINISHED;
}
void View2D_OT_view_zoomout(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Zoom Out";
ot->idname= "View2D_OT_view_zoomout";
/* api callbacks */
ot->exec= view_zoomout_exec;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
RNA_def_property(ot->srna, "zoomfacx", PROP_FLOAT, PROP_NONE);
RNA_def_property(ot->srna, "zoomfacy", PROP_FLOAT, PROP_NONE);
}
/* ********************************************************* */
/* DRAG-ZOOM OPERATOR */
/* MMB Drag - allows non-uniform scaling by dragging mouse
*
* In order to make sure this works, each operator must define the following RNA-Operator Props:
* deltax, deltay - amounts to add to each side of the 'cur' rect
*/
/* ------------------ Shared 'core' stuff ---------------------- */
/* temp customdata for operator */
typedef struct v2dViewZoomData {
View2D *v2d; /* view2d we're operating in */
int lastx, lasty; /* previous x/y values of mouse in window */
float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
} v2dViewZoomData;
/* initialise panning customdata */
static int view_zoomdrag_init(bContext *C, wmOperator *op)
{
ARegion *ar= CTX_wm_region(C);
v2dViewZoomData *vzd;
View2D *v2d;
/* regions now have v2d-data by default, so check for region */
if (ar == NULL)
return 0;
v2d= &ar->v2d;
/* check that 2d-view is zoomable */
if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
return 0;
/* set custom-data for operator */
vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
op->customdata= vzd;
/* set pointers to owners */
vzd->v2d= v2d;
return 1;
}
/* apply transform to view (i.e. adjust 'cur' rect) */
static void view_zoomdrag_apply(bContext *C, wmOperator *op)
{
v2dViewZoomData *vzd= op->customdata;
View2D *v2d= vzd->v2d;
float dx, dy;
/* get amount to move view by */
dx= RNA_float_get(op->ptr, "deltax");
dy= RNA_float_get(op->ptr, "deltay");
/* only move view on an axis if change is allowed */
if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
v2d->cur.xmin += dx;
v2d->cur.xmax -= dx;
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
v2d->cur.ymin += dy;
v2d->cur.ymax -= dy;
}
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
/* request updates to be done... */
ED_area_tag_redraw(CTX_wm_area(C));
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
}
/* cleanup temp customdata */
static void view_zoomdrag_exit(bContext *C, wmOperator *op)
{
if (op->customdata) {
MEM_freeN(op->customdata);
op->customdata= NULL;
}
}
/* for 'redo' only, with no user input */
static int view_zoomdrag_exec(bContext *C, wmOperator *op)
{
if (!view_zoomdrag_init(C, op))
return OPERATOR_PASS_THROUGH;
view_zoomdrag_apply(C, op);
view_zoomdrag_exit(C, op);
return OPERATOR_FINISHED;
}
/* set up modal operator and relevant settings */
static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
wmWindow *window= CTX_wm_window(C);
v2dViewZoomData *vzd;
View2D *v2d;
/* set up customdata */
if (!view_zoomdrag_init(C, op))
return OPERATOR_PASS_THROUGH;
vzd= op->customdata;
v2d= vzd->v2d;
/* set initial settings */
vzd->lastx= event->x;
vzd->lasty= event->y;
RNA_float_set(op->ptr, "deltax", 0);
RNA_float_set(op->ptr, "deltay", 0);
if (v2d->keepofs & V2D_LOCKOFS_X)
WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
else if (v2d->keepofs & V2D_LOCKOFS_Y)
WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
else
WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
/* add temp handler */
WM_event_add_modal_handler(C, &window->handlers, op);
return OPERATOR_RUNNING_MODAL;
}
/* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
{
v2dViewZoomData *vzd= op->customdata;
View2D *v2d= vzd->v2d;
/* execute the events */
switch (event->type) {
case MOUSEMOVE:
{
float dx, dy;
/* calculate new delta transform, based on zooming mode */
if (U.viewzoom == USER_ZOOM_SCALE) {
/* 'scale' zooming */
float dist;
/* x-axis transform */
dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
/* y-axis transform */
dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
}
else {
/* 'continuous' or 'dolly' */
float fac;
/* x-axis transform */
fac= 0.01f * (event->x - vzd->lastx);
dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
/* y-axis transform */
fac= 0.01f * (event->y - vzd->lasty);
dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
/* continous zoom shouldn't move that fast... */
if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
dx /= 20.0f;
dy /= 20.0f;
}
}
/* set transform amount, and add current deltas to stored total delta (for redo) */
RNA_float_set(op->ptr, "deltax", dx);
RNA_float_set(op->ptr, "deltay", dy);
vzd->dx += dx;
vzd->dy += dy;
/* store mouse coordinates for next time, if not doing continuous zoom
* - continuous zoom only depends on distance of mouse to starting point to determine rate of change
*/
if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
vzd->lastx= event->x;
vzd->lasty= event->y;
}
/* apply zooming */
view_zoomdrag_apply(C, op);
}
break;
case MIDDLEMOUSE:
if (event->val==0) {
/* for redo, store the overall deltas - need to respect zoom-locks here... */
if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
RNA_float_set(op->ptr, "deltax", vzd->dx);
else
RNA_float_set(op->ptr, "deltax", 0);
if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
RNA_float_set(op->ptr, "deltay", vzd->dy);
else
RNA_float_set(op->ptr, "deltay", 0);
/* free customdata */
view_zoomdrag_exit(C, op);
WM_cursor_restore(CTX_wm_window(C));
return OPERATOR_FINISHED;
}
break;
}
return OPERATOR_RUNNING_MODAL;
}
void View2D_OT_view_zoom(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name= "Zoom View";
ot->idname= "View2D_OT_view_zoom";
/* api callbacks */
ot->exec= view_zoomdrag_exec;
ot->invoke= view_zoomdrag_invoke;
ot->modal= view_zoomdrag_modal;
/* operator is repeatable */
ot->flag= OPTYPE_REGISTER;
/* rna - must keep these in sync with the other operators */
prop= RNA_def_property(ot->srna, "deltax", PROP_FLOAT, PROP_NONE);
prop= RNA_def_property(ot->srna, "deltay", PROP_FLOAT, PROP_NONE);
}
/* ********************************************************* */
/* BORDER-ZOOM */
/* The user defines a rect using standard borderselect tools, and we use this rect to
* define the new zoom-level of the view in the following ways:
* 1) LEFTMOUSE - zoom in to view
* 2) RIGHTMOUSE - zoom out of view
*
* Currently, these key mappings are hardcoded, but it shouldn't be too important to
* have custom keymappings for this...
*/
static int view_borderzoom_exec(bContext *C, wmOperator *op)
{
ARegion *ar= CTX_wm_region(C);
View2D *v2d= &ar->v2d;
rctf rect;
int event_type;
/* convert coordinates of rect to 'tot' rect coordinates */
UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
/* check if zooming in/out view */
// XXX hardcoded for now!
event_type= RNA_int_get(op->ptr, "event_type");
if (event_type == LEFTMOUSE) {
/* zoom in:
* - 'cur' rect will be defined by the coordinates of the border region
* - just set the 'cur' rect to have the same coordinates as the border region
* if zoom is allowed to be changed
*/
if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
v2d->cur.xmin= rect.xmin;
v2d->cur.xmax= rect.xmax;
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
v2d->cur.ymin= rect.ymin;
v2d->cur.ymax= rect.ymax;
}
}
else {
/* zoom out:
* - the current 'cur' rect coordinates are going to end upwhere the 'rect' ones are,
* but the 'cur' rect coordinates will need to be adjusted to take in more of the view
* - calculate zoom factor, and adjust using center-point
*/
float zoom, center, size;
// TODO: is this zoom factor calculation valid? It seems to produce same results everytime...
if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
size= (v2d->cur.xmax - v2d->cur.xmin);
zoom= size / (rect.xmax - rect.xmin);
center= (v2d->cur.xmax + v2d->cur.xmin) * 0.5f;
v2d->cur.xmin= center - (size * zoom);
v2d->cur.xmax= center + (size * zoom);
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
size= (v2d->cur.ymax - v2d->cur.ymin);
zoom= size / (rect.ymax - rect.ymin);
center= (v2d->cur.ymax + v2d->cur.ymin) * 0.5f;
v2d->cur.ymin= center - (size * zoom);
v2d->cur.ymax= center + (size * zoom);
}
}
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
/* request updates to be done... */
ED_area_tag_redraw(CTX_wm_area(C));
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
return OPERATOR_FINISHED;
}
void View2D_OT_view_borderzoom(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Zoom to Border";
ot->idname= "View2D_OT_view_borderzoom";
/* api callbacks */
ot->invoke= WM_border_select_invoke;
ot->exec= view_borderzoom_exec;
ot->modal= WM_border_select_modal;
ot->poll= ED_operator_areaactive;
/* rna */
RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
}
/* ********************************************************* */
/* SCROLLERS */
/* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
* 1) 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable,
* enlarge 'cur' rect on the relevant side
* 2) 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite)
*
* In order to make sure this works, each operator must define the following RNA-Operator Props:
* deltax, deltay - define how much to move view by (relative to zoom-correction factor)
*/
/* customdata for scroller-invoke data */
typedef struct v2dScrollerMove {
View2D *v2d; /* View2D data that this operation affects */
short scroller; /* scroller that mouse is in ('h' or 'v') */
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?)
float fac; /* view adjustment factor, based on size of region */
float delta; /* amount moved by mouse on axis of interest */
int lastx, lasty; /* previous mouse coordinates (in screen coordinates) for determining movement */
} v2dScrollerMove;
/* View2DScrollers is typedef'd in UI_view2d.h
* This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info
* WARNING: the start of this struct must not change, so that it stays in sync with the 'real' version
* For now, we don't need to have a separate (internal) header for structs like this...
*/
struct View2DScrollers {
/* focus bubbles */
int vert_min, vert_max; /* vertical scrollbar */
int hor_min, hor_max; /* horizontal scrollbar */
};
/* quick enum for vsm->zone (scroller handles) */
enum {
SCROLLHANDLE_MIN= -1,
SCROLLHANDLE_BAR,
SCROLLHANDLE_MAX
} eV2DScrollerHandle_Zone;
/* ------------------------ */
/* check if mouse is within scroller handle
* - mouse = relevant mouse coordinate in region space
* - sc_min, sc_max = extents of scroller
* - sh_min, sh_max = positions of scroller handles
*/
static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
{
short in_min, in_max, in_view=1;
/* firstly, check if
* - 'bubble' fills entire scroller
* - 'bubble' completely out of view on either side
*/
if ((sh_min <= sc_min) && (sh_max >= sc_max)) in_view= 0;
if (sh_min == sh_max) {
if (sh_min <= sc_min) in_view= 0;
if (sh_max >= sc_max) in_view= 0;
}
else {
if (sh_max <= sc_min) in_view= 0;
if (sh_min >= sc_max) in_view= 0;
}
if (in_view == 0) {
/* handles are only activated if the mouse is within the relative quater lengths of the scroller */
int qLen = (sc_max + sc_min) / 4;
if (mouse >= (sc_max - qLen))
return SCROLLHANDLE_MAX;
else if (mouse <= qLen)
return SCROLLHANDLE_MIN;
else
return SCROLLHANDLE_BAR;
}
/* check if mouse is in or past either handle */
in_max= ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
in_min= ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
/* check if overlap --> which means user clicked on bar, as bar is within handles region */
if (in_max && in_min)
return SCROLLHANDLE_BAR;
else if (in_max)
return SCROLLHANDLE_MAX;
else if (in_min)
return SCROLLHANDLE_MIN;
/* unlikely to happen, though we just cover it in case */
return SCROLLHANDLE_BAR;
}
/* initialise customdata for scroller manipulation operator */
static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event, short in_scroller)
{
v2dScrollerMove *vsm;
View2DScrollers *scrollers;
ARegion *ar= CTX_wm_region(C);
View2D *v2d= &ar->v2d;
float mask_size;
int x, y;
/* set custom-data for operator */
vsm= MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove");
op->customdata= vsm;
/* set general data */
vsm->v2d= v2d;
vsm->scroller= in_scroller;
/* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
vsm->lastx = event->x;
vsm->lasty = event->y;
x= event->x - ar->winrct.xmin;
y= event->y - ar->winrct.ymin;
/* 'zone' depends on where mouse is relative to bubble
* - zooming must be allowed on this axis, otherwise, default to pan
*/
scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
if (in_scroller == 'h') {
/* horizontal scroller - calculate adjustment factor first */
mask_size= (float)(v2d->hor.xmax - v2d->hor.xmin);
vsm->fac= (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
/* get 'zone' (i.e. which part of scroller is activated) */
if (v2d->keepzoom & V2D_LOCKZOOM_X) {
/* default to scroll, as handles not usable */
vsm->zone= SCROLLHANDLE_BAR;
}
else {
/* check which handle we're in */
vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
}
}
else {
/* vertical scroller - calculate adjustment factor first */
mask_size= (float)(v2d->vert.ymax - v2d->vert.ymin);
vsm->fac= (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
/* get 'zone' (i.e. which part of scroller is activated) */
if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
/* default to scroll, as handles not usable */
vsm->zone= SCROLLHANDLE_BAR;
}
else {
/* check which handle we're in */
vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max);
}
}
UI_view2d_scrollers_free(scrollers);
}
/* cleanup temp customdata */
static void scroller_activate_exit(bContext *C, wmOperator *op)
{
if (op->customdata) {
MEM_freeN(op->customdata);
op->customdata= NULL;
}
}
/* apply transform to view (i.e. adjust 'cur' rect) */
static void scroller_activate_apply(bContext *C, wmOperator *op)
{
v2dScrollerMove *vsm= op->customdata;
View2D *v2d= vsm->v2d;
float temp;
/* calculate amount to move view by */
temp= vsm->fac * vsm->delta;
/* type of movement */
switch (vsm->zone) {
case SCROLLHANDLE_MIN:
/* only expand view on axis if zoom is allowed */
if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
v2d->cur.xmin -= temp;
if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
v2d->cur.ymin -= temp;
break;
case SCROLLHANDLE_MAX:
/* only expand view on axis if zoom is allowed */
if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
v2d->cur.xmax += temp;
if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
v2d->cur.ymax += temp;
break;
default: /* SCROLLHANDLE_BAR */
/* only move view on an axis if panning is allowed */
if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
v2d->cur.xmin += temp;
v2d->cur.xmax += temp;
}
if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) {
v2d->cur.ymin += temp;
v2d->cur.ymax += temp;
}
break;
}
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
/* request updates to be done... */
ED_area_tag_redraw(CTX_wm_area(C));
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
}
/* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
{
v2dScrollerMove *vsm= op->customdata;
/* execute the events */
switch (event->type) {
case MOUSEMOVE:
{
/* calculate new delta transform, then store mouse-coordinates for next-time */
if (vsm->zone != SCROLLHANDLE_MIN) {
/* if using bar (i.e. 'panning') or 'max' zoom widget */
switch (vsm->scroller) {
case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
vsm->delta= (float)(event->x - vsm->lastx);
break;
case 'v': /* vertical scroller - so only vertical movement ('cur' moves opposite to mouse) */
vsm->delta= (float)(event->y - vsm->lasty);
break;
}
}
else {
/* using 'min' zoom widget */
switch (vsm->scroller) {
case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
vsm->delta= (float)(vsm->lastx - event->x);
break;
case 'v': /* vertical scroller - so only vertical movement ('cur' moves with to mouse) */
vsm->delta= (float)(vsm->lasty - event->y);
break;
}
}
/* store previous coordinates */
vsm->lastx= event->x;
vsm->lasty= event->y;
scroller_activate_apply(C, op);
}
break;
case LEFTMOUSE:
if (event->val==0) {
scroller_activate_exit(C, op);
return OPERATOR_FINISHED;
}
break;
}
return OPERATOR_RUNNING_MODAL;
}
/* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
View2D *v2d= NULL;
short in_scroller= 0;
/* firstly, check context to see if mouse is actually in region */
// XXX isn't this the job of poll() callbacks which can't check events, but only context?
if (ar == NULL)
return OPERATOR_PASS_THROUGH;//OPERATOR_CANCELLED;
else
v2d= &ar->v2d;
/* check if mouse in scrollbars, if they're enabled */
in_scroller= UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
/* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
if (in_scroller) {
v2dScrollerMove *vsm;
/* initialise customdata */
scroller_activate_init(C, op, event, in_scroller);
vsm= (v2dScrollerMove *)op->customdata;
/* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
if (vsm->zone == SCROLLHANDLE_BAR) {
if ( ((vsm->scroller=='h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
((vsm->scroller=='v') && (v2d->keepofs & V2D_LOCKOFS_Y)) )
{
/* free customdata initialised */
scroller_activate_exit(C, op);
/* can't catch this event for ourselves, so let it go to someone else? */
return OPERATOR_PASS_THROUGH;
}
}
/* still ok, so can add */
WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
return OPERATOR_RUNNING_MODAL;
}
else {
/* not in scroller, so nothing happened... (pass through let's something else catch event) */
return OPERATOR_PASS_THROUGH;
}
}
/* LMB-Drag in Scrollers - not repeatable operator! */
void View2D_OT_scroller_activate(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Scroller Activate";
ot->idname= "View2D_OT_scroller_activate";
/* api callbacks */
ot->invoke= scroller_activate_invoke;
ot->modal= scroller_activate_modal;
}
/* ********************************************************* */
/* Registration */
void ui_view2d_operatortypes(void)
{
WM_operatortype_append(View2D_OT_view_pan);
WM_operatortype_append(View2D_OT_view_scrollleft);
WM_operatortype_append(View2D_OT_view_scrollright);
WM_operatortype_append(View2D_OT_view_scrollup);
WM_operatortype_append(View2D_OT_view_scrolldown);
WM_operatortype_append(View2D_OT_view_zoomin);
WM_operatortype_append(View2D_OT_view_zoomout);
WM_operatortype_append(View2D_OT_view_zoom);
WM_operatortype_append(View2D_OT_view_borderzoom);
WM_operatortype_append(View2D_OT_scroller_activate);
}
void UI_view2d_keymap(wmWindowManager *wm)
{
ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
/* pan/scroll */
WM_keymap_add_item(keymap, "View2D_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_rightscroll", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_leftscroll", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_downscroll", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_upscroll", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
/* zoom - single step */
WM_keymap_add_item(keymap, "View2D_OT_view_zoomout", WHEELOUTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_zoomin", WHEELINMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_zoomout", PADMINUS, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_zoomin", PADPLUSKEY, KM_PRESS, 0, 0);
/* scroll up/down - no modifiers, only when zoom fails */
/* these may fail if zoom is disallowed, in which case they should pass on event */
WM_keymap_add_item(keymap, "View2D_OT_view_downscroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_upscroll", WHEELUPMOUSE, KM_PRESS, 0, 0);
/* these may be necessary if vertical scroll is disallowed */
WM_keymap_add_item(keymap, "View2D_OT_view_rightscroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "View2D_OT_view_leftscroll", WHEELUPMOUSE, KM_PRESS, 0, 0);
/* zoom - drag */
WM_keymap_add_item(keymap, "View2D_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
/* borderzoom - drag */
WM_keymap_add_item(keymap, "View2D_OT_view_borderzoom", ZKEY, KM_PRESS, KM_SHIFT, 0);
/* scrollers */
WM_keymap_add_item(keymap, "View2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
}
|