diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/kotlin/keybindings/GenericInputButton.kt | 26 | ||||
| -rw-r--r-- | src/main/kotlin/keybindings/SavedKeyBinding.kt | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/main/kotlin/keybindings/GenericInputButton.kt b/src/main/kotlin/keybindings/GenericInputButton.kt index 53c0e56..ddbf509 100644 --- a/src/main/kotlin/keybindings/GenericInputButton.kt +++ b/src/main/kotlin/keybindings/GenericInputButton.kt @@ -247,18 +247,44 @@ data class InputModifiers( ) } + fun ofKeyCodes(vararg keys: Int): InputModifiers { + var mods = 0 + for (key in keys) { + if (key in superKeys) + mods = mods or GLFW.GLFW_MOD_SUPER + if (key in controlKeys) + mods = mods or GLFW.GLFW_MOD_CONTROL + if (key in altKeys) + mods = mods or GLFW.GLFW_MOD_ALT + if (key in shiftKeys) + mods = mods or GLFW.GLFW_MOD_SHIFT + } + return of(mods) + } + @JvmStatic fun of(modifiers: Int) = InputModifiers(modifiers) fun none(): InputModifiers { return InputModifiers(0) } + + fun ofKey(button: GenericInputButton): InputModifiers { + return when (button) { + is GenericInputButton.KeyCodeButton -> ofKeyCodes(button.keyCode) + else -> none() + } + } } fun isAtLeast(other: InputModifiers): Boolean { return this.modifiers and other.modifiers == this.modifiers } + fun without(other: InputModifiers): InputModifiers { + return InputModifiers(this.modifiers and other.modifiers.inv()) + } + fun isEmpty() = modifiers == 0 fun getFlag(flag: Int) = modifiers and flag != 0 diff --git a/src/main/kotlin/keybindings/SavedKeyBinding.kt b/src/main/kotlin/keybindings/SavedKeyBinding.kt index 48716d3..8f08e5f 100644 --- a/src/main/kotlin/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/keybindings/SavedKeyBinding.kt @@ -22,6 +22,7 @@ data class SavedKeyBinding( if (!button.isPressed()) return false val mods = InputModifiers.current() + .without(InputModifiers.ofKey(button)) return mods.matches(this.modifiers, atLeast) } |
