Bug 18: Separated ShapeRenderer II
This commit is contained in:
parent
3b5c9bc108
commit
c92659f3be
@ -49,6 +49,9 @@ dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.3"
|
||||
implementation "com.pixelgamelibrary:pixel:$pixelVersion"
|
||||
|
||||
implementation "com.github.earlygrey:shapedrawer:$shapedrawerVersion"
|
||||
|
||||
}
|
||||
|
||||
sourceCompatibility = '11'
|
||||
|
@ -20,4 +20,5 @@ gwtPluginVersion=1.1.29
|
||||
pixelVersion=0.0.0-SNAPSHOT
|
||||
lombokVersion=1.18.34
|
||||
gdxVersion=1.12.1
|
||||
shapedrawerVersion=2.6.0
|
||||
|
||||
|
@ -0,0 +1,92 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: LibGDX Backend.
|
||||
// Copyright (C) 2024 the original author or authors.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see
|
||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.backend.libgdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.pixelgamelibrary.api.graphics.Color;
|
||||
import com.pixelgamelibrary.api.graphics.Texture;
|
||||
import com.pixelgamelibrary.api.math.Angle;
|
||||
import com.pixelgamelibrary.backend.libgdx.utils.LibGdxBackendUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class LibGdxShapeRenderer implements com.pixelgamelibrary.api.graphics.ShapeRenderer {
|
||||
|
||||
private space.earlygrey.shapedrawer.ShapeDrawer internalShapeRenderer;
|
||||
private boolean disposed = false;
|
||||
|
||||
public LibGdxShapeRenderer(SpriteBatch spriteBatchIn) {
|
||||
this(new space.earlygrey.shapedrawer.ShapeDrawer(spriteBatchIn, new TextureRegion()));
|
||||
}
|
||||
|
||||
public LibGdxShapeRenderer(space.earlygrey.shapedrawer.ShapeDrawer internalShapeRendererIn) {
|
||||
this.internalShapeRenderer = internalShapeRendererIn;
|
||||
}
|
||||
space.earlygrey.shapedrawer.ShapeDrawer getShapeRenderer() {
|
||||
return this.internalShapeRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisposed() {
|
||||
return this.disposed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color colorIn) {
|
||||
this.color = colorIn;
|
||||
internalShapeRenderer.setColor(LibGdxBackendUtils.convertToLibGdxColor(color));
|
||||
}
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
private Color color = Color.BLACK;
|
||||
|
||||
@Override
|
||||
public void filledRectangle(float x, float y, float width, float height, Angle rotation, Color color) {
|
||||
float anticlockwiseRadians = rotation == null || rotation.asDegrees() == 0f ? 0f : Angle.ofDegrees(360f - rotation.asDegrees()).asGradians();
|
||||
internalShapeRenderer.filledRectangle(x, y, width, height, anticlockwiseRadians);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextureRegion(com.pixelgamelibrary.api.graphics.TextureRegion textureRegion) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.pixelgamelibrary.api.graphics.TextureRegion getTextureRegion() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(Texture texture) {
|
||||
com.badlogic.gdx.graphics.Texture gdxTexture = ((LibGdxTexture)texture).getInternalTexture();
|
||||
|
||||
internalShapeRenderer.setTextureRegion(new com.badlogic.gdx.graphics.g2d.TextureRegion(gdxTexture));
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,8 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.backend.libgdx.graphics;
|
||||
|
||||
import com.pixelgamelibrary.api.graphics.ShapeRenderer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
@ -27,6 +29,7 @@ public class LibGdxSpriteBatch implements com.pixelgamelibrary.api.graphics.Spri
|
||||
|
||||
private com.badlogic.gdx.graphics.g2d.SpriteBatch internalBatch;
|
||||
private boolean disposed = false;
|
||||
private ShapeRenderer shapeRenderer = null;
|
||||
|
||||
public LibGdxSpriteBatch() {
|
||||
this(new com.badlogic.gdx.graphics.g2d.SpriteBatch());
|
||||
@ -73,4 +76,12 @@ public class LibGdxSpriteBatch implements com.pixelgamelibrary.api.graphics.Spri
|
||||
this.internalBatch.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeRenderer drawShape() {
|
||||
if(shapeRenderer == null) {
|
||||
shapeRenderer = new LibGdxShapeRenderer(internalBatch);
|
||||
}
|
||||
return shapeRenderer;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.pixelgamelibrary.backend.libgdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.TextureData;
|
||||
import com.pixelgamelibrary.api.files.File;
|
||||
import com.pixelgamelibrary.api.graphics.ColorMode;
|
||||
import com.pixelgamelibrary.api.graphics.Pixmap;
|
||||
@ -103,5 +104,19 @@ public class LibGdxTexture implements com.pixelgamelibrary.api.graphics.Texture
|
||||
public boolean isDisposed() {
|
||||
return this.disposed;
|
||||
}
|
||||
@Override
|
||||
public void clear() {
|
||||
TextureData textureData = internalTexture.getTextureData();
|
||||
com.badlogic.gdx.graphics.Pixmap pixmap = null;
|
||||
if (textureData.isPrepared()) {
|
||||
pixmap = textureData.consumePixmap();
|
||||
} else {
|
||||
textureData.prepare();
|
||||
pixmap = textureData.consumePixmap();
|
||||
}
|
||||
|
||||
pixmap.setColor(0, 0, 0, 0);
|
||||
pixmap.fill();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.pixelgamelibrary.backend.libgdx.graphics;
|
||||
|
||||
import com.pixelgamelibrary.api.files.File;
|
||||
import com.pixelgamelibrary.api.graphics.Pixmap;
|
||||
import com.pixelgamelibrary.api.graphics.Texture;
|
||||
import com.pixelgamelibrary.api.graphics.TextureFactory;
|
||||
|
||||
@ -42,7 +41,7 @@ public class LibGdxTextureFactory implements TextureFactory{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture create(Pixmap pixmap) {
|
||||
public Texture create(com.pixelgamelibrary.api.graphics.Pixmap pixmap) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@ -50,5 +49,17 @@ public class LibGdxTextureFactory implements TextureFactory{
|
||||
public Texture create(int width, int height) {
|
||||
return new LibGdxTexture(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture createTransparent(int width, int height) {
|
||||
com.badlogic.gdx.graphics.Pixmap pixmap = new com.badlogic.gdx.graphics.Pixmap(width, height, com.badlogic.gdx.graphics.Pixmap.Format.RGBA8888);
|
||||
pixmap.setColor(0, 0, 0, 0);
|
||||
pixmap.fill();
|
||||
|
||||
com.badlogic.gdx.graphics.Texture texture = new com.badlogic.gdx.graphics.Texture(pixmap);
|
||||
texture.setFilter(com.badlogic.gdx.graphics.Texture.TextureFilter.Linear, com.badlogic.gdx.graphics.Texture.TextureFilter.Linear);
|
||||
return new LibGdxTexture(texture);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,12 +105,12 @@ public class GraphicsLibGDXImpl implements com.pixelgamelibrary.api.interfaces.G
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpriteBatchFactory newSpriteBatchFactory() {
|
||||
public SpriteBatchFactory getSpriteBatchFactory() {
|
||||
return new LibGdxSpriteBatchFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitmapFontFactory newBitmapFontFactory() {
|
||||
public BitmapFontFactory getBitmapFontFactory() {
|
||||
return new LibGdxBitmapFontFactory();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user