Bug 18: Separated SpriteBatch and BitmapFont
This commit is contained in:
parent
571d1b304f
commit
5fd48921c3
@ -25,5 +25,5 @@ package com.pixelgamelibrary.api.app;
|
||||
* @author robertvokac
|
||||
*/
|
||||
public enum LogLevel {
|
||||
NONE, ERROR, INFO, WARN, DEBUG;
|
||||
NONE, FATAL, ERROR, INFO, WARN, DEBUG, TRACE;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// 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.api.graphics;
|
||||
|
||||
import com.pixelgamelibrary.api.Disposable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface BitmapFont extends Disposable {
|
||||
void setScale(float f);
|
||||
void setColor(Color color);
|
||||
default void setColor(float r, float g, float b, float a) {
|
||||
setColor(new Color(0f, 0f, 1f, 1f));
|
||||
}
|
||||
void draw(SpriteBatch batch, String text, float x, float y);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// 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.api.graphics;
|
||||
|
||||
import com.pixelgamelibrary.api.storage.FileHandle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface BitmapFontFactory {
|
||||
|
||||
boolean FLIP_DEFAULT = false;
|
||||
|
||||
BitmapFont create(boolean flip);
|
||||
|
||||
default BitmapFont create() {
|
||||
return create(FLIP_DEFAULT);
|
||||
}
|
||||
|
||||
BitmapFont create(FileHandle fontFile, TextureRegion region, boolean flip);
|
||||
|
||||
default BitmapFont create(FileHandle fontFile, TextureRegion region) {
|
||||
return create(fontFile, region, FLIP_DEFAULT);
|
||||
}
|
||||
|
||||
BitmapFont create(FileHandle fontFile, boolean flip);
|
||||
|
||||
default BitmapFont create(FileHandle fontFile) {
|
||||
return create(fontFile, FLIP_DEFAULT);
|
||||
}
|
||||
// Pixel.files().assets("com/badlogic/gdx/utils/lsans-15.fnt"), Pixel.files().assets("com/badlogic/gdx/utils/lsans-15.png"),
|
||||
// false, true
|
||||
// );
|
||||
|
||||
BitmapFont create(FileHandle fontFile, FileHandle imageFile, boolean flip);
|
||||
|
||||
default BitmapFont create(FileHandle fontFile, FileHandle imageFile) {
|
||||
return create(fontFile, imageFile, FLIP_DEFAULT);
|
||||
}
|
||||
|
||||
}
|
@ -58,6 +58,54 @@ import lombok.Data;
|
||||
@Data
|
||||
public final class Color {
|
||||
|
||||
public static final Color BLUE = new Color(0, 0, 255);
|
||||
public static final Color RED = new Color(255, 0, 0);
|
||||
public static final Color GREEN = new Color(0, 255, 0);
|
||||
public static final Color BLACK = new Color(0, 0, 0);
|
||||
public static final Color WHITE = new Color(255, 255, 255);
|
||||
public static final Color YELLOW = new Color(255, 255, 0);
|
||||
public static final Color CYAN = new Color(0, 255, 255);
|
||||
public static final Color MAGENTA = new Color(255, 0, 255);
|
||||
public static final Color GRAY = new Color(128, 128, 128);
|
||||
public static final Color LIGHT_GRAY = new Color(192, 192, 192);
|
||||
public static final Color DARK_GRAY = new Color(64, 64, 64);
|
||||
public static final Color ORANGE = new Color(255, 165, 0);
|
||||
public static final Color PINK = new Color(255, 192, 203);
|
||||
public static final Color BROWN = new Color(165, 42, 42);
|
||||
public static final Color PURPLE = new Color(128, 0, 128);
|
||||
public static final Color VIOLET = new Color(238, 130, 238);
|
||||
public static final Color LIME = new Color(0, 255, 0);
|
||||
public static final Color TURQUOISE = new Color(64, 224, 208);
|
||||
public static final Color INDIGO = new Color(75, 0, 130);
|
||||
public static final Color GOLD = new Color(255, 215, 0);
|
||||
public static final Color SILVER = new Color(192, 192, 192);
|
||||
public static final Color MAROON = new Color(128, 0, 0);
|
||||
public static final Color NAVY = new Color(0, 0, 128);
|
||||
public static final Color TEAL = new Color(0, 128, 128);
|
||||
public static final Color OLIVE = new Color(128, 128, 0);
|
||||
public static final Color BEIGE = new Color(245, 245, 220);
|
||||
public static final Color SALMON = new Color(250, 128, 114);
|
||||
public static final Color CORAL = new Color(255, 127, 80);
|
||||
public static final Color HOT_PINK = new Color(255, 105, 180);
|
||||
public static final Color CHARTREUSE = new Color(127, 255, 0);
|
||||
public static final Color SKY_BLUE = new Color(135, 206, 235);
|
||||
public static final Color LIGHT_BLUE = new Color(173, 216, 230);
|
||||
public static final Color DARK_BLUE = new Color(0, 0, 139);
|
||||
public static final Color MINT = new Color(189, 252, 201);
|
||||
public static final Color PEACH = new Color(255, 218, 185);
|
||||
public static final Color PLUM = new Color(221, 160, 221);
|
||||
public static final Color IVORY = new Color(255, 255, 240);
|
||||
public static final Color LAVENDER = new Color(230, 230, 250);
|
||||
public static final Color MINT_CREAM = new Color(245, 255, 250);
|
||||
public static final Color WHEAT = new Color(245, 222, 179);
|
||||
public static final Color TAN = new Color(210, 180, 140);
|
||||
public static final Color KHAKI = new Color(240, 230, 140);
|
||||
public static final Color PERIWINKLE = new Color(204, 204, 255);
|
||||
public static final Color SLATE_GRAY = new Color(112, 128, 144);
|
||||
public static final Color SEA_GREEN = new Color(46, 139, 87);
|
||||
public static final Color FOREST_GREEN = new Color(34, 139, 34);
|
||||
public static final Color MIDNIGHT_BLUE = new Color(25, 25, 112);
|
||||
|
||||
private static final int EIGHT_BITS_TO_DECIMAL_WITHOUT_ONE = 255;
|
||||
|
||||
|
||||
|
@ -17,21 +17,22 @@
|
||||
// <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.api.graphics;
|
||||
|
||||
import com.pixelgamelibrary.api.Disposable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface SpriteBatch {
|
||||
public interface SpriteBatch extends Disposable {
|
||||
|
||||
//https://libgdx.com/wiki/graphics/2d/spritebatch-textureregions-and-sprites
|
||||
//draw (Texture texture, float x, float y) Draws the texture using the texture's width and height.
|
||||
//draw (Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) Draws a portion of the texture.
|
||||
//draw (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) Draws a portion of a texture, stretched to the width and height, and optionally flipped.
|
||||
//draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) This monster method draws a portion of a texture, stretched to the width and height, scaled and rotated around an origin, and optionally flipped.
|
||||
//draw (Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2) This draws a portion of a texture, stretched to the width and height. This is a somewhat advanced method as it uses texture coordinates from 0-1 rather than pixel coordinates.
|
||||
//draw (Texture texture, float[] spriteVertices, int offset, int length) This is an advanced method for passing in the raw geometry, texture coordinates, and color information. This can be used to draw any quadrilateral, not just rectangles.
|
||||
void begin();
|
||||
|
||||
void end();
|
||||
|
||||
void draw(Texture texture, int x, int y, int width, int height);
|
||||
|
||||
void draw(Texture texture, int x, int y);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// 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.api.graphics;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface SpriteBatchFactory {
|
||||
SpriteBatch create();
|
||||
}
|
@ -31,8 +31,11 @@ import com.pixelgamelibrary.api.app.Preferences;
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface App {
|
||||
String DEFAULT_TAG = "APP";
|
||||
Platform getPlatform();
|
||||
|
||||
default boolean isPlatforms(Platform platform) {
|
||||
return getPlatform() == platform;
|
||||
}
|
||||
default boolean isOneOfPlatforms(Platform ... platforms) {
|
||||
for(Platform p: platforms) {
|
||||
if(getPlatform() == p) {
|
||||
@ -42,10 +45,44 @@ public interface App {
|
||||
return false;
|
||||
}
|
||||
void exit();
|
||||
void log(String msg);
|
||||
void warn(String msg);
|
||||
void error(String msg);
|
||||
void debug(String msg);
|
||||
|
||||
void fatal(String tag, String msg);
|
||||
|
||||
void error(String tag, String msg);
|
||||
|
||||
void log(String tag, String msg);
|
||||
|
||||
void warn(String tag, String msg);
|
||||
|
||||
void debug(String tag, String msg);
|
||||
|
||||
void trace(String tag, String msg);
|
||||
|
||||
default void fatal(String msg) {
|
||||
fatal(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
default void error(String msg) {
|
||||
error(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
default void log(String msg) {
|
||||
log(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
default void warn(String msg) {
|
||||
warn(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
default void debug(String msg) {
|
||||
debug(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
default void trace(String msg) {
|
||||
trace(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
|
||||
void setLogLevel(LogLevel logLevel);
|
||||
Preferences getPreferences(String preferencesName);
|
||||
void setAppName(String appName);
|
||||
|
@ -32,35 +32,35 @@ import static com.pixelgamelibrary.api.storage.StorageType.EXTERNAL;
|
||||
*/
|
||||
public interface Files {
|
||||
|
||||
Storage assets();
|
||||
Storage assetsStorage();
|
||||
|
||||
Storage local();
|
||||
Storage localStorage();
|
||||
|
||||
Storage external();
|
||||
Storage externalStorage();
|
||||
|
||||
Storage relative();
|
||||
Storage relativeStorage();
|
||||
|
||||
Storage absolute();
|
||||
Storage absoluteStorage();
|
||||
|
||||
Storage tmp();
|
||||
Storage tmpStorage();
|
||||
|
||||
default FileHandle assetsFile(String path) {
|
||||
return assets().file(path);
|
||||
default FileHandle assets(String path) {
|
||||
return assetsStorage().file(path);
|
||||
}
|
||||
default FileHandle localFile(String path) {
|
||||
return local().file(path);
|
||||
default FileHandle local(String path) {
|
||||
return localStorage().file(path);
|
||||
}
|
||||
default FileHandle externalFile(String path) {
|
||||
return external().file(path);
|
||||
default FileHandle external(String path) {
|
||||
return externalStorage().file(path);
|
||||
}
|
||||
default FileHandle relativeFile(String path) {
|
||||
return relative().file(path);
|
||||
default FileHandle relative(String path) {
|
||||
return relativeStorage().file(path);
|
||||
}
|
||||
default FileHandle absoluteFile(String path) {
|
||||
return absolute().file(path);
|
||||
default FileHandle absolute(String path) {
|
||||
return absoluteStorage().file(path);
|
||||
}
|
||||
default FileHandle tmpFile(String path) {
|
||||
return tmp().file(path);
|
||||
default FileHandle tmp(String path) {
|
||||
return tmpStorage().file(path);
|
||||
}
|
||||
|
||||
|
||||
@ -68,17 +68,17 @@ public interface Files {
|
||||
default FileHandle file(java.lang.String path, StorageType type) {
|
||||
switch (type) {
|
||||
case ASSETS:
|
||||
return assets().file(path);
|
||||
return assetsStorage().file(path);
|
||||
case LOCAL:
|
||||
return local().file(path);
|
||||
return localStorage().file(path);
|
||||
case EXTERNAL:
|
||||
return external().file(path);
|
||||
return externalStorage().file(path);
|
||||
case RELATIVE:
|
||||
return relative().file(path);
|
||||
return relativeStorage().file(path);
|
||||
case ABSOLUTE:
|
||||
return absolute().file(path);
|
||||
return absoluteStorage().file(path);
|
||||
case TMP:
|
||||
return tmp().file(path);
|
||||
return tmpStorage().file(path);
|
||||
default:
|
||||
throw new StorageException("Unsupported StorageType: " + type);
|
||||
}
|
||||
|
@ -19,30 +19,102 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.api.interfaces;
|
||||
|
||||
import com.pixelgamelibrary.api.graphics.BitmapFont;
|
||||
import com.pixelgamelibrary.api.graphics.BitmapFontFactory;
|
||||
import com.pixelgamelibrary.api.graphics.Cursor;
|
||||
import com.pixelgamelibrary.api.graphics.Monitor;
|
||||
import java.util.List;
|
||||
import com.pixelgamelibrary.api.graphics.Pixmap;
|
||||
import com.pixelgamelibrary.api.graphics.SpriteBatch;
|
||||
import com.pixelgamelibrary.api.graphics.SpriteBatchFactory;
|
||||
import com.pixelgamelibrary.api.graphics.Texture;
|
||||
import com.pixelgamelibrary.api.graphics.TextureFactory;
|
||||
import com.pixelgamelibrary.api.graphics.TextureRegion;
|
||||
import com.pixelgamelibrary.api.storage.FileHandle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface Graphics {
|
||||
|
||||
|
||||
List<Monitor> getMonitors();
|
||||
|
||||
Monitor getMonitor();
|
||||
|
||||
Monitor getPrimaryMonitor();
|
||||
|
||||
String getTitle();
|
||||
|
||||
void setTitle(String title);
|
||||
|
||||
Cursor newCursor(Pixmap pixMap, int x, int y);
|
||||
|
||||
default Cursor newCursor(Pixmap pixMap) {
|
||||
Monitor monitor = getPrimaryMonitor();
|
||||
Monitor monitor = getPrimaryMonitor();
|
||||
return newCursor(pixMap, monitor.getVirtualWidth() / 2, monitor.getVirtualWidth() / 2);
|
||||
}
|
||||
void setCursor (Cursor cursor);
|
||||
float getDeltaTime ();
|
||||
|
||||
void setCursor(Cursor cursor);
|
||||
|
||||
float getDeltaTime();
|
||||
|
||||
void setTargetFPS();
|
||||
|
||||
int getTargetFPS();
|
||||
|
||||
|
||||
TextureFactory getTextureFactory();
|
||||
|
||||
default Texture newTexture(String assetPath) {
|
||||
return getTextureFactory().create(assetPath);
|
||||
}
|
||||
|
||||
default Texture newTexture(FileHandle fileHandle) {
|
||||
return getTextureFactory().create(fileHandle);
|
||||
}
|
||||
|
||||
default Texture newTexture(Pixmap pixmap) {
|
||||
return getTextureFactory().create(pixmap);
|
||||
}
|
||||
|
||||
default Texture newTexture(int width, int height) {
|
||||
return getTextureFactory().create(width, height);
|
||||
}
|
||||
|
||||
SpriteBatchFactory newSpriteBatchFactory();
|
||||
|
||||
default SpriteBatch newSpriteBatch() {
|
||||
return newSpriteBatchFactory().create();
|
||||
}
|
||||
|
||||
BitmapFontFactory newBitmapFontFactory();
|
||||
|
||||
default BitmapFont newBitmapFont() {
|
||||
return newBitmapFontFactory().create();
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(boolean flip) {
|
||||
return newBitmapFontFactory().create(flip);
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(FileHandle fontFile, TextureRegion region) {
|
||||
return newBitmapFontFactory().create(fontFile, region);
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(FileHandle fontFile, TextureRegion region, boolean flip) {
|
||||
return newBitmapFontFactory().create(fontFile, region, flip);
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(FileHandle fontFile) {
|
||||
return newBitmapFontFactory().create(fontFile);
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(FileHandle fontFile, boolean flip) {
|
||||
return newBitmapFontFactory().create(fontFile, flip);
|
||||
}
|
||||
|
||||
default BitmapFont newBitmapFont(FileHandle fontFile, FileHandle imageFile, boolean flip) {
|
||||
return newBitmapFontFactory().create(fontFile, imageFile, flip);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,6 +125,36 @@ public class MapStorageTest {
|
||||
public boolean isFeatureEnabled(String feature) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String tag, String msg) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user