diff --git a/app/src/main/java/com/scrat/everchanging/Background.java b/app/src/main/java/com/scrat/everchanging/Background.java index a949852..f42f027 100644 --- a/app/src/main/java/com/scrat/everchanging/Background.java +++ b/app/src/main/java/com/scrat/everchanging/Background.java @@ -206,13 +206,16 @@ final class Background extends TextureObject { R.drawable.image_301 //Red }}; - private final float scale; + private float scale; private int currentSeason = -1; Background(final Context context) { super(context, textureList, null); + readScale(context); + } + private void readScale(final Context context) { final TypedValue outValue = new TypedValue(); context.getResources().getValue(R.dimen.background_scale, outValue, true); scale = outValue.getFloat(); @@ -234,14 +237,18 @@ void createObject(final int season) { iterator.release(); } else { final Object object = objects.obtain(texture, scale); - object.setObjectScale(1.0f); - object.resetMatrix(); - object.resetViewMatrix(); - object.setScale(ratio, ratio); //Масштабируем по высоте, иначе не красиво. - object.setTranslate(width - (object.texture.width) * scale * 0.5f * ratio, (object.texture.height) * scale * 0.5f * ratio); + setObjectScaleAndTranslation(object); } } + private void setObjectScaleAndTranslation(final Object object) { + object.setObjectScale(1.0f); + object.resetMatrix(); + object.resetViewMatrix(); + object.setScale(ratio, ratio); //Масштабируем по высоте, иначе не красиво. + object.setTranslate(width - (object.texture.width) * scale * 0.5f * ratio, (object.texture.height) * scale * 0.5f * ratio); + } + void update(final int season, final int timesOfDay) { int s = season == 5 ? 4 : season; if (currentSeason != s) createObject(s); @@ -255,4 +262,21 @@ void update(final int season, final int timesOfDay) { iterator.release(); } + + @Override + public void setupPosition(final int width, final int height, final float ratio) { + super.setupPosition(width, height, ratio); + readScale(textureManager.getContext()); + if (objects.objectsInUseCount() != 0) { + final ReusableIterator iterator = objects.iterator(); + iterator.acquire(); + + while (iterator.hasNext()) { + final Object object = iterator.next(); + setObjectScaleAndTranslation(object); + } + + iterator.release(); + } + } } diff --git a/app/src/main/java/com/scrat/everchanging/EverchangingRender.java b/app/src/main/java/com/scrat/everchanging/EverchangingRender.java index 4381c06..d301973 100644 --- a/app/src/main/java/com/scrat/everchanging/EverchangingRender.java +++ b/app/src/main/java/com/scrat/everchanging/EverchangingRender.java @@ -146,9 +146,6 @@ final class EverchangingRender implements GLSurfaceView.Renderer { private int lastSceneMaxFps = Scene.MINIMUM_FPS; - private int lastSurfaceWidth; - private int lastSurfaceHeight; - EverchangingRender(final Context context, final FrameScheduler frameScheduler) { this.context = context; this.frameScheduler = frameScheduler; @@ -198,21 +195,6 @@ public void onSurfaceCreated(final GL10 gl, final EGLConfig config) { @Override public void onSurfaceChanged(final GL10 gl, final int width, final int height) { - boolean dimensionsChanged = false; - if (lastSurfaceWidth != 0 && lastSurfaceHeight != 0) { - if (lastSurfaceWidth != width || lastSurfaceHeight != height) { - dimensionsChanged = true; - } - } - - lastSurfaceWidth = width; - lastSurfaceHeight = height; - - if (dimensionsChanged) { - scenes.clear(); - onSurfaceCreated(gl, null); - } - final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); assert windowManager != null; diff --git a/app/src/main/java/com/scrat/everchanging/Foreground.java b/app/src/main/java/com/scrat/everchanging/Foreground.java index 44c6b1a..50e7d04 100644 --- a/app/src/main/java/com/scrat/everchanging/Foreground.java +++ b/app/src/main/java/com/scrat/everchanging/Foreground.java @@ -286,13 +286,16 @@ final class Foreground extends TextureObject { {{0, 0, 0}, {0, 38, 0}, {84, 225, 0}}, }; - private final float scale; + private float scale; private int current = -1; Foreground(final Context context) { super(context, textureList, null); + readScale(context); + } + private void readScale(final Context context) { final TypedValue outValue = new TypedValue(); context.getResources().getValue(R.dimen.foreground_scale, outValue, true); scale = outValue.getFloat(); @@ -316,6 +319,18 @@ void update(final int foregroundIndex, final int timesOfDay) { iterator.release(); } + @Override + public void setupPosition(final int width, final int height, final float ratio) { + super.setupPosition(width, height, ratio); + readScale(textureManager.getContext()); + + if (current != -1) { + objects.markAllAsUnused(); + resetMatrix(); + createObjects(); + } + } + private void createObjects() { int textureListCurrentLength = textureList[current].length; if (!isWideScreen()) { @@ -325,6 +340,7 @@ private void createObjects() { for (int i = 0; i < textureListCurrentLength; i++) { int textureIndex = textureManager.getTextureIndex(textureList[current][i]); Object object = objects.obtain(textureManager.getTexture(textureIndex), scale); + object.resetMatrix(); object.resetViewMatrix(); object.setObjectScale(1.0f); } @@ -343,7 +359,6 @@ private void setObjectsPosition() { final Object object = iterator.next(); float spriteWidth = object.texture.width * scale; float spriteHeight = object.texture.height * scale; - object.resetMatrix(); final float y = deltaHeight - spriteHeight + offsetValues[current][index][0]; diff --git a/app/src/main/java/com/scrat/everchanging/Object.java b/app/src/main/java/com/scrat/everchanging/Object.java index bddd8cc..b73725d 100644 --- a/app/src/main/java/com/scrat/everchanging/Object.java +++ b/app/src/main/java/com/scrat/everchanging/Object.java @@ -29,6 +29,7 @@ class Object { public boolean used; public float scale = 1.0f; + private float textureScale = 1f; public FloatBuffer vertexBuffer; //Буффер описания размеров прямоугольника public TextureManager.Texture texture; @@ -61,11 +62,13 @@ class Object { vertexBuffer = objectVerticesBuffer.asFloatBuffer(); resetMatrix(); + textureScale = scale; if (texture != null) setTexture(texture, scale); } Object(TextureManager.Texture texture, float scale) { this(); + textureScale = scale; if (texture != null) setTexture(texture, scale); } @@ -110,8 +113,9 @@ void copyFrom(final Object source) { } void setTexture(TextureManager.Texture texture, float scale) { - if (this.texture != texture) { + if (this.texture != texture || textureScale != scale) { this.texture = texture; + this.textureScale = scale; final float x_width = texture.width * scale; final float y_height = texture.height * scale; final float x_begin = (0 - texture.pivot[0]) * scale; diff --git a/app/src/main/java/com/scrat/everchanging/TextureManager.java b/app/src/main/java/com/scrat/everchanging/TextureManager.java index 77d769c..c226332 100644 --- a/app/src/main/java/com/scrat/everchanging/TextureManager.java +++ b/app/src/main/java/com/scrat/everchanging/TextureManager.java @@ -110,6 +110,10 @@ float dipToPixels(final float dipValue) { } } + public Context getContext() { + return context; + } + Texture getTexture(final int index) { return textures[index]; }