Skip to content

Commit

Permalink
feat: Add ImageScreenMode#CENTERED_FILL.
Browse files Browse the repository at this point in the history
  • Loading branch information
crykn committed Oct 29, 2023
1 parent 2a2884a commit f34eea0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class AbstractEskalonUIScreen extends AbstractImageScreen {
protected Table mainTable;

public AbstractEskalonUIScreen() {
this.setMode(ImageScreenMode.CENTERED_ORIGINAL_SIZE);
this.setMode(ImageScreenMode.CENTERED_FILL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public enum ImageScreenMode {
/**
* The image is displayed in its original size and centered.
*/
CENTERED_ORIGINAL_SIZE
CENTERED_ORIGINAL_SIZE,
/**
* The image is scaled to fit the screen while keeping its aspect ratio.
*/
CENTERED_FILL;
}

public static final ImageScreenMode DEFAULT_SCREEN_MODE = ImageScreenMode.STRETCH;
Expand Down Expand Up @@ -146,6 +150,19 @@ private void calculateDimensions() {
Gdx.graphics.getHeight());
this.position.set(0, 0);
break;
case CENTERED_FILL:
scl = Gdx.graphics.getHeight()
/ (float) Gdx.graphics.getWidth() < image.getHeight()
/ (float) image.getWidth()
? Gdx.graphics.getWidth()
/ (float) image.getWidth()
: Gdx.graphics.getHeight()
/ (float) image.getHeight();
this.dimensions.set(image.getWidth() * scl,
image.getHeight() * scl);
this.position.set((Gdx.graphics.getWidth() - dimensions.x) / 2F,
(Gdx.graphics.getHeight() - dimensions.y) / 2F);
break;
case SCALE:
scl = image.getWidth() - Gdx.graphics.getWidth() >= image
.getHeight() - Gdx.graphics.getHeight()
Expand Down

0 comments on commit f34eea0

Please sign in to comment.