Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Added UntransformedSizeBmpCoordsWithInstance #492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.soywiz.korge.view

import com.soywiz.korim.bitmap.*
import com.soywiz.korma.geom.*
import kotlin.test.*

class BitmapSliceViewTest {
@Test
fun test() {
val coords = Bitmap32(64, 128).slice().rotatedRight()
val image1 = Image(coords)
val image2 = Image(UntransformedSizeBmpCoordsWithInstance(coords))

assertEquals(Size(128, 64), image1.getLocalBoundsOptimized().size)
assertEquals(Size(64, 128), image2.getLocalBoundsOptimized().size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ data class BmpCoordsWithInstance<T : ISizeInt>(
override val br_x: Float, override val br_y: Float,
override val bl_x: Float, override val bl_y: Float,
override val name: String? = null
) : BmpCoordsWithInstanceBase<T>(base, tl_x, tl_y, tr_x, tr_y, br_x, br_y, bl_x, bl_y, name) {
constructor(base: T, coords: BmpCoords, name: String? = null) : this(
base,
coords.tl_x, coords.tl_y,
coords.tr_x, coords.tr_y,
coords.br_x, coords.br_y,
coords.bl_x, coords.bl_y,
name
)
}

open class BmpCoordsWithInstanceBase<T : ISizeInt>(
override val base: T,
override val tl_x: Float, override val tl_y: Float,
override val tr_x: Float, override val tr_y: Float,
override val br_x: Float, override val br_y: Float,
override val bl_x: Float, override val bl_y: Float,
override val name: String? = null
) : BmpCoordsWithT<T> {
constructor(base: T, coords: BmpCoords, name: String? = null) : this(
base,
Expand All @@ -91,12 +109,35 @@ data class BmpCoordsWithInstance<T : ISizeInt>(
coords.bl_x, coords.bl_y,
name
)
constructor(base: BmpCoordsWithT<T>, name: String? = null) : this(base.base, base, name ?: base.name)

override fun close() {
if (base is Closeable) base.close()
(base as? Closeable)?.close()
}
}

open class UntransformedSizeBmpCoordsWithInstance<T : ISizeInt>(
val baseCoords: BmpCoordsWithT<T>
) : BmpCoordsWithInstanceBase<T>(baseCoords) {
override val width: Int get() = baseCoords.baseWidth
override val height: Int get() = baseCoords.baseHeight

override fun toString(): String =
"UntransformedSizeBmpCoordsWithInstance(width=$width, height=$height, baseCoords=$baseCoords)"
}

// @TODO: This was failing because frameWidth, and frameHeight was being delegated to the original instance

//open class UntransformedSizeBmpCoordsWithInstance<T : ISizeInt>(
// val baseCoords: BmpCoordsWithT<T>
//) : BmpCoordsWithT<T> by baseCoords {
// override val width: Int get() = baseCoords.baseWidth
// override val height: Int get() = baseCoords.baseHeight
//
// override fun toString(): String =
// "UntransformedSizeBmpCoordsWithInstance(width=$width, height=$height, baseCoords=$baseCoords)"
//}

fun <T : ISizeInt> BmpCoordsWithT<T>.copy(
base: T = this.base,
tl_x: Float = this.tl_x, tl_y: Float = this.tl_y,
Expand Down