6 #include <unordered_map>
7 #include "../generic/property.h"
8 #include "../generic/managed.h"
9 #include "../keycodes.h"
10 #include "../signals/signal.h"
11 #include "../event_listener.h"
24 typedef std::function<void (InputAxis*)> EachAxisCallback;
25 typedef std::vector<InputAxis*> AxisList;
33 KeyboardCode keyboard_code = KEYBOARD_CODE_NONE;
40 bool cancelled =
false;
45 enum JoystickButton : int8_t;
64 InputAxis* new_axis(
const std::string& name);
65 AxisList axises(
const std::string& name);
66 void each_axis(EachAxisCallback callback);
67 void destroy_axises(
const std::string& name);
69 std::size_t axis_count(
const std::string& name)
const;
71 float axis_value(
const std::string& name)
const;
72 int8_t axis_value_hard(
const std::string& name)
const;
74 void update(
float dt);
77 bool axis_was_pressed(
const std::string& name)
const;
80 bool axis_was_released(
const std::string& name)
const;
95 return text_input_enabled_;
98 bool onscreen_keyboard_active()
const {
99 return bool(keyboard_);
103 InputState* controller_;
105 std::multimap<std::string, std::shared_ptr<InputAxis>> axises_;
107 std::unordered_map<std::string, bool> prev_axis_states_;
108 std::unordered_map<std::string, bool> axis_states_;
110 float _calculate_value(InputAxis* axis)
const;
112 bool _update_keyboard_axis(InputAxis* axis,
float dt);
113 bool _update_mouse_button_axis(InputAxis* axis,
float dt);
114 bool _update_joystick_button_axis(InputAxis* axis,
float dt);
115 void _update_mouse_axis_axis(InputAxis *axis,
float dt);
116 bool _update_joystick_axis_axis(InputAxis* axis,
float dt);
117 bool _update_joystick_hat_axis(InputAxis* axis,
float dt);
119 void _process_mouse(int8_t
id, int8_t pbtn, int8_t nbtn,
bool* positive_pressed,
bool* negative_pressed);
120 void _process_game_controller(GameController* controller, JoystickButton pbtn, JoystickButton nbtn,
bool *positive_pressed,
bool *negative_pressed);
121 void _process_keyboard(int8_t
id, KeyboardCode pbtn, KeyboardCode nbtn,
bool *positive_pressed,
bool *negative_pressed);
123 bool text_input_enabled_ =
false;
127 class TextInputHandler :
public EventListener {
129 TextInputHandler(InputManager*
self): self_(self) {}
131 void on_key_down(
const KeyEvent& evt)
override;
136 TextInputHandler event_listener_ = {
this};
138 StagePtr keyboard_stage_;
139 CameraPtr keyboard_camera_;
140 PipelinePtr keyboard_pipeline_;
141 ui::Keyboard* keyboard_ =
nullptr;
143 sig::connection scene_deactivated_conn_;
144 void on_scene_deactivated(std::string, SceneBase* scene);
147 S_DEFINE_PROPERTY(state, &InputManager::controller_);
148 S_DEFINE_PROPERTY(onscreen_keyboard, &InputManager::keyboard_);