1+ /*
2+ * Copyright 2026 Lambda
3+ *
4+ * This program is free software: you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation, either version 3 of the License, or
7+ * (at your option) any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+ package com.lambda.event.events
19+
20+ import com.lambda.config.settings.complex.Bind
21+ import com.lambda.event.Event
22+ import com.lambda.event.callback.Cancellable
23+ import com.lambda.event.callback.ICancellable
24+ import com.lambda.util.KeyCode
25+ import com.lambda.util.math.Vec2d
26+ import org.lwjgl.glfw.GLFW.GLFW_PRESS
27+ import org.lwjgl.glfw.GLFW.GLFW_RELEASE
28+ import org.lwjgl.glfw.GLFW.GLFW_REPEAT
29+
30+ sealed class ButtonEvent : ICancellable by Cancellable () {
31+ abstract val action: Int
32+ abstract val modifiers: Int
33+
34+ val isPressed get() = action >= GLFW_PRESS
35+ val isReleased get() = action == GLFW_RELEASE
36+ val isRepeated get() = action == GLFW_REPEAT
37+
38+ abstract fun satisfies (bind : Bind ): Boolean
39+
40+ sealed class Mouse {
41+ /* *
42+ * Represents a mouse click event
43+ *
44+ * @property button The button that was clicked
45+ * @property action The action performed (e.g., press or release)
46+ * @property modifiers An integer representing any modifiers (e.g., shift or ctrl) active during the event
47+ */
48+ data class Click (
49+ val button : Int ,
50+ override val action : Int ,
51+ override val modifiers : Int ,
52+ ) : ButtonEvent() {
53+ override fun satisfies (bind : Bind ) = bind.modifiers and modifiers == bind.modifiers && bind.mouse == button
54+ }
55+
56+ /* *
57+ * Represents a mouse scroll event
58+ *
59+ * @property delta The amount of scrolling in the x and y directions
60+ */
61+ data class Scroll (
62+ val delta : Vec2d ,
63+ ) : ICancellable by Cancellable()
64+
65+ /* *
66+ * Represents a mouse move event.
67+ *
68+ * @property position The x and y position of the mouse on the screen.
69+ */
70+ data class Move (
71+ val position : Vec2d ,
72+ ) : ICancellable by Cancellable()
73+ }
74+
75+ sealed class Keyboard {
76+ /* *
77+ * Represents a key press
78+ *
79+ * @property keyCode The key code of the key that was pressed
80+ * @property scanCode The scan code of the key that was pressed
81+ * @property action The action that was performed on the key (Pressed, Released)
82+ * @property modifiers The modifiers that were active when the key was pressed
83+ *
84+ * @see <a href="https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keyboard-input-model">About Keyboards</a>
85+ */
86+ data class Press (
87+ val keyCode : Int ,
88+ val scanCode : Int ,
89+ override val action : Int ,
90+ override val modifiers : Int ,
91+ ) : ButtonEvent() {
92+ val bind: Bind
93+ get() = Bind (translated.code, modifiers, - 1 )
94+
95+ val translated: KeyCode
96+ get() = KeyCode .virtualMapUS(keyCode, scanCode)
97+
98+ override fun satisfies (bind : Bind ) = bind.key == translated.code && bind.modifiers and modifiers == bind.modifiers
99+ }
100+
101+ /* *
102+ * Represents glfwSetCharCallback events
103+ *
104+ * Keys and characters do not map 1:1.
105+ * A single key press may produce several characters, and a single
106+ * character may require several keys to produce
107+ */
108+ data class Char (val char : kotlin.Char ) : Event
109+ }
110+ }
0 commit comments