| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2010 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-01 23:57:06 +00:00
										 |  |  | #include <list>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-05 15:32:13 -06:00
										 |  |  | #include <SDL.h>
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if SDL_VERSION_ATLEAST(1, 3, 0)
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define USE_SDL_HAPTIC
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef USE_SDL_HAPTIC
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #include <SDL_haptic.h>
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace ciface | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | namespace SDL | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-12 17:08:04 +02:00
										 |  |  | void Init(); | 
					
						
							| 
									
										
										
										
											2016-10-16 13:39:05 -07:00
										 |  |  | void PopulateDevices(); | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 20:07:10 -04:00
										 |  |  | class Joystick : public Core::Device | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-14 01:20:11 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   class Button : public Core::Device::Input | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  |     Button(u8 index, SDL_Joystick* js) : m_js(js), m_index(index) {} | 
					
						
							|  |  |  |     ControlState GetState() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     SDL_Joystick* const m_js; | 
					
						
							|  |  |  |     const u8 m_index; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class Axis : public Core::Device::Input | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  |     Axis(u8 index, SDL_Joystick* js, Sint16 range) : m_js(js), m_range(range), m_index(index) {} | 
					
						
							|  |  |  |     ControlState GetState() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     SDL_Joystick* const m_js; | 
					
						
							|  |  |  |     const Sint16 m_range; | 
					
						
							|  |  |  |     const u8 m_index; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class Hat : public Input | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  |     Hat(u8 index, SDL_Joystick* js, u8 direction) : m_js(js), m_direction(direction), m_index(index) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ControlState GetState() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     SDL_Joystick* const m_js; | 
					
						
							|  |  |  |     const u8 m_direction; | 
					
						
							|  |  |  |     const u8 m_index; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef USE_SDL_HAPTIC
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   class HapticEffect : public Output | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     HapticEffect(SDL_Haptic* haptic) : m_haptic(haptic), m_id(-1) {} | 
					
						
							|  |  |  |     ~HapticEffect() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_effect.type = 0; | 
					
						
							|  |  |  |       Update(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected: | 
					
						
							|  |  |  |     void Update(); | 
					
						
							|  |  |  |     virtual void SetSDLHapticEffect(ControlState state) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SDL_HapticEffect m_effect; | 
					
						
							|  |  |  |     SDL_Haptic* m_haptic; | 
					
						
							|  |  |  |     int m_id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     virtual void SetState(ControlState state) override final; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ConstantEffect : public HapticEffect | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void SetSDLHapticEffect(ControlState state) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class RampEffect : public HapticEffect | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void SetSDLHapticEffect(ControlState state) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class SineEffect : public HapticEffect | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void SetSDLHapticEffect(ControlState state) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class TriangleEffect : public HapticEffect | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void SetSDLHapticEffect(ControlState state) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class LeftRightEffect : public HapticEffect | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     LeftRightEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} | 
					
						
							|  |  |  |     std::string GetName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void SetSDLHapticEffect(ControlState state) override; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-14 01:20:11 +00:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void UpdateInput() override; | 
					
						
							| 
									
										
										
										
											2015-06-08 13:43:39 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 10:25:52 +02:00
										 |  |  |   Joystick(SDL_Joystick* const joystick, const int sdl_index); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ~Joystick(); | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::string GetName() const override; | 
					
						
							|  |  |  |   std::string GetSource() const override; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SDL_Joystick* const m_joystick; | 
					
						
							|  |  |  |   const int m_sdl_index; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef USE_SDL_HAPTIC
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   SDL_Haptic* m_haptic; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } |