2008-07-30 13:47:54 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2014-02-18 02:34:21 +01:00
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2008-07-30 13:47:54 +00:00
|
|
|
|
2008-09-30 13:51:01 +00:00
|
|
|
#ifndef COMMON_HARDWARE_KEY_H
|
|
|
|
#define COMMON_HARDWARE_KEY_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/events.h"
|
2012-02-27 13:28:40 -06:00
|
|
|
#include "common/keyboard.h"
|
|
|
|
#include "common/str.h"
|
2008-07-21 00:11:25 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
2012-02-24 13:55:48 -06:00
|
|
|
typedef uint32 HardwareInputCode;
|
|
|
|
|
|
|
|
enum HardwareInputType {
|
2020-01-26 12:18:52 +01:00
|
|
|
/** Empty / invalid input type */
|
|
|
|
kHardwareInputTypeInvalid,
|
2012-02-24 13:55:48 -06:00
|
|
|
/** Input that sends single events */
|
2020-01-26 16:33:25 +01:00
|
|
|
kHardwareInputTypeCustom,
|
|
|
|
/** Keyboard input that sends -up and -down events */
|
|
|
|
kHardwareInputTypeKeyboard,
|
|
|
|
/** Joystick input that sends -up and -down events */
|
|
|
|
kHardwareInputTypeJoystick
|
2012-02-24 13:55:48 -06:00
|
|
|
};
|
|
|
|
|
2008-07-21 00:11:25 +00:00
|
|
|
/**
|
2012-02-24 13:23:55 -06:00
|
|
|
* Describes an available hardware input
|
2008-07-21 00:11:25 +00:00
|
|
|
*/
|
2012-02-24 13:23:55 -06:00
|
|
|
struct HardwareInput {
|
2008-07-21 00:11:25 +00:00
|
|
|
/** unique id used for saving/loading to config */
|
2012-02-22 07:17:38 -06:00
|
|
|
String id;
|
2009-01-21 02:02:55 +00:00
|
|
|
|
2008-07-21 00:11:25 +00:00
|
|
|
/** Human readable description */
|
2009-05-24 15:17:42 +00:00
|
|
|
String description;
|
2009-01-21 02:02:55 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/** Type tag */
|
|
|
|
HardwareInputType type;
|
2012-02-24 13:55:48 -06:00
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
/**
|
2012-02-24 13:55:48 -06:00
|
|
|
* A platform specific unique identifier for an input event
|
|
|
|
* generated when this input is triggered.
|
|
|
|
* This is only relevant when type == kHardwareInputTypeGeneric
|
|
|
|
*/
|
|
|
|
HardwareInputCode inputCode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The KeyState that is generated by the back-end
|
|
|
|
* when this hardware key is pressed.
|
|
|
|
* This is only relevant when type == kHardwareInputTypeKeyboard
|
|
|
|
*/
|
2008-07-21 00:11:25 +00:00
|
|
|
KeyState key;
|
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
HardwareInput()
|
|
|
|
: inputCode(0), type(kHardwareInputTypeInvalid) { }
|
|
|
|
|
2020-01-26 16:33:25 +01:00
|
|
|
static HardwareInput createCustom(const String &i, HardwareInputCode ic, const String &desc) {
|
|
|
|
HardwareInput hardwareInput;
|
|
|
|
hardwareInput.id = i;
|
|
|
|
hardwareInput.description = desc;
|
|
|
|
hardwareInput.type = kHardwareInputTypeCustom;
|
|
|
|
hardwareInput.inputCode = ic;
|
|
|
|
return hardwareInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HardwareInput createKeyboard(const String &i, KeyState ky, const String &desc) {
|
|
|
|
HardwareInput hardwareInput;
|
|
|
|
hardwareInput.id = i;
|
|
|
|
hardwareInput.description = desc;
|
|
|
|
hardwareInput.type = kHardwareInputTypeKeyboard;
|
|
|
|
hardwareInput.inputCode = 0;
|
|
|
|
hardwareInput.key = ky;
|
|
|
|
return hardwareInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HardwareInput createJoystick(const String &i, uint8 button, const String &desc) {
|
|
|
|
HardwareInput hardwareInput;
|
|
|
|
hardwareInput.id = i;
|
|
|
|
hardwareInput.description = desc;
|
|
|
|
hardwareInput.type = kHardwareInputTypeJoystick;
|
|
|
|
hardwareInput.inputCode = button;
|
|
|
|
return hardwareInput;
|
|
|
|
}
|
2012-02-24 13:55:48 -06:00
|
|
|
};
|
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/**
|
|
|
|
* Entry in a static table of custom backend hardware inputs
|
|
|
|
*/
|
2012-02-24 13:55:48 -06:00
|
|
|
struct HardwareInputTableEntry {
|
|
|
|
const char *hwId;
|
|
|
|
HardwareInputCode code;
|
|
|
|
const char *desc;
|
2008-07-21 00:11:25 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 01:26:11 -06:00
|
|
|
/**
|
|
|
|
* Entry in a static table of available non-modifier keys
|
|
|
|
*/
|
|
|
|
struct KeyTableEntry {
|
|
|
|
const char *hwId;
|
|
|
|
KeyCode keycode;
|
|
|
|
const char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry in a static table of available key modifiers
|
|
|
|
*/
|
|
|
|
struct ModifierTableEntry {
|
|
|
|
byte flag;
|
|
|
|
const char *id;
|
|
|
|
const char *desc;
|
|
|
|
};
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2017-08-18 18:07:04 +02:00
|
|
|
/**
|
2020-01-26 12:18:52 +01:00
|
|
|
* Interface for querying information about a hardware input device
|
2017-08-18 18:07:04 +02:00
|
|
|
*/
|
2020-01-26 12:18:52 +01:00
|
|
|
class HardwareInputSet {
|
|
|
|
public:
|
|
|
|
virtual ~HardwareInputSet();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a hardware input description from an unique identifier
|
|
|
|
*
|
|
|
|
* In case no input was found with the specified id, an empty
|
|
|
|
* HardwareInput structure is return with the type set to
|
|
|
|
* kHardwareInputTypeInvalid.
|
|
|
|
*/
|
|
|
|
virtual HardwareInput findHardwareInput(const String &id) const = 0;
|
2017-08-18 18:07:04 +02:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/**
|
|
|
|
* Retrieve a hardware input description from one of the events
|
|
|
|
* produced when the input is triggered.
|
|
|
|
*
|
|
|
|
* In case the specified event is not produced by this device,
|
|
|
|
* an empty HardwareInput structure is return with the type set to
|
|
|
|
* kHardwareInputTypeInvalid.
|
|
|
|
*/
|
|
|
|
virtual HardwareInput findHardwareInput(const Event &event) const = 0;
|
2017-08-18 18:07:04 +02:00
|
|
|
};
|
|
|
|
|
2008-07-21 00:11:25 +00:00
|
|
|
/**
|
2020-01-26 12:18:52 +01:00
|
|
|
* A keyboard input device
|
|
|
|
*
|
|
|
|
* Describes the keys and key + modifiers combinations as HardwareInputs
|
2009-05-24 15:17:42 +00:00
|
|
|
*/
|
2020-01-26 12:18:52 +01:00
|
|
|
class KeyboardHardwareInputSet : public HardwareInputSet {
|
2008-07-21 00:11:25 +00:00
|
|
|
public:
|
2020-01-26 12:18:52 +01:00
|
|
|
KeyboardHardwareInputSet(const KeyTableEntry *keys, const ModifierTableEntry *modifiers);
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
// HardwareInputSet API
|
|
|
|
HardwareInput findHardwareInput(const String &id) const override;
|
|
|
|
HardwareInput findHardwareInput(const Event &event) const override;
|
2012-02-09 01:26:11 -06:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
private:
|
|
|
|
const KeyTableEntry *_keys;
|
|
|
|
const ModifierTableEntry *_modifiers;
|
|
|
|
};
|
|
|
|
|
2020-01-26 16:33:25 +01:00
|
|
|
/**
|
|
|
|
* A joystick input device
|
|
|
|
*/
|
|
|
|
class JoystickHardwareInputSet : public HardwareInputSet {
|
|
|
|
public:
|
|
|
|
JoystickHardwareInputSet(const HardwareInputTableEntry *buttonEntries);
|
|
|
|
|
|
|
|
// HardwareInputSet API
|
|
|
|
HardwareInput findHardwareInput(const String &id) const override;
|
|
|
|
HardwareInput findHardwareInput(const Event &event) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const HardwareInputTableEntry *_buttonEntries;
|
|
|
|
};
|
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/**
|
|
|
|
* A custom backend input device
|
|
|
|
*
|
|
|
|
* @todo This is currently unused. Perhaps it should be removed.
|
|
|
|
*/
|
|
|
|
class CustomHardwareInputSet : public HardwareInputSet {
|
|
|
|
public:
|
|
|
|
CustomHardwareInputSet(const HardwareInputTableEntry *hardwareEntries);
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
// HardwareInputSet API
|
|
|
|
HardwareInput findHardwareInput(const String &id) const override;
|
|
|
|
HardwareInput findHardwareInput(const Event &event) const override;
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
private:
|
|
|
|
const HardwareInputTableEntry *_hardwareEntries;
|
|
|
|
};
|
2012-02-24 13:55:48 -06:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/**
|
|
|
|
* A composite input device that delegates to a set of actual input devices.
|
|
|
|
*/
|
|
|
|
class CompositeHardwareInputSet : public HardwareInputSet {
|
|
|
|
public:
|
|
|
|
~CompositeHardwareInputSet() override;
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
// HardwareInputSet API
|
|
|
|
HardwareInput findHardwareInput(const String &id) const override;
|
|
|
|
HardwareInput findHardwareInput(const Event &event) const override;
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2012-02-28 06:38:07 -06:00
|
|
|
/**
|
2020-01-26 12:18:52 +01:00
|
|
|
* Add an input device to this composite device
|
|
|
|
*
|
|
|
|
* Takes ownership of the hardware input set
|
2012-02-28 06:38:07 -06:00
|
|
|
*/
|
2020-01-26 12:18:52 +01:00
|
|
|
void addHardwareInputSet(HardwareInputSet *hardwareInputSet);
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2012-02-28 06:38:07 -06:00
|
|
|
private:
|
2020-01-26 12:18:52 +01:00
|
|
|
Array<HardwareInputSet *> _inputSets;
|
|
|
|
};
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/** A standard set of keyboard keys */
|
|
|
|
extern const KeyTableEntry defaultKeys[];
|
2017-08-18 18:07:04 +02:00
|
|
|
|
2020-01-26 12:18:52 +01:00
|
|
|
/** A standard set of keyboard modifiers */
|
|
|
|
extern const ModifierTableEntry defaultModifiers[];
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2020-01-26 16:33:25 +01:00
|
|
|
/** A standard set of joystick buttons based on the ScummVM event model */
|
|
|
|
extern const HardwareInputTableEntry defaultJoystickButtons[];
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Common
|
2008-07-21 00:11:25 +00:00
|
|
|
|
2008-09-30 13:51:01 +00:00
|
|
|
#endif // #ifndef COMMON_HARDWARE_KEY_H
|