Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6614e77
commit 8d5e6c3
Showing
101 changed files
with
1,505 additions
and
1,174 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
130 changes: 118 additions & 12 deletions
130
zircon.core/src/main/kotlin/org/hexworks/zircon/api/behavior/InputEmitter.kt
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 |
---|---|---|
@@ -1,29 +1,135 @@ | ||
package org.hexworks.zircon.api.behavior | ||
|
||
import org.hexworks.zircon.api.event.Subscription | ||
import org.hexworks.zircon.api.input.Input | ||
import org.hexworks.zircon.api.input.MouseAction | ||
import org.hexworks.zircon.api.input.MouseActionType.* | ||
import org.hexworks.zircon.api.kotlin.map | ||
import org.hexworks.zircon.api.listener.InputListener | ||
import org.hexworks.zircon.api.listener.KeyStrokeListener | ||
import org.hexworks.zircon.api.listener.MouseListener | ||
import org.hexworks.zircon.api.util.Consumer | ||
|
||
/** | ||
* Represents an object which (re) emits the [Input]s | ||
* it has received from the underlying technology (like Swing or LibGDX). | ||
*/ | ||
|
||
interface InputEmitter { | ||
|
||
/** | ||
* Adds an input listener to this [InputEmitter]. | ||
* It will be notified when an [Input] is consumed | ||
* by this object. | ||
* Adds an [InputListener] listener to this [InputEmitter]. It will be notified when any | ||
* kind of [Input] is received by this object. | ||
*/ | ||
fun onInput(listener: InputListener): Subscription | ||
|
||
/** | ||
* Adds a [KeyStrokeListener] listener to this [InputEmitter]. It will be notified when a | ||
* [org.hexworks.zircon.api.input.KeyStroke] is received by this object. | ||
*/ | ||
fun onInput(listener: Consumer<Input>) | ||
fun onKeyStroke(listener: KeyStrokeListener): Subscription { | ||
return onInput(object : InputListener { | ||
override fun inputEmitted(input: Input) { | ||
input.asKeyStroke().map { | ||
listener.keyStroked(it) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Adds an input listener to this [InputEmitter]. | ||
* It will be notified when an [Input] is consumed | ||
* by this object. | ||
* Adds a [MouseListener] listener to this [InputEmitter]. It will be notified when a | ||
* [org.hexworks.zircon.api.input.MouseAction] is received by this object. | ||
*/ | ||
fun onInput(listener: (Input) -> Unit) = onInput(object : Consumer<Input> { | ||
override fun accept(p: Input) { | ||
listener.invoke(p) | ||
} | ||
}) | ||
fun onMouseAction(listener: MouseListener): Subscription { | ||
return onInput(object : InputListener { | ||
override fun inputEmitted(input: Input) { | ||
input.asMouseAction().map { | ||
when (it.actionType) { | ||
MOUSE_CLICKED -> listener.mouseClicked(it) | ||
MOUSE_PRESSED -> listener.mousePressed(it) | ||
MOUSE_RELEASED -> listener.mouseReleased(it) | ||
MOUSE_ENTERED -> listener.mouseEntered(it) | ||
MOUSE_EXITED -> listener.mouseExited(it) | ||
MOUSE_WHEEL_ROTATED_UP -> listener.mouseWheelRotatedUp(it) | ||
MOUSE_WHEEL_ROTATED_DOWN -> listener.mouseWheelRotatedDown(it) | ||
MOUSE_DRAGGED -> listener.mouseDragged(it) | ||
MOUSE_MOVED -> listener.mouseMoved(it) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseClicked(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseClicked(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMousePressed(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mousePressed(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseReleased(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseReleased(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseEntered(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseEntered(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseExited(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseExited(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseWheelRotatedUp(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseWheelRotatedUp(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseWheelRotatedDown(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseWheelRotatedDown(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseDragged(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseDragged(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
|
||
fun onMouseMoved(consumer: Consumer<MouseAction>): Subscription { | ||
return onMouseAction(object : MouseListener { | ||
override fun mouseMoved(action: MouseAction) { | ||
consumer.accept(action) | ||
} | ||
}) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...c/main/kotlin/org/hexworks/zircon/api/component/renderer/impl/BorderDecorationRenderer.kt
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
14 changes: 0 additions & 14 deletions
14
zircon.core/src/main/kotlin/org/hexworks/zircon/api/data/AbsolutePosition.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.