@@ -435,7 +435,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
435435 }
436436 this . setResolutionPolicy ( resolutionPolicy ) ;
437437 if ( policy = this . _resolutionPolicy )
438- policy . init ( this ) ;
438+ policy . preApply ( this ) ;
439439 else {
440440 cc . log ( "should set resolutionPolicy" ) ;
441441 return ;
@@ -460,12 +460,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
460460 this . _scaleY = result . scale [ 1 ] ;
461461 }
462462 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 . _origin . x = ( designW - visible . _size . width ) / 2 ;
468- visible . _origin . 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 . _origin . x = - vp . x / this . _scaleX ;
467+ visible . _origin . y = - vp . y / this . _scaleY ;
469468 }
470469
471470 // reset director's member variables to fit visible rect
@@ -486,6 +485,8 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
486485 }
487486
488487 cc . VisibleRect . init ( this . getVisibleSize ( ) ) ;
488+
489+ policy . postApply ( this ) ;
489490 } ,
490491
491492 /**
@@ -842,10 +843,10 @@ cc.EGLView.getInstance = function () {
842843
843844cc . ContainerStrategy = cc . Class . extend ( {
844845 /**
845- * Function to init the strategy
846+ * Manipulation before appling the strategy
846847 * @param {cc.EGLView } The target view
847848 */
848- init : function ( view ) {
849+ preApply : function ( view ) {
849850 } ,
850851
851852 /**
@@ -856,6 +857,13 @@ cc.ContainerStrategy = cc.Class.extend({
856857 apply : function ( view , designedResolution ) {
857858 } ,
858859
860+ /**
861+ * Manipulation after appling the strategy
862+ * @param {cc.EGLView } The target view
863+ */
864+ postApply : function ( view ) {
865+ } ,
866+
859867 _setupContainer : function ( frame , w , h ) {
860868 if ( cc . Browser . isMobile && frame == document . documentElement ) {
861869 // Automatically full screen when user touches on mobile version
@@ -905,7 +913,7 @@ cc.ContainerStrategy = cc.Class.extend({
905913} ) ;
906914
907915/**
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,
909917 * it controls the behavior of how to scale the scene and setup the viewport for the game</p>
910918 *
911919 * @class
@@ -920,7 +928,9 @@ cc.ContentStrategy = cc.Class.extend({
920928 } ,
921929
922930 _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 ) ;
924934
925935 // Translate the content
926936 if ( cc . renderContextType == cc . CANVAS )
@@ -932,10 +942,10 @@ cc.ContentStrategy = cc.Class.extend({
932942 } ,
933943
934944 /**
935- * Function to init the strategy
945+ * Manipulation before appling the strategy
936946 * @param {cc.EGLView } The target view
937947 */
938- init : function ( view ) {
948+ preApply : function ( view ) {
939949 } ,
940950
941951 /**
@@ -948,6 +958,13 @@ cc.ContentStrategy = cc.Class.extend({
948958 */
949959 apply : function ( view , designedResolution ) {
950960 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 ) {
951968 }
952969} ) ;
953970
@@ -985,7 +1002,7 @@ cc.ContentStrategy = cc.Class.extend({
9851002 } ) ;
9861003
9871004 var EqualToWindow = EqualToFrame . extend ( {
988- init : function ( view ) {
1005+ preApply : function ( view ) {
9891006 view . _frame = document . documentElement ;
9901007 } ,
9911008
@@ -997,7 +1014,7 @@ cc.ContentStrategy = cc.Class.extend({
9971014 } ) ;
9981015
9991016 var ProportionalToWindow = ProportionalToFrame . extend ( {
1000- init : function ( view ) {
1017+ preApply : function ( view ) {
10011018 view . _frame = document . documentElement ;
10021019 } ,
10031020
@@ -1062,22 +1079,28 @@ cc.ContentStrategy = cc.Class.extend({
10621079 var FixedHeight = cc . ContentStrategy . extend ( {
10631080 apply : function ( view , designedResolution ) {
10641081 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 ;
10681084
10691085 return this . _buildResult ( containerW , containerH , contentW , contentH , scale , scale ) ;
1086+ } ,
1087+
1088+ postApply : function ( view ) {
1089+ cc . Director . getInstance ( ) . _winSizeInPoints = view . getVisibleSize ( ) ;
10701090 }
10711091 } ) ;
10721092
10731093 var FixedWidth = cc . ContentStrategy . extend ( {
10741094 apply : function ( view , designedResolution ) {
10751095 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 ;
10791098
10801099 return this . _buildResult ( containerW , containerH , contentW , contentH , scale , scale ) ;
1100+ } ,
1101+
1102+ postApply : function ( view ) {
1103+ cc . Director . getInstance ( ) . _winSizeInPoints = view . getVisibleSize ( ) ;
10811104 }
10821105 } ) ;
10831106
@@ -1111,12 +1134,12 @@ cc.ResolutionPolicy = cc.Class.extend({
11111134 } ,
11121135
11131136 /**
1114- * Function to init the resolution policy
1137+ * Manipulation before appling the resolution policy
11151138 * @param {cc.EGLView } The target view
11161139 */
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 ) ;
11201143 } ,
11211144
11221145 /**
@@ -1132,6 +1155,15 @@ cc.ResolutionPolicy = cc.Class.extend({
11321155 return this . _contentStrategy . apply ( view , designedResolution ) ;
11331156 } ,
11341157
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+
11351167 /**
11361168 * Setup the container's scale strategy
11371169 * @param {cc.ContainerStrategy } containerStg
0 commit comments