Skip to content

Commit 8e5a095

Browse files
authored
Merge pull request #568 from Cobrand/master
Fix usage of isize + reverted some changes for Mouse
2 parents c9a3786 + c772fdf commit 8e5a095

16 files changed

+759
-836
lines changed

examples/keyboard-state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn main() {
3434
let old_keys = &prev_keys - &keys;
3535

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

4040
prev_keys = keys;

src/sdl2/audio.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,29 @@ impl AudioSubsystem {
113113
}
114114
}
115115

116+
#[repr(i32)]
116117
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
117118
pub enum AudioFormat {
118119
/// Unsigned 8-bit samples
119-
U8 = ll::AUDIO_U8 as isize,
120+
U8 = ll::AUDIO_U8 as i32,
120121
/// Signed 8-bit samples
121-
S8 = ll::AUDIO_S8 as isize,
122+
S8 = ll::AUDIO_S8 as i32,
122123
/// Unsigned 16-bit samples, little-endian
123-
U16LSB = ll::AUDIO_U16LSB as isize,
124+
U16LSB = ll::AUDIO_U16LSB as i32,
124125
/// Unsigned 16-bit samples, big-endian
125-
U16MSB = ll::AUDIO_U16MSB as isize,
126+
U16MSB = ll::AUDIO_U16MSB as i32,
126127
/// Signed 16-bit samples, little-endian
127-
S16LSB = ll::AUDIO_S16LSB as isize,
128+
S16LSB = ll::AUDIO_S16LSB as i32,
128129
/// Signed 16-bit samples, big-endian
129-
S16MSB = ll::AUDIO_S16MSB as isize,
130+
S16MSB = ll::AUDIO_S16MSB as i32,
130131
/// Signed 32-bit samples, little-endian
131-
S32LSB = ll::AUDIO_S32LSB as isize,
132+
S32LSB = ll::AUDIO_S32LSB as i32,
132133
/// Signed 32-bit samples, big-endian
133-
S32MSB = ll::AUDIO_S32MSB as isize,
134+
S32MSB = ll::AUDIO_S32MSB as i32,
134135
/// 32-bit floating point samples, little-endian
135-
F32LSB = ll::AUDIO_F32LSB as isize,
136+
F32LSB = ll::AUDIO_F32LSB as i32,
136137
/// 32-bit floating point samples, big-endian
137-
F32MSB = ll::AUDIO_F32MSB as isize
138+
F32MSB = ll::AUDIO_F32MSB as i32
138139
}
139140

140141
impl AudioFormat {
@@ -184,12 +185,12 @@ impl AudioFormat {
184185
#[inline] pub fn f32_sys() -> AudioFormat { AudioFormat::F32MSB }
185186
}
186187

187-
#[repr(C)]
188+
#[repr(i32)]
188189
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
189190
pub enum AudioStatus {
190-
Stopped = ll::SDL_AUDIO_STOPPED as isize,
191-
Playing = ll::SDL_AUDIO_PLAYING as isize,
192-
Paused = ll::SDL_AUDIO_PAUSED as isize,
191+
Stopped = ll::SDL_AUDIO_STOPPED as i32,
192+
Playing = ll::SDL_AUDIO_PLAYING as i32,
193+
Paused = ll::SDL_AUDIO_PAUSED as i32,
193194
}
194195

195196
impl FromPrimitive for AudioStatus {

src/sdl2/event.rs

Lines changed: 62 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::ffi::CStr;
66
use std::mem;
77
use libc::{c_int, c_void, uint32_t};
88
use num::FromPrimitive;
9-
use num::ToPrimitive;
109
use std::ptr;
1110
use std::borrow::ToOwned;
1211
use std::iter::FromIterator;
@@ -267,56 +266,56 @@ impl ::EventSubsystem {
267266
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
268267
#[repr(u32)]
269268
pub enum EventType {
270-
First = ll::SDL_FIRSTEVENT,
271-
272-
Quit = ll::SDL_QUIT,
273-
AppTerminating = ll::SDL_APP_TERMINATING,
274-
AppLowMemory = ll::SDL_APP_LOWMEMORY,
275-
AppWillEnterBackground = ll::SDL_APP_WILLENTERBACKGROUND,
276-
AppDidEnterBackground = ll::SDL_APP_DIDENTERBACKGROUND,
277-
AppWillEnterForeground = ll::SDL_APP_WILLENTERFOREGROUND,
278-
AppDidEnterForeground = ll::SDL_APP_DIDENTERFOREGROUND,
279-
280-
Window = ll::SDL_WINDOWEVENT,
281-
// TODO: SysWM = ll::SDL_SYSWMEVENT,
282-
283-
KeyDown = ll::SDL_KEYDOWN,
284-
KeyUp = ll::SDL_KEYUP,
285-
TextEditing = ll::SDL_TEXTEDITING,
286-
TextInput = ll::SDL_TEXTINPUT,
287-
288-
MouseMotion = ll::SDL_MOUSEMOTION,
289-
MouseButtonDown = ll::SDL_MOUSEBUTTONDOWN,
290-
MouseButtonUp = ll::SDL_MOUSEBUTTONUP,
291-
MouseWheel = ll::SDL_MOUSEWHEEL,
292-
293-
JoyAxisMotion = ll::SDL_JOYAXISMOTION,
294-
JoyBallMotion = ll::SDL_JOYBALLMOTION,
295-
JoyHatMotion = ll::SDL_JOYHATMOTION,
296-
JoyButtonDown = ll::SDL_JOYBUTTONDOWN,
297-
JoyButtonUp = ll::SDL_JOYBUTTONUP,
298-
JoyDeviceAdded = ll::SDL_JOYDEVICEADDED,
299-
JoyDeviceRemoved = ll::SDL_JOYDEVICEREMOVED,
300-
301-
ControllerAxisMotion = ll::SDL_CONTROLLERAXISMOTION,
302-
ControllerButtonDown = ll::SDL_CONTROLLERBUTTONDOWN,
303-
ControllerButtonUp = ll::SDL_CONTROLLERBUTTONUP,
304-
ControllerDeviceAdded = ll::SDL_CONTROLLERDEVICEADDED,
305-
ControllerDeviceRemoved = ll::SDL_CONTROLLERDEVICEREMOVED,
306-
ControllerDeviceRemapped = ll::SDL_CONTROLLERDEVICEREMAPPED,
307-
308-
FingerDown = ll::SDL_FINGERDOWN,
309-
FingerUp = ll::SDL_FINGERUP,
310-
FingerMotion = ll::SDL_FINGERMOTION,
311-
DollarGesture = ll::SDL_DOLLARGESTURE,
312-
DollarRecord = ll::SDL_DOLLARRECORD,
313-
MultiGesture = ll::SDL_MULTIGESTURE,
314-
315-
ClipboardUpdate = ll::SDL_CLIPBOARDUPDATE,
316-
DropFile = ll::SDL_DROPFILE,
317-
318-
User = ll::SDL_USEREVENT,
319-
Last = ll::SDL_LASTEVENT,
269+
First = ll::SDL_FIRSTEVENT as u32,
270+
271+
Quit = ll::SDL_QUIT as u32,
272+
AppTerminating = ll::SDL_APP_TERMINATING as u32,
273+
AppLowMemory = ll::SDL_APP_LOWMEMORY as u32,
274+
AppWillEnterBackground = ll::SDL_APP_WILLENTERBACKGROUND as u32,
275+
AppDidEnterBackground = ll::SDL_APP_DIDENTERBACKGROUND as u32,
276+
AppWillEnterForeground = ll::SDL_APP_WILLENTERFOREGROUND as u32,
277+
AppDidEnterForeground = ll::SDL_APP_DIDENTERFOREGROUND as u32,
278+
279+
Window = ll::SDL_WINDOWEVENT as u32,
280+
// TODO: SysWM = ll::SDL_SYSWMEVENT as u32,
281+
282+
KeyDown = ll::SDL_KEYDOWN as u32,
283+
KeyUp = ll::SDL_KEYUP as u32,
284+
TextEditing = ll::SDL_TEXTEDITING as u32,
285+
TextInput = ll::SDL_TEXTINPUT as u32,
286+
287+
MouseMotion = ll::SDL_MOUSEMOTION as u32,
288+
MouseButtonDown = ll::SDL_MOUSEBUTTONDOWN as u32,
289+
MouseButtonUp = ll::SDL_MOUSEBUTTONUP as u32,
290+
MouseWheel = ll::SDL_MOUSEWHEEL as u32,
291+
292+
JoyAxisMotion = ll::SDL_JOYAXISMOTION as u32,
293+
JoyBallMotion = ll::SDL_JOYBALLMOTION as u32,
294+
JoyHatMotion = ll::SDL_JOYHATMOTION as u32,
295+
JoyButtonDown = ll::SDL_JOYBUTTONDOWN as u32,
296+
JoyButtonUp = ll::SDL_JOYBUTTONUP as u32,
297+
JoyDeviceAdded = ll::SDL_JOYDEVICEADDED as u32,
298+
JoyDeviceRemoved = ll::SDL_JOYDEVICEREMOVED as u32,
299+
300+
ControllerAxisMotion = ll::SDL_CONTROLLERAXISMOTION as u32,
301+
ControllerButtonDown = ll::SDL_CONTROLLERBUTTONDOWN as u32,
302+
ControllerButtonUp = ll::SDL_CONTROLLERBUTTONUP as u32,
303+
ControllerDeviceAdded = ll::SDL_CONTROLLERDEVICEADDED as u32,
304+
ControllerDeviceRemoved = ll::SDL_CONTROLLERDEVICEREMOVED as u32,
305+
ControllerDeviceRemapped = ll::SDL_CONTROLLERDEVICEREMAPPED as u32,
306+
307+
FingerDown = ll::SDL_FINGERDOWN as u32,
308+
FingerUp = ll::SDL_FINGERUP as u32,
309+
FingerMotion = ll::SDL_FINGERMOTION as u32,
310+
DollarGesture = ll::SDL_DOLLARGESTURE as u32,
311+
DollarRecord = ll::SDL_DOLLARRECORD as u32,
312+
MultiGesture = ll::SDL_MULTIGESTURE as u32,
313+
314+
ClipboardUpdate = ll::SDL_CLIPBOARDUPDATE as u32,
315+
DropFile = ll::SDL_DROPFILE as u32,
316+
317+
User = ll::SDL_USEREVENT as u32,
318+
Last = ll::SDL_LASTEVENT as u32,
320319
}
321320

322321
impl FromPrimitive for EventType {
@@ -515,15 +514,15 @@ pub enum Event {
515514
timestamp: u32,
516515
window_id: u32,
517516
which: u32,
518-
mouse_btn: Option<MouseButton>,
517+
mouse_btn: MouseButton,
519518
x: i32,
520519
y: i32
521520
},
522521
MouseButtonUp {
523522
timestamp: u32,
524523
window_id: u32,
525524
which: u32,
526-
mouse_btn: Option<MouseButton>,
525+
mouse_btn: MouseButton,
527526
x: i32,
528527
y: i32
529528
},
@@ -746,10 +745,10 @@ fn mk_keysym(scancode: Option<Scancode>,
746745
keycode: Option<Keycode>,
747746
keymod: Mod) -> syskeyboard::SDL_Keysym {
748747
let scancode = scancode
749-
.map(|sc| sc.to_u32().unwrap_or(0u32))
748+
.map(|sc| sc as scancode::SDL_Scancode)
750749
.unwrap_or(scancode::SDL_SCANCODE_UNKNOWN);
751750
let keycode = keycode
752-
.map(|kc| kc.to_i32().unwrap_or(0i32))
751+
.map(|kc| kc as keycode::SDL_Keycode)
753752
.unwrap_or(keycode::SDLK_UNKNOWN);
754753
let keymod = keymod.bits() as u16;
755754
syskeyboard::SDL_Keysym {
@@ -760,11 +759,6 @@ fn mk_keysym(scancode: Option<Scancode>,
760759
}
761760
}
762761

763-
/// Helper function is only to unwrap a mouse_button to u8
764-
fn mk_mouse_button(mouse_button: Option<MouseButton>) -> u8 {
765-
mouse_button.unwrap().to_ll().unwrap()
766-
}
767-
768762
// TODO: Remove this when from_utf8 is updated in Rust
769763
// This would honestly be nice if it took &self instead of self,
770764
// but Event::User's raw pointers kind of removes that possibility.
@@ -905,13 +899,12 @@ impl Event {
905899
x,
906900
y
907901
} => {
908-
let button = mk_mouse_button(mouse_btn);
909902
let event = ll::SDL_MouseButtonEvent {
910903
type_: ll::SDL_MOUSEBUTTONDOWN,
911904
timestamp: timestamp,
912905
windowID: window_id,
913906
which: which,
914-
button: button,
907+
button: mouse_btn as u8,
915908
state: ll::SDL_PRESSED,
916909
padding1: 0,
917910
padding2: 0,
@@ -931,13 +924,12 @@ impl Event {
931924
x,
932925
y
933926
} => {
934-
let button = mk_mouse_button(mouse_btn);
935927
let event = ll::SDL_MouseButtonEvent {
936928
type_: ll::SDL_MOUSEBUTTONUP,
937929
timestamp: timestamp,
938930
windowID: window_id,
939931
which: which,
940-
button: button,
932+
button: mouse_btn as u8,
941933
state: ll::SDL_RELEASED,
942934
padding1: 0,
943935
padding2: 0,
@@ -1304,8 +1296,8 @@ impl Event {
13041296
Event::KeyDown {
13051297
timestamp: event.timestamp,
13061298
window_id: event.windowID,
1307-
keycode: FromPrimitive::from_i32(event.keysym.sym),
1308-
scancode: FromPrimitive::from_u32(event.keysym.scancode),
1299+
keycode: Keycode::from_i32(event.keysym.sym as i32),
1300+
scancode: Scancode::from_i32(event.keysym.scancode as i32),
13091301
keymod: keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod).unwrap(),
13101302
repeat: event.repeat != 0
13111303
}
@@ -1316,8 +1308,8 @@ impl Event {
13161308
Event::KeyUp {
13171309
timestamp: event.timestamp,
13181310
window_id: event.windowID,
1319-
keycode: FromPrimitive::from_i32(event.keysym.sym),
1320-
scancode: FromPrimitive::from_u32(event.keysym.scancode),
1311+
keycode: Keycode::from_i32(event.keysym.sym as i32),
1312+
scancode: Scancode::from_i32(event.keysym.scancode as i32),
13211313
keymod: keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod).unwrap(),
13221314
repeat: event.repeat != 0
13231315
}
@@ -1909,7 +1901,7 @@ mod test {
19091901
timestamp: 5634,
19101902
window_id: 2,
19111903
which: 0,
1912-
mouse_btn: Some(MouseButton::Left),
1904+
mouse_btn: MouseButton::Left,
19131905
x: 543,
19141906
y: 345,
19151907
};
@@ -1921,7 +1913,7 @@ mod test {
19211913
timestamp: 0,
19221914
window_id: 2,
19231915
which: 0,
1924-
mouse_btn: Some(MouseButton::Left),
1916+
mouse_btn: MouseButton::Left,
19251917
x: 543,
19261918
y: 345,
19271919

src/sdl2/gfx/imagefilter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ pub fn clip_to_range(src1: CVec<u8>, tmin: u8, tmax: u8) -> Result<CVec<u8>, Str
420420
}
421421

422422
/// Filter using NormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin).
423-
pub fn normalize_linear(src1: CVec<u8>, cmin: isize, cmax: isize, nmin: isize, nmax: isize) -> Result<CVec<u8>, String> {
423+
pub fn normalize_linear(src1: CVec<u8>, cmin: i32, cmax: i32, nmin: i32, nmax: i32) -> Result<CVec<u8>, String> {
424424
let size = src1.len();
425425
let dest = cvec_with_size(size);
426426
let ret = unsafe { ll::SDL_imageFilterNormalizeLinear(mem::transmute(src1.get(0)),

src/sdl2/gfx/primitives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub trait DrawRenderer {
267267
fn aa_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], color: C) -> Result<(), String>;
268268
fn filled_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], color: C) -> Result<(), String>;
269269
fn textured_polygon<C: ToColor>(&self, vx: &[i16], vy: &[i16], texture: &Surface, texture_dx: i16, texture_dy: i16, color: C) -> Result<(), String>;
270-
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: isize, color: C) -> Result<(), String>;
270+
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: i32, color: C) -> Result<(), String>;
271271
fn character<C: ToColor>(&self, x: i16, y: i16, c: char, color: C) -> Result<(), String>;
272272
fn string<C: ToColor>(&self, x: i16, y: i16, s: &str, color: C) -> Result<(), String>;
273273
}
@@ -462,7 +462,7 @@ impl<'a> DrawRenderer for Renderer<'a> {
462462
unimplemented!()
463463
}
464464

465-
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: isize, color: C) -> Result<(), String> {
465+
fn bezier<C: ToColor>(&self, vx: &[i16], vy: &[i16], s: i32, color: C) -> Result<(), String> {
466466
assert_eq!(vx.len(), vy.len());
467467
let n = vx.len() as c_int;
468468
let ret = unsafe {

src/sdl2/gfx/rotozoom.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ pub trait RotozoomSurface {
4646
/// Zoom a surface by independent horizontal and vertical factors with optional smoothing.
4747
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface, String>;
4848
/// Shrink a surface by an integer ratio using averaging.
49-
fn shrink(&self, factorx: isize, factory: isize) -> Result<Surface, String>;
49+
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String>;
5050
/// Rotates a 8/16/24/32 bit surface in increments of 90 degrees.
51-
fn rotate_90deg(&self, turns: isize) -> Result<Surface, String>;
51+
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String>;
5252
}
5353

5454
impl<'a> RotozoomSurface for Surface<'a> {
@@ -82,7 +82,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
8282
unsafe { Ok(Surface::from_ll(raw)) }
8383
}
8484
}
85-
fn shrink(&self, factorx: isize, factory: isize) -> Result<Surface, String> {
85+
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String> {
8686
let raw = unsafe {
8787
ll::shrinkSurface(self.raw(), factorx as c_int, factory as c_int)
8888
};
@@ -92,7 +92,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
9292
unsafe { Ok(Surface::from_ll(raw)) }
9393
}
9494
}
95-
fn rotate_90deg(&self, turns: isize) -> Result<Surface, String> {
95+
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String> {
9696
let raw = unsafe {
9797
ll::rotateSurface90Degrees(self.raw(), turns as c_int)
9898
};
@@ -104,23 +104,23 @@ impl<'a> RotozoomSurface for Surface<'a> {
104104
}
105105
}
106106

107-
pub fn get_zoom_size(width: isize, height: isize, zoomx: f64, zoomy: f64) -> (isize, isize) {
107+
pub fn get_zoom_size(width: i32, height: i32, zoomx: f64, zoomy: f64) -> (i32, i32) {
108108
let mut w: c_int = 0;
109109
let mut h: c_int = 0;
110110
unsafe { ll::zoomSurfaceSize(width as c_int, height as c_int, zoomx, zoomy, &mut w, &mut h) }
111-
(w as isize, h as isize)
111+
(w as i32, h as i32)
112112
}
113113

114-
pub fn get_rotozoom_size(width: isize, height: isize, angle: f64, zoom: f64) -> (isize, isize) {
114+
pub fn get_rotozoom_size(width: i32, height: i32, angle: f64, zoom: f64) -> (i32, i32) {
115115
let mut w: c_int = 0;
116116
let mut h: c_int = 0;
117117
unsafe { ll::rotozoomSurfaceSize(width as c_int, height as c_int, angle, zoom, &mut w, &mut h) }
118-
(w as isize, h as isize)
118+
(w as i32, h as i32)
119119
}
120120

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

0 commit comments

Comments
 (0)