Skip to content

Commit

Permalink
Hide SDL events from public API
Browse files Browse the repository at this point in the history
Been wanting to do this for a while. I can always add a 'get raw event' method if needs be.
  • Loading branch information
17cupsofcoffee committed Dec 2, 2024
1 parent 5cfd751 commit 2073d54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ impl App {

pub fn handle_events(&mut self, event_handler: &mut impl EventHandler) {
while let Some(event) = self.window.next_event() {
if let Some(event) = Event::try_from_sdl_event(&event) {
if let Event::Quit = event {
self.is_running = false;
}
if let Event::Quit = event {
self.is_running = false;
}

self.input.event(&event);
self.input.event(&event);

event_handler.event(self, event);
}
event_handler.event(self, event);
}
}
}
12 changes: 8 additions & 4 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ impl Window {
}
}

pub fn next_event(&mut self) -> Option<SDL_Event> {
pub fn next_event(&mut self) -> Option<Event> {
unsafe {
let mut event = MaybeUninit::uninit();
let mut raw_event = MaybeUninit::uninit();

if SDL_PollEvent(event.as_mut_ptr()) {
Some(event.assume_init())
if SDL_PollEvent(raw_event.as_mut_ptr()) {
let raw_event = raw_event.assume_init();

Event::try_from_sdl_event(&raw_event)
} else {
None
}
Expand Down Expand Up @@ -172,3 +174,5 @@ macro_rules! sdl_panic {
}

pub(crate) use sdl_panic;

use crate::input::Event;

0 comments on commit 2073d54

Please sign in to comment.