summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
committerJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
commit7dfced21a2e5aac7195e0e1ad76468e30306766b (patch)
treebd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
parentc25be031fc1031d795157d8344b87b7841145197 (diff)
parent7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff)
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.h')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
new file mode 100644
index 0000000000..408a36fefa
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
@@ -0,0 +1,130 @@
+// Copyright 2010 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <algorithm>
+#include <map>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "Common/CommonTypes.h"
+#include "Common/Thread.h"
+#include "InputCommon/ControllerInterface/Device.h"
+#include "InputCommon/ControllerInterface/ExpressionParser.h"
+
+// enable disable sources
+#ifdef _WIN32
+ #define CIFACE_USE_XINPUT
+ #define CIFACE_USE_DINPUT
+#endif
+#if defined(HAVE_X11) && HAVE_X11
+ #define CIFACE_USE_XLIB
+ #if defined(HAVE_X11_XINPUT2) && HAVE_X11_XINPUT2
+ #define CIFACE_USE_X11_XINPUT2
+ #endif
+#endif
+#if defined(__APPLE__)
+ #define CIFACE_USE_OSX
+#endif
+#ifdef ANDROID
+ #define CIFACE_USE_ANDROID
+#endif
+#if defined(HAVE_SDL) && HAVE_SDL
+ #define CIFACE_USE_SDL
+#endif
+
+//
+// ControllerInterface
+//
+// Some crazy shit I made to control different device inputs and outputs
+// from lots of different sources, hopefully more easily.
+//
+class ControllerInterface : public ciface::Core::DeviceContainer
+{
+public:
+
+ //
+ // ControlReference
+ //
+ // These are what you create to actually use the inputs, InputReference or OutputReference.
+ //
+ // 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
+ //
+ class ControlReference
+ {
+ friend class ControllerInterface;
+ public:
+ virtual ControlState State(const ControlState state = 0) = 0;
+ virtual ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) = 0;
+
+ ControlState range;
+ std::string expression;
+ const bool is_input;
+ ciface::ExpressionParser::ExpressionParseStatus parse_error;
+
+ virtual ~ControlReference()
+ {
+ delete parsed_expression;
+ }
+
+ int BoundCount()
+ {
+ if (parsed_expression)
+ return parsed_expression->num_controls;
+ else
+ return 0;
+ }
+
+ protected:
+ ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(nullptr) {}
+ ciface::ExpressionParser::Expression *parsed_expression;
+ };
+
+ //
+ // InputReference
+ //
+ // Control reference for inputs
+ //
+ class InputReference : public ControlReference
+ {
+ public:
+ InputReference() : ControlReference(true) {}
+ ControlState State(const ControlState state) override;
+ ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
+ };
+
+ //
+ // OutputReference
+ //
+ // Control reference for outputs
+ //
+ class OutputReference : public ControlReference
+ {
+ public:
+ OutputReference() : ControlReference(false) {}
+ ControlState State(const ControlState state) override;
+ ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
+ };
+
+ ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
+
+ void Initialize(void* const hwnd);
+ void Reinitialize();
+ void Shutdown();
+ bool IsInit() const { return m_is_init; }
+
+ void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const;
+ void UpdateInput();
+
+private:
+ bool m_is_init;
+ void* m_hwnd;
+};
+
+extern ControllerInterface g_controller_interface;