Skip to content
Snippets Groups Projects
Commit 34bb120d authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#12 Scale keeping viewport implementation

parent 799eb941
Branches
Tags
No related merge requests found
......@@ -49,76 +49,76 @@ public abstract class TablexiaApplication implements ApplicationListener {
//////////////////////////// LIBGDX LIFECYCLE
@Override
public void dispose () {
inputMultiplexer.removeProcessor(stage);
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo.dispose();
}
stage.dispose();
if (lastScreen != null) {
lastScreen.hide();
lastScreen.dispose();
}
if (screen != null) {
screen.hide();
screen.dispose();
}
}
@Override
public void pause () {
if (lastScreen != null) lastScreen.pause();
if (screen != null) screen.pause();
}
@Override
public void resume () {
if (lastScreen != null) lastScreen.resume();
if (screen != null) screen.resume();
}
@Override
public void create() {
stage = new Stage();
inputMultiplexer = new InputMultiplexer(stage);
Gdx.input.setInputProcessor(inputMultiplexer);
prepareDebugInfo();
}
@Override
public void render () {
// clear screen every frame
Gdx.gl.glClearColor(BACKGROUND_COLOR.r, BACKGROUND_COLOR.g, BACKGROUND_COLOR.b, BACKGROUND_COLOR.a);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo.update();
}
float deltaTime = Gdx.graphics.getDeltaTime();
if (lastScreen != null) lastScreen.render(deltaTime);
if (screen != null) screen.render(deltaTime);
stage.act(deltaTime);
stage.draw();
}
@Override
public void resize (int width, int height) {
if (lastScreen != null) lastScreen.resize(width, height);
if (screen != null) screen.resize(width, height);
stage.getViewport().update(width, height, true);
}
@Override
public void dispose() {
inputMultiplexer.removeProcessor(stage);
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo.dispose();
}
stage.dispose();
if (lastScreen != null) {
lastScreen.hide();
lastScreen.dispose();
}
if (screen != null) {
screen.hide();
screen.dispose();
}
}
@Override
public void pause() {
if (lastScreen != null) lastScreen.pause();
if (screen != null) screen.pause();
}
@Override
public void resume() {
if (lastScreen != null) lastScreen.resume();
if (screen != null) screen.resume();
}
@Override
public void create() {
stage = new Stage(new XFillViewport());
inputMultiplexer = new InputMultiplexer(stage);
Gdx.input.setInputProcessor(inputMultiplexer);
prepareDebugInfo();
}
@Override
public void render() {
// clear screen every frame
Gdx.gl.glClearColor(BACKGROUND_COLOR.r, BACKGROUND_COLOR.g, BACKGROUND_COLOR.b, BACKGROUND_COLOR.a);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo.update();
}
float deltaTime = Gdx.graphics.getDeltaTime();
if (lastScreen != null) lastScreen.render(deltaTime);
if (screen != null) screen.render(deltaTime);
stage.act(deltaTime);
stage.draw();
}
@Override
public void resize(int width, int height) {
if (lastScreen != null) lastScreen.resize(width, height);
if (screen != null) screen.resize(width, height);
stage.getViewport().update(width, height, true);
}
//////////////////////////// DEBUG INFO
private void prepareDebugInfo() {
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo = new DebugInfo(getStage().getWidth(), getStage().getHeight());
getStage().addActor(debugInfo);
}
}
private void prepareDebugInfo() {
if (TablexiaSettings.getInstance().isDebug()) {
debugInfo = new DebugInfo(getStage().getWidth(), getStage().getHeight());
getStage().addActor(debugInfo);
}
}
//////////////////////////// SCREEN HANDLING
......
......@@ -2,6 +2,7 @@ package cz.nic.tablexia.screen.gamemenu;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.pages.OfficeMenuPage;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.ViewPager;
public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
......@@ -18,6 +19,9 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
vp.addPage(new OfficeMenuPage());
vp.addPage(new OfficeMenuPage());
vp.setSize(getStage().getWidth(), getStage().getHeight());
Log.info(getClass().getName(), "ViewPager size: " + getStage().getWidth() + "x" + getStage().getHeight());
getStage().addActor(vp);
}
}
package cz.nic.tablexia.util.ui;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.Viewport;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.util.Log;
......@@ -8,15 +10,31 @@ import cz.nic.tablexia.util.Log;
/**
* Created by lhoracek on 3/6/15.
*/
public class XFillViewport extends FitViewport {
public class XFillViewport extends Viewport {
private float worldWidth, worldHeight;
/**
* Creates a new viewport using a new {@link com.badlogic.gdx.graphics.OrthographicCamera}.
* Creates a new viewport using a new {@link com.badlogic.gdx.graphics.OrthographicCamera} with no maximum world size.
*/
public XFillViewport() {
super(TablexiaSettings.getDefaultScreenWidth(), TablexiaSettings.getMinScreenHeight());
Log.info(getClass().getName(), "Viewport size: " + TablexiaSettings.getDefaultScreenWidth() +"x"+ TablexiaSettings.getMinScreenHeight());
//super(Scaling.fill, TablexiaSettings.getDefaultScreenWidth(), TablexiaSettings.getMinScreenHeight());
this(TablexiaSettings.getDefaultScreenWidth(), TablexiaSettings.getMinScreenHeight(), new OrthographicCamera());
Log.info(getClass().getName(), "Viewport size: " + TablexiaSettings.getDefaultScreenWidth() + "x" + TablexiaSettings.getMinScreenHeight());
}
/**
* Creates a new viewport with a maximum world size.
*/
public XFillViewport(float worldWidth, float worldHeight, Camera camera) {
setWorldSize(worldWidth, worldHeight);
setCamera(camera);
}
@Override
public void update(int screenWidth, int screenHeight, boolean centerCamera) {
int height = (int) Math.min(screenHeight, screenWidth * TablexiaSettings.getMaximuRatio());
setScreenBounds(0, Math.max(0, (screenHeight - height) / 2), screenWidth, height);
apply(centerCamera);
}
}
\ No newline at end of file
......@@ -33,9 +33,9 @@
<pattern>org.apache.harmony.security.provider.crypto.CryptoProvider</pattern>
</forceLinkClasses>
<libs>
<lib>build/libs/ios/libgdx.a</lib>
<lib>build/libs/ios/libgdx-freetype.a</lib>
<lib>build/libs/ios/libObjectAL.a</lib>
<lib>build/libs/ios/libgdx.a</lib>
</libs>
<frameworks>
<framework>UIKit</framework>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment