Skip to content

Commit

Permalink
renamed image buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobbyshop committed Apr 25, 2024
1 parent 22867e3 commit 75bec1f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/neptuneclient/voidui/utils/dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
fun image(path: String) = ImageBuffer(path(path))
5 changes: 3 additions & 2 deletions src/main/kotlin/com/neptuneclient/voidui/widgets/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!!)
}
Expand Down Expand Up @@ -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!")

Expand All @@ -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!")

Expand Down

0 comments on commit 75bec1f

Please sign in to comment.