input_device_provider.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29
30
31 #pragma once
32
33 #include "../Window/input_device.h"
34 #include "../../Core/System/disposable_object.h"
35 #include <memory>
36 #include "../../Core/Signals/signal.h"
37
38 namespace clan
39 {
42
44 class InputDeviceProvider : public DisposableObject
45 {
48
49 public:
50 virtual ~InputDeviceProvider() { return; }
51
55
56 public:
58 virtual std::string get_name() const = 0;
59
61 virtual std::string get_device_name() const = 0;
62
64 virtual InputDevice::Type get_type() const = 0;
65
68 // should only be used to display the name of the key to the user
69 // and not as a key identifier inside key binding configuration
70 // files and such.
71 virtual std::string get_key_name(int id) const = 0;
72
74 virtual bool supports_keyid_mapping() const { return false; }
75
77 virtual std::string keyid_to_string(int /* keycode */) const { return std::string(); }
78
80 virtual int string_to_keyid(const std::string &/* str */) const { return 0; }
81
84 virtual bool get_keycode(int keycode) const = 0;
85
88 virtual Pointf get_position() const { return Pointf(0.f, 0.f); }
89
92 virtual Point get_device_position() const { return Point(0, 0); }
93
95 virtual float get_axis(int index) const { return 0.f; }
96
98 virtual std::vector<int> get_axis_ids() const { return std::vector<int>(); }
99
102 virtual int get_hat(int /* index */) const { return -1; }
103
106 virtual int get_button_count() const = 0;
107
109 virtual bool in_proximity() const { return false; }
110
114
115 public:
119 virtual void init(Signal<void(const InputEvent &)> *sig_provider_event) = 0;
120
122 virtual void set_position(float x, float y) { }
123
125 virtual void set_device_position(int x, int y) { }
126
130
131 private:
133 };
134
135 }
136
clan
Definition: clanapp.h:35
clan::InputDeviceProvider::string_to_keyid
virtual int string_to_keyid(const std::string &) const
Returns the key code for the specified generic string key name.
Definition: input_device_provider.h:80
clan::InputDeviceProvider::keyid_to_string
virtual std::string keyid_to_string(int) const
Returns a generic string name for the specified key code.
Definition: input_device_provider.h:77
clan::DisposableObject
DisposableObject.
Definition: disposable_object.h:36
clan::InputDevice::Type
Type
Input device types.
Definition: input_device.h:51
clan::InputDeviceProvider::get_axis_ids
virtual std::vector< int > get_axis_ids() const
Returns the number of axes available on this device. (Joysticks only)
Definition: input_device_provider.h:98
clan::Key::x
clan::InputDeviceProvider::get_keycode
virtual bool get_keycode(int keycode) const =0
Returns true if the passed key code is down for this device. See keys.h for list of key codes...
clan::InputDeviceProvider::get_hat
virtual int get_hat(int) const
Returns the current position of a joystick hat. (Joysticks only)
Definition: input_device_provider.h:102
clan::InputDeviceProvider::supports_keyid_mapping
virtual bool supports_keyid_mapping() const
Returns true if this provider implements keyid to/from string mapping.
Definition: input_device_provider.h:74
clan::InputDeviceProvider::set_position
virtual void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
Definition: input_device_provider.h:122
clan::InputDeviceProvider::get_name
virtual std::string get_name() const =0
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
clan::InputDeviceProvider::set_device_position
virtual void set_device_position(int x, int y)
Sets the actual position of the device. (Pointing devices only)
Definition: input_device_provider.h:125
clan::StyleTokenType::string
@ keyword
clan::InputDeviceProvider::get_device_position
virtual Point get_device_position() const
Returns the current device-supplied x and y position of the device. (Pointing devices only) The retur...
Definition: input_device_provider.h:92
clan::Key::f
clan::InputDeviceProvider::~InputDeviceProvider
virtual ~InputDeviceProvider()
Definition: input_device_provider.h:50
clan::Key::y
clan::InputDeviceProvider
Interface for implementing a InputDevice source.
Definition: input_device_provider.h:44
clan::InputDeviceProvider::get_type
virtual InputDevice::Type get_type() const =0
Returns the input device type.
clan::InputDeviceProvider::get_axis
virtual float get_axis(int index) const
Returns the the current position of a joystick axis. (Joysticks only)
Definition: input_device_provider.h:95
clan::Signal
Definition: signal.h:104
clan::Point
2D (x,y) point structure - Integer
Definition: point.h:62
clan::InputDeviceProvider::get_position
virtual Pointf get_position() const
Returns the current device-independent x and y position (DIP) of the device. (Pointing devices only) ...
Definition: input_device_provider.h:88
clan::InputDeviceProvider::get_device_name
virtual std::string get_device_name() const =0
Return the hardware id/device for this device (i.e. /dev/input/js0)
clan::InputDeviceProvider::get_key_name
virtual std::string get_key_name(int id) const =0
Retrieves the localized friendly key name for specified identifier (i.e. A, B, Leertaste, Backspace, Mouse Left, ...).
clan::Pointf
2D (x,y) point structure - Float
Definition: point.h:72
clan::InputEvent
Input event class.
Definition: input_event.h:43
clan::InputDeviceProvider::get_button_count
virtual int get_button_count() const =0
Returns the number of buttons available on this device. If used on a keyboard or mouse...
clan::InputDeviceProvider::in_proximity
virtual bool in_proximity() const
Returns true if the input device is in proximity mode. (Tablets only)
Definition: input_device_provider.h:109
clan::InputDeviceProvider::init
virtual void init(Signal< void(const InputEvent &)> *sig_provider_event)=0
Initialize input device provider. The device field of InputEvent should not be set when emitting even...