@@ -6,60 +6,35 @@ const sf = struct {
6
6
pub usingnamespace sfml .system ;
7
7
};
8
8
9
- pub const Event = union (Event . Type ) {
9
+ pub const Event = union (enum ) {
10
10
const Self = @This ();
11
11
12
- pub const Type = enum (c_int ) {
13
- closed ,
14
- resized ,
15
- lostFocus ,
16
- gainedFocus ,
17
- textEntered ,
18
- keyPressed ,
19
- keyReleased ,
20
- mouseWheelScrolled ,
21
- mouseButtonPressed ,
22
- mouseButtonReleased ,
23
- mouseMoved ,
24
- mouseEntered ,
25
- mouseLeft ,
26
- joystickButtonPressed ,
27
- joystickButtonReleased ,
28
- joystickMoved ,
29
- joystickConnected ,
30
- joystickDisconnected ,
31
- touchBegan ,
32
- touchMoved ,
33
- touchEnded ,
34
- sensorChanged ,
35
- };
36
-
37
12
// Big oof
38
13
/// Creates this event from a csfml one
39
14
pub fn _fromCSFML (event : sf.c.sfEvent ) Self {
40
15
return switch (event .type ) {
41
16
sf .c .sfEvtClosed = > .closed ,
42
17
sf .c .sfEvtResized = > .{ .resized = .{ .size = .{ .x = event .size .width , .y = event .size .height } } },
43
- sf .c .sfEvtLostFocus = > .lostFocus ,
44
- sf .c .sfEvtGainedFocus = > .gainedFocus ,
45
- sf .c .sfEvtTextEntered = > .{ .textEntered = .{ .unicode = event .text .unicode } },
46
- sf .c .sfEvtKeyPressed = > .{ .keyPressed = .{ .code = @as (sf .window .keyboard .KeyCode , @enumFromInt (event .key .code )), .alt = (event .key .alt != 0 ), .control = (event .key .control != 0 ), .shift = (event .key .shift != 0 ), .system = (event .key .system != 0 ) } },
47
- sf .c .sfEvtKeyReleased = > .{ .keyReleased = .{ .code = @as (sf .window .keyboard .KeyCode , @enumFromInt (event .key .code )), .alt = (event .key .alt != 0 ), .control = (event .key .control != 0 ), .shift = (event .key .shift != 0 ), .system = (event .key .system != 0 ) } },
48
- sf .c .sfEvtMouseWheelScrolled = > .{ .mouseWheelScrolled = .{ .wheel = @as (sf .window .mouse .Wheel , @enumFromInt (event .mouseWheelScroll .wheel )), .delta = event .mouseWheelScroll .delta , .pos = .{ .x = event .mouseWheelScroll .x , .y = event .mouseWheelScroll .y } } },
49
- sf .c .sfEvtMouseButtonPressed = > .{ .mouseButtonPressed = .{ .button = @as (sf .window .mouse .Button , @enumFromInt (event .mouseButton .button )), .pos = .{ .x = event .mouseButton .x , .y = event .mouseButton .y } } },
50
- sf .c .sfEvtMouseButtonReleased = > .{ .mouseButtonReleased = .{ .button = @as (sf .window .mouse .Button , @enumFromInt (event .mouseButton .button )), .pos = .{ .x = event .mouseButton .x , .y = event .mouseButton .y } } },
51
- sf .c .sfEvtMouseMoved = > .{ .mouseMoved = .{ .pos = .{ .x = event .mouseMove .x , .y = event .mouseMove .y } } },
52
- sf .c .sfEvtMouseEntered = > .mouseEntered ,
53
- sf .c .sfEvtMouseLeft = > .mouseLeft ,
54
- sf .c .sfEvtJoystickButtonPressed = > .{ .joystickButtonPressed = .{ .joystickId = event .joystickButton .joystickId , .button = event .joystickButton .button } },
55
- sf .c .sfEvtJoystickButtonReleased = > .{ .joystickButtonReleased = .{ .joystickId = event .joystickButton .joystickId , .button = event .joystickButton .button } },
56
- sf .c .sfEvtJoystickMoved = > .{ .joystickMoved = .{ .joystickId = event .joystickMove .joystickId , .axis = event .joystickMove .axis , .position = event .joystickMove .position } },
57
- sf .c .sfEvtJoystickConnected = > .{ .joystickConnected = .{ .joystickId = event .joystickConnect .joystickId } },
58
- sf .c .sfEvtJoystickDisconnected = > .{ .joystickDisconnected = .{ .joystickId = event .joystickConnect .joystickId } },
59
- sf .c .sfEvtTouchBegan = > .{ .touchBegan = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
60
- sf .c .sfEvtTouchMoved = > .{ .touchMoved = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
61
- sf .c .sfEvtTouchEnded = > .{ .touchEnded = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
62
- sf .c .sfEvtSensorChanged = > .{ .sensorChanged = .{ .sensorType = event .sensor .sensorType , .vector = .{ .x = event .sensor .x , .y = event .sensor .y , .z = event .sensor .z } } },
18
+ sf .c .sfEvtLostFocus = > .lost_focus ,
19
+ sf .c .sfEvtGainedFocus = > .gained_focus ,
20
+ sf .c .sfEvtTextEntered = > .{ .text_entered = .{ .unicode = event .text .unicode } },
21
+ sf .c .sfEvtKeyPressed = > .{ .key_pressed = .{ .code = @as (sf .window .keyboard .KeyCode , @enumFromInt (event .key .code )), .alt = (event .key .alt != 0 ), .control = (event .key .control != 0 ), .shift = (event .key .shift != 0 ), .system = (event .key .system != 0 ) } },
22
+ sf .c .sfEvtKeyReleased = > .{ .key_released = .{ .code = @as (sf .window .keyboard .KeyCode , @enumFromInt (event .key .code )), .alt = (event .key .alt != 0 ), .control = (event .key .control != 0 ), .shift = (event .key .shift != 0 ), .system = (event .key .system != 0 ) } },
23
+ sf .c .sfEvtMouseWheelScrolled = > .{ .mouse_wheel_scrolled = .{ .wheel = @as (sf .window .mouse .Wheel , @enumFromInt (event .mouseWheelScroll .wheel )), .delta = event .mouseWheelScroll .delta , .pos = .{ .x = event .mouseWheelScroll .x , .y = event .mouseWheelScroll .y } } },
24
+ sf .c .sfEvtMouseButtonPressed = > .{ .mouse_button_pressed = .{ .button = @as (sf .window .mouse .Button , @enumFromInt (event .mouseButton .button )), .pos = .{ .x = event .mouseButton .x , .y = event .mouseButton .y } } },
25
+ sf .c .sfEvtMouseButtonReleased = > .{ .mouse_button_released = .{ .button = @as (sf .window .mouse .Button , @enumFromInt (event .mouseButton .button )), .pos = .{ .x = event .mouseButton .x , .y = event .mouseButton .y } } },
26
+ sf .c .sfEvtMouseMoved = > .{ .mouse_moved = .{ .pos = .{ .x = event .mouseMove .x , .y = event .mouseMove .y } } },
27
+ sf .c .sfEvtMouseEntered = > .mouse_entered ,
28
+ sf .c .sfEvtMouseLeft = > .mouse_left ,
29
+ sf .c .sfEvtJoystickButtonPressed = > .{ .joystick_button_pressed = .{ .joystickId = event .joystickButton .joystickId , .button = event .joystickButton .button } },
30
+ sf .c .sfEvtJoystickButtonReleased = > .{ .joystick_button_released = .{ .joystickId = event .joystickButton .joystickId , .button = event .joystickButton .button } },
31
+ sf .c .sfEvtJoystickMoved = > .{ .joystick_moved = .{ .joystickId = event .joystickMove .joystickId , .axis = event .joystickMove .axis , .position = event .joystickMove .position } },
32
+ sf .c .sfEvtJoystickConnected = > .{ .joystick_connected = .{ .joystickId = event .joystickConnect .joystickId } },
33
+ sf .c .sfEvtJoystickDisconnected = > .{ .joystick_disconnected = .{ .joystickId = event .joystickConnect .joystickId } },
34
+ sf .c .sfEvtTouchBegan = > .{ .touch_began = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
35
+ sf .c .sfEvtTouchMoved = > .{ .touch_moved = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
36
+ sf .c .sfEvtTouchEnded = > .{ .touch_ended = .{ .finger = event .touch .finger , .pos = .{ .x = event .touch .x , .y = event .touch .y } } },
37
+ sf .c .sfEvtSensorChanged = > .{ .sensor_changed = .{ .sensorType = event .sensor .sensorType , .vector = .{ .x = event .sensor .x , .y = event .sensor .y , .z = event .sensor .z } } },
63
38
sf .c .sfEvtCount = > @panic ("sfEvtCount should't exist as an event!" ),
64
39
else = > @panic ("Unknown event!" ),
65
40
};
@@ -140,24 +115,24 @@ pub const Event = union(Event.Type) {
140
115
// An event is one of those
141
116
closed ,
142
117
resized : SizeEvent ,
143
- lostFocus ,
144
- gainedFocus ,
145
- textEntered : TextEvent ,
146
- keyPressed : KeyEvent ,
147
- keyReleased : KeyEvent ,
148
- mouseWheelScrolled : MouseWheelScrollEvent ,
149
- mouseButtonPressed : MouseButtonEvent ,
150
- mouseButtonReleased : MouseButtonEvent ,
151
- mouseMoved : MouseMoveEvent ,
152
- mouseEntered ,
153
- mouseLeft ,
154
- joystickButtonPressed : JoystickButtonEvent ,
155
- joystickButtonReleased : JoystickButtonEvent ,
156
- joystickMoved : JoystickMoveEvent ,
157
- joystickConnected : JoystickConnectEvent ,
158
- joystickDisconnected : JoystickConnectEvent ,
159
- touchBegan : TouchEvent ,
160
- touchMoved : TouchEvent ,
161
- touchEnded : TouchEvent ,
162
- sensorChanged : SensorEvent ,
118
+ lost_focus ,
119
+ gained_focus ,
120
+ text_entered : TextEvent ,
121
+ key_pressed : KeyEvent ,
122
+ key_released : KeyEvent ,
123
+ mouse_wheel_scrolled : MouseWheelScrollEvent ,
124
+ mouse_button_pressed : MouseButtonEvent ,
125
+ mouse_button_released : MouseButtonEvent ,
126
+ mouse_moved : MouseMoveEvent ,
127
+ mouse_entered ,
128
+ mouse_left ,
129
+ joystick_button_pressed : JoystickButtonEvent ,
130
+ joystick_button_released : JoystickButtonEvent ,
131
+ joystick_moved : JoystickMoveEvent ,
132
+ joystick_connected : JoystickConnectEvent ,
133
+ joystick_disconnected : JoystickConnectEvent ,
134
+ touch_began : TouchEvent ,
135
+ touch_moved : TouchEvent ,
136
+ touch_ended : TouchEvent ,
137
+ sensor_changed : SensorEvent ,
163
138
};
0 commit comments