From 75bec1f21fa6d39b739f43d6422ce89999addbe6 Mon Sep 17 00:00:00 2001 From: "marc." Date: Thu, 25 Apr 2024 20:05:07 +0200 Subject: [PATCH] renamed image buffer --- .../neptuneclient/voidui/rendering/Renderer.kt | 16 ++++++++-------- .../voidui/utils/{Image.kt => ImageBuffer.kt} | 2 +- .../kotlin/com/neptuneclient/voidui/utils/dsl.kt | 2 +- .../com/neptuneclient/voidui/widgets/Image.kt | 5 +++-- .../neptuneclient/voidui/tests/TestRenderer.kt | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) rename src/main/kotlin/com/neptuneclient/voidui/utils/{Image.kt => ImageBuffer.kt} (96%) diff --git a/src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt b/src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt index 7b953f8..8695e0e 100644 --- a/src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt +++ b/src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt @@ -5,7 +5,7 @@ import com.neptuneclient.voidui.framework.Size import com.neptuneclient.voidui.objects.CornerRadius import com.neptuneclient.voidui.theme.TextStyle import com.neptuneclient.voidui.utils.Font -import com.neptuneclient.voidui.utils.Image +import com.neptuneclient.voidui.utils.ImageBuffer import java.awt.Color import java.nio.ByteBuffer import java.nio.file.Path @@ -74,7 +74,7 @@ interface Renderer { * * @param image The image to be deleted. */ - fun unregisterImage(image: Image) + fun unregisterImage(image: ImageBuffer) /** * Renders a rectangle with the given dimensions, size, radius and color. @@ -165,9 +165,9 @@ interface Renderer { * @param height The height of the image. * @param image An image object which contains data about the image. */ - fun image(x: Float, y: Float, width: Float, height: Float, image: Image) + fun image(x: Float, y: Float, width: Float, height: Float, image: ImageBuffer) - fun image(x: Int, y: Int, width: Int, height: Int, image: Image) { + fun image(x: Int, y: Int, width: Int, height: Int, image: ImageBuffer) { image(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), image) } @@ -181,17 +181,17 @@ interface Renderer { * @param radius The radius of the image's corners. * @param image An image object which contains data about the image. */ - fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: CornerRadius, image: Image) + fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: CornerRadius, image: ImageBuffer) - fun roundedImage(x: Int, y: Int, width: Int, height: Int, radius: CornerRadius, image: Image) { + fun roundedImage(x: Int, y: Int, width: Int, height: Int, radius: CornerRadius, image: ImageBuffer) { roundedImage(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), radius, image) } - fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: Float, image: Image) { + fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: Float, image: ImageBuffer) { roundedImage(x, y, width, height, CornerRadius.all(radius), image) } - fun roundedImage(x: Int, y: Int, width: Int, height: Int, radius: Int, image: Image) { + fun roundedImage(x: Int, y: Int, width: Int, height: Int, radius: Int, image: ImageBuffer) { roundedImage(x, y, width, height, CornerRadius.all(radius.toFloat()), image) } diff --git a/src/main/kotlin/com/neptuneclient/voidui/utils/Image.kt b/src/main/kotlin/com/neptuneclient/voidui/utils/ImageBuffer.kt similarity index 96% rename from src/main/kotlin/com/neptuneclient/voidui/utils/Image.kt rename to src/main/kotlin/com/neptuneclient/voidui/utils/ImageBuffer.kt index 3e619c1..6b8e210 100644 --- a/src/main/kotlin/com/neptuneclient/voidui/utils/Image.kt +++ b/src/main/kotlin/com/neptuneclient/voidui/utils/ImageBuffer.kt @@ -8,7 +8,7 @@ import java.nio.file.Path /** * Holds values which define an image in the library. */ -data class Image(val path: Path) { +data class ImageBuffer(val path: Path) { /** * The identifier of the image, if this is null, the image has not been initialized yet. diff --git a/src/main/kotlin/com/neptuneclient/voidui/utils/dsl.kt b/src/main/kotlin/com/neptuneclient/voidui/utils/dsl.kt index 8fe2ef0..c46d4b1 100644 --- a/src/main/kotlin/com/neptuneclient/voidui/utils/dsl.kt +++ b/src/main/kotlin/com/neptuneclient/voidui/utils/dsl.kt @@ -10,4 +10,4 @@ fun path(path: String) = Path.of(path) /** * Creates an image from the given string path. */ -fun image(path: String) = Image(path(path)) \ No newline at end of file +fun image(path: String) = ImageBuffer(path(path)) \ No newline at end of file diff --git a/src/main/kotlin/com/neptuneclient/voidui/widgets/Image.kt b/src/main/kotlin/com/neptuneclient/voidui/widgets/Image.kt index 3dd32aa..2fd3ec5 100644 --- a/src/main/kotlin/com/neptuneclient/voidui/widgets/Image.kt +++ b/src/main/kotlin/com/neptuneclient/voidui/widgets/Image.kt @@ -4,6 +4,7 @@ import com.neptuneclient.voidui.framework.* import com.neptuneclient.voidui.objects.CornerRadius import com.neptuneclient.voidui.rendering.RenderObject import com.neptuneclient.voidui.rendering.Renderer +import com.neptuneclient.voidui.utils.ImageBuffer /** * A widget which renders an image to the screen. @@ -13,7 +14,7 @@ import com.neptuneclient.voidui.rendering.Renderer * @param cornerRadius A custom corner radius for the image, if this is not set, the default value from the theme will be used. */ class Image( - private val src: com.neptuneclient.voidui.utils.Image, + private val src: ImageBuffer, private val imageSize: Size? = null, private val cornerRadius: CornerRadius? = null ) : LeafWidget() { @@ -42,7 +43,7 @@ class Image( } } -private class ImageRenderObject(offset: Offset, size: Size, private val image: com.neptuneclient.voidui.utils.Image, private val radius: CornerRadius) : RenderObject(offset, size) { +private class ImageRenderObject(offset: Offset, size: Size, private val image: ImageBuffer, private val radius: CornerRadius) : RenderObject(offset, size) { override fun render(renderer: Renderer) { if (!radius.isEmpty()) renderer.roundedImage(offset.x, offset.y, size.width, size.height, radius, image) diff --git a/src/test/kotlin/com/neptuneclient/voidui/tests/TestRenderer.kt b/src/test/kotlin/com/neptuneclient/voidui/tests/TestRenderer.kt index 828b2a2..bb8bc1b 100644 --- a/src/test/kotlin/com/neptuneclient/voidui/tests/TestRenderer.kt +++ b/src/test/kotlin/com/neptuneclient/voidui/tests/TestRenderer.kt @@ -6,7 +6,7 @@ import com.neptuneclient.voidui.framework.Size import com.neptuneclient.voidui.objects.CornerRadius import com.neptuneclient.voidui.theme.TextStyle import com.neptuneclient.voidui.utils.Font -import com.neptuneclient.voidui.utils.Image +import com.neptuneclient.voidui.utils.ImageBuffer import org.lwjgl.BufferUtils import org.lwjgl.glfw.GLFW import org.lwjgl.nanovg.NVGColor @@ -143,7 +143,7 @@ class TestRenderer : Renderer { return NanoVG.nvgCreateImageMem(vg, NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, data) } - override fun unregisterImage(image: Image) { + override fun unregisterImage(image: ImageBuffer) { if (image.id != null) NanoVG.nvgDeleteImage(vg, image.id!!) } @@ -216,7 +216,7 @@ class TestRenderer : Renderer { } } - override fun image(x: Float, y: Float, width: Float, height: Float, image: Image) { + override fun image(x: Float, y: Float, width: Float, height: Float, image: ImageBuffer) { if (image.id == null) throw IllegalStateException("Image was not registered properly!") @@ -229,7 +229,7 @@ class TestRenderer : Renderer { paint.free() } - override fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: CornerRadius, image: Image) { + override fun roundedImage(x: Float, y: Float, width: Float, height: Float, radius: CornerRadius, image: ImageBuffer) { if (image.id == null) throw IllegalStateException("Image was not registered properly!")