diff --git a/src/main/java/com/pixelgamelibrary/api/utils/Disposable.java b/src/main/java/com/pixelgamelibrary/api/Disposable.java similarity index 93% rename from src/main/java/com/pixelgamelibrary/api/utils/Disposable.java rename to src/main/java/com/pixelgamelibrary/api/Disposable.java index 8202019..e1384f1 100644 --- a/src/main/java/com/pixelgamelibrary/api/utils/Disposable.java +++ b/src/main/java/com/pixelgamelibrary/api/Disposable.java @@ -18,12 +18,14 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /////////////////////////////////////////////////////////////////////////////////////////////// -package com.pixelgamelibrary.api.utils; +package com.pixelgamelibrary.api; /** * * @author robertvokac */ public interface Disposable { - + void dispose (); + boolean isDisposed(); + } diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/Cursor.java b/src/main/java/com/pixelgamelibrary/api/graphics/Cursor.java index a680d78..bb5aa46 100644 --- a/src/main/java/com/pixelgamelibrary/api/graphics/Cursor.java +++ b/src/main/java/com/pixelgamelibrary/api/graphics/Cursor.java @@ -20,13 +20,12 @@ package com.pixelgamelibrary.api.graphics; +import com.pixelgamelibrary.api.Disposable; + /** * * @author robertvokac */ -public class Cursor { - public Cursor() { -//todo - } +public interface Cursor extends Disposable { } diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/Drawable.java b/src/main/java/com/pixelgamelibrary/api/graphics/Drawable.java new file mode 100644 index 0000000..bea6df5 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/graphics/Drawable.java @@ -0,0 +1,101 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.graphics; + +/** + * Interface for drawable objects, providing methods for drawing shapes, + * filling areas, and manipulating colors. + * + * @author robertvokac + */ +public interface Drawable { + + // Set the color using a Color object + void setColor(Color color); + + // Set the color using float values for red, green, blue, and alpha + void setColor(float red, float green, float blue, float alpha); + + // Set the color using float values for red, green, and blue + void setColor(float red, float green, float blue); + + // Set the color using integer values for red, green, blue, and alpha + void setColor(int red, int green, int blue, int alpha); + + // Set the color using integer values for red, green, and blue + void setColor(int red, int green, int blue); + + // Fill the current shape with the set color + void fill(); + + // Draw a line from (x, y) to (x2, y2) + void drawLine(int x, int y, int x2, int y2); + + // Draw a rectangle at (x, y) with specified width and height + void drawRectangle(int x, int y, int width, int height); + + // Draw a pixmap at (x, y) + void drawPixmap(Pixmap pixmap, int x, int y); + + // Draw a portion of a pixmap defined by source coordinates and dimensions + void drawPixmap(Pixmap pixmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight); + + // Draw a portion of a pixmap to a destination defined by destination coordinates and dimensions + void drawPixmap(Pixmap pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight); + + // Fill a rectangle at (x, y) with specified width and height + void fillRectangle(int x, int y, int width, int height); + + // Draw a circle with center at (x, y) and specified radius + void drawCircle(int x, int y, int radius); + + // Fill a circle with center at (x, y) and specified radius + void fillCircle(int x, int y, int radius); + + // Fill a triangle defined by three points + void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3); + + // Get the color of the pixel at (x, y) + int getPixel(int x, int y); + + // Get the width of the drawable area + int getWidth(); + + // Get the height of the drawable area + int getHeight(); + + // Dispose of resources used by the drawable + void dispose(); + + // Check if the drawable has been disposed + boolean isDisposed(); + + // Draw a pixel at (x, y) using the currently set color + void drawPixel(int x, int y); + + // Draw a pixel at (x, y) with a specified color + void drawPixel(int x, int y, int color); + + // Get all pixels as a byte array + byte[] getPixels(); + + // Set the pixels using a byte array + void setPixels(byte[] pixels); +} diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/Monitor.java b/src/main/java/com/pixelgamelibrary/api/graphics/Monitor.java index 905c791..a096245 100644 --- a/src/main/java/com/pixelgamelibrary/api/graphics/Monitor.java +++ b/src/main/java/com/pixelgamelibrary/api/graphics/Monitor.java @@ -68,6 +68,7 @@ public interface Monitor { boolean isMonitorInUse(); boolean isMonitorModeChangeSupported(); + int getDpi(); } diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/PixMapFactory.java b/src/main/java/com/pixelgamelibrary/api/graphics/PixMapFactory.java new file mode 100644 index 0000000..426ceff --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/graphics/PixMapFactory.java @@ -0,0 +1,33 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// 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 PixMapFactory { + Pixmap create(int width, int height); + Pixmap create(FileHandle fileHandle); + +} diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/PixMap.java b/src/main/java/com/pixelgamelibrary/api/graphics/Pixmap.java similarity index 91% rename from src/main/java/com/pixelgamelibrary/api/graphics/PixMap.java rename to src/main/java/com/pixelgamelibrary/api/graphics/Pixmap.java index 779caad..1c819b2 100644 --- a/src/main/java/com/pixelgamelibrary/api/graphics/PixMap.java +++ b/src/main/java/com/pixelgamelibrary/api/graphics/Pixmap.java @@ -20,10 +20,12 @@ package com.pixelgamelibrary.api.graphics; +import com.pixelgamelibrary.api.Disposable; + /** * * @author robertvokac */ -public interface PixMap { +public interface Pixmap extends Disposable, Drawable { } diff --git a/src/main/java/com/pixelgamelibrary/api/interfaces/App.java b/src/main/java/com/pixelgamelibrary/api/interfaces/App.java index 36fa795..320e04c 100644 --- a/src/main/java/com/pixelgamelibrary/api/interfaces/App.java +++ b/src/main/java/com/pixelgamelibrary/api/interfaces/App.java @@ -55,7 +55,10 @@ public interface App { void setGame(Game game); Game getGame(); - boolean isFeatureEnabled(PixelFeature feature); + default boolean isFeatureEnabled(PixelFeature feature) { + return isFeatureEnabled(feature.name()); + } + boolean isFeatureEnabled(String feature); boolean isMobileDevice(); void postRunnable(Runnable runnable); ClipBoard getClipBoard(); diff --git a/src/main/java/com/pixelgamelibrary/api/interfaces/Graphics.java b/src/main/java/com/pixelgamelibrary/api/interfaces/Graphics.java index 7102ae1..e83459b 100644 --- a/src/main/java/com/pixelgamelibrary/api/interfaces/Graphics.java +++ b/src/main/java/com/pixelgamelibrary/api/interfaces/Graphics.java @@ -19,8 +19,10 @@ /////////////////////////////////////////////////////////////////////////////////////////////// package com.pixelgamelibrary.api.interfaces; +import com.pixelgamelibrary.api.graphics.Cursor; import com.pixelgamelibrary.api.graphics.Monitor; import java.util.List; +import com.pixelgamelibrary.api.graphics.Pixmap; /** * @@ -33,5 +35,14 @@ public interface Graphics { Monitor getPrimaryMonitor(); String getTitle(); void setTitle(String title); + Cursor newCursor(Pixmap pixMap, int x, int y); + default Cursor newCursor(Pixmap pixMap) { + Monitor monitor = getPrimaryMonitor(); + return newCursor(pixMap, monitor.getVirtualWidth() / 2, monitor.getVirtualWidth() / 2); + } + void setCursor (Cursor cursor); + float getDeltaTime (); + void setTargetFPS(); + int getTargetFPS(); } diff --git a/src/main/java/com/pixelgamelibrary/api/interfaces/PixelBackend.java b/src/main/java/com/pixelgamelibrary/api/interfaces/PixelBackend.java index 098dcbe..5a9be2e 100644 --- a/src/main/java/com/pixelgamelibrary/api/interfaces/PixelBackend.java +++ b/src/main/java/com/pixelgamelibrary/api/interfaces/PixelBackend.java @@ -28,6 +28,9 @@ import com.pixelgamelibrary.api.extension.ExtensionImpl; */ public interface PixelBackend { + default String name() { + return getClass().getSimpleName(); + } App app(); Graphics graphics(); Audio audio(); diff --git a/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java b/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java index 8ff82ce..2530d7e 100644 --- a/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java +++ b/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java @@ -120,6 +120,11 @@ public class MapStorageTest { public ClipBoard getClipBoard() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } + + @Override + public boolean isFeatureEnabled(String feature) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } }; }