Skip to content

Commit

Permalink
Merge pull request #105 from xpenatan/master
Browse files Browse the repository at this point in the history
Release v1.0.0-b6
  • Loading branch information
xpenatan committed Jul 23, 2023
2 parents c78498a + 142fc7a commit bd32b5c
Show file tree
Hide file tree
Showing 38 changed files with 873 additions and 260 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[1.0.0-SNAPSHOT]
-

[1.0.0-b6]
- Update libgdx to version 1.12.0
- Update jParser to version b3
- Update teavm to version 0.9.0-dev-7

[1.0.0-b5]
- Option in App config to show download logs. Default is set to false.
- Implement setApplicationLogger method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.badlogic.gdx.utils.reflect.ArrayReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
import com.github.xpenatan.gdx.backends.teavm.plugins.TeaReflectionSupplier;
import com.github.xpenatan.gdx.backends.teavm.util.GenericTypeProvider;
import com.github.xpenatan.gdx.backends.teavm.utils.GenericTypeProvider;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down
104 changes: 52 additions & 52 deletions backends/backend-teavm/emu/com/badlogic/gdx/graphics/PixmapEmu.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static int toGlType (FormatEmu format) {
private HTMLVideoElementWrapper videoElement;

private int color = 0;
private Gdx2DPixmapEmu pixmap;
private Gdx2DPixmapEmu nativePixmap;
private boolean disposed;

public static void downloadFromUrl(String url, final Pixmap.DownloadPixmapResponseListener responseListener) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public PixmapEmu(FileHandle file) {
if(config.useNativePixmap) {
Int8ArrayWrapper response = object.getData();
byte[] bytes = Gdx2DPixmapEmu.get(response);
pixmap = new Gdx2DPixmapEmu(bytes, 0, bytes.length, 0);
nativePixmap = new Gdx2DPixmapEmu(bytes, 0, bytes.length, 0);
initPixmapEmu(-1, -1, null, null);
}
else {
Expand All @@ -149,7 +149,7 @@ public PixmapEmu(byte[] encodedData, int offset, int len) {
TeaApplication app = (TeaApplication)Gdx.app;
TeaApplicationConfiguration config = app.getConfig();
if(config.useNativePixmap) {
pixmap = new Gdx2DPixmapEmu(encodedData, offset, len, 0);
nativePixmap = new Gdx2DPixmapEmu(encodedData, offset, len, 0);
initPixmapEmu(-1, -1, null, null);
}
}
Expand Down Expand Up @@ -234,11 +234,11 @@ private void ensureCanvasExists() {
}

public boolean canUsePixmapData() {
return canvas == null && pixmap != null;
return canvas == null && nativePixmap != null;
}

public Uint8ArrayWrapper getPixmapData() {
return pixmap.getPixels();
return nativePixmap.getPixels();
}

public boolean canUseImageElement() {
Expand All @@ -263,7 +263,7 @@ public HTMLVideoElementWrapper getVideoElement() {
* @param color the color, encoded as RGBA8888
*/
public void setColor(int color) {
if(pixmap != null) {
if(nativePixmap != null) {
this.color = color;
}
else {
Expand All @@ -287,7 +287,7 @@ public void setColor(int color) {
* @param a The alpha component.
*/
public void setColor(float r, float g, float b, float a) {
if(pixmap != null) {
if(nativePixmap != null) {
this.color = Color.rgba8888(r, g, b, a);
}
else {
Expand Down Expand Up @@ -315,8 +315,8 @@ public void setColor(Color color) {
* Fills the complete bitmap with the currently set color.
*/
public void fill() {
if(pixmap != null) {
pixmap.clear(color);
if(nativePixmap != null) {
nativePixmap.clear(color);
}
else {
ensureCanvasExists();
Expand All @@ -341,8 +341,8 @@ public void fill() {
* @param y2 The y-coordinate of the first point
*/
public void drawLine(int x, int y, int x2, int y2) {
if(pixmap != null) {
pixmap.drawLine(x, y, x2, y2, color);
if(nativePixmap != null) {
nativePixmap.drawLine(x, y, x2, y2, color);
}
else {
line(x, y, x2, y2, DrawType.STROKE);
Expand All @@ -359,8 +359,8 @@ public void drawLine(int x, int y, int x2, int y2) {
* @param height The height in pixels
*/
public void drawRectangle(int x, int y, int width, int height) {
if(pixmap != null) {
pixmap.drawRect(x, y, width, height, color);
if(nativePixmap != null) {
nativePixmap.drawRect(x, y, width, height, color);
}
else {
rectangle(x, y, width, height, DrawType.STROKE);
Expand All @@ -375,7 +375,7 @@ public void drawRectangle(int x, int y, int width, int height) {
* @param y The target y-coordinate (top left corner)
*/
public void drawPixmap(PixmapEmu pixmap, int x, int y) {
if(pixmap != null) {
if(nativePixmap != null) {
drawPixmap(pixmap, x, y, 0, 0, pixmap.getWidth(), pixmap.getHeight());
}
else {
Expand All @@ -385,8 +385,8 @@ public void drawPixmap(PixmapEmu pixmap, int x, int y) {
}

public void drawPixmap(PixmapEmu pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) {
if(pixmap != null) {
this.pixmap.drawPixmap(pixmap.pixmap, srcx, srcy, x, y, srcWidth, srcHeight);
if(nativePixmap != null) {
this.nativePixmap.drawPixmap(pixmap.nativePixmap, srcx, srcy, x, y, srcWidth, srcHeight);
}
else {
HTMLCanvasElementWrapper image = pixmap.getCanvasElement();
Expand All @@ -395,53 +395,53 @@ public void drawPixmap(PixmapEmu pixmap, int x, int y, int srcx, int srcy, int s
}

public void drawPixmap(PixmapEmu pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight) {
if(pixmap != null) {
this.pixmap.drawPixmap(pixmap.pixmap, srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
if(nativePixmap != null) {
this.nativePixmap.drawPixmap(pixmap.nativePixmap, srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
}
else {
image(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
}
}

public void fillRectangle(int x, int y, int width, int height) {
if(pixmap != null) {
pixmap.fillRect(x, y, width, height, color);
if(nativePixmap != null) {
nativePixmap.fillRect(x, y, width, height, color);
}
else {
rectangle(x, y, width, height, DrawType.FILL);
}
}

public void drawCircle(int x, int y, int radius) {
if(pixmap != null) {
pixmap.drawCircle(x, y, radius, color);
if(nativePixmap != null) {
nativePixmap.drawCircle(x, y, radius, color);
}
else {
circle(x, y, radius, DrawType.STROKE);
}
}

public void fillCircle(int x, int y, int radius) {
if(pixmap != null) {
pixmap.fillCircle(x, y, radius, color);
if(nativePixmap != null) {
nativePixmap.fillCircle(x, y, radius, color);
}
else {
circle(x, y, radius, DrawType.FILL);
}
}

public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
if(pixmap != null) {
pixmap.fillTriangle(x1, y1, x2, y2, x3, y3, color);
if(nativePixmap != null) {
nativePixmap.fillTriangle(x1, y1, x2, y2, x3, y3, color);
}
else {
triangle(x1, y1, x2, y2, x3, y3, DrawType.FILL);
}
}

public int getPixel(int x, int y) {
if(pixmap != null) {
return pixmap.getPixel(x, y);
if(nativePixmap != null) {
return nativePixmap.getPixel(x, y);
}
else {
ensureCanvasExists();
Expand All @@ -456,17 +456,17 @@ public int getPixel(int x, int y) {
}

public int getWidth() {
if(pixmap != null) {
return pixmap.getWidth();
if(nativePixmap != null) {
return nativePixmap.getWidth();
}
else {
return width;
}
}

public int getHeight() {
if(pixmap != null) {
return pixmap.getHeight();
if(nativePixmap != null) {
return nativePixmap.getHeight();
}
else {
return height;
Expand All @@ -477,8 +477,8 @@ public int getHeight() {
public void dispose() {
if (disposed) throw new GdxRuntimeException("Pixmap already disposed!");
pixmaps.remove(id);
if(pixmap != null) {
pixmap.dispose();
if(nativePixmap != null) {
nativePixmap.dispose();
}
disposed = true;
}
Expand All @@ -488,17 +488,17 @@ public boolean isDisposed () {
}

public void drawPixel(int x, int y) {
if(pixmap != null) {
pixmap.setPixel(x, y, color);
if(nativePixmap != null) {
nativePixmap.setPixel(x, y, color);
}
else {
rectangle(x, y, 1, 1, DrawType.FILL);
}
}

public void drawPixel(int x, int y, int color) {
if(pixmap != null) {
pixmap.setPixel(x, y, color);
if(nativePixmap != null) {
nativePixmap.setPixel(x, y, color);
}
else {
setColor(color);
Expand All @@ -507,22 +507,22 @@ public void drawPixel(int x, int y, int color) {
}

public int getGLFormat () {
if(pixmap != null) {
return pixmap.getGLFormat();
if(nativePixmap != null) {
return nativePixmap.getGLFormat();
}
return GL20.GL_RGBA;
}

public int getGLInternalFormat () {
if(pixmap != null) {
return pixmap.getGLInternalFormat();
if(nativePixmap != null) {
return nativePixmap.getGLInternalFormat();
}
return GL20.GL_RGBA;
}

public int getGLType () {
if(pixmap != null) {
return pixmap.getGLType();
if(nativePixmap != null) {
return nativePixmap.getGLType();
}
return GL20.GL_UNSIGNED_BYTE;
}
Expand All @@ -532,9 +532,9 @@ public ByteBuffer getPixels() {
}

public void setPixels(ByteBuffer pixels) {
if(pixmap != null) {
if(nativePixmap != null) {
if (!pixels.isDirect()) throw new GdxRuntimeException("Couldn't setPixels from non-direct ByteBuffer");
Uint8ArrayWrapper dst = pixmap.getPixels();
Uint8ArrayWrapper dst = nativePixmap.getPixels();
//TODO find a way to use byteBuffer
// BufferUtils.copy(pixels, dst, dst.limit())
}
Expand All @@ -552,16 +552,16 @@ public void setPixels(ByteBuffer pixels) {
}

public Pixmap.Format getFormat () {
if(pixmap != null) {
return Pixmap.Format.fromGdx2DPixmapFormat(pixmap.getFormat());
if(nativePixmap != null) {
return Pixmap.Format.fromGdx2DPixmapFormat(nativePixmap.getFormat());
}
return Pixmap.Format.RGBA8888;
}

public void setFilter(Pixmap.Filter filter) {
this.filter = filter;
if(pixmap != null) {
pixmap.setScale(filter == Pixmap.Filter.NearestNeighbour ? Gdx2DPixmapEmu.GDX2D_SCALE_NEAREST : Gdx2DPixmapEmu.GDX2D_SCALE_LINEAR);
if(nativePixmap != null) {
nativePixmap.setScale(filter == Pixmap.Filter.NearestNeighbour ? Gdx2DPixmapEmu.GDX2D_SCALE_NEAREST : Gdx2DPixmapEmu.GDX2D_SCALE_LINEAR);
}
}

Expand All @@ -571,8 +571,8 @@ public Pixmap.Filter getFilter() {

public void setBlending(Pixmap.Blending blending) {
this.blending = blending;
if(pixmap != null) {
pixmap.setBlend(blending == Pixmap.Blending.None ? 0 : 1);
if(nativePixmap != null) {
nativePixmap.setBlend(blending == Pixmap.Blending.None ? 0 : 1);
}
else {
this.ensureCanvasExists();
Expand Down
Loading

0 comments on commit bd32b5c

Please sign in to comment.