Gosu
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Gosu::Input Class Reference

Manages initialization and shutdown of the input system. More...

Public Member Functions

 Input (void *window)
 
bool feed_sdl_event (void *event)
 
 ~Input ()
 
double mouse_x () const
 Returns the horizontal position of the mouse relative to the top left corner of the window given to Input's constructor. More...
 
double mouse_y () const
 See mouse_x. More...
 
void set_mouse_position (double x, double y)
 Immediately moves the mouse as far towards the desired position as possible. More...
 
void set_mouse_factors (double factor_x, double factor_y, double offset_x=0, double offset_y=0)
 
const Touchescurrent_touches () const
 Currently known touches. More...
 
GOSU_DEPRECATED double accelerometer_x () const
 Accelerometer positions in all three dimensions (smoothened). More...
 
GOSU_DEPRECATED double accelerometer_y () const
 
GOSU_DEPRECATED double accelerometer_z () const
 
void update ()
 Collects new information about which buttons are pressed, where the mouse is and calls on_button_up/on_button_down, if assigned. More...
 
TextInputtext_input () const
 Returns the currently active TextInput instance, or nullptr. More...
 
void set_text_input (TextInput *input)
 Sets the currently active TextInput, or resets it to the nullptr. More...
 

Static Public Member Functions

static std::string id_to_char (Button btn)
 Returns the character (as a UTF-8 encoded string) that a button usually produces. More...
 
static Button char_to_id (std::string ch)
 Returns the button that has to be pressed to produce the given character (as a UTF-8 encoded string), or NO_BUTTON. More...
 
static bool down (Button btn)
 Returns true if a button is currently pressed. More...
 

Public Attributes

std::function< void(Button)> on_button_down
 Assignable events that are called by update. More...
 
std::function< void(Button)> on_button_up
 
std::function< void(Touch)> on_touch_began
 Assignable events that are called by update. More...
 
std::function< void(Touch)> on_touch_moved
 
std::function< void(Touch)> on_touch_ended
 
std::function< void(Touch)> on_touch_cancelled
 

Detailed Description

Manages initialization and shutdown of the input system.

Only one Input instance can exist per application.

Definition at line 53 of file Input.hpp.

Constructor & Destructor Documentation

◆ Input()

Gosu::Input::Input ( void *  window)

◆ ~Input()

Gosu::Input::~Input ( )

Member Function Documentation

◆ accelerometer_x()

GOSU_DEPRECATED double Gosu::Input::accelerometer_x ( ) const

Accelerometer positions in all three dimensions (smoothened).

Note: Not really deprecated, but temporarily defunct.

◆ accelerometer_y()

GOSU_DEPRECATED double Gosu::Input::accelerometer_y ( ) const

◆ accelerometer_z()

GOSU_DEPRECATED double Gosu::Input::accelerometer_z ( ) const

◆ char_to_id()

static Button Gosu::Input::char_to_id ( std::string  ch)
static

Returns the button that has to be pressed to produce the given character (as a UTF-8 encoded string), or NO_BUTTON.

◆ current_touches()

const Touches& Gosu::Input::current_touches ( ) const

Currently known touches.

◆ down()

static bool Gosu::Input::down ( Button  btn)
static

Returns true if a button is currently pressed.

Updated every tick.

◆ feed_sdl_event()

bool Gosu::Input::feed_sdl_event ( void *  event)

◆ id_to_char()

static std::string Gosu::Input::id_to_char ( Button  btn)
static

Returns the character (as a UTF-8 encoded string) that a button usually produces.

Returns the empty string if nothing can be found.

◆ mouse_x()

double Gosu::Input::mouse_x ( ) const

Returns the horizontal position of the mouse relative to the top left corner of the window given to Input's constructor.

◆ mouse_y()

double Gosu::Input::mouse_y ( ) const

See mouse_x.

◆ set_mouse_factors()

void Gosu::Input::set_mouse_factors ( double  factor_x,
double  factor_y,
double  offset_x = 0,
double  offset_y = 0 
)

◆ set_mouse_position()

void Gosu::Input::set_mouse_position ( double  x,
double  y 
)

Immediately moves the mouse as far towards the desired position as possible.

x and y are relative to the window, just as in mouse_x() and mouse_y(), so (0, 0) is the top left corner of the window..

◆ set_text_input()

void Gosu::Input::set_text_input ( TextInput input)

Sets the currently active TextInput, or resets it to the nullptr.

◆ text_input()

TextInput* Gosu::Input::text_input ( ) const

Returns the currently active TextInput instance, or nullptr.

◆ update()

void Gosu::Input::update ( )

Collects new information about which buttons are pressed, where the mouse is and calls on_button_up/on_button_down, if assigned.

Member Data Documentation

◆ on_button_down

std::function<void (Button)> Gosu::Input::on_button_down

Assignable events that are called by update.

You can bind these to your own functions. If you use the Window class, it will assign these to its own methods.

Definition at line 111 of file Input.hpp.

◆ on_button_up

std::function<void (Button)> Gosu::Input::on_button_up

Definition at line 111 of file Input.hpp.

◆ on_touch_began

std::function<void (Touch)> Gosu::Input::on_touch_began

Assignable events that are called by update.

You can bind these to your own functions. If you use the Window class, it will assign these to its own methods.

Definition at line 115 of file Input.hpp.

◆ on_touch_cancelled

std::function<void (Touch)> Gosu::Input::on_touch_cancelled

Definition at line 115 of file Input.hpp.

◆ on_touch_ended

std::function<void (Touch)> Gosu::Input::on_touch_ended

Definition at line 115 of file Input.hpp.

◆ on_touch_moved

std::function<void (Touch)> Gosu::Input::on_touch_moved

Definition at line 115 of file Input.hpp.


The documentation for this class was generated from the following file: