-
Notifications
You must be signed in to change notification settings - Fork 33
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
e79ddb2
commit bff8571
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/graphics/scenery/controls/behaviours/ConfirmableClickBehaviour.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package graphics.scenery.controls.behaviours | ||
|
||
import org.scijava.ui.behaviour.ClickBehaviour | ||
import kotlin.concurrent.thread | ||
|
||
/** | ||
* [ClickBehaviour] that waits [timeout] for confirmation by re-executing the behaviour. | ||
* Executes [armedAction] on first invocation, and [confirmAction] on second invocation, if | ||
* it happens within [timeout]. | ||
* | ||
* @author Ulrik Guenther <[email protected]> | ||
*/ | ||
class ConfirmableClickBehaviour(val armedAction: (Long) -> Any, val confirmAction: (Long) -> Any, var timeout: Long = 3000): ClickBehaviour { | ||
/** Whether the action is armed at the moment. Action becomes disarmed after [timeout]. */ | ||
private var armed: Boolean = false | ||
|
||
/** | ||
* Action fired at position [x]/[y]. Parameters not used in VR actions. | ||
*/ | ||
override fun click(x : Int, y : Int) { | ||
if(!armed) { | ||
armed = true | ||
armedAction.invoke(timeout) | ||
|
||
thread { | ||
Thread.sleep(timeout) | ||
armed = false | ||
} | ||
} else { | ||
confirmAction.invoke(timeout) | ||
} | ||
} | ||
} |