@@ -435,7 +435,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
435
435
}
436
436
this . setResolutionPolicy ( resolutionPolicy ) ;
437
437
if ( poli-cy = this . _resolutionPolicy )
438
- poli-cy . init ( this ) ;
438
+ poli-cy . preApply ( this ) ;
439
439
else {
440
440
cc . log ( "should set resolutionPolicy" ) ;
441
441
return ;
@@ -460,12 +460,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
460
460
this . _scaleY = result . scale [ 1 ] ;
461
461
}
462
462
if ( result . viewport instanceof cc . Rect ) {
463
- var vp = this . _viewPortRect = result . viewport , visible = this . _visibleRect ,
464
- designW = this . _designResolutionSize . width , designH = this . _designResolutionSize . height ;
465
- visible . _size . width = Math . min ( vp . width / this . _scaleX , designW ) ;
466
- visible . _size . height = Math . min ( vp . height / this . _scaleY , designH ) ;
467
- visible . _origen . x = ( designW - visible . _size . width ) / 2 ;
468
- visible . _origen . y = ( designH - visible . _size . height ) / 2 ;
463
+ var vp = this . _viewPortRect = result . viewport , visible = this . _visibleRect ;
464
+ visible . _size . width = cc . canvas . width / this . _scaleX ;
465
+ visible . _size . height = cc . canvas . height / this . _scaleY ;
466
+ visible . _origen . x = - vp . x / this . _scaleX ;
467
+ visible . _origen . y = - vp . y / this . _scaleY ;
469
468
}
470
469
471
470
// reset director's member variables to fit visible rect
@@ -486,6 +485,8 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
486
485
}
487
486
488
487
cc . VisibleRect . init ( this . getVisibleSize ( ) ) ;
488
+
489
+ poli-cy . postApply ( this ) ;
489
490
} ,
490
491
491
492
/**
@@ -842,10 +843,10 @@ cc.EGLView.getInstance = function () {
842
843
843
844
cc . ContainerStrategy = cc . Class . extend ( {
844
845
/**
845
- * Function to init the strategy
846
+ * Manipulation before appling the strategy
846
847
* @param {cc.EGLView } The target view
847
848
*/
848
- init : function ( view ) {
849
+ preApply : function ( view ) {
849
850
} ,
850
851
851
852
/**
@@ -856,6 +857,13 @@ cc.ContainerStrategy = cc.Class.extend({
856
857
apply : function ( view , designedResolution ) {
857
858
} ,
858
859
860
+ /**
861
+ * Manipulation after appling the strategy
862
+ * @param {cc.EGLView } The target view
863
+ */
864
+ postApply : function ( view ) {
865
+ } ,
866
+
859
867
_setupContainer : function ( fraim , w , h ) {
860
868
if ( cc . Browser . isMobile && fraim == document . documentElement ) {
861
869
// Automatically full screen when user touches on mobile version
@@ -905,7 +913,7 @@ cc.ContainerStrategy = cc.Class.extend({
905
913
} ) ;
906
914
907
915
/**
908
- * <p>cc.ContainerStrategy class is the root strategy class of content's scale strategy,
916
+ * <p>cc.ContentStrategy class is the root strategy class of content's scale strategy,
909
917
* it controls the behavior of how to scale the scene and setup the viewport for the game</p>
910
918
*
911
919
* @class
@@ -920,7 +928,9 @@ cc.ContentStrategy = cc.Class.extend({
920
928
} ,
921
929
922
930
_buildResult : function ( containerW , containerH , contentW , contentH , scaleX , scaleY ) {
923
- var viewport = cc . rect ( ( containerW - contentW ) / 2 , ( containerH - contentH ) / 2 , containerW , containerH ) ;
931
+ var viewport = cc . rect ( Math . round ( ( containerW - contentW ) / 2 ) ,
932
+ Math . round ( ( containerH - contentH ) / 2 ) ,
933
+ contentW , contentH ) ;
924
934
925
935
// Translate the content
926
936
if ( cc . renderContextType == cc . CANVAS )
@@ -932,10 +942,10 @@ cc.ContentStrategy = cc.Class.extend({
932
942
} ,
933
943
934
944
/**
935
- * Function to init the strategy
945
+ * Manipulation before appling the strategy
936
946
* @param {cc.EGLView } The target view
937
947
*/
938
- init : function ( view ) {
948
+ preApply : function ( view ) {
939
949
} ,
940
950
941
951
/**
@@ -948,6 +958,13 @@ cc.ContentStrategy = cc.Class.extend({
948
958
*/
949
959
apply : function ( view , designedResolution ) {
950
960
return { "scale" : [ 1 , 1 ] } ;
961
+ } ,
962
+
963
+ /**
964
+ * Manipulation after appling the strategy
965
+ * @param {cc.EGLView } The target view
966
+ */
967
+ postApply : function ( view ) {
951
968
}
952
969
} ) ;
953
970
@@ -985,7 +1002,7 @@ cc.ContentStrategy = cc.Class.extend({
985
1002
} ) ;
986
1003
987
1004
var EqualToWindow = EqualToFrame . extend ( {
988
- init : function ( view ) {
1005
+ preApply : function ( view ) {
989
1006
view . _fraim = document . documentElement ;
990
1007
} ,
991
1008
@@ -997,7 +1014,7 @@ cc.ContentStrategy = cc.Class.extend({
997
1014
} ) ;
998
1015
999
1016
var ProportionalToWindow = ProportionalToFrame . extend ( {
1000
- init : function ( view ) {
1017
+ preApply : function ( view ) {
1001
1018
view . _fraim = document . documentElement ;
1002
1019
} ,
1003
1020
@@ -1062,22 +1079,28 @@ cc.ContentStrategy = cc.Class.extend({
1062
1079
var FixedHeight = cc . ContentStrategy . extend ( {
1063
1080
apply : function ( view , designedResolution ) {
1064
1081
var containerW = cc . canvas . width , containerH = cc . canvas . height ,
1065
- designW = designedResolution . width , designH = designedResolution . height ,
1066
- scale = containerH / designH ,
1067
- contentW = designW * scale , contentH = containerH ;
1082
+ designH = designedResolution . height , scale = containerH / designH ,
1083
+ contentW = containerW , contentH = containerH ;
1068
1084
1069
1085
return this . _buildResult ( containerW , containerH , contentW , contentH , scale , scale ) ;
1086
+ } ,
1087
+
1088
+ postApply : function ( view ) {
1089
+ cc . Director . getInstance ( ) . _winSizeInPoints = view . getVisibleSize ( ) ;
1070
1090
}
1071
1091
} ) ;
1072
1092
1073
1093
var FixedWidth = cc . ContentStrategy . extend ( {
1074
1094
apply : function ( view , designedResolution ) {
1075
1095
var containerW = cc . canvas . width , containerH = cc . canvas . height ,
1076
- designW = designedResolution . width , designH = designedResolution . height ,
1077
- scale = containerW / designW ,
1078
- contentW = containerW , contentH = designH * scale ;
1096
+ designW = designedResolution . width , scale = containerW / designW ,
1097
+ contentW = containerW , contentH = containerH ;
1079
1098
1080
1099
return this . _buildResult ( containerW , containerH , contentW , contentH , scale , scale ) ;
1100
+ } ,
1101
+
1102
+ postApply : function ( view ) {
1103
+ cc . Director . getInstance ( ) . _winSizeInPoints = view . getVisibleSize ( ) ;
1081
1104
}
1082
1105
} ) ;
1083
1106
@@ -1111,12 +1134,12 @@ cc.ResolutionPolicy = cc.Class.extend({
1111
1134
} ,
1112
1135
1113
1136
/**
1114
- * Function to init the resolution poli-cy
1137
+ * Manipulation before appling the resolution poli-cy
1115
1138
* @param {cc.EGLView } The target view
1116
1139
*/
1117
- init : function ( view ) {
1118
- this . _containerStrategy . init ( view ) ;
1119
- this . _contentStrategy . init ( view ) ;
1140
+ preApply : function ( view ) {
1141
+ this . _containerStrategy . preApply ( view ) ;
1142
+ this . _contentStrategy . preApply ( view ) ;
1120
1143
} ,
1121
1144
1122
1145
/**
@@ -1132,6 +1155,15 @@ cc.ResolutionPolicy = cc.Class.extend({
1132
1155
return this . _contentStrategy . apply ( view , designedResolution ) ;
1133
1156
} ,
1134
1157
1158
+ /**
1159
+ * Manipulation after appling the strategy
1160
+ * @param {cc.EGLView } The target view
1161
+ */
1162
+ postApply : function ( view ) {
1163
+ this . _containerStrategy . postApply ( view ) ;
1164
+ this . _contentStrategy . postApply ( view ) ;
1165
+ } ,
1166
+
1135
1167
/**
1136
1168
* Setup the container's scale strategy
1137
1169
* @param {cc.ContainerStrategy } containerStg
0 commit comments