Gosu
Input.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Gosu/Fwd.hpp>
4 #include <Gosu/Buttons.hpp>
5 #include <Gosu/Platform.hpp>
6 #include <Gosu/Utility.hpp>
7 #include <functional>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 namespace Gosu
13 {
16  struct Touch
17  {
19  void* id;
21  double x, y;
22  };
23  typedef std::vector<Touch> Touches;
24 
28  {
29  struct Impl;
30  std::unique_ptr<Impl> pimpl;
31 
32  public:
33  #ifdef GOSU_IS_IPHONE
34  Input(void* view, float update_interval);
35  void feed_touch_event(std::function<void (Touch)>& callback, void* touches);
36  #else
37  explicit Input(void* window);
38  bool feed_sdl_event(void* event);
39  #endif
40 
41  ~Input();
42 
45  static std::string id_to_char(Button btn);
48  static Button char_to_id(std::string ch);
49 
52  static std::string button_name(Button btn);
53 
56  static std::string gamepad_name(int index);
57 
60  static bool down(Button btn);
61 
65  static double axis(Button btn);
66 
69  double mouse_x() const;
71  double mouse_y() const;
72 
76  void set_mouse_position(double x, double y);
77 
78  // Undocumented for the moment. Also applies to current_touches().
79  void set_mouse_factors(double factor_x, double factor_y,
80  double offset_x = 0, double offset_y = 0);
81 
83  const Touches& current_touches() const;
84 
87  GOSU_DEPRECATED double accelerometer_x() const;
88  GOSU_DEPRECATED double accelerometer_y() const;
89  GOSU_DEPRECATED double accelerometer_z() const;
90 
93  void update();
94 
97  std::function<void (Button)> on_button_down, on_button_up;
98 
99  std::function<void (int)> on_gamepad_connected, on_gamepad_disconnected;
100 
103  std::function<void (Touch)> on_touch_began, on_touch_moved, on_touch_ended,
104  on_touch_cancelled;
105 
107  TextInput* text_input() const;
109  void set_text_input(TextInput* input);
110  };
111 }
double y
Definition: Input.hpp:21
#define GOSU_DEPRECATED
Definition: Platform.hpp:69
Definition: Audio.hpp:12
Manages initialization and shutdown of the input system.
Definition: Input.hpp:27
std::function< void(int)> on_gamepad_disconnected
Definition: Input.hpp:99
Struct that saves information about a touch on the surface of a multi-touch device.
Definition: Input.hpp:16
std::function< void(Touch)> on_touch_moved
Definition: Input.hpp:103
std::function< void(Button)> on_button_up
Definition: Input.hpp:97
double x
Position of a touch on the touch screen.
Definition: Input.hpp:21
std::vector< Touch > Touches
Definition: Input.hpp:23
double offset_x(double angle, double radius)
Returns the horizontal distance between the origin and the point to which you would get if you moved ...
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void * id
Allows for identification of a touch across calls.
Definition: Input.hpp:19
Button
List of button IDs that can be used with Gosu::Input.
Definition: Buttons.hpp:8
TextInput instances are invisible objects that build a text string from input, using the current oper...
Definition: TextInput.hpp:21
double offset_y(double angle, double radius)
Returns the vertical distance between the origin and the point to which you would get if you moved ra...