Skip to content

Commit

Permalink
Merge branch 'libgdx:master' into tiledmap_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Garnier committed Apr 28, 2024
2 parents 458fb61 + a523316 commit 7a8aefc
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
- iOS: The iOS backend now implements AudioDevice. It can be configured through IOSApplicationConfiguration with audioDeviceBufferSize/audioDeviceBufferCount
- Fixed GlyphLayout for fixed width glyph offsets at the start and end of lines.
- Fixed scene2d.ui layout for fractional positions and sizes.
- LWJGL3: Added pauseWhenMinimized and pauseWhenLostFocus flags to Lwjgl3ApplicationConfiguration.
- libGDX is now built using Java 17 due to Gradle 8 requirements.
- New GDX Setup projects now use Gradle 8.4 and AGP Plugin 8.1.2 which require at least Java 17.
- Fixed Timer#stop, remember time spent stopped and delay tasks when started again. #7281
- Android: Add configuration option to render under the cutout if available on the device.
- Fix: Keep SelectBox popup from extending past right edge of stage.
- Added Framebuffer multisample support (see GL31FrameBufferMultisampleTest.java for basic usage)
- Fix: Fonts generated with gdx-freetype no longer bleed when drawn with a shadow

[1.12.1]
- LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public Lwjgl3Window newWindow (ApplicationListener listener, Lwjgl3WindowConfigu

private Lwjgl3Window createWindow (final Lwjgl3ApplicationConfiguration config, ApplicationListener listener,
final long sharedContext) {
final Lwjgl3Window window = new Lwjgl3Window(listener, config, this);
final Lwjgl3Window window = new Lwjgl3Window(listener, lifecycleListeners, config, this);
if (sharedContext == 0) {
// the main window is created immediately
createWindow(window, config, sharedContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.PrintStream;
import java.nio.IntBuffer;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.LifecycleListener;
import org.lwjgl.BufferUtils;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -66,6 +68,9 @@ public enum GLEmulation {
int idleFPS = 60;
int foregroundFPS = 0;

boolean pauseWhenMinimized = true;
boolean pauseWhenLostFocus = false;

String preferencesDirectory = ".prefs/";
Files.FileType preferencesFileType = FileType.External;

Expand Down Expand Up @@ -99,6 +104,8 @@ void set (Lwjgl3ApplicationConfiguration config) {
transparentFramebuffer = config.transparentFramebuffer;
idleFPS = config.idleFPS;
foregroundFPS = config.foregroundFPS;
pauseWhenMinimized = config.pauseWhenMinimized;
pauseWhenLostFocus = config.pauseWhenLostFocus;
preferencesDirectory = config.preferencesDirectory;
preferencesFileType = config.preferencesFileType;
hdpiMode = config.hdpiMode;
Expand Down Expand Up @@ -185,6 +192,18 @@ public void setForegroundFPS (int fps) {
this.foregroundFPS = fps;
}

/** Sets whether to pause the application {@link ApplicationListener#pause()} and fire
* {@link LifecycleListener#pause()}/{@link LifecycleListener#resume()} events on when window is minimized/restored. **/
public void setPauseWhenMinimized (boolean pauseWhenMinimized) {
this.pauseWhenMinimized = pauseWhenMinimized;
}

/** Sets whether to pause the application {@link ApplicationListener#pause()} and fire
* {@link LifecycleListener#pause()}/{@link LifecycleListener#resume()} events on when window loses/gains focus. **/
public void setPauseWhenLostFocus (boolean pauseWhenLostFocus) {
this.pauseWhenLostFocus = pauseWhenLostFocus;
}

/** Sets the directory where {@link Preferences} will be stored, as well as the file type to be used to store them. Defaults to
* "$USER_HOME/.prefs/" and {@link FileType#External}. */
public void setPreferencesConfig (String preferencesDirectory, Files.FileType preferencesFileType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.IntBuffer;

import com.badlogic.gdx.*;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWDropCallback;
Expand All @@ -28,10 +29,6 @@
import org.lwjgl.glfw.GLFWWindowMaximizeCallback;
import org.lwjgl.glfw.GLFWWindowRefreshCallback;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
Expand All @@ -40,6 +37,7 @@
public class Lwjgl3Window implements Disposable {
private long windowHandle;
final ApplicationListener listener;
private final Array<LifecycleListener> lifecycleListeners;
final Lwjgl3ApplicationBase application;
private boolean listenerInitialized = false;
Lwjgl3WindowListener windowListener;
Expand All @@ -62,9 +60,24 @@ public void invoke (long windowHandle, final boolean focused) {
public void run () {
if (windowListener != null) {
if (focused) {
if (config.pauseWhenLostFocus) {
synchronized (lifecycleListeners) {
for (LifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.resume();
}
}
}
windowListener.focusGained();
} else {
windowListener.focusLost();
if (config.pauseWhenLostFocus) {
synchronized (lifecycleListeners) {
for (LifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.pause();
}
}
listener.pause();
}
}
Lwjgl3Window.this.focused = focused;
}
Expand All @@ -84,9 +97,23 @@ public void run () {
}
Lwjgl3Window.this.iconified = iconified;
if (iconified) {
listener.pause();
if (config.pauseWhenMinimized) {
synchronized (lifecycleListeners) {
for (LifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.pause();
}
}
listener.pause();
}
} else {
listener.resume();
if (config.pauseWhenMinimized) {
synchronized (lifecycleListeners) {
for (LifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.resume();
}
}
listener.resume();
}
}
}
});
Expand Down Expand Up @@ -156,8 +183,10 @@ public void run () {
}
};

Lwjgl3Window (ApplicationListener listener, Lwjgl3ApplicationConfiguration config, Lwjgl3ApplicationBase application) {
Lwjgl3Window (ApplicationListener listener, Array<LifecycleListener> lifecycleListeners, Lwjgl3ApplicationConfiguration config,
Lwjgl3ApplicationBase application) {
this.listener = listener;
this.lifecycleListeners = lifecycleListeners;
this.windowListener = config.windowListener;
this.config = config;
this.application = application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData;
import com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph;
import com.badlogic.gdx.graphics.g2d.Gdx2DPixmap;
import com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.GuillotineStrategy;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.PackStrategy;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.PixmapPackerRectangle;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.SkylineStrategy;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.Bitmap;
Expand All @@ -42,7 +44,6 @@
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.SizeMetrics;
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.Stroker;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.GdxRuntimeException;
Expand Down Expand Up @@ -527,7 +528,11 @@ public FreeTypeBitmapFontData generateData (FreeTypeFontParameter parameter, Fre
int mainW = mainPixmap.getWidth(), mainH = mainPixmap.getHeight();
int shadowOffsetX = Math.max(parameter.shadowOffsetX, 0), shadowOffsetY = Math.max(parameter.shadowOffsetY, 0);
int shadowW = mainW + Math.abs(parameter.shadowOffsetX), shadowH = mainH + Math.abs(parameter.shadowOffsetY);
Pixmap shadowPixmap = new Pixmap(shadowW, shadowH, mainPixmap.getFormat());
// use the Gdx2DPixmap constructor to avoid filling the pixmap twice
Pixmap shadowPixmap = new Pixmap(
new Gdx2DPixmap(shadowW, shadowH, Pixmap.Format.toGdx2DPixmapFormat(mainPixmap.getFormat())));
shadowPixmap.setColor(packer.getTransparentColor());
shadowPixmap.fill();

Color shadowColor = parameter.shadowColor;
float a = shadowColor.a;
Expand Down Expand Up @@ -598,9 +603,8 @@ public FreeTypeBitmapFontData generateData (FreeTypeFontParameter parameter, Fre
}
}

String pixmapName = glyph.hashCode() + "_" + glyph.id;
Rectangle rect = packer.pack(pixmapName, mainPixmap);
glyph.page = packer.getPageIndex(pixmapName);
PixmapPackerRectangle rect = packer.pack(mainPixmap);
glyph.page = packer.getPages().indexOf(rect.page, true);
glyph.srcX = (int)rect.x;
glyph.srcY = (int)rect.y;

Expand Down
14 changes: 8 additions & 6 deletions gdx/src/com/badlogic/gdx/graphics/g2d/PixmapPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void sort (Array<Pixmap> images) {

/** Inserts the pixmap without a name. It cannot be looked up by name.
* @see #pack(String, Pixmap) */
public synchronized Rectangle pack (Pixmap image) {
public synchronized PixmapPackerRectangle pack (Pixmap image) {
return pack(null, image);
}

Expand All @@ -162,7 +162,7 @@ public synchronized Rectangle pack (Pixmap image) {
* @return Rectangle describing the area the pixmap was rendered to.
* @throws GdxRuntimeException in case the image did not fit due to the page size being too small or providing a duplicate
* name. */
public synchronized Rectangle pack (String name, Pixmap image) {
public synchronized PixmapPackerRectangle pack (String name, Pixmap image) {
if (disposed) return null;
if (name != null && getRect(name) != null)
throw new GdxRuntimeException("Pixmap has already been packed with name: " + name);
Expand Down Expand Up @@ -282,6 +282,7 @@ public synchronized Rectangle pack (String name, Pixmap image) {
pixmapToDispose.dispose();
}

rect.page = page;
return rect;
}

Expand Down Expand Up @@ -849,10 +850,11 @@ private int getSplitPoint (Pixmap raster, int startX, int startY, boolean startP
}

public static class PixmapPackerRectangle extends Rectangle {
int[] splits;
int[] pads;
int offsetX, offsetY;
int originalWidth, originalHeight;
public Page page;
public int[] splits;
public int[] pads;
public int offsetX, offsetY;
public int originalWidth, originalHeight;

PixmapPackerRectangle (int x, int y, int width, int height) {
super(x, y, width, height);
Expand Down
2 changes: 2 additions & 0 deletions gdx/src/com/badlogic/gdx/graphics/g2d/TextureAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public void parse (Region region) {
line = reader.readLine();
} else if (page == null) {
page = new Page();
page.name = line;
page.textureFile = imagesDir.child(line);
while (true) {
if (readEntry(entry, line = reader.readLine()) == 0) break;
Expand Down Expand Up @@ -479,6 +480,7 @@ static private interface Field<T> {
}

static public class Page {
public String name;
/** May be null if this page isn't associated with a file. In that case, {@link #texture} must be set. */
public @Null FileHandle textureFile;
/** May be null if the texture is not yet loaded. */
Expand Down
8 changes: 8 additions & 0 deletions gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ public void draw (Batch batch, float parentAlpha) {
drawMessageText(batch, messageFont, x + bgLeftWidth, y + textY + yOffset, width - bgLeftWidth - bgRightWidth);
}
} else {
BitmapFontData data = font.getData();
boolean markupEnabled = data.markupEnabled;
data.markupEnabled = false;
font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha);
drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
data.markupEnabled = markupEnabled;
}
if (!disabled && cursorOn && cursorPatch != null) {
drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
Expand Down Expand Up @@ -418,7 +422,11 @@ void updateDisplayText () {
} else
displayText = newDisplayText;

boolean markupEnabled = data.markupEnabled;
data.markupEnabled = false;
layout.setText(font, displayText.toString().replace('\r', ' ').replace('\n', ' '));
data.markupEnabled = markupEnabled;

glyphPositions.clear();
float x = 0;
if (layout.runs.size > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ public boolean handle (Event e) {
case touchUp:
if (event.isTouchFocusCancel()) {
detector.reset();
actor = null;
touchDownTarget = null;
return false;
}
this.event = event;
actor = event.getListenerActor();
detector.touchUp(event.getStageX(), event.getStageY(), event.getPointer(), event.getButton());
actor.stageToLocalCoordinates(tmpCoords.set(event.getStageX(), event.getStageY()));
touchUp(event, tmpCoords.x, tmpCoords.y, event.getPointer(), event.getButton());
actor = null;
touchDownTarget = null;
return true;
case touchDragged:
this.event = event;
Expand Down Expand Up @@ -170,6 +174,7 @@ public GestureDetector getGestureDetector () {
return detector;
}

/** Returns null if there is no current touch down. */
public @Null Actor getTouchDownTarget () {
return touchDownTarget;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.LifecycleListener;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics;
Expand All @@ -48,6 +49,22 @@ public static void main (String[] argv) throws NoSuchFieldException, SecurityExc

@Override
public void create () {
Gdx.app.addLifecycleListener(new LifecycleListener() {
@Override
public void pause () {
Gdx.app.log("LifecycleListener", "Application pause()");
}

@Override
public void resume () {
Gdx.app.log("LifecycleListener", "Application resume()");
}

@Override
public void dispose () {
Gdx.app.log("LifecycleListener", "Application dispose()");
}
});
BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
texture = new Texture("data/badlogic.jpg");
batch = new SpriteBatch();
Expand Down

0 comments on commit 7a8aefc

Please sign in to comment.