Skip to content

Commit

Permalink
Merge pull request #103 from jcmoyer/bitflags
Browse files Browse the repository at this point in the history
Replace flags.rs with stdlib bitflags macro
  • Loading branch information
AngryLawyer committed May 15, 2014
2 parents aacc6d7 + add7ed7 commit c54c09a
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 222 deletions.
8 changes: 4 additions & 4 deletions src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ impl Event {
KeyDownEvent(event.timestamp as uint, window,
FromPrimitive::from_int(event.keysym.sym as int).unwrap(),
FromPrimitive::from_int(event.keysym.scancode as int).unwrap(),
keyboard::Mod::new(event.keysym._mod as SDL_Keymod))
keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod))
}
KeyUpEventType => {
let event = *raw.key();
Expand All @@ -774,7 +774,7 @@ impl Event {
KeyUpEvent(event.timestamp as uint, window,
FromPrimitive::from_int(event.keysym.sym as int).unwrap(),
FromPrimitive::from_int(event.keysym.scancode as int).unwrap(),
keyboard::Mod::new(event.keysym._mod as SDL_Keymod))
keyboard::Mod::from_bits(event.keysym._mod as SDL_Keymod))
}
TextEditingEventType => {
let event = *raw.edit();
Expand Down Expand Up @@ -813,7 +813,7 @@ impl Event {

MouseMotionEvent(event.timestamp as uint, window,
event.which as uint,
mouse::MouseState::new(event.state),
mouse::MouseState::from_bits(event.state),
event.x as int, event.y as int,
event.xrel as int, event.yrel as int)
}
Expand Down Expand Up @@ -874,7 +874,7 @@ impl Event {
let event = *raw.jhat();
JoyHatMotionEvent(event.timestamp as uint, event.which as int,
event.hat as int,
joystick::HatState::new(event.value))
joystick::HatState::from_bits(event.value))
}
JoyButtonDownEventType => {
let event = *raw.jbutton();
Expand Down
133 changes: 0 additions & 133 deletions src/sdl2/flags.rs

This file was deleted.

20 changes: 10 additions & 10 deletions src/sdl2/joystick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ pub mod ll {
}
}

flag_type!(HatState: u8 {
CenteredHatState = 0,
UpHatState = 0x01,
RightHatState = 0x02,
DownHatState = 0x04,
LeftHatState = 0x08,
RightUpHatState = 0x02 | 0x01, // RightHatState | UpHatState
RightDownHatState = 0x02 | 0x04, // RightHatState | DownHatState,
LeftUpHatState = 0x08 | 0x01, // LeftHatState | UpHatState,
LeftDownHatState = 0x08 | 0x04 // LeftHatState | DownHatState
bitflags!(flags HatState: u8 {
static CenteredHatState = 0,
static UpHatState = 0x01,
static RightHatState = 0x02,
static DownHatState = 0x04,
static LeftHatState = 0x08,
static RightUpHatState = 0x02 | 0x01, // RightHatState | UpHatState
static RightDownHatState = 0x02 | 0x04, // RightHatState | DownHatState,
static LeftUpHatState = 0x08 | 0x01, // LeftHatState | UpHatState,
static LeftDownHatState = 0x08 | 0x04 // LeftHatState | DownHatState
})
32 changes: 16 additions & 16 deletions src/sdl2/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ pub mod ll {
}
}

flag_type!(Mod {
NoMod = 0x0000,
LShiftMod = 0x0001,
RShiftMod = 0x0002,
LCtrlMod = 0x0040,
RCtrlMod = 0x0080,
LAltMod = 0x0100,
RAltMod = 0x0200,
LGuiMod = 0x0400,
RGuiMod = 0x0800,
NumMod = 0x1000,
CapsMod = 0x2000,
ModeMod = 0x4000,
ReservedMod = 0x8000
bitflags!(flags Mod: u32 {
static NoMod = 0x0000,
static LShiftMod = 0x0001,
static RShiftMod = 0x0002,
static LCtrlMod = 0x0040,
static RCtrlMod = 0x0080,
static LAltMod = 0x0100,
static RAltMod = 0x0200,
static LGuiMod = 0x0400,
static RGuiMod = 0x0800,
static NumMod = 0x1000,
static CapsMod = 0x2000,
static ModeMod = 0x4000,
static ReservedMod = 0x8000
})

pub fn get_keyboard_focus() -> Option<Window> {
Expand Down Expand Up @@ -93,11 +93,11 @@ pub fn get_keyboard_state() -> HashMap<ScanCode, bool> {
}

pub fn get_mod_state() -> Mod {
unsafe { Mod::new(ll::SDL_GetModState()) }
unsafe { Mod::from_bits(ll::SDL_GetModState()) }
}

pub fn set_mod_state(flags: Mod) {
unsafe { ll::SDL_SetModState(flags.get()); }
unsafe { ll::SDL_SetModState(flags.bits()); }
}

pub fn get_key_from_scancode(scancode: ScanCode) -> KeyCode {
Expand Down
1 change: 0 additions & 1 deletion src/sdl2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod keycode;
#[path = "generated/scancode.rs"]
pub mod scancode;

pub mod flags;
pub mod event;
pub mod gesture;
pub mod touch;
Expand Down
26 changes: 14 additions & 12 deletions src/sdl2/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ pub enum Mouse {
UnknownMouse(u8)
}

flag_type!(MouseState {
LeftMouseState = 0x01,
MiddleMouseState = 0x02,
RightMouseState = 0x04,
X1MouseState = 0x08,
X2MouseState = 0x10
bitflags!(flags MouseState: u32 {
static LeftMouseState = 0x01,
static MiddleMouseState = 0x02,
static RightMouseState = 0x04,
static X1MouseState = 0x08,
static X2MouseState = 0x10
})

pub fn wrap_mouse(bitflags: u8) -> Mouse {
Expand All @@ -173,17 +173,19 @@ pub fn get_mouse_focus() -> Option<video::Window> {
pub fn get_mouse_state() -> (MouseState, int, int) {
let x = 0;
let y = 0;
let raw = unsafe { ll::SDL_GetMouseState(&x, &y) };

return (MouseState::new(raw), x as int, y as int);
unsafe {
let raw = ll::SDL_GetMouseState(&x, &y);
return (MouseState::from_bits(raw), x as int, y as int);
}
}

pub fn get_relative_mouse_state() -> (MouseState, int, int) {
let x = 0;
let y = 0;
let raw = unsafe { ll::SDL_GetRelativeMouseState(&x, &y) };

return (MouseState::new(raw), x as int, y as int);
unsafe {
let raw = ll::SDL_GetRelativeMouseState(&x, &y);
return (MouseState::from_bits(raw), x as int, y as int);
}
}

pub fn warp_mouse_in_window(window: &video::Window, x: i32, y: i32) {
Expand Down
16 changes: 8 additions & 8 deletions src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ pub enum TextureAccess {
AccessTarget = ll::SDL_TEXTUREACCESS_TARGET as int
}

flag_type!(RendererFlags {
Software = ll::SDL_RENDERER_SOFTWARE,
Accelerated = ll::SDL_RENDERER_ACCELERATED,
PresentVSync = ll::SDL_RENDERER_PRESENTVSYNC,
TargetTexture = ll::SDL_RENDERER_TARGETTEXTURE
bitflags!(flags RendererFlags: u32 {
static Software = ll::SDL_RENDERER_SOFTWARE as u32,
static Accelerated = ll::SDL_RENDERER_ACCELERATED as u32,
static PresentVSync = ll::SDL_RENDERER_PRESENTVSYNC as u32,
static TargetTexture = ll::SDL_RENDERER_TARGETTEXTURE as u32
})

#[deriving(Eq)]
Expand Down Expand Up @@ -180,7 +180,7 @@ pub enum RendererFlip {

impl RendererInfo {
pub fn from_ll(info: &ll::SDL_RendererInfo) -> RendererInfo {
let actual_flags = RendererFlags::new(info.flags);
let actual_flags = unsafe { RendererFlags::from_bits(info.flags) };

unsafe {
let texture_formats: Vec<pixels::PixelFormatFlag> = info.texture_formats.slice(0, info.num_texture_formats as uint).iter().map(|&format| {
Expand Down Expand Up @@ -229,7 +229,7 @@ impl Renderer {
};

let raw = unsafe {
ll::SDL_CreateRenderer(window.raw, index as c_int, renderer_flags.get())
ll::SDL_CreateRenderer(window.raw, index as c_int, renderer_flags.bits())
};

if raw == ptr::null() {
Expand All @@ -242,7 +242,7 @@ impl Renderer {
pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result<Renderer, ~str> {
let raw_window: *video::ll::SDL_Window = ptr::null();
let raw_renderer: *ll::SDL_Renderer = ptr::null();
let result = unsafe { ll::SDL_CreateWindowAndRenderer(width as c_int, height as c_int, window_flags.get(), &raw_window, &raw_renderer) == 0};
let result = unsafe { ll::SDL_CreateWindowAndRenderer(width as c_int, height as c_int, window_flags.bits(), &raw_window, &raw_renderer) == 0};
if result {
let window = video::Window {
raw: raw_window,
Expand Down
Loading

0 comments on commit c54c09a

Please sign in to comment.