Trait ggez::event::EventHandler
[−]
[src]
pub trait EventHandler { fn update(&mut self, _ctx: &mut Context) -> GameResult<()>; fn draw(&mut self, _ctx: &mut Context) -> GameResult<()>; fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: i32,
_y: i32
) { ... } fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: i32,
_y: i32
) { ... } fn mouse_motion_event(
&mut self,
_ctx: &mut Context,
_state: MouseState,
_x: i32,
_y: i32,
_xrel: i32,
_yrel: i32
) { ... } fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: i32, _y: i32) { ... } fn key_down_event(
&mut self,
ctx: &mut Context,
keycode: Keycode,
_keymod: Mod,
_repeat: bool
) { ... } fn key_up_event(
&mut self,
_ctx: &mut Context,
_keycode: Keycode,
_keymod: Mod,
_repeat: bool
) { ... } fn text_editing_event(
&mut self,
_ctx: &mut Context,
_text: String,
_start: i32,
_length: i32
) { ... } fn text_input_event(&mut self, _ctx: &mut Context, _text: String) { ... } fn controller_button_down_event(
&mut self,
_ctx: &mut Context,
_btn: Button,
_instance_id: i32
) { ... } fn controller_button_up_event(
&mut self,
_ctx: &mut Context,
_btn: Button,
_instance_id: i32
) { ... } fn controller_axis_event(
&mut self,
_ctx: &mut Context,
_axis: Axis,
_value: i16,
_instance_id: i32
) { ... } fn focus_event(&mut self, _ctx: &mut Context, _gained: bool) { ... } fn quit_event(&mut self, _ctx: &mut Context) -> bool { ... } fn resize_event(&mut self, _ctx: &mut Context, _width: u32, _height: u32) { ... } }
A trait defining event callbacks; your primary interface with
ggez
's event loop. Have a type implement this trait and
override at least the update() and draw() methods, then pass it to
event::run()
to run the game's mainloop.
The default event handlers do nothing, apart from
key_down_event()
, which will by default exit the game if escape
is pressed. Just override the methods you want to do things with.
Required Methods
fn update(&mut self, _ctx: &mut Context) -> GameResult<()>
Called upon each physics update to the game. This should be where the game's logic takes place.
fn draw(&mut self, _ctx: &mut Context) -> GameResult<()>
Called to do the drawing of your game.
You probably want to start this with
graphics::clear()
and end it with
graphics::present()
and timer::yield_now()
Provided Methods
A mouse button was pressed
A mouse button was released
fn mouse_motion_event(
&mut self,
_ctx: &mut Context,
_state: MouseState,
_x: i32,
_y: i32,
_xrel: i32,
_yrel: i32
)
&mut self,
_ctx: &mut Context,
_state: MouseState,
_x: i32,
_y: i32,
_xrel: i32,
_yrel: i32
)
The mouse was moved; it provides both absolute x and y coordinates in the window, and relative x and y coordinates compared to its last position.
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: i32, _y: i32)
The mousewheel was scrolled, vertically (y, positive away from and negative toward the user) or horizontally (x, positive to the right and negative to the left).
fn key_down_event(
&mut self,
ctx: &mut Context,
keycode: Keycode,
_keymod: Mod,
_repeat: bool
)
&mut self,
ctx: &mut Context,
keycode: Keycode,
_keymod: Mod,
_repeat: bool
)
A keyboard button was pressed.
fn key_up_event(
&mut self,
_ctx: &mut Context,
_keycode: Keycode,
_keymod: Mod,
_repeat: bool
)
&mut self,
_ctx: &mut Context,
_keycode: Keycode,
_keymod: Mod,
_repeat: bool
)
A keyboard button was released.
fn text_editing_event(
&mut self,
_ctx: &mut Context,
_text: String,
_start: i32,
_length: i32
)
&mut self,
_ctx: &mut Context,
_text: String,
_start: i32,
_length: i32
)
Candidate text is passed by the OS (via Input Method Editor). Refer to: https://wiki.libsdl.org/SDL_TextEditingEvent https://wiki.libsdl.org/SDL_TextInputEvent https://wiki.libsdl.org/Tutorials/TextInput
fn text_input_event(&mut self, _ctx: &mut Context, _text: String)
Resulting text (usually a unicode character) is passed by the OS (via Input Method Editor). Refer to: https://wiki.libsdl.org/SDL_TextEditingEvent https://wiki.libsdl.org/SDL_TextInputEvent https://wiki.libsdl.org/Tutorials/TextInput
A controller button was pressed; instance_id identifies which controller.
A controller button was released.
fn controller_axis_event(
&mut self,
_ctx: &mut Context,
_axis: Axis,
_value: i16,
_instance_id: i32
)
&mut self,
_ctx: &mut Context,
_axis: Axis,
_value: i16,
_instance_id: i32
)
A controller axis moved.
fn focus_event(&mut self, _ctx: &mut Context, _gained: bool)
Called when the window is shown or hidden.
fn quit_event(&mut self, _ctx: &mut Context) -> bool
Called upon a quit event. If it returns true, the game does not exit.
fn resize_event(&mut self, _ctx: &mut Context, _width: u32, _height: u32)
Called when the user resizes the window.
Is not called when you resize it yourself with
graphics::set_mode()
though.