MCPcopy Create free account
hub / github.com/17cupsofcoffee/nova / from_raw

Method from_raw

src/input/event.rs:55–178  ·  view source on GitHub ↗
(event: &SDL_Event)

Source from the content-addressed store, hash-verified

53
54impl Event {
55 pub fn from_raw(event: &SDL_Event) -> Option<Event> {
56 unsafe {
57 match SDL_EventType(event.r#type) {
58 SDL_EVENT_QUIT => {
59 return Some(Event::Quit);
60 }
61
62 SDL_EVENT_KEY_DOWN if !event.key.repeat => {
63 if let Some(key) = Key::from_raw(event.key.scancode) {
64 return Some(Event::KeyDown(key));
65 }
66 }
67
68 SDL_EVENT_KEY_UP if !event.key.repeat => {
69 if let Some(key) = Key::from_raw(event.key.scancode) {
70 return Some(Event::KeyUp(key));
71 }
72 }
73
74 SDL_EVENT_MOUSE_BUTTON_DOWN => {
75 if let Some(button) = MouseButton::from_raw(event.button.button as i32) {
76 return Some(Event::MouseButtonDown(button));
77 }
78 }
79
80 SDL_EVENT_MOUSE_BUTTON_UP => {
81 if let Some(button) = MouseButton::from_raw(event.button.button as i32) {
82 return Some(Event::MouseButtonUp(button));
83 }
84 }
85
86 SDL_EVENT_MOUSE_MOTION => {
87 return Some(Event::MouseMotion {
88 new_position: Vec2::new(event.motion.x, event.motion.y),
89 });
90 }
91
92 SDL_EVENT_GAMEPAD_ADDED => {
93 let handle = SDL_OpenGamepad(event.gdevice.which);
94
95 if handle.is_null() {
96 // TODO: Should probably log here
97 return None;
98 }
99
100 let joystick = JoystickID::from_raw(event.gdevice.which);
101 let gamepad = Gamepad::from_raw(handle);
102
103 return Some(Event::ControllerDeviceAdded { joystick, gamepad });
104 }
105
106 SDL_EVENT_GAMEPAD_REMOVED => {
107 return Some(Event::ControllerDeviceRemoved {
108 joystick: JoystickID::from_raw(event.gdevice.which),
109 });
110 }
111
112 SDL_EVENT_GAMEPAD_BUTTON_DOWN => {

Callers

nothing calls this directly

Calls 1

into_ownedMethod · 0.80

Tested by

no test coverage detected