-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves CachedContainer with
renderQuality
and provides korim.Qual…
…ity (#1803) * Added `korlibs.image.Quality` and make `GameWindow.Quality` implement it + tests * Add Views.quality as an alias of GameWindow::quality * Make enumerable debug view properties to support nullable values * Add Missing Quality.LIST * Test Quality.LIST * Adds QualityProvider with a ViewPropertyProvider listing available Qualities * Adds CachedContainer.renderQuality, backporting changes from @eaboll in #1760 * Backport example from other PR, but do not change the virtual size to avoid it to be misleading; just scale the container
- Loading branch information
Showing
10 changed files
with
195 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package korlibs.image | ||
|
||
fun Quality(level: Float, name: String? = null): Quality = QualityImpl(level, name) | ||
//interface Quality : Comparable<Quality> { | ||
interface Quality { | ||
val level: Float | ||
|
||
operator fun compareTo(other: Quality): Int = this.level.compareTo(other.level) | ||
|
||
companion object { | ||
val LOWEST: Quality = QualityImpl(0f, "LOWEST") | ||
val LOW: Quality = QualityImpl(.25f, "LOW") | ||
val MEDIUM: Quality = QualityImpl(.5f, "MEDIUM") | ||
val HIGH: Quality = QualityImpl(.75f, "HIGH") | ||
val HIGHEST: Quality = QualityImpl(1f, "HIGHEST") | ||
|
||
val LIST = listOf(LOWEST, LOW, MEDIUM, HIGH, HIGHEST) | ||
} | ||
} | ||
|
||
val Quality.isLow: Boolean get() = level <= 0.25f | ||
val Quality.isMedium: Boolean get() = !isLow && !isHigh | ||
val Quality.isHigh: Boolean get() = level >= 0.75f | ||
|
||
private data class QualityImpl(override val level: Float, val name: String? = null) : Quality { | ||
override fun toString(): String = name ?: super.toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package korlibs.image | ||
|
||
import korlibs.io.util.* | ||
import kotlin.test.* | ||
|
||
class QualityTest { | ||
@Test | ||
fun testLevels() { | ||
fun Quality.result(): String = "$this: ${level.niceStr(2, zeroSuffix = true)}: $isLow, $isMedium, $isHigh : ${this <= Quality.MEDIUM}, ${this >= Quality.MEDIUM}" | ||
|
||
assertEquals( | ||
""" | ||
LOWEST: 0.0: true, false, false : true, false | ||
CUSTOM1: 0.1: true, false, false : true, false | ||
LOW: 0.25: true, false, false : true, false | ||
MEDIUM: 0.5: false, true, false : true, true | ||
HIGH: 0.75: false, false, true : false, true | ||
CUSTOM9: 0.9: false, false, true : false, true | ||
HIGHEST: 1.0: false, false, true : false, true | ||
""".trimIndent(), | ||
""" | ||
${Quality.LOWEST.result()} | ||
${Quality(.1f, name = "CUSTOM1").result()} | ||
${Quality.LOW.result()} | ||
${Quality.MEDIUM.result()} | ||
${Quality.HIGH.result()} | ||
${Quality(.9f, name = "CUSTOM9").result()} | ||
${Quality.HIGHEST.result()} | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
@Test | ||
fun testLevelsList() { | ||
assertEquals( | ||
listOf(Quality.LOWEST, Quality.LOW, Quality.MEDIUM, Quality.HIGH, Quality.HIGHEST), | ||
Quality.LIST | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters