Skip to content

Commit ac9b2bf

Browse files
reimacaryhaynie
authored andcommitted
Refer to enum variants with their full name (see rust-lang/rust#18973).
1 parent 0533a57 commit ac9b2bf

File tree

10 files changed

+383
-354
lines changed

10 files changed

+383
-354
lines changed

src/sdl2/audio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ pub enum AudioDevice{
259259
impl AudioDevice {
260260
fn to_id(self) -> AudioDeviceID {
261261
match self {
262-
PlaybackDevice(id) => id,
263-
RecordingDevice(id) => id
262+
AudioDevice::PlaybackDevice(id) => id,
263+
AudioDevice::RecordingDevice(id) => id
264264
}
265265
}
266266

@@ -282,9 +282,9 @@ impl AudioDevice {
282282
Err(get_error())
283283
} else {
284284
if iscapture == 0 { // plaback device
285-
Ok((PlaybackDevice(ret as AudioDeviceID), obtained))
285+
Ok((AudioDevice::PlaybackDevice(ret as AudioDeviceID), obtained))
286286
} else {
287-
Ok((RecordingDevice(ret as AudioDeviceID), obtained))
287+
Ok((AudioDevice::RecordingDevice(ret as AudioDeviceID), obtained))
288288
}
289289
}
290290
}

src/sdl2/controller.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ pub enum ControllerAxis {
140140

141141
pub fn wrap_controller_axis(bitflags: u8) -> ControllerAxis {
142142
match bitflags as c_int {
143-
ll::SDL_CONTROLLER_AXIS_LEFTX => LeftXAxis,
144-
ll::SDL_CONTROLLER_AXIS_LEFTY => LeftYAxis,
145-
ll::SDL_CONTROLLER_AXIS_RIGHTX => RightXAxis,
146-
ll::SDL_CONTROLLER_AXIS_RIGHTY => RightYAxis,
147-
ll::SDL_CONTROLLER_AXIS_TRIGGERLEFT => TriggerLeftAxis,
148-
ll::SDL_CONTROLLER_AXIS_TRIGGERRIGHT => TriggerRightAxis,
143+
ll::SDL_CONTROLLER_AXIS_LEFTX => ControllerAxis::LeftXAxis,
144+
ll::SDL_CONTROLLER_AXIS_LEFTY => ControllerAxis::LeftYAxis,
145+
ll::SDL_CONTROLLER_AXIS_RIGHTX => ControllerAxis::RightXAxis,
146+
ll::SDL_CONTROLLER_AXIS_RIGHTY => ControllerAxis::RightYAxis,
147+
ll::SDL_CONTROLLER_AXIS_TRIGGERLEFT => ControllerAxis::TriggerLeftAxis,
148+
ll::SDL_CONTROLLER_AXIS_TRIGGERRIGHT => ControllerAxis::TriggerRightAxis,
149149
_ => panic!("unhandled controller axis")
150150
}
151151
}
@@ -173,21 +173,21 @@ pub enum ControllerButton {
173173

174174
pub fn wrap_controller_button(bitflags: u8) -> ControllerButton {
175175
match bitflags as c_int {
176-
ll::SDL_CONTROLLER_BUTTON_A => AButton,
177-
ll::SDL_CONTROLLER_BUTTON_B => BButton,
178-
ll::SDL_CONTROLLER_BUTTON_X => XButton,
179-
ll::SDL_CONTROLLER_BUTTON_Y => YButton,
180-
ll::SDL_CONTROLLER_BUTTON_BACK => BackButton,
181-
ll::SDL_CONTROLLER_BUTTON_GUIDE => GuideButton,
182-
ll::SDL_CONTROLLER_BUTTON_START => StartButton,
183-
ll::SDL_CONTROLLER_BUTTON_LEFTSTICK => LeftStickButton,
184-
ll::SDL_CONTROLLER_BUTTON_RIGHTSTICK => RightStickButton,
185-
ll::SDL_CONTROLLER_BUTTON_LEFTSHOULDER => LeftShoulderButton,
186-
ll::SDL_CONTROLLER_BUTTON_RIGHTSHOULDER => RightShoulderButton,
187-
ll::SDL_CONTROLLER_BUTTON_DPAD_UP => DPadUpButton,
188-
ll::SDL_CONTROLLER_BUTTON_DPAD_DOWN => DPadDownButton,
189-
ll::SDL_CONTROLLER_BUTTON_DPAD_LEFT => DPadLeftButton,
190-
ll::SDL_CONTROLLER_BUTTON_DPAD_RIGHT => DPadRightButton,
176+
ll::SDL_CONTROLLER_BUTTON_A => ControllerButton::AButton,
177+
ll::SDL_CONTROLLER_BUTTON_B => ControllerButton::BButton,
178+
ll::SDL_CONTROLLER_BUTTON_X => ControllerButton::XButton,
179+
ll::SDL_CONTROLLER_BUTTON_Y => ControllerButton::YButton,
180+
ll::SDL_CONTROLLER_BUTTON_BACK => ControllerButton::BackButton,
181+
ll::SDL_CONTROLLER_BUTTON_GUIDE => ControllerButton::GuideButton,
182+
ll::SDL_CONTROLLER_BUTTON_START => ControllerButton::StartButton,
183+
ll::SDL_CONTROLLER_BUTTON_LEFTSTICK => ControllerButton::LeftStickButton,
184+
ll::SDL_CONTROLLER_BUTTON_RIGHTSTICK => ControllerButton::RightStickButton,
185+
ll::SDL_CONTROLLER_BUTTON_LEFTSHOULDER => ControllerButton::LeftShoulderButton,
186+
ll::SDL_CONTROLLER_BUTTON_RIGHTSHOULDER => ControllerButton::RightShoulderButton,
187+
ll::SDL_CONTROLLER_BUTTON_DPAD_UP => ControllerButton::DPadUpButton,
188+
ll::SDL_CONTROLLER_BUTTON_DPAD_DOWN => ControllerButton::DPadDownButton,
189+
ll::SDL_CONTROLLER_BUTTON_DPAD_LEFT => ControllerButton::DPadLeftButton,
190+
ll::SDL_CONTROLLER_BUTTON_DPAD_RIGHT => ControllerButton::DPadRightButton,
191191
_ => panic!("unhandled controller button")
192192
}
193193
}

src/sdl2/event.rs

Lines changed: 221 additions & 212 deletions
Large diffs are not rendered by default.

src/sdl2/keyboard.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::ptr;
44
use std::string;
55
use std::vec;
66

7-
use keycode::{KeyCode, UnknownKey};
7+
use keycode::KeyCode;
88
use rect::Rect;
9-
use scancode::{ScanCode, UnknownScanCode};
9+
use scancode::ScanCode;
1010
use video::Window;
1111

1212
#[allow(non_camel_case_types)]
@@ -87,7 +87,7 @@ pub fn get_keyboard_state() -> HashMap<ScanCode, bool> {
8787
let mut current = 0;
8888
while current < raw.len() {
8989
state.insert(FromPrimitive::from_int(current as int)
90-
.unwrap_or(UnknownScanCode),
90+
.unwrap_or(ScanCode::UnknownScanCode),
9191
raw[current] == 1);
9292
current += 1;
9393
}
@@ -106,14 +106,14 @@ pub fn set_mod_state(flags: Mod) {
106106
pub fn get_key_from_scancode(scancode: ScanCode) -> KeyCode {
107107
unsafe {
108108
FromPrimitive::from_int(ll::SDL_GetKeyFromScancode(scancode as u32) as int)
109-
.unwrap_or(UnknownKey)
109+
.unwrap_or(KeyCode::UnknownKey)
110110
}
111111
}
112112

113113
pub fn get_scancode_from_key(key: KeyCode) -> ScanCode {
114114
unsafe {
115115
FromPrimitive::from_int(ll::SDL_GetScancodeFromKey(key as i32) as int)
116-
.unwrap_or(UnknownScanCode)
116+
.unwrap_or(ScanCode::UnknownScanCode)
117117
}
118118
}
119119

@@ -128,7 +128,7 @@ pub fn get_scancode_from_name(name: &str) -> ScanCode {
128128
unsafe {
129129
name.with_c_str(|name| {
130130
FromPrimitive::from_int(ll::SDL_GetScancodeFromName(name) as int)
131-
.unwrap_or(UnknownScanCode)
131+
.unwrap_or(ScanCode::UnknownScanCode)
132132
})
133133
}
134134
}
@@ -144,7 +144,7 @@ pub fn get_key_from_name(name: &str) -> KeyCode {
144144
unsafe {
145145
name.with_c_str(|name| {
146146
FromPrimitive::from_int(ll::SDL_GetKeyFromName(name) as int)
147-
.unwrap_or(UnknownKey)
147+
.unwrap_or(KeyCode::UnknownKey)
148148
})
149149
}
150150
}

src/sdl2/messagebox.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub mod ll {
2020

2121
bitflags! {
2222
flags MessageBoxFlag: u32 {
23-
const MESSAGEBOX_ERROR = ll::SDL_MESSAGEBOX_ERROR as u32,
24-
const MESSAGEBOX_WARNING = ll::SDL_MESSAGEBOX_WARNING as u32,
25-
const MESSAGEBOX_INFORMATION = ll::SDL_MESSAGEBOX_INFORMATION as u32
23+
const MESSAGEBOX_ERROR = ll::SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR as u32,
24+
const MESSAGEBOX_WARNING = ll::SDL_MessageBoxFlags::SDL_MESSAGEBOX_WARNING as u32,
25+
const MESSAGEBOX_INFORMATION = ll::SDL_MessageBoxFlags::SDL_MESSAGEBOX_INFORMATION as u32
2626
}
2727
}
2828

src/sdl2/mouse.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ bitflags! {
157157

158158
pub fn wrap_mouse(bitflags: u8) -> Mouse {
159159
match bitflags {
160-
1 => LeftMouse,
161-
2 => MiddleMouse,
162-
3 => RightMouse,
163-
4 => X1Mouse,
164-
5 => X2Mouse,
165-
_ => UnknownMouse(bitflags)
160+
1 => Mouse::LeftMouse,
161+
2 => Mouse::MiddleMouse,
162+
3 => Mouse::RightMouse,
163+
4 => Mouse::X1Mouse,
164+
5 => Mouse::X2Mouse,
165+
_ => Mouse::UnknownMouse(bitflags)
166166
}
167167
}
168168

src/sdl2/pixels.rs

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ pub enum Color {
106106
impl Color {
107107
pub fn to_u32(&self, format: &PixelFormat) -> u32 {
108108
match self {
109-
&RGB(r, g, b) => {
109+
&Color::RGB(r, g, b) => {
110110
unsafe { ll::SDL_MapRGB(format.raw, r, g, b) }
111111
}
112-
&RGBA(r, g, b, a) => {
112+
&Color::RGBA(r, g, b, a) => {
113113
unsafe { ll::SDL_MapRGBA(format.raw, r, g, b, a) }
114114
}
115115
}
@@ -124,21 +124,21 @@ impl Color {
124124
unsafe {
125125
ll::SDL_GetRGBA(pixel, format.raw, &r, &g, &b, &a)
126126
};
127-
RGBA(r, g, b, a)
127+
Color::RGBA(r, g, b, a)
128128
}
129129

130130
pub fn get_rgb(&self) -> (u8, u8, u8) {
131131
match self {
132-
&RGB(r, g, b) => (r, g, b),
133-
&RGBA(r, g, b, _) => (r, g, b)
132+
&Color::RGB(r, g, b) => (r, g, b),
133+
&Color::RGBA(r, g, b, _) => (r, g, b)
134134
}
135135
}
136136
}
137137

138138
impl rand::Rand for Color {
139139
fn rand<R: rand::Rng>(rng: &mut R) -> Color {
140-
if rng.gen() { RGBA(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
141-
else { RGB(rng.gen(), rng.gen(), rng.gen()) }
140+
if rng.gen() { Color::RGBA(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
141+
else { Color::RGB(rng.gen(), rng.gen(), rng.gen()) }
142142
}
143143
}
144144

@@ -193,53 +193,73 @@ pub enum PixelFormatFlag {
193193
impl PixelFormatFlag {
194194
pub fn byte_size_of_pixels(&self, num_of_pixels: uint) -> uint {
195195
match *self {
196-
RGB332
196+
PixelFormatFlag::RGB332
197197
=> num_of_pixels * 1,
198-
RGB444 | RGB555 | BGR555 | ARGB4444 | RGBA4444 | ABGR4444 |
199-
BGRA4444 | ARGB1555 | RGBA5551 | ABGR1555 | BGRA5551 | RGB565 |
200-
BGR565
198+
PixelFormatFlag::RGB444 | PixelFormatFlag::RGB555 |
199+
PixelFormatFlag::BGR555 | PixelFormatFlag::ARGB4444 |
200+
PixelFormatFlag::RGBA4444 | PixelFormatFlag::ABGR4444 |
201+
PixelFormatFlag::BGRA4444 | PixelFormatFlag::ARGB1555 |
202+
PixelFormatFlag::RGBA5551 | PixelFormatFlag::ABGR1555 |
203+
PixelFormatFlag::BGRA5551 | PixelFormatFlag::RGB565 |
204+
PixelFormatFlag::BGR565
201205
=> num_of_pixels * 2,
202-
RGB24 | BGR24
206+
PixelFormatFlag::RGB24 | PixelFormatFlag::BGR24
203207
=> num_of_pixels * 3,
204-
RGB888 | RGBX8888 | BGR888 | BGRX8888 | ARGB8888 | RGBA8888 |
205-
ABGR8888 | BGRA8888 | ARGB2101010
208+
PixelFormatFlag::RGB888 | PixelFormatFlag::RGBX8888 |
209+
PixelFormatFlag::BGR888 | PixelFormatFlag::BGRX8888 |
210+
PixelFormatFlag::ARGB8888 | PixelFormatFlag::RGBA8888 |
211+
PixelFormatFlag::ABGR8888 | PixelFormatFlag::BGRA8888 |
212+
PixelFormatFlag::ARGB2101010
206213
=> num_of_pixels * 4,
207214
// YUV formats
208215
// FIXME: rounding error here?
209-
YV12 | IYUV
216+
PixelFormatFlag::YV12 | PixelFormatFlag::IYUV
210217
=> num_of_pixels / 2 * 3,
211-
YUY2 | UYVY | YVYU
218+
PixelFormatFlag::YUY2 | PixelFormatFlag::UYVY |
219+
PixelFormatFlag::YVYU
212220
=> num_of_pixels * 2,
213221
// Unsupported formats
214-
Index8
222+
PixelFormatFlag::Index8
215223
=> num_of_pixels * 1,
216-
Unknown | Index1LSB | Index1MSB | Index4LSB | Index4MSB
224+
PixelFormatFlag::Unknown | PixelFormatFlag::Index1LSB |
225+
PixelFormatFlag::Index1MSB | PixelFormatFlag::Index4LSB |
226+
PixelFormatFlag::Index4MSB
217227
=> panic!("not supported format: {}", *self),
218228
}
219229
}
220230

221231
pub fn byte_size_per_pixel(&self) -> uint {
222232
match *self {
223-
RGB332
233+
PixelFormatFlag::RGB332
224234
=> 1,
225-
RGB444 | RGB555 | BGR555 | ARGB4444 | RGBA4444 | ABGR4444 |
226-
BGRA4444 | ARGB1555 | RGBA5551 | ABGR1555 | BGRA5551 | RGB565 |
227-
BGR565
235+
PixelFormatFlag::RGB444 | PixelFormatFlag::RGB555 |
236+
PixelFormatFlag::BGR555 | PixelFormatFlag::ARGB4444 |
237+
PixelFormatFlag::RGBA4444 | PixelFormatFlag::ABGR4444 |
238+
PixelFormatFlag::BGRA4444 | PixelFormatFlag::ARGB1555 |
239+
PixelFormatFlag::RGBA5551 | PixelFormatFlag::ABGR1555 |
240+
PixelFormatFlag::BGRA5551 | PixelFormatFlag::RGB565 |
241+
PixelFormatFlag::BGR565
228242
=> 2,
229-
RGB24 | BGR24
243+
PixelFormatFlag::RGB24 | PixelFormatFlag::BGR24
230244
=> 3,
231-
RGB888 | RGBX8888 | BGR888 | BGRX8888 | ARGB8888 | RGBA8888 |
232-
ABGR8888 | BGRA8888 | ARGB2101010
245+
PixelFormatFlag::RGB888 | PixelFormatFlag::RGBX8888 |
246+
PixelFormatFlag::BGR888 | PixelFormatFlag::BGRX8888 |
247+
PixelFormatFlag::ARGB8888 | PixelFormatFlag::RGBA8888 |
248+
PixelFormatFlag::ABGR8888 | PixelFormatFlag::BGRA8888 |
249+
PixelFormatFlag::ARGB2101010
233250
=> 4,
234251
// YUV formats
235-
YV12 | IYUV
252+
PixelFormatFlag::YV12 | PixelFormatFlag::IYUV
236253
=> 2,
237-
YUY2 | UYVY | YVYU
254+
PixelFormatFlag::YUY2 | PixelFormatFlag::UYVY |
255+
PixelFormatFlag::YVYU
238256
=> 2,
239257
// Unsupported formats
240-
Index8
258+
PixelFormatFlag::Index8
241259
=> 1,
242-
Unknown | Index1LSB | Index1MSB | Index4LSB | Index4MSB
260+
PixelFormatFlag::Unknown | PixelFormatFlag::Index1LSB |
261+
PixelFormatFlag::Index1MSB | PixelFormatFlag::Index4LSB |
262+
PixelFormatFlag::Index4MSB
243263
=> panic!("not supported format: {}", *self),
244264
}
245265
}

0 commit comments

Comments
 (0)