Skip to content

Fix usage of isize + reverted some changes for Mouse #568

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

Merged
merged 6 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/keyboard-state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn main() {
let old_keys = &prev_keys - &keys;

if !new_keys.is_empty() || !old_keys.is_empty() {
println!("{:?} -> {:?}", new_keys, old_keys);
println!("new_keys: {:?}\told_keys:{:?}", new_keys, old_keys);
}

prev_keys = keys;
Expand Down
29 changes: 15 additions & 14 deletions src/sdl2/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,29 @@ impl AudioSubsystem {
}
}

#[repr(i32)]
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
pub enum AudioFormat {
/// Unsigned 8-bit samples
U8 = ll::AUDIO_U8 as isize,
U8 = ll::AUDIO_U8 as i32,
/// Signed 8-bit samples
S8 = ll::AUDIO_S8 as isize,
S8 = ll::AUDIO_S8 as i32,
/// Unsigned 16-bit samples, little-endian
U16LSB = ll::AUDIO_U16LSB as isize,
U16LSB = ll::AUDIO_U16LSB as i32,
/// Unsigned 16-bit samples, big-endian
U16MSB = ll::AUDIO_U16MSB as isize,
U16MSB = ll::AUDIO_U16MSB as i32,
/// Signed 16-bit samples, little-endian
S16LSB = ll::AUDIO_S16LSB as isize,
S16LSB = ll::AUDIO_S16LSB as i32,
/// Signed 16-bit samples, big-endian
S16MSB = ll::AUDIO_S16MSB as isize,
S16MSB = ll::AUDIO_S16MSB as i32,
/// Signed 32-bit samples, little-endian
S32LSB = ll::AUDIO_S32LSB as isize,
S32LSB = ll::AUDIO_S32LSB as i32,
/// Signed 32-bit samples, big-endian
S32MSB = ll::AUDIO_S32MSB as isize,
S32MSB = ll::AUDIO_S32MSB as i32,
/// 32-bit floating point samples, little-endian
F32LSB = ll::AUDIO_F32LSB as isize,
F32LSB = ll::AUDIO_F32LSB as i32,
/// 32-bit floating point samples, big-endian
F32MSB = ll::AUDIO_F32MSB as isize
F32MSB = ll::AUDIO_F32MSB as i32
}

impl AudioFormat {
Expand Down Expand Up @@ -184,12 +185,12 @@ impl AudioFormat {
#[inline] pub fn f32_sys() -> AudioFormat { AudioFormat::F32MSB }
}

#[repr(C)]
#[repr(i32)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum AudioStatus {
Stopped = ll::SDL_AUDIO_STOPPED as isize,
Playing = ll::SDL_AUDIO_PLAYING as isize,
Paused = ll::SDL_AUDIO_PAUSED as isize,
Stopped = ll::SDL_AUDIO_STOPPED as i32,
Playing = ll::SDL_AUDIO_PLAYING as i32,
Paused = ll::SDL_AUDIO_PAUSED as i32,
}

impl FromPrimitive for AudioStatus {
Expand Down
132 changes: 62 additions & 70 deletions src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::ffi::CStr;
use std::mem;
use libc::{c_int, c_void, uint32_t};
use num::FromPrimitive;
use num::ToPrimitive;
use std::ptr;
use std::borrow::ToOwned;
use std::iter::FromIterator;
Expand Down Expand Up @@ -267,56 +266,56 @@ impl ::EventSubsystem {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[repr(u32)]
pub enum EventType {
First = ll::SDL_FIRSTEVENT,

Quit = ll::SDL_QUIT,
AppTerminating = ll::SDL_APP_TERMINATING,
AppLowMemory = ll::SDL_APP_LOWMEMORY,
AppWillEnterBackground = ll::SDL_APP_WILLENTERBACKGROUND,
AppDidEnterBackground = ll::SDL_APP_DIDENTERBACKGROUND,
AppWillEnterForeground = ll::SDL_APP_WILLENTERFOREGROUND,
AppDidEnterForeground = ll::SDL_APP_DIDENTERFOREGROUND,

Window = ll::SDL_WINDOWEVENT,
// TODO: SysWM = ll::SDL_SYSWMEVENT,

KeyDown = ll::SDL_KEYDOWN,
KeyUp = ll::SDL_KEYUP,
TextEditing = ll::SDL_TEXTEDITING,
TextInput = ll::SDL_TEXTINPUT,

MouseMotion = ll::SDL_MOUSEMOTION,
MouseButtonDown = ll::SDL_MOUSEBUTTONDOWN,
MouseButtonUp = ll::SDL_MOUSEBUTTONUP,
MouseWheel = ll::SDL_MOUSEWHEEL,

JoyAxisMotion = ll::SDL_JOYAXISMOTION,
JoyBallMotion = ll::SDL_JOYBALLMOTION,
JoyHatMotion = ll::SDL_JOYHATMOTION,
JoyButtonDown = ll::SDL_JOYBUTTONDOWN,
JoyButtonUp = ll::SDL_JOYBUTTONUP,
JoyDeviceAdded = ll::SDL_JOYDEVICEADDED,
JoyDeviceRemoved = ll::SDL_JOYDEVICEREMOVED,

ControllerAxisMotion = ll::SDL_CONTROLLERAXISMOTION,
ControllerButtonDown = ll::SDL_CONTROLLERBUTTONDOWN,
ControllerButtonUp = ll::SDL_CONTROLLERBUTTONUP,
ControllerDeviceAdded = ll::SDL_CONTROLLERDEVICEADDED,
ControllerDeviceRemoved = ll::SDL_CONTROLLERDEVICEREMOVED,
ControllerDeviceRemapped = ll::SDL_CONTROLLERDEVICEREMAPPED,

FingerDown = ll::SDL_FINGERDOWN,
FingerUp = ll::SDL_FINGERUP,
FingerMotion = ll::SDL_FINGERMOTION,
DollarGesture = ll::SDL_DOLLARGESTURE,
DollarRecord = ll::SDL_DOLLARRECORD,
MultiGesture = ll::SDL_MULTIGESTURE,

ClipboardUpdate = ll::SDL_CLIPBOARDUPDATE,
DropFile = ll::SDL_DROPFILE,

User = ll::SDL_USEREVENT,
Last = ll::SDL_LASTEVENT,
First = ll::SDL_FIRSTEVENT as u32,

Quit = ll::SDL_QUIT as u32,
AppTerminating = ll::SDL_APP_TERMINATING as u32,
AppLowMemory = ll::SDL_APP_LOWMEMORY as u32,
AppWillEnterBackground = ll::SDL_APP_WILLENTERBACKGROUND as u32,
AppDidEnterBackground = ll::SDL_APP_DIDENTERBACKGROUND as u32,
AppWillEnterForeground = ll::SDL_APP_WILLENTERFOREGROUND as u32,
AppDidEnterForeground = ll::SDL_APP_DIDENTERFOREGROUND as u32,

Window = ll::SDL_WINDOWEVENT as u32,
// TODO: SysWM = ll::SDL_SYSWMEVENT as u32,

KeyDown = ll::SDL_KEYDOWN as u32,
KeyUp = ll::SDL_KEYUP as u32,
TextEditing = ll::SDL_TEXTEDITING as u32,
TextInput = ll::SDL_TEXTINPUT as u32,

MouseMotion = ll::SDL_MOUSEMOTION as u32,
MouseButtonDown = ll::SDL_MOUSEBUTTONDOWN as u32,
MouseButtonUp = ll::SDL_MOUSEBUTTONUP as u32,
MouseWheel = ll::SDL_MOUSEWHEEL as u32,

JoyAxisMotion = ll::SDL_JOYAXISMOTION as u32,
JoyBallMotion = ll::SDL_JOYBALLMOTION as u32,
JoyHatMotion = ll::SDL_JOYHATMOTION as u32,
JoyButtonDown = ll::SDL_JOYBUTTONDOWN as u32,
JoyButtonUp = ll::SDL_JOYBUTTONUP as u32,
JoyDeviceAdded = ll::SDL_JOYDEVICEADDED as u32,
JoyDeviceRemoved = ll::SDL_JOYDEVICEREMOVED as u32,

ControllerAxisMotion = ll::SDL_CONTROLLERAXISMOTION as u32,
ControllerButtonDown = ll::SDL_CONTROLLERBUTTONDOWN as u32,
ControllerButtonUp = ll::SDL_CONTROLLERBUTTONUP as u32,
ControllerDeviceAdded = ll::SDL_CONTROLLERDEVICEADDED as u32,
ControllerDeviceRemoved = ll::SDL_CONTROLLERDEVICEREMOVED as u32,
ControllerDeviceRemapped = ll::SDL_CONTROLLERDEVICEREMAPPED as u32,

FingerDown = ll::SDL_FINGERDOWN as u32,
FingerUp = ll::SDL_FINGERUP as u32,
FingerMotion = ll::SDL_FINGERMOTION as u32,
DollarGesture = ll::SDL_DOLLARGESTURE as u32,
DollarRecord = ll::SDL_DOLLARRECORD as u32,
MultiGesture = ll::SDL_MULTIGESTURE as u32,

ClipboardUpdate = ll::SDL_CLIPBOARDUPDATE as u32,
DropFile = ll::SDL_DROPFILE as u32,

User = ll::SDL_USEREVENT as u32,
Last = ll::SDL_LASTEVENT as u32,
}

impl FromPrimitive for EventType {
Expand Down Expand Up @@ -515,15 +514,15 @@ pub enum Event {
timestamp: u32,
window_id: u32,
which: u32,
mouse_btn: Option<MouseButton>,
mouse_btn: MouseButton,
x: i32,
y: i32
},
MouseButtonUp {
timestamp: u32,
window_id: u32,
which: u32,
mouse_btn: Option<MouseButton>,
mouse_btn: MouseButton,
x: i32,
y: i32
},
Expand Down Expand Up @@ -746,10 +745,10 @@ fn mk_keysym(scancode: Option<Scancode>,
keycode: Option<Keycode>,
keymod: Mod) -> syskeyboard::SDL_Keysym {
let scancode = scancode
.map(|sc| sc.to_u32().unwrap_or(0u32))
.map(|sc| sc as scancode::SDL_Scancode)
.unwrap_or(scancode::SDL_SCANCODE_UNKNOWN);
let keycode = keycode
.map(|kc| kc.to_i32().unwrap_or(0i32))
.map(|kc| kc as keycode::SDL_Keycode)
.unwrap_or(keycode::SDLK_UNKNOWN);
let keymod = keymod.bits() as u16;
syskeyboard::SDL_Keysym {
Expand All @@ -760,11 +759,6 @@ fn mk_keysym(scancode: Option<Scancode>,
}
}

/// Helper function is only to unwrap a mouse_button to u8
fn mk_mouse_button(mouse_button: Option<MouseButton>) -> u8 {
mouse_button.unwrap().to_ll().unwrap()
}

// TODO: Remove this when from_utf8 is updated in Rust
// This would honestly be nice if it took &self instead of self,
// but Event::User's raw pointers kind of removes that possibility.
Expand Down Expand Up @@ -905,13 +899,12 @@ impl Event {
x,
y
} => {
let button = mk_mouse_button(mouse_btn);
let event = ll::SDL_MouseButtonEvent {
type_: ll::SDL_MOUSEBUTTONDOWN,
timestamp: timestamp,
windowID: window_id,
which: which,
button: button,
button: mouse_btn as u8,
state: ll::SDL_PRESSED,
padding1: 0,
padding2: 0,
Expand All @@ -931,13 +924,12 @@ impl Event {
x,
y
} => {
let button = mk_mouse_button(mouse_btn);
let event = ll::SDL_MouseButtonEvent {
type_: ll::SDL_MOUSEBUTTONUP,
timestamp: timestamp,
windowID: window_id,
which: which,
button: button,
button: mouse_btn as u8,
state: ll::SDL_RELEASED,
padding1: 0,
padding2: 0,
Expand Down Expand Up @@ -1304,8 +1296,8 @@ impl Event {
Event::KeyDown {
timestamp: event.timestamp,
window_id: event.windowID,
keycode: FromPrimitive::from_i32(event.keysym.sym),
scancode: FromPrimitive::from_u32(event.keysym.scancode),
keycode: Keycode::from_i32(event.keysym.sym as i32),
scancode: Scancode::from_i32(event.keysym.scancode as i32),
keymod: keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod).unwrap(),
repeat: event.repeat != 0
}
Expand All @@ -1316,8 +1308,8 @@ impl Event {
Event::KeyUp {
timestamp: event.timestamp,
window_id: event.windowID,
keycode: FromPrimitive::from_i32(event.keysym.sym),
scancode: FromPrimitive::from_u32(event.keysym.scancode),
keycode: Keycode::from_i32(event.keysym.sym as i32),
scancode: Scancode::from_i32(event.keysym.scancode as i32),
keymod: keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod).unwrap(),
repeat: event.repeat != 0
}
Expand Down Expand Up @@ -1909,7 +1901,7 @@ mod test {
timestamp: 5634,
window_id: 2,
which: 0,
mouse_btn: Some(MouseButton::Left),
mouse_btn: MouseButton::Left,
x: 543,
y: 345,
};
Expand All @@ -1921,7 +1913,7 @@ mod test {
timestamp: 0,
window_id: 2,
which: 0,
mouse_btn: Some(MouseButton::Left),
mouse_btn: MouseButton::Left,
x: 543,
y: 345,

Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/gfx/imagefilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub fn clip_to_range(src1: CVec<u8>, tmin: u8, tmax: u8) -> Result<CVec<u8>, Str
}

/// Filter using NormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin).
pub fn normalize_linear(src1: CVec<u8>, cmin: isize, cmax: isize, nmin: isize, nmax: isize) -> Result<CVec<u8>, String> {
pub fn normalize_linear(src1: CVec<u8>, cmin: i32, cmax: i32, nmin: i32, nmax: i32) -> Result<CVec<u8>, String> {
let size = src1.len();
let dest = cvec_with_size(size);
let ret = unsafe { ll::SDL_imageFilterNormalizeLinear(mem::transmute(src1.get(0)),
Expand Down
4 changes: 2 additions & 2 deletions src/sdl2/gfx/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub trait DrawRenderer {
fn aa_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], color: C) -> Result<(), String>;
fn filled_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], color: C) -> Result<(), String>;
fn textured_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], texture: &Surface, texture_dx: i16, texture_dy: i16, color: C) -> Result<(), String>;
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: isize, color: C) -> Result<(), String>;
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: i32, color: C) -> Result<(), String>;
fn character<C: ToColor>(&self, x: i16, y: i16, c: char, color: C) -> Result<(), String>;
fn string<C: ToColor>(&self, x: i16, y: i16, s: &str, color: C) -> Result<(), String>;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a> DrawRenderer for Renderer<'a> {
unimplemented!()
}

fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: isize, color: C) -> Result<(), String> {
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: i32, color: C) -> Result<(), String> {
assert_eq!(vx.len(), vy.len());
let n = vx.len() as c_int;
let ret = unsafe {
Expand Down
20 changes: 10 additions & 10 deletions src/sdl2/gfx/rotozoom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub trait RotozoomSurface {
/// Zoom a surface by independent horizontal and vertical factors with optional smoothing.
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface, String>;
/// Shrink a surface by an integer ratio using averaging.
fn shrink(&self, factorx: isize, factory: isize) -> Result<Surface, String>;
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String>;
/// Rotates a 8/16/24/32 bit surface in increments of 90 degrees.
fn rotate_90deg(&self, turns: isize) -> Result<Surface, String>;
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String>;
}

impl<'a> RotozoomSurface for Surface<'a> {
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
unsafe { Ok(Surface::from_ll(raw)) }
}
}
fn shrink(&self, factorx: isize, factory: isize) -> Result<Surface, String> {
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String> {
let raw = unsafe {
ll::shrinkSurface(self.raw(), factorx as c_int, factory as c_int)
};
Expand All @@ -92,7 +92,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
unsafe { Ok(Surface::from_ll(raw)) }
}
}
fn rotate_90deg(&self, turns: isize) -> Result<Surface, String> {
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String> {
let raw = unsafe {
ll::rotateSurface90Degrees(self.raw(), turns as c_int)
};
Expand All @@ -104,23 +104,23 @@ impl<'a> RotozoomSurface for Surface<'a> {
}
}

pub fn get_zoom_size(width: isize, height: isize, zoomx: f64, zoomy: f64) -> (isize, isize) {
pub fn get_zoom_size(width: i32, height: i32, zoomx: f64, zoomy: f64) -> (i32, i32) {
let mut w: c_int = 0;
let mut h: c_int = 0;
unsafe { ll::zoomSurfaceSize(width as c_int, height as c_int, zoomx, zoomy, &mut w, &mut h) }
(w as isize, h as isize)
(w as i32, h as i32)
}

pub fn get_rotozoom_size(width: isize, height: isize, angle: f64, zoom: f64) -> (isize, isize) {
pub fn get_rotozoom_size(width: i32, height: i32, angle: f64, zoom: f64) -> (i32, i32) {
let mut w: c_int = 0;
let mut h: c_int = 0;
unsafe { ll::rotozoomSurfaceSize(width as c_int, height as c_int, angle, zoom, &mut w, &mut h) }
(w as isize, h as isize)
(w as i32, h as i32)
}

pub fn get_rotozoom_xy_size(width: isize, height: isize, angle: f64, zoomx: f64, zoomy: f64) -> (isize, isize) {
pub fn get_rotozoom_xy_size(width: i32, height: i32, angle: f64, zoomx: f64, zoomy: f64) -> (i32, i32) {
let mut w: c_int = 0;
let mut h: c_int = 0;
unsafe { ll::rotozoomSurfaceSizeXY(width as c_int, height as c_int, angle, zoomx, zoomy, &mut w, &mut h) }
(w as isize, h as isize)
(w as i32, h as i32)
}
Loading