| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | // Copyright 2013 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Common/Common.h"
 | 
					
						
							|  |  |  | #include "Common/Thread.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerInterface/Device.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-19 02:17:31 +01:00
										 |  |  | #include "InputCommon/ControllerInterface/ExpressionParser.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // enable disable sources
 | 
					
						
							|  |  |  | #ifdef _WIN32
 | 
					
						
							|  |  |  | 	#define CIFACE_USE_XINPUT
 | 
					
						
							| 
									
										
										
										
											2010-07-03 08:04:10 +00:00
										 |  |  | 	#define CIFACE_USE_DINPUT
 | 
					
						
							| 
									
										
										
										
											2010-07-16 19:17:35 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #if defined(HAVE_X11) && HAVE_X11
 | 
					
						
							|  |  |  | 	#define CIFACE_USE_XLIB
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:49:58 -08:00
										 |  |  | 	#if defined(HAVE_X11_XINPUT2) && HAVE_X11_XINPUT2
 | 
					
						
							|  |  |  | 		#define CIFACE_USE_X11_XINPUT2
 | 
					
						
							|  |  |  | 	#endif
 | 
					
						
							| 
									
										
										
										
											2010-07-16 19:17:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-04-02 09:41:43 +00:00
										 |  |  | #if defined(__APPLE__)
 | 
					
						
							|  |  |  | 	#define CIFACE_USE_OSX
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-04-14 23:02:53 -05:00
										 |  |  | #ifdef ANDROID
 | 
					
						
							|  |  |  | 	#define CIFACE_USE_ANDROID
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-05-04 19:41:02 -05:00
										 |  |  | #if defined(HAVE_SDL) && HAVE_SDL
 | 
					
						
							|  |  |  | 	#define CIFACE_USE_SDL
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-06-16 20:07:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace ciface::Core; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | // ControllerInterface
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | // Some crazy shit I made to control different device inputs and outputs
 | 
					
						
							|  |  |  | // from lots of different sources, hopefully more easily.
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2013-06-16 20:07:10 -04:00
										 |  |  | class ControllerInterface : public DeviceContainer | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// ControlReference
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// These are what you create to actually use the inputs, InputReference or OutputReference.
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// After being bound to devices and controls with ControllerInterface::UpdateReference,
 | 
					
						
							|  |  |  | 	// each one can link to multiple devices and controls
 | 
					
						
							|  |  |  | 	// when you change a ControlReference's expression,
 | 
					
						
							|  |  |  | 	// you must use ControllerInterface::UpdateReference on it to rebind controls
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	class ControlReference | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 		friend class ControllerInterface; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 		virtual ControlState State(const ControlState state = 0) = 0; | 
					
						
							|  |  |  | 		virtual Device::Control* Detect(const unsigned int ms, Device* const device) = 0; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-13 23:09:55 -04:00
										 |  |  | 		ControlState range; | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 		std::string  expression; | 
					
						
							|  |  |  | 		const bool   is_input; | 
					
						
							| 
									
										
										
										
											2013-07-22 02:36:26 -04:00
										 |  |  | 		ciface::ExpressionParser::ExpressionParseStatus parse_error; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 		virtual ~ControlReference() | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2013-06-13 23:09:55 -04:00
										 |  |  | 			delete parsed_expression; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 		int BoundCount() | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2013-06-13 23:09:55 -04:00
										 |  |  | 			if (parsed_expression) | 
					
						
							|  |  |  | 				return parsed_expression->num_controls; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-13 23:09:55 -04:00
										 |  |  | 	protected: | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 		ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(nullptr) {} | 
					
						
							| 
									
										
										
										
											2013-06-13 23:09:55 -04:00
										 |  |  | 		ciface::ExpressionParser::Expression *parsed_expression; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// InputReference
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// Control reference for inputs
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	class InputReference : public ControlReference | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 		InputReference() : ControlReference(true) {} | 
					
						
							| 
									
										
										
										
											2014-03-08 01:54:44 +01:00
										 |  |  | 		ControlState State(const ControlState state) override; | 
					
						
							|  |  |  | 		Device::Control* Detect(const unsigned int ms, Device* const device) override; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// OutputReference
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	// Control reference for outputs
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	class OutputReference : public ControlReference | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 		OutputReference() : ControlReference(false) {} | 
					
						
							| 
									
										
										
										
											2014-03-08 01:54:44 +01:00
										 |  |  | 		ControlState State(const ControlState state) override; | 
					
						
							|  |  |  | 		Device::Control* Detect(const unsigned int ms, Device* const device) override; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 	ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {} | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 	void SetHwnd(void* const hwnd); | 
					
						
							| 
									
										
										
										
											2010-10-12 19:42:29 +00:00
										 |  |  | 	void Initialize(); | 
					
						
							|  |  |  | 	void Shutdown(); | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 	bool IsInit() const { return m_is_init; } | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-21 03:12:16 +00:00
										 |  |  | 	void UpdateReference(ControlReference* control, const DeviceQualifier& default_device) const; | 
					
						
							| 
									
										
										
										
											2010-07-26 05:30:50 +00:00
										 |  |  | 	bool UpdateInput(const bool force = false); | 
					
						
							|  |  |  | 	bool UpdateOutput(const bool force = false); | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-07 00:16:38 +00:00
										 |  |  | 	std::recursive_mutex update_lock; | 
					
						
							| 
									
										
										
										
											2010-07-26 05:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | 	bool   m_is_init; | 
					
						
							|  |  |  | 	void*  m_hwnd; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 19:42:29 +00:00
										 |  |  | extern ControllerInterface g_controller_interface; |