@@ -37,7 +37,7 @@ wm.Weltmeister = ig.Class.extend({
37
37
38
38
tilsetSelectDialog : null ,
39
39
levelSavePathDialog : null ,
40
- rot : 0 ,
40
+ labelsStep : 32 ,
41
41
42
42
collisionSolid : 1 ,
43
43
@@ -55,6 +55,7 @@ wm.Weltmeister = ig.Class.extend({
55
55
56
56
ig . system . context . textBaseline = 'top' ;
57
57
ig . system . context . font = wm . config . labels . font ;
58
+ this . labelsStep = wm . config . labels . step ;
58
59
59
60
60
61
@@ -209,6 +210,50 @@ wm.Weltmeister = ig.Class.extend({
209
210
} ,
210
211
211
212
213
+ drag : function ( ) {
214
+ this . screen . x -= ig . input . mouse . x - this . mouseLast . x ;
215
+ this . screen . y -= ig . input . mouse . y - this . mouseLast . y ;
216
+ this . _rscreen . x = Math . round ( this . screen . x * ig . system . scale ) / ig . system . scale ;
217
+ this . _rscreen . y = Math . round ( this . screen . y * ig . system . scale ) / ig . system . scale ;
218
+ for ( var i = 0 ; i < this . layers . length ; i ++ ) {
219
+ this . layers [ i ] . setScreenPos ( this . screen . x , this . screen . y ) ;
220
+ }
221
+ } ,
222
+
223
+
224
+ zoom : function ( delta ) {
225
+ var z = wm . config . view . zoom ;
226
+ var mx = ig . input . mouse . x * z ,
227
+ my = ig . input . mouse . y * z ;
228
+
229
+ if ( z <= 1 ) {
230
+ if ( delta < 0 ) {
231
+ z /= 2 ;
232
+ }
233
+ else {
234
+ z *= 2 ;
235
+ }
236
+ }
237
+ else {
238
+ z += delta ;
239
+ }
240
+
241
+ wm . config . view . zoom = z . limit ( wm . config . view . zoomMin , wm . config . view . zoomMax ) ;
242
+ wm . config . labels . step = Math . round ( this . labelsStep / wm . config . view . zoom ) ;
243
+ $ ( '#zoomIndicator' ) . text ( wm . config . view . zoom + 'x' ) . stop ( true , true ) . show ( ) . delay ( 300 ) . fadeOut ( ) ;
244
+
245
+ // Adjust mouse pos and screen coordinates
246
+ ig . input . mouse . x = mx / wm . config . view . zoom ;
247
+ ig . input . mouse . y = my / wm . config . view . zoom ;
248
+ this . drag ( ) ;
249
+
250
+ for ( var i in ig . Image . cache ) {
251
+ ig . Image . cache [ i ] . resize ( wm . config . view . zoom ) ;
252
+ }
253
+
254
+ this . resize ( ) ;
255
+ } ,
256
+
212
257
213
258
// -------------------------------------------------------------------------
214
259
// Loading
@@ -531,6 +576,7 @@ wm.Weltmeister = ig.Class.extend({
531
576
this . collisionLayer = null ;
532
577
}
533
578
579
+
534
580
this . activeLayer . setName ( newName ) ;
535
581
this . setModified ( ) ;
536
582
this . draw ( ) ;
@@ -586,13 +632,7 @@ wm.Weltmeister = ig.Class.extend({
586
632
587
633
// scroll map
588
634
if ( ig . input . state ( 'drag' ) ) {
589
- this . screen . x -= ig . input . mouse . x - this . mouseLast . x ;
590
- this . screen . y -= ig . input . mouse . y - this . mouseLast . y ;
591
- this . _rscreen . x = Math . round ( this . screen . x * ig . system . scale ) / ig . system . scale ;
592
- this . _rscreen . y = Math . round ( this . screen . y * ig . system . scale ) / ig . system . scale ;
593
- for ( var i = 0 ; i < this . layers . length ; i ++ ) {
594
- this . layers [ i ] . setScreenPos ( this . screen . x , this . screen . y ) ;
595
- }
635
+ this . drag ( ) ;
596
636
}
597
637
598
638
else if ( ig . input . state ( 'draw' ) ) {
@@ -700,6 +740,13 @@ wm.Weltmeister = ig.Class.extend({
700
740
}
701
741
}
702
742
743
+ else if ( action == 'zoomin' ) {
744
+ this . zoom ( 1 ) ;
745
+ }
746
+ else if ( action == 'zoomout' ) {
747
+ this . zoom ( - 1 ) ;
748
+ }
749
+
703
750
704
751
if ( action == 'draw' ) {
705
752
// select tile
@@ -846,6 +893,46 @@ wm.Weltmeister.getMaxHeight = function() {
846
893
} ;
847
894
848
895
896
+ // Custom ig.Image class for use in Weltmeister. To make the zoom function
897
+ // work, we need some additional scaling behavior:
898
+ // Keep the original image, maintain a cache of scaled versions and use the
899
+ // default Canvas scaling (~bicubic) instead of nearest neighbor when
900
+ // zooming out.
901
+ ig . Image . inject ( {
902
+ scaleCache : { } ,
903
+ resize : function ( scale ) {
904
+ if ( this . scaleCache [ 'x' + scale ] ) {
905
+ this . data = this . scaleCache [ 'x' + scale ] ;
906
+ this . width = this . data . width ;
907
+ this . width = this . data . height ;
908
+ return ;
909
+ }
910
+
911
+ // Retain the original image when scaling
912
+ this . origData = this . data = this . origData || this . data ;
913
+
914
+ this . width = this . data . width ;
915
+ this . height = this . data . height ;
916
+
917
+ if ( scale > 1 ) {
918
+ // Nearest neighbor when zooming in
919
+ this . parent ( scale ) ;
920
+ }
921
+ else {
922
+ // Otherwise blur
923
+ var scaled = ig . $new ( 'canvas' ) ;
924
+ scaled . width = this . width * scale ;
925
+ scaled . height = this . height * scale ;
926
+ var scaledCtx = scaled . getContext ( '2d' ) ;
927
+ scaledCtx . drawImage ( this . data , 0 , 0 , this . width , this . height , 0 , 0 , scaled . width , scaled . height ) ;
928
+ this . data = scaled ;
929
+ }
930
+
931
+ this . scaleCache [ scale ] = this . data ;
932
+ }
933
+ } ) ;
934
+
935
+
849
936
850
937
// Create a custom loader, to skip sound files and the run loop creation
851
938
wm . Loader = ig . Loader . extend ( {
0 commit comments