supertux
mobile_controller.hpp
1 // SuperTux
2 // Copyright (C) 2021 A. Semphris <semphris@protonmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_CONTROL_MOBILE_CONTROLLER_HPP
18 #define HEADER_SUPERTUX_CONTROL_MOBILE_CONTROLLER_HPP
19 
20 #include <SDL.h>
21 #include <map>
22 
23 #include "config.h"
24 
25 
26 #include "math/rectf.hpp"
27 #include "math/vector.hpp"
28 #include "video/surface_ptr.hpp"
29 
30 class Controller;
31 class DrawingContext;
32 
33 class MobileController final
34 {
35 public:
37  void draw(DrawingContext& context);
38  void apply(Controller& controller) const;
39  void update();
40 
42  bool process_finger_down_event(const SDL_TouchFingerEvent& event);
44  bool process_finger_up_event(const SDL_TouchFingerEvent& event);
46  bool process_finger_motion_event(const SDL_TouchFingerEvent& event);
47 
48 private:
49  void activate_widget_at_pos(float x, float y);
50 
51 private:
52  bool m_up, m_down, m_left, m_right, m_jump, m_action, m_cheats, m_debug, m_escape;
53  bool m_old_up, m_old_down, m_old_left, m_old_right, m_old_jump, m_old_action, m_old_cheats, m_old_debug, m_old_escape;
54 
55  std::map<SDL_FingerID, Vector> m_fingers;
56 
57  Rectf m_rect_directions, m_rect_jump, m_rect_action, m_rect_cheats,
58  m_rect_debug, m_rect_escape;
59  Rectf m_draw_directions, m_draw_jump, m_draw_action, m_draw_cheats,
60  m_draw_debug, m_draw_escape;
61  const SurfacePtr m_tex_dirs, m_tex_btn, m_tex_btn_press, m_tex_pause,
62  m_tex_up, m_tex_dwn, m_tex_lft, m_tex_rgt,
63  m_tex_jump, m_tex_action, m_tex_cheats, m_tex_debug;
64 
65  int m_screen_width, m_screen_height;
66  float m_mobile_controls_scale;
67 
68 private:
69  MobileController(const MobileController&) = delete;
70  MobileController& operator=(const MobileController&) = delete;
71 };
72 
73 #endif
74 
75 /* EOF */
Definition: controller.hpp:57
bool process_finger_motion_event(const SDL_TouchFingerEvent &event)
returns true if the finger event was inside the screen button area
Definition: mobile_controller.cpp:252
Definition: rectf.hpp:31
bool process_finger_down_event(const SDL_TouchFingerEvent &event)
returns true if the finger event was inside the screen button area
Definition: mobile_controller.cpp:226
bool process_finger_up_event(const SDL_TouchFingerEvent &event)
returns true if the finger event was inside the screen button area
Definition: mobile_controller.cpp:239
Definition: mobile_controller.hpp:33
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42