input_device_provider.h Source File - ClanLib SDK
Description: input_device_provider.h Source File

input_device_provider.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
31
32#include "../Window/input_device.h"
33#include "../../Core/System/disposable_object.h"
34#include <memory>
35#include "../../Core/Signals/signal.h"
36
37namespace clan
38{
41
43 class InputDeviceProvider : public DisposableObject
44 {
45 public:
46 virtual ~InputDeviceProvider() { return; }
47
49 virtual std::string get_name() const = 0;
50
52 virtual std::string get_device_name() const = 0;
53
55 virtual InputDevice::Type get_type() const = 0;
56
59 // should only be used to display the name of the key to the user
60 // and not as a key identifier inside key binding configuration
61 // files and such.
62 virtual std::string get_key_name(int id) const = 0;
63
65 virtual bool supports_keyid_mapping() const { return false; }
66
68 virtual std::string keyid_to_string(int /* keycode */) const { return std::string(); }
69
71 virtual int string_to_keyid(const std::string &/* str */) const { return 0; }
72
75 virtual bool get_keycode(int keycode) const = 0;
76
79 virtual Pointf get_position() const { return Pointf(0.f, 0.f); }
80
83 virtual Point get_device_position() const { return Point(0, 0); }
84
86 virtual float get_axis(int index) const { return 0.f; }
87
89 virtual std::vector<int> get_axis_ids() const { return std::vector<int>(); }
90
93 virtual int get_hat(int /* index */) const { return -1; }
94
97 virtual int get_button_count() const = 0;
98
100 virtual void set_position(float x, float y) { }
101
103 virtual void set_device_position(int x, int y) { }
104 };
105
107}
clan::DisposableObject
DisposableObject.
Definition disposable_object.h:35
clan::InputDeviceProvider
Interface for implementing a InputDevice source.
Definition input_device_provider.h:44
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:86
clan::InputDeviceProvider::get_button_count
virtual int get_button_count() const =0
Returns the number of buttons available on this device. \warn If used on a keyboard or mouse,...
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_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:89
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:79
clan::InputDeviceProvider::~InputDeviceProvider
virtual ~InputDeviceProvider()
Definition input_device_provider.h:46
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:103
clan::InputDeviceProvider::get_type
virtual InputDevice::Type get_type() const =0
Returns the input device type.
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,...
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:71
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_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:83
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:65
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:93
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_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:100
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:68
clan::InputDevice::Type
Type
Input device types.
Definition input_device.h:51
clan::Point
2D (x,y) point structure - Integer
Definition point.h:62
clan::Pointf
2D (x,y) point structure - Float
Definition point.h:72
clan
Definition clanapp.h:36
clan::Key::y
@ y
clan::Key::x
@ x