1 /*=============================================================================
2 Blobby Volley 2
3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de)
4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de)
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 =============================================================================*/
20 
21 #pragma once
22 
23 #include <map>
24 
25 #include <SDL2/SDL_events.h>
26 
27 #include "BlobbyDebug.h"
28 
29 class JoystickPool : public ObjectCounter<JoystickPool>
30 {
31 	public:
32 		static JoystickPool& getSingleton();
33 
34 		SDL_Joystick* getJoystick(int id);
35 
36 		void probeJoysticks();
37 		void closeJoysticks();
38 
39 	private:
40 		typedef std::map<int, SDL_Joystick*> JoyMap;
41 		JoyMap mJoyMap;
42 		static JoystickPool* mSingleton;
43 };
44 
45 struct JoystickAction : public ObjectCounter<JoystickAction>
46 {
47 	enum Type
48 	{
49 		AXIS,
50 		BUTTON,
51 // 	We don't implement these exotic input methods here
52 //		HAT,
53 //		TRACKBALL
54 	};
55 
56 	JoystickAction(std::string string);
JoystickActionJoystickAction57 	JoystickAction(int _joyid, Type _type, int _number)
58 		: type(_type), joy(0), joyid(_joyid),
59 			number(_number) {}
60 	~JoystickAction();
61 	JoystickAction(const JoystickAction& action);
62 
63 	std::string toString();
64 
65 	Type type;
66 
67 	SDL_Joystick* joy;
68 	int joyid;
69 
70 	// Note: Axis are stored as the SDL axis +1, so we can used
71 	// the signedness as direction indication
72 	int number;
73 };
74