1 // 2 // SuperTuxKart - a fun racing game with go-kart 3 // Copyright (C) 2013-2015 SuperTuxKart-Team 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 3 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 #ifndef HEADER_MULTITOUCH_DEVICE_HPP 20 #define HEADER_MULTITOUCH_DEVICE_HPP 21 22 #include <array> 23 #include <map> 24 #include <vector> 25 26 #include "input/input_device.hpp" 27 #include "utils/types.hpp" 28 #include "IEventReceiver.h" 29 30 #define NUMBER_OF_MULTI_TOUCHES 10 31 32 enum MultitouchButtonType 33 { 34 BUTTON_STEERING, 35 BUTTON_UP_DOWN, 36 BUTTON_FIRE, 37 BUTTON_NITRO, 38 BUTTON_SKIDDING, 39 BUTTON_LOOK_BACKWARDS, 40 BUTTON_RESCUE, 41 BUTTON_ESCAPE, 42 BUTTON_UP, 43 BUTTON_DOWN, 44 BUTTON_LEFT, 45 BUTTON_RIGHT, 46 BUTTON_CUSTOM 47 }; 48 49 struct MultitouchEvent 50 { 51 int id; 52 bool touched; 53 int x; 54 int y; 55 }; 56 57 struct MultitouchButton 58 { 59 MultitouchButtonType type; 60 PlayerAction action; 61 bool pressed; 62 unsigned int event_id; 63 int x; 64 int y; 65 int width; 66 int height; 67 float axis_x; 68 float axis_y; 69 unsigned int id; 70 void (*callback)(unsigned int, bool); 71 }; 72 73 class Controller; 74 75 class MultitouchDevice : public InputDevice 76 { 77 private: 78 /** The list of pointers to all created buttons */ 79 std::vector<MultitouchButton*> m_buttons; 80 81 Controller* m_controller; 82 83 /** The parameter that is used for steering button and determines dead area 84 * in a center of button */ 85 float m_deadzone; 86 87 /** A parameter in range that determines the sensitivity for x axis. */ 88 float m_sensitivity_x; 89 90 /** A parameter in range that determines the sensitivity for y axis. */ 91 float m_sensitivity_y; 92 93 float m_orientation; 94 uint64_t m_gyro_time; 95 96 /** Pointer to the irrlicht device */ 97 IrrlichtDevice* m_irrlicht_device; 98 99 float getSteeringFactor(float value, float sensitivity); 100 void handleControls(MultitouchButton* button); 101 bool isGameRunning(); 102 103 std::map<unsigned, std::vector<MultitouchButton*> > m_affected_linked_buttons; 104 105 public: 106 /** The array that contains data for all multitouch input events */ 107 std::array<MultitouchEvent, NUMBER_OF_MULTI_TOUCHES> m_events; 108 109 MultitouchDevice(); 110 virtual ~MultitouchDevice(); 111 112 /** Unused function */ processAndMapInput(Input::InputType type,const int id,InputManager::InputDriverMode mode,PlayerAction * action,int * value=NULL)113 bool processAndMapInput(Input::InputType type, const int id, 114 InputManager::InputDriverMode mode, 115 PlayerAction *action, int* value = NULL) 116 {return true;} 117 118 unsigned int getActiveTouchesCount(); 119 120 void addButton(MultitouchButtonType type, int x, int y, int width, 121 int height, void (*callback)(unsigned int, bool) = NULL); 122 void clearButtons(); 123 void reset(); 124 125 /** Returns the number of created buttons */ getButtonsCount()126 unsigned int getButtonsCount() { return (unsigned int)m_buttons.size();} 127 128 /** Returns pointer to the selected button */ getButton(unsigned int i)129 MultitouchButton* getButton(unsigned int i) {return m_buttons.at(i);} 130 131 void activateAccelerometer(); 132 void deactivateAccelerometer(); 133 bool isAccelerometerActive(); 134 135 void activateGyroscope(); 136 void deactivateGyroscope(); 137 bool isGyroscopeActive(); 138 139 void updateAxisX(float value); 140 void updateAxisY(float value); 141 float getOrientation(); 142 void updateOrientationFromAccelerometer(float x, float y); 143 void updateOrientationFromGyroscope(float z); 144 void updateDeviceState(unsigned int event_id); 145 void updateController(); 146 void updateConfigParams(); 147 148 }; // MultitouchDevice 149 150 #endif 151