summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/api
diff options
context:
space:
mode:
authorromangraef <romangraef@loves.dicksinhisan.us>2019-01-16 19:24:56 +0100
committerromangraef <romangraef@loves.dicksinhisan.us>2019-01-16 19:24:56 +0100
commit0a98f4c4c2689c488839ce16fb2adf618fd4af2a (patch)
tree31102fdac1d9d7a8d604cc9d41df5c3733fd8da4 /src/main/kotlin/de/romjaki/pluggabledino/api
parentf872cabbe7e4a3eda2aaff9bff8616e62c2d4ff4 (diff)
parentf58a6414f0df1115f86331762c7b7773a61a7e06 (diff)
downloadpluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.tar.gz
pluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.tar.bz2
pluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.zip
Merge branch 'master' of github.com:romangraef/pluggabledino
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/api')
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt9
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt7
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt6
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt9
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt8
5 files changed, 33 insertions, 6 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt
index edced5a..439acb8 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt
@@ -6,7 +6,10 @@ import org.newdawn.slick.Input
import java.awt.Rectangle
import kotlin.math.max
-class Button(private val text: String, val x: Float, val y: Float) {
+class Button(private val text: String, val x: Float, val y: Float) : SettingsElement {
+ override fun render(g: Graphics) {
+ draw(g)
+ }
val width = max(buttonImage.width, font.getWidth(text) + 10)
val image = buttonImage.getScaledCopy(width, buttonImage.height)
@@ -40,14 +43,14 @@ class Button(private val text: String, val x: Float, val y: Float) {
override fun toString(): String =
"X: $leftX - $rightX, $topY - $bottomY, width=$width"
- fun enter() {
+ override fun enter() {
lastClicked = true
}
fun isClicked(input: Input): Boolean =
input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && isMouseOver(input)
- fun update(input: Input) {
+ override fun update(input: Input) {
val ret = isClicked(input)
if (!lastClicked && ret) {
clickHandlers.forEach({ it() })
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt
new file mode 100644
index 0000000..f7ac4be
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt
@@ -0,0 +1,7 @@
+package de.romjaki.pluggabledino.api
+
+import org.newdawn.slick.Graphics
+
+interface Renderable {
+ fun render(g: Graphics)
+}
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt
new file mode 100644
index 0000000..8ca7a37
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt
@@ -0,0 +1,6 @@
+package de.romjaki.pluggabledino.api
+
+import de.romjaki.pluggabledino.api.Renderable
+import de.romjaki.pluggabledino.api.Updateable
+
+interface SettingsElement : Renderable, Updateable
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt
index cce59fc..b776637 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt
@@ -8,7 +8,10 @@ import kotlin.math.max
typealias ChangeListener = (index: Int) -> Unit
-class ToggleButton(private val texts: List<String>, val x: Float, val y: Float) {
+class ToggleButton(private val texts: List<String>, val x: Float, val y: Float) : SettingsElement {
+ override fun render(g: Graphics) {
+ draw(g)
+ }
val width = max(buttonImage.width, texts.map { font.getWidth(it) + 10 }.max()!!)
val image = buttonImage.getScaledCopy(width, buttonImage.height)
@@ -43,14 +46,14 @@ class ToggleButton(private val texts: List<String>, val x: Float, val y: Float)
override fun toString(): String =
"X: $leftX - $rightX, $topY - $bottomY, width=$width"
- fun enter() {
+ override fun enter() {
lastClicked = true
}
fun isClicked(input: Input): Boolean =
input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && isMouseOver(input)
- fun update(input: Input) {
+ override fun update(input: Input) {
val ret = isClicked(input)
if (!lastClicked && ret) {
index = (index + 1) % texts.size
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt
new file mode 100644
index 0000000..42798bc
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt
@@ -0,0 +1,8 @@
+package de.romjaki.pluggabledino.api
+
+import org.newdawn.slick.Input
+
+interface Updateable {
+ fun update(input: Input)
+ fun enter()
+}