Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conversion between event and render coordinates. #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/sdl3/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,34 @@ impl Event {
pub fn is_unknown(&self) -> bool {
matches!(self, Self::Unknown { .. })
}

// Returns `None` if the event cannot be converted to its raw form (should not happen).
pub fn get_converted_coords<T: crate::render::RenderTarget>(
&self,
canvas: crate::render::Canvas<T>,
) -> Option<Event> {
let mut raw = self.to_ll()?;
unsafe {
sys::render::SDL_ConvertEventToRenderCoordinates(canvas.raw(), &mut raw);
}
Some(Self::from_ll(raw))
}

// Returns `true` on success and false if the event cannot be converted to its raw form (should not happen)
pub fn convert_coords<T: crate::render::RenderTarget>(
&mut self,
canvas: crate::render::Canvas<T>,
) -> bool {
if let Some(mut raw) = self.to_ll() {
unsafe {
sys::render::SDL_ConvertEventToRenderCoordinates(canvas.raw(), &mut raw);
}
*self = Self::from_ll(raw);
true
} else {
false
}
}
}

unsafe fn poll_event() -> Option<Event> {
Expand Down
Loading