Skip to content

Commit

Permalink
event, log, messagebox, pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Oct 15, 2024
1 parent 48b464c commit d70d9b6
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 141 deletions.
8 changes: 4 additions & 4 deletions src/sdl3/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ impl Event {
type_: SDL_EventType::SDL_EVENT_GAMEPAD_AXIS_MOTION as u32,
timestamp,
which,
axis: axisval as u8,
axis: axisval.into(),
value,
padding1: 0,
padding2: 0,
Expand Down Expand Up @@ -1374,7 +1374,7 @@ impl Event {
which,
// This conversion turns an i32 into a u8; signed-to-unsigned conversions
// are a bit of a code smell, but that appears to be how SDL defines it.
button: buttonval as u8,
button: buttonval .into(),
state: sys::events::SDL_Event::SDL_PRESSED as u8,
padding1: 0,
padding2: 0,
Expand All @@ -1399,7 +1399,7 @@ impl Event {
type_: SDL_EventType::SDL_EVENT_GAMEPAD_BUTTON_UP as u32,
timestamp,
which,
button: buttonval as u8,
button: buttonval .into(),
state: sys::events::SDL_Event::SDL_RELEASED as u8,
padding1: 0,
padding2: 0,
Expand Down Expand Up @@ -3119,7 +3119,7 @@ impl<'a, CB: EventWatchCallback + 'a> EventWatch<'a, CB> {
}

fn filter(&self) -> SDL_EventFilter {
Some(event_callback_marshall::<CB> as _)
Some(event_callback_marshall::<CB>.into())
}

fn callback(&mut self) -> *mut c_void {
Expand Down
30 changes: 15 additions & 15 deletions src/sdl3/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ pub enum Category {
impl Category {
#[allow(dead_code)]
fn from_ll(value: u32) -> Category {
if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_APPLICATION as u32 {
if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_APPLICATION as u32 {
Category::Application
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_ERROR as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_ERROR as u32 {
Category::Error
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_ASSERT as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_ASSERT as u32 {
Category::Assert
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_SYSTEM as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_SYSTEM as u32 {
Category::System
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_AUDIO as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_AUDIO as u32 {
Category::Audio
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_VIDEO as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_VIDEO as u32 {
Category::Video
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_RENDER as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_RENDER as u32 {
Category::Render
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_INPUT as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_INPUT as u32 {
Category::Input
} else if value == sys::SDL_LogCategory::SDL_LOG_CATEGORY_TEST as u32 {
} else if value == sys::log::SDL_LogCategory::SDL_LOG_CATEGORY_TEST as u32 {
Category::Test
} else {
Category::Custom
Expand All @@ -55,8 +55,8 @@ pub enum Priority {
}

impl Priority {
fn from_ll(value: sys::SDL_LogPriority) -> Priority {
use crate::sys::SDL_LogPriority::*;
fn from_ll(value: sys::log::SDL_LogPriority) -> Priority {
use crate::sys::log::SDL_LogPriority::*;
match value {
SDL_LOG_PRIORITY_VERBOSE => Priority::Verbose,
SDL_LOG_PRIORITY_DEBUG => Priority::Debug,
Expand All @@ -77,7 +77,7 @@ static mut custom_log_fn: fn(Priority, Category, &str) = dummy;
unsafe extern "C" fn rust_sdl2_log_fn(
_userdata: *mut libc::c_void,
category: libc::c_int,
priority: sys::SDL_LogPriority,
priority: sys::log::SDL_LogPriority,
message: *const libc::c_char,
) {
let category = Category::from_ll(category as u32);
Expand All @@ -86,11 +86,11 @@ unsafe extern "C" fn rust_sdl2_log_fn(
custom_log_fn(priority, category, &*message);
}

#[doc(alias = "SDL_LogSetOutputFunction")]
#[doc(alias = "SDL_SetLogOutputFunction")]
pub fn set_output_function(callback: fn(Priority, Category, &str)) {
unsafe {
custom_log_fn = callback;
sys::SDL_LogSetOutputFunction(Some(rust_sdl2_log_fn), null_mut());
sys::log::SDL_SetLogOutputFunction(Some(rust_sdl2_log_fn), null_mut());
};
}

Expand All @@ -101,6 +101,6 @@ pub fn log(message: &str) {
let message = message.replace('%', "%%");
let message = CString::new(message).unwrap();
unsafe {
crate::sys::SDL_Log(message.into_raw());
crate::sys::log::SDL_Log(message.into_raw());
}
}
50 changes: 25 additions & 25 deletions src/sdl3/messagebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ use crate::sys;
bitflags! {
pub struct MessageBoxFlag: u32 {
const ERROR =
sys::SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR as u32;
sys::messagebox::SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR as u32;
const WARNING =
sys::SDL_MessageBoxFlags::SDL_MESSAGEBOX_WARNING as u32;
sys::messagebox::SDL_MessageBoxFlags::SDL_MESSAGEBOX_WARNING as u32;
const INFORMATION =
sys::SDL_MessageBoxFlags::SDL_MESSAGEBOX_INFORMATION as u32;
sys::messagebox::SDL_MessageBoxFlags::SDL_MESSAGEBOX_INFORMATION as u32;
}
}

bitflags! {
pub struct MessageBoxButtonFlag: u32 {
const ESCAPEKEY_DEFAULT =
sys::SDL_MessageBoxButtonFlags::SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT as u32;
sys::messagebox::SDL_MessageBoxButtonFlags::SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT as u32;
const RETURNKEY_DEFAULT =
sys::SDL_MessageBoxButtonFlags::SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT as u32;
sys::messagebox::SDL_MessageBoxButtonFlags::SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT as u32;
const NOTHING = 0;
}
}
Expand All @@ -39,16 +39,16 @@ pub struct MessageBoxColorScheme {
pub button_selected: (u8, u8, u8),
}

impl Into<sys::SDL_MessageBoxColorScheme> for MessageBoxColorScheme {
fn into(self) -> sys::SDL_MessageBoxColorScheme {
sys::SDL_MessageBoxColorScheme {
impl Into<sys::messagebox::SDL_MessageBoxColorScheme> for MessageBoxColorScheme {
fn into(self) -> sys::messagebox::SDL_MessageBoxColorScheme {
sys::messagebox::SDL_MessageBoxColorScheme {
colors: self.into(),
}
}
}

impl From<sys::SDL_MessageBoxColorScheme> for MessageBoxColorScheme {
fn from(prim: sys::SDL_MessageBoxColorScheme) -> MessageBoxColorScheme {
impl From<sys::messagebox::SDL_MessageBoxColorScheme> for MessageBoxColorScheme {
fn from(prim: sys::messagebox::SDL_MessageBoxColorScheme) -> MessageBoxColorScheme {
prim.colors.into()
}
}
Expand All @@ -69,10 +69,10 @@ pub enum ClickedButton<'a> {
CustomButton(&'a ButtonData<'a>),
}

impl From<MessageBoxColorScheme> for [sys::SDL_MessageBoxColor; 5] {
fn from(scheme: MessageBoxColorScheme) -> [sys::SDL_MessageBoxColor; 5] {
fn to_message_box_color(t: (u8, u8, u8)) -> sys::SDL_MessageBoxColor {
sys::SDL_MessageBoxColor {
impl From<MessageBoxColorScheme> for [sys::messagebox::SDL_MessageBoxColor; 5] {
fn from(scheme: MessageBoxColorScheme) -> [sys::messagebox::SDL_MessageBoxColor; 5] {
fn to_message_box_color(t: (u8, u8, u8)) -> sys::messagebox::SDL_MessageBoxColor {
sys::messagebox::SDL_MessageBoxColor {
r: t.0,
g: t.1,
b: t.2,
Expand All @@ -88,9 +88,9 @@ impl From<MessageBoxColorScheme> for [sys::SDL_MessageBoxColor; 5] {
}
}

impl Into<MessageBoxColorScheme> for [sys::SDL_MessageBoxColor; 5] {
impl Into<MessageBoxColorScheme> for [sys::messagebox::SDL_MessageBoxColor; 5] {
fn into(self) -> MessageBoxColorScheme {
fn from_message_box_color(prim_color: sys::SDL_MessageBoxColor) -> (u8, u8, u8) {
fn from_message_box_color(prim_color: sys::messagebox::SDL_MessageBoxColor) -> (u8, u8, u8) {
(prim_color.r, prim_color.g, prim_color.b)
}
MessageBoxColorScheme {
Expand Down Expand Up @@ -164,13 +164,13 @@ where
Ok(s) => s,
Err(err) => return Err(InvalidMessage(err)),
};
sys::SDL_ShowSimpleMessageBox(
sys::messagebox::SDL_ShowSimpleMessageBox(
flags.bits(),
title.as_ptr() as *const c_char,
message.as_ptr() as *const c_char,
window.into().map_or(ptr::null_mut(), |win| win.raw()),
)
} == 0;
};

if result {
Ok(())
Expand Down Expand Up @@ -222,33 +222,33 @@ where
Ok(b) => b,
Err(e) => return Err(InvalidButton(e.0, e.1)),
};
let raw_buttons: Vec<sys::SDL_MessageBoxButtonData> = buttons
let raw_buttons: Vec<sys::messagebox::SDL_MessageBoxButtonData> = buttons
.iter()
.zip(button_texts.iter())
.map(|(b, b_text)| sys::SDL_MessageBoxButtonData {
.map(|(b, b_text)| sys::messagebox::SDL_MessageBoxButtonData {
flags: b.flags.bits(),
buttonid: b.button_id as c_int,
buttonID: b.button_id as c_int,
text: b_text.as_ptr(),
})
.collect();
let result = unsafe {
let msg_box_data = sys::SDL_MessageBoxData {
let msg_box_data = sys::messagebox::SDL_MessageBoxData {
flags: flags.bits(),
window: window.map_or(ptr::null_mut(), |win| win.raw()),
title: title.as_ptr() as *const c_char,
message: message.as_ptr() as *const c_char,
numbuttons: raw_buttons.len() as c_int,
buttons: raw_buttons.as_ptr(),
colorScheme: if let Some(scheme) = scheme {
&sys::SDL_MessageBoxColorScheme {
&sys::messagebox::SDL_MessageBoxColorScheme {
colors: From::from(scheme),
} as *const _
} else {
ptr::null()
},
};
sys::SDL_ShowMessageBox(&msg_box_data as *const _, &mut button_id as &mut _)
} == 0;
sys::messagebox::SDL_ShowMessageBox(&msg_box_data as *const _, &mut button_id as &mut _)
} ;
if result {
match button_id {
-1 => Ok(ClickedButton::CloseButton),
Expand Down
Loading

0 comments on commit d70d9b6

Please sign in to comment.