fn event_from_sdl_event(event: &sdl2::event::Event) -> Option<Event> {
    use sdl2::event::{Event as SdlEvent, WindowEvent};

    match event {
        // window events are a seperate enum in sdl, but flattened in the engine
        // to make it easier to pattern match against
        SdlEvent::Window { win_event, .. } => match win_event {
            WindowEvent::FocusGained => Some(Event::FocusGained),
            WindowEvent::FocusLost => Some(Event::FocusLost),
            WindowEvent::Resized(width, height) => Some(Event::Resize {
                width: *width as u32,
                height: *height as u32,
            }),
            _ => None,
        },

        SdlEvent::KeyDown {
            scancode: Some(scancode),
            ..
        } => Some(Event::KeyDown {
            key: convert_scancode(*scancode)?,
        }),

        SdlEvent::KeyUp {
            scancode: Some(scancode),
            ..
        } => Some(Event::KeyUp {
            key: convert_scancode(*scancode)?,
        }),

        SdlEvent::MouseButtonDown { mouse_btn, .. } => Some(Event::MouseButton {
            state: MouseButtonState::Pressed,
            button: convert_mouse_button(*mouse_btn)?,
        }),

        SdlEvent::MouseButtonUp { mouse_btn, .. } => Some(Event::MouseButton {
            state: MouseButtonState::Released,
            button: convert_mouse_button(*mouse_btn)?,
        }),

        SdlEvent::TextInput { ref text, .. } => Some(Event::TextInput {
            text: text.to_owned(),
        }),

        SdlEvent::MouseWheel { x, y, .. } => Some(Event::Scroll { x: *x, y: *y }),

        SdlEvent::Quit { .. } => Some(Event::Quit),

        _ => None,
    }
}
/// Try to convert an sdl event into this engine's event type
Try to convert an sdl event into this engine's event type
Try to convert an sdl event into this engine ' s event type
fn event_from_sdl_event(event: &sdl2::event::Event) -> Option<Event> {
    use sdl2::event::{Event as SdlEvent, WindowEvent};
    match event {
        // window events are a seperate enum in sdl, but flattened in the engine
        // to make it easier to pattern match against
        SdlEvent::Window { win_event, .. } => match win_event {
            WindowEvent::FocusGained => Some(Event::FocusGained),
            WindowEvent::FocusLost => Some(Event::FocusLost),
            WindowEvent::Resized(width, height) => Some(Event::Resize {
                width: *width as u32,
                height: *height as u32,
            }),
            _ => None,
        },
        SdlEvent::KeyDown {
            scancode: Some(scancode),
            ..
        } => Some(Event::KeyDown {
            key: convert_scancode(*scancode)?,
        }),
        SdlEvent::KeyUp {
            scancode: Some(scancode),
            ..
        } => Some(Event::KeyUp {
            key: convert_scancode(*scancode)?,
        }),
        SdlEvent::MouseButtonDown { mouse_btn, .. } => Some(Event::MouseButton {
            state: MouseButtonState::Pressed,
            button: convert_mouse_button(*mouse_btn)?,
        }),
        SdlEvent::MouseButtonUp { mouse_btn, .. } => Some(Event::MouseButton {
            state: MouseButtonState::Released,
            button: convert_mouse_button(*mouse_btn)?,
        }),
        SdlEvent::TextInput { ref text, .. } => Some(Event::TextInput {
            text: text.to_owned(),
        }),
        SdlEvent::MouseWheel { x, y, .. } => Some(Event::Scroll { x: *x, y: *y }),
        SdlEvent::Quit { .. } => Some(Event::Quit),
        _ => None,
    }
}
fn event_from_sdl_event ( event : & sdl2 :: event :: Event ) -> Option < Event > { use sdl2 :: event :: { Event as SdlEvent , WindowEvent } ; match event { // window events are a seperate enum in sdl, but flattened in the engine // to make it easier to pattern match against SdlEvent :: Window { win_event , .. } => match win_event { WindowEvent :: FocusGained => Some ( Event :: FocusGained ) , WindowEvent :: FocusLost => Some ( Event :: FocusLost ) , WindowEvent :: Resized ( width , height ) => Some ( Event :: Resize { width : * width as u32 , height : * height as u32 , } ) , _ => None , } , SdlEvent :: KeyDown { scancode : Some ( scancode ) , .. } => Some ( Event :: KeyDown { key : convert_scancode ( * scancode ) ? , } ) , SdlEvent :: KeyUp { scancode : Some ( scancode ) , .. } => Some ( Event :: KeyUp { key : convert_scancode ( * scancode ) ? , } ) , SdlEvent :: MouseButtonDown { mouse_btn , .. } => Some ( Event :: MouseButton { state : MouseButtonState :: Pressed , button : convert_mouse_button ( * mouse_btn ) ? , } ) , SdlEvent :: MouseButtonUp { mouse_btn , .. } => Some ( Event :: MouseButton { state : MouseButtonState :: Released , button : convert_mouse_button ( * mouse_btn ) ? , } ) , SdlEvent :: TextInput { ref text , .. } => Some ( Event :: TextInput { text : text . to_owned ( ) , } ) , SdlEvent :: MouseWheel { x , y , .. } => Some ( Event :: Scroll { x : * x , y : * y } ) , SdlEvent :: Quit { .. } => Some ( Event :: Quit ) , _ => None , } }
Try to convert an sdl event into this engine's event type
Try to convert an sdl event into this engine ' s event type
event
&sdl2::event::Event
event
&sdl2::event::Event