Refactor library keyboard to dedicated namespace
This commit is contained in:
parent
0cf09e958d
commit
dd486e7ff8
29 changed files with 605 additions and 737 deletions
|
@ -10,17 +10,17 @@
|
|||
#include <iostream>
|
||||
#include "misc.hpp"
|
||||
#include "library/keyboard.hpp"
|
||||
#include "library/keymapper.hpp"
|
||||
#include "library/keyboard-mapper.hpp"
|
||||
#include "library/joystick2.hpp"
|
||||
|
||||
/**
|
||||
* Our keyboard
|
||||
*/
|
||||
extern keyboard lsnes_kbd;
|
||||
extern keyboard::keyboard lsnes_kbd;
|
||||
/**
|
||||
* Our key mapper.
|
||||
*/
|
||||
extern keyboard_mapper lsnes_mapper;
|
||||
extern keyboard::mapper lsnes_mapper;
|
||||
|
||||
/**
|
||||
* Gamepad HW.
|
||||
|
|
|
@ -26,23 +26,23 @@ struct keypress
|
|||
/**
|
||||
* Create new keypress.
|
||||
*/
|
||||
keypress(keyboard_modifier_set mod, keyboard_key& _key, short _value);
|
||||
keypress(keyboard::modifier_set mod, keyboard::key& _key, short _value);
|
||||
/**
|
||||
* Create new keypress (two keys).
|
||||
*/
|
||||
keypress(keyboard_modifier_set mod, keyboard_key& _key, keyboard_key& _key2, short _value);
|
||||
keypress(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value);
|
||||
/**
|
||||
* Modifier set.
|
||||
*/
|
||||
keyboard_modifier_set modifiers;
|
||||
keyboard::modifier_set modifiers;
|
||||
/**
|
||||
* The actual key (first)
|
||||
*/
|
||||
keyboard_key* key1;
|
||||
keyboard::key* key1;
|
||||
/**
|
||||
* The actual key (second)
|
||||
*/
|
||||
keyboard_key* key2;
|
||||
keyboard::key* key2;
|
||||
/**
|
||||
* Value for the press
|
||||
*/
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
#ifndef _library__keyboard_cmd_bridge__hpp__
|
||||
#define _library__keyboard_cmd_bridge__hpp__
|
||||
|
||||
#include "keyboard.hpp"
|
||||
#include "command.hpp"
|
||||
|
||||
class inverse_bind;
|
||||
|
||||
/**
|
||||
* Bridge between keyboard and command group.
|
||||
*/
|
||||
class keyboard_command_bridge
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a bridge.
|
||||
*/
|
||||
keyboard_command_bridge(keyboard& kgroup, command::group& cgroup);
|
||||
/**
|
||||
* Destroy a bridge.
|
||||
*/
|
||||
~keyboard_command_bridge() throw();
|
||||
/**
|
||||
* Bind a key.
|
||||
*
|
||||
* Parameter mod: The modifiers.
|
||||
* Parameter mask: The modifier mask.
|
||||
* Parameter key: The key.
|
||||
* Parameter cmd: The command to execute.
|
||||
*/
|
||||
void bind(const std::string& mod, const std::string& mask, const std::string& key, const std::string& cmd)
|
||||
throw(std::bad_alloc);
|
||||
/**
|
||||
* Unbind a key.
|
||||
*
|
||||
* Parameter mod: The modifiers.
|
||||
* Parameter mask: The modifier mask.
|
||||
* Parameter key: The key.
|
||||
*/
|
||||
void unbind(const std::string& mod, const std::string& mask, const std::string& key) throw(std::runtime_error);
|
||||
/**
|
||||
* Get set of used keyspecs.
|
||||
*/
|
||||
std::set<std::string> all_keyspecs() throw(std::bad_alloc);
|
||||
/**
|
||||
* Get command for key.
|
||||
*
|
||||
* Parameter keyspec: The keyspec (<mod>/<mask>|<key>).
|
||||
* Returns: The command bound.
|
||||
*/
|
||||
std::string get_command(const std::string& keyspec) throw(std::bad_alloc);
|
||||
/**
|
||||
* Set command for key.
|
||||
*
|
||||
* Parameter keyspec: The keyspec (<mod>/<mask>|<key>).
|
||||
* Parameter cmd: The command to bind.
|
||||
*/
|
||||
void set_command(const std::string& keyspec, const std::string& cmd) throw(std::bad_alloc,
|
||||
std::runtime_error);
|
||||
/**
|
||||
* Get set of all inverse binds.
|
||||
*
|
||||
* Returns: The set of all inverses.
|
||||
*/
|
||||
std::set<inverse_bind*> all_inverses() throw(std::bad_alloc);
|
||||
/**
|
||||
* Find inverse by command.
|
||||
*
|
||||
* Parameter command: The command.
|
||||
* Returns: The instance, or NULL if there is none.
|
||||
*/
|
||||
inverse_bind* get_inverse(const std::string& command) throw(std::bad_alloc);
|
||||
/**
|
||||
* Register an inverse.
|
||||
*/
|
||||
void do_register(const std::string& name, inverse_bind& inv);
|
||||
/**
|
||||
* Unregister an inverse.
|
||||
*/
|
||||
void do_unregister(const std::string& name);
|
||||
private:
|
||||
keyboard_command_bridge(keyboard_command_bridge&);
|
||||
keyboard_command_bridge& operator=(keyboard_command_bridge&);
|
||||
std::map<std::string, inverse_bind*> inverses;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inverse key binding.
|
||||
*/
|
||||
class inverse_bind
|
||||
{
|
||||
/**
|
||||
* Create a new inverse binding.
|
||||
*
|
||||
* Parameter bridge: The bridge to associate with.
|
||||
* Parameter name: The name of the command.
|
||||
* Parameter cmd: The command to create inverse for.
|
||||
*/
|
||||
inverse_bind(keyboard_command_bridge& bridge, const std::string& name, const std::string& cmd)
|
||||
throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~inverse_bind() throw();
|
||||
/**
|
||||
* Get keyspec.
|
||||
*
|
||||
* Parameter primary: If true, get the primary key, else secondary key.
|
||||
* Returns: The keyspec.
|
||||
*/
|
||||
std::string get(bool primary) throw(std::bad_alloc);
|
||||
/**
|
||||
* Clear key (if primary is cleared, secondary becomes primary).
|
||||
*
|
||||
* Parameter primary: If true, clear the primary, else the secondary.
|
||||
*/
|
||||
void clear(bool primary) throw(std::bad_alloc);
|
||||
/**
|
||||
* Set key.
|
||||
*
|
||||
* Parameter keyspec: The new keyspec.
|
||||
* Parameter primary: If true, set the primary, else the secondary.
|
||||
*/
|
||||
void set(std::string keyspec, bool primary) throw(std::bad_alloc);
|
||||
/**
|
||||
* Get name for command.
|
||||
*/
|
||||
std::string get_name() throw() { return name; }
|
||||
/**
|
||||
* Get command for inverse.
|
||||
*/
|
||||
std::string get_command() throw() { return cmd; }
|
||||
private:
|
||||
friend class keyboard_command_bridge;
|
||||
inverse_bind(inverse_bind&);
|
||||
inverse_bind& operator=(inverse_bind&);
|
||||
keyboard_command_bridge& bridge;
|
||||
std::string cmd;
|
||||
std::string name;
|
||||
std::string primary;
|
||||
std::string secondary;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _library__keymapper__hpp__included__
|
||||
#define _library__keymapper__hpp__included__
|
||||
#ifndef _library__keyboard_mapper__hpp__included__
|
||||
#define _library__keyboard_mapper__hpp__included__
|
||||
|
||||
#include "command.hpp"
|
||||
#include <set>
|
||||
|
@ -8,27 +8,29 @@
|
|||
#include <string>
|
||||
#include "keyboard.hpp"
|
||||
|
||||
class inverse_bind;
|
||||
class controller_key;
|
||||
namespace keyboard
|
||||
{
|
||||
class invbind;
|
||||
class ctrlrkey;
|
||||
|
||||
std::pair<keyboard_key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const std::string& name, bool axis)
|
||||
throw(std::bad_alloc, std::runtime_error);
|
||||
std::pair<key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const std::string& name,
|
||||
bool axis) throw(std::bad_alloc, std::runtime_error);
|
||||
|
||||
/**
|
||||
* Key specifier
|
||||
*/
|
||||
struct key_specifier
|
||||
struct keyspec
|
||||
{
|
||||
/**
|
||||
* Create a new key specifier (invalid).
|
||||
*/
|
||||
key_specifier() throw(std::bad_alloc);
|
||||
keyspec() throw(std::bad_alloc);
|
||||
/**
|
||||
* Create a new key specifier from keyspec.
|
||||
*
|
||||
* Parameter keyspec: The key specifier.
|
||||
*/
|
||||
key_specifier(const std::string& keyspec) throw(std::bad_alloc, std::runtime_error);
|
||||
keyspec(const std::string& keyspec) throw(std::bad_alloc, std::runtime_error);
|
||||
/**
|
||||
* Get the key specifier as a keyspec.
|
||||
*/
|
||||
|
@ -48,11 +50,11 @@ struct key_specifier
|
|||
/**
|
||||
* Compare for equality.
|
||||
*/
|
||||
bool operator==(const key_specifier& keyspec);
|
||||
bool operator==(const keyspec& keyspec);
|
||||
/**
|
||||
* Compare for not-equality.
|
||||
*/
|
||||
bool operator!=(const key_specifier& keyspec);
|
||||
bool operator!=(const keyspec& keyspec);
|
||||
/**
|
||||
* The modifier.
|
||||
*/
|
||||
|
@ -71,17 +73,17 @@ struct key_specifier
|
|||
/**
|
||||
* Keyboard mapper. Maps keyboard keys into commands.
|
||||
*/
|
||||
class keyboard_mapper : public keyboard_event_listener
|
||||
class mapper : public event_listener
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create new keyboard mapper.
|
||||
*/
|
||||
keyboard_mapper(keyboard& kbd, command::group& domain) throw(std::bad_alloc);
|
||||
mapper(keyboard& kbd, command::group& domain) throw(std::bad_alloc);
|
||||
/**
|
||||
* Destroy a keyboard mapper.
|
||||
*/
|
||||
~keyboard_mapper() throw();
|
||||
~mapper() throw();
|
||||
/**
|
||||
* Binds a key, erroring out if binding would conflict with existing one.
|
||||
*
|
||||
|
@ -110,52 +112,52 @@ public:
|
|||
*
|
||||
* Returns: The set of keyspecs that are bound.
|
||||
*/
|
||||
std::list<key_specifier> get_bindings() throw(std::bad_alloc);
|
||||
std::list<keyspec> get_bindings() throw(std::bad_alloc);
|
||||
/**
|
||||
* Get command for key.
|
||||
*/
|
||||
std::string get(const key_specifier& keyspec) throw(std::bad_alloc);
|
||||
std::string get(const keyspec& keyspec) throw(std::bad_alloc);
|
||||
/**
|
||||
* Bind command for key.
|
||||
*
|
||||
* Parameter keyspec: The key specifier to bind to.
|
||||
* Parameter cmd: The command to bind. If "", the key is unbound.
|
||||
*/
|
||||
void set(const key_specifier& keyspec, const std::string& cmd) throw(std::bad_alloc, std::runtime_error);
|
||||
void set(const keyspec& keyspec, const std::string& cmd) throw(std::bad_alloc, std::runtime_error);
|
||||
/**
|
||||
* Get set of inverse binds.
|
||||
*
|
||||
* Returns: The set of all inverses.
|
||||
*/
|
||||
std::set<inverse_bind*> get_inverses() throw(std::bad_alloc);
|
||||
std::set<invbind*> get_inverses() throw(std::bad_alloc);
|
||||
/**
|
||||
* Find inverse bind by command.
|
||||
*
|
||||
* Parameter command: The command.
|
||||
* Returns: The inverse bind, or NULL if none.
|
||||
*/
|
||||
inverse_bind* get_inverse(const std::string& command) throw(std::bad_alloc);
|
||||
invbind* get_inverse(const std::string& command) throw(std::bad_alloc);
|
||||
/**
|
||||
* Get set of controller keys.
|
||||
*
|
||||
* Returns: The set of all controller keys.
|
||||
*/
|
||||
std::set<controller_key*> get_controller_keys() throw(std::bad_alloc);
|
||||
std::set<ctrlrkey*> get_controller_keys() throw(std::bad_alloc);
|
||||
/**
|
||||
* Get specific controller key.
|
||||
*/
|
||||
controller_key* get_controllerkey(const std::string& command) throw(std::bad_alloc);
|
||||
ctrlrkey* get_controllerkey(const std::string& command) throw(std::bad_alloc);
|
||||
/**
|
||||
* Get list of controller keys for specific keyboard key.
|
||||
*/
|
||||
std::list<controller_key*> get_controllerkeys_kbdkey(keyboard_key* kbdkey) throw(std::bad_alloc);
|
||||
std::list<ctrlrkey*> get_controllerkeys_kbdkey(key* kbdkey) throw(std::bad_alloc);
|
||||
/**
|
||||
* Proxy for inverse bind registrations.
|
||||
*/
|
||||
struct _inverse_proxy
|
||||
{
|
||||
_inverse_proxy(keyboard_mapper& mapper) : _mapper(mapper) {}
|
||||
void do_register(const std::string& name, inverse_bind& ibind)
|
||||
_inverse_proxy(mapper& mapper) : _mapper(mapper) {}
|
||||
void do_register(const std::string& name, invbind& ibind)
|
||||
{
|
||||
_mapper.do_register_inverse(name, ibind);
|
||||
}
|
||||
|
@ -164,15 +166,15 @@ public:
|
|||
_mapper.do_unregister_inverse(name);
|
||||
}
|
||||
private:
|
||||
keyboard_mapper& _mapper;
|
||||
mapper& _mapper;
|
||||
} inverse_proxy;
|
||||
/**
|
||||
* Proxy for controller key registrations.
|
||||
*/
|
||||
struct _controllerkey_proxy
|
||||
{
|
||||
_controllerkey_proxy(keyboard_mapper& mapper) : _mapper(mapper) {}
|
||||
void do_register(const std::string& name, controller_key& ckey)
|
||||
_controllerkey_proxy(mapper& mapper) : _mapper(mapper) {}
|
||||
void do_register(const std::string& name, ctrlrkey& ckey)
|
||||
{
|
||||
_mapper.do_register_ckey(name, ckey);
|
||||
}
|
||||
|
@ -181,12 +183,12 @@ public:
|
|||
_mapper.do_unregister_ckey(name);
|
||||
}
|
||||
private:
|
||||
keyboard_mapper& _mapper;
|
||||
mapper& _mapper;
|
||||
} controllerkey_proxy;
|
||||
/**
|
||||
* Register inverse bind.
|
||||
*/
|
||||
void do_register_inverse(const std::string& name, inverse_bind& bind) throw(std::bad_alloc);
|
||||
void do_register_inverse(const std::string& name, invbind& bind) throw(std::bad_alloc);
|
||||
/**
|
||||
* Unregister inverse bind.
|
||||
*/
|
||||
|
@ -194,7 +196,7 @@ public:
|
|||
/**
|
||||
* Register controller key.
|
||||
*/
|
||||
void do_register_ckey(const std::string& name, controller_key& ckey) throw(std::bad_alloc);
|
||||
void do_register_ckey(const std::string& name, ctrlrkey& ckey) throw(std::bad_alloc);
|
||||
/**
|
||||
* Unregister inverse bind.
|
||||
*/
|
||||
|
@ -218,31 +220,31 @@ public:
|
|||
private:
|
||||
struct triplet
|
||||
{
|
||||
triplet(keyboard_modifier_set mod, keyboard_modifier_set mask, keyboard_key& key, unsigned subkey);
|
||||
triplet(keyboard_key& key, unsigned subkey);
|
||||
triplet(keyboard& k, const key_specifier& spec);
|
||||
triplet(modifier_set mod, modifier_set mask, key& kkey, unsigned subkey);
|
||||
triplet(key& kkey, unsigned subkey);
|
||||
triplet(keyboard& k, const keyspec& spec);
|
||||
bool operator<(const struct triplet& a) const;
|
||||
bool operator==(const struct triplet& a) const;
|
||||
bool operator<=(const struct triplet& a) const { return !(a > *this); }
|
||||
bool operator!=(const struct triplet& a) const { return !(a == *this); }
|
||||
bool operator>=(const struct triplet& a) const { return !(a < *this); }
|
||||
bool operator>(const struct triplet& a) const { return (a < *this); }
|
||||
key_specifier as_keyspec() const throw(std::bad_alloc);
|
||||
keyspec as_keyspec() const throw(std::bad_alloc);
|
||||
bool index;
|
||||
keyboard_modifier_set mod;
|
||||
keyboard_modifier_set mask;
|
||||
keyboard_key* key;
|
||||
modifier_set mod;
|
||||
modifier_set mask;
|
||||
key* _key;
|
||||
unsigned subkey;
|
||||
};
|
||||
void change_command(const key_specifier& spec, const std::string& old, const std::string& newc);
|
||||
void on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event);
|
||||
void on_key_event_subkey(keyboard_modifier_set& mods, keyboard_key& key, unsigned skey, bool polarity);
|
||||
keyboard_mapper(const keyboard_mapper&);
|
||||
keyboard_mapper& operator=(const keyboard_mapper&);
|
||||
std::map<std::string, inverse_bind*> ibinds;
|
||||
std::map<std::string, controller_key*> ckeys;
|
||||
void change_command(const keyspec& spec, const std::string& old, const std::string& newc);
|
||||
void on_key_event(modifier_set& mods, key& key, event& event);
|
||||
void on_key_event_subkey(modifier_set& mods, key& key, unsigned skey, bool polarity);
|
||||
mapper(const mapper&);
|
||||
mapper& operator=(const mapper&);
|
||||
std::map<std::string, invbind*> ibinds;
|
||||
std::map<std::string, ctrlrkey*> ckeys;
|
||||
std::map<triplet, std::string> bindings;
|
||||
std::set<keyboard_key*> listening;
|
||||
std::set<key*> listening;
|
||||
keyboard& kbd;
|
||||
command::group& domain;
|
||||
mutex_class mutex;
|
||||
|
@ -251,7 +253,7 @@ private:
|
|||
/**
|
||||
* Inverse bind. Can map up to 2 keys to some command (and follows forward binds).
|
||||
*/
|
||||
class inverse_bind
|
||||
class invbind
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -261,19 +263,19 @@ public:
|
|||
* Parameter command: Command this is for.
|
||||
* Parameter name: Name of inverse key.
|
||||
*/
|
||||
inverse_bind(keyboard_mapper& mapper, const std::string& command, const std::string& name)
|
||||
invbind(mapper& kmapper, const std::string& command, const std::string& name)
|
||||
throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~inverse_bind() throw();
|
||||
~invbind() throw();
|
||||
/**
|
||||
* Get keyspec.
|
||||
*
|
||||
* Parameter index: Index of the keyspec to get.
|
||||
* Returns: The keyspec.
|
||||
*/
|
||||
key_specifier get(unsigned index) throw(std::bad_alloc);
|
||||
keyspec get(unsigned index) throw(std::bad_alloc);
|
||||
/**
|
||||
* Clear key (subsequent keys fill the gap).
|
||||
*
|
||||
|
@ -285,7 +287,7 @@ public:
|
|||
*
|
||||
* Parameter keyspec: The new keyspec.
|
||||
*/
|
||||
void append(const key_specifier& keyspec) throw(std::bad_alloc);
|
||||
void append(const keyspec& keyspec) throw(std::bad_alloc);
|
||||
/**
|
||||
* Get name for command.
|
||||
*
|
||||
|
@ -293,14 +295,14 @@ public:
|
|||
*/
|
||||
std::string getname() throw(std::bad_alloc);
|
||||
private:
|
||||
friend class keyboard_mapper;
|
||||
inverse_bind(const inverse_bind&);
|
||||
inverse_bind& operator=(const inverse_bind&);
|
||||
void addkey(const key_specifier& keyspec);
|
||||
keyboard_mapper& mapper;
|
||||
friend class mapper;
|
||||
invbind(const invbind&);
|
||||
invbind& operator=(const invbind&);
|
||||
void addkey(const keyspec& keyspec);
|
||||
mapper& _mapper;
|
||||
std::string cmd;
|
||||
std::string oname;
|
||||
std::vector<key_specifier> specs;
|
||||
std::vector<keyspec> specs;
|
||||
mutex_class mutex;
|
||||
};
|
||||
|
||||
|
@ -309,7 +311,7 @@ private:
|
|||
*
|
||||
* Can overlap with any other bind.
|
||||
*/
|
||||
class controller_key : public keyboard_event_listener
|
||||
class ctrlrkey : public event_listener
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -320,16 +322,16 @@ public:
|
|||
* Parameter name: Name of controller key.
|
||||
* Parameter axis: If true, create a axis-type key.
|
||||
*/
|
||||
controller_key(keyboard_mapper& mapper, const std::string& command, const std::string& name,
|
||||
ctrlrkey(mapper& kmapper, const std::string& command, const std::string& name,
|
||||
bool axis = false) throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~controller_key() throw();
|
||||
~ctrlrkey() throw();
|
||||
/**
|
||||
* Get the trigger key.
|
||||
*/
|
||||
std::pair<keyboard_key*, unsigned> get(unsigned index) throw();
|
||||
std::pair<key*, unsigned> get(unsigned index) throw();
|
||||
/**
|
||||
* Get the trigger key.
|
||||
*/
|
||||
|
@ -337,7 +339,7 @@ public:
|
|||
/**
|
||||
* Set the trigger key (appends).
|
||||
*/
|
||||
void append(keyboard_key* key, unsigned subkey) throw();
|
||||
void append(key* key, unsigned subkey) throw();
|
||||
/**
|
||||
* Set the trigger key (appends).
|
||||
*/
|
||||
|
@ -345,7 +347,7 @@ public:
|
|||
/**
|
||||
* Remove the trigger key.
|
||||
*/
|
||||
void remove(keyboard_key* key, unsigned subkey) throw();
|
||||
void remove(key* key, unsigned subkey) throw();
|
||||
/**
|
||||
* Get the command.
|
||||
*/
|
||||
|
@ -359,13 +361,14 @@ public:
|
|||
*/
|
||||
bool is_axis() const throw() { return axis; }
|
||||
private:
|
||||
void on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event);
|
||||
keyboard_mapper& mapper;
|
||||
void on_key_event(modifier_set& mods, key& key, event& event);
|
||||
mapper& _mapper;
|
||||
std::string cmd;
|
||||
std::string oname;
|
||||
std::vector<std::pair<keyboard_key*, unsigned>> keys;
|
||||
std::vector<std::pair<key*, unsigned>> keys;
|
||||
bool axis;
|
||||
mutex_class mutex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -9,11 +9,13 @@
|
|||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
class keyboard_modifier;
|
||||
class keyboard_key;
|
||||
class keyboard_key_axis;
|
||||
class keyboard_key_mouse;
|
||||
class keyboard_event_listener;
|
||||
namespace keyboard
|
||||
{
|
||||
class modifier;
|
||||
class key;
|
||||
class key_axis;
|
||||
class key_mouse;
|
||||
class event_listener;
|
||||
|
||||
/**
|
||||
* A group of modifiers and keys.
|
||||
|
@ -43,7 +45,7 @@ public:
|
|||
struct _modifier_proxy
|
||||
{
|
||||
_modifier_proxy(keyboard& kbd) : _kbd(kbd) {}
|
||||
void do_register(const std::string& name, keyboard_modifier& mod)
|
||||
void do_register(const std::string& name, modifier& mod)
|
||||
{
|
||||
_kbd.do_register_modifier(name, mod);
|
||||
}
|
||||
|
@ -64,7 +66,7 @@ public:
|
|||
struct _key_proxy
|
||||
{
|
||||
_key_proxy(keyboard& kbd) : _kbd(kbd) {}
|
||||
void do_register(const std::string& name, keyboard_key& key)
|
||||
void do_register(const std::string& name, key& key)
|
||||
{
|
||||
_kbd.do_register_key(name, key);
|
||||
}
|
||||
|
@ -82,27 +84,27 @@ public:
|
|||
* Returns: The modifier.
|
||||
* Throws std::runtime_error: No such modifier.
|
||||
*/
|
||||
keyboard_modifier& lookup_modifier(const std::string& name) throw(std::runtime_error);
|
||||
modifier& lookup_modifier(const std::string& name) throw(std::runtime_error);
|
||||
/**
|
||||
* Try lookup modifier by name.
|
||||
*
|
||||
* Parameter name: The name of the modifier.
|
||||
* Returns: The modifier, or NULL if not found.
|
||||
*/
|
||||
keyboard_modifier* try_lookup_modifier(const std::string& name) throw();
|
||||
modifier* try_lookup_modifier(const std::string& name) throw();
|
||||
/**
|
||||
* Look up all modifiers.
|
||||
*
|
||||
* Returns: The set of modifiers.
|
||||
*/
|
||||
std::list<keyboard_modifier*> all_modifiers() throw(std::bad_alloc);
|
||||
std::list<modifier*> all_modifiers() throw(std::bad_alloc);
|
||||
/**
|
||||
* Register a modifier.
|
||||
*
|
||||
* Parameter name: The name of the modifier.
|
||||
* Parameter mod: The modifier.
|
||||
*/
|
||||
void do_register_modifier(const std::string& name, keyboard_modifier& mod) throw(std::bad_alloc);
|
||||
void do_register_modifier(const std::string& name, modifier& mod) throw(std::bad_alloc);
|
||||
/**
|
||||
* Unregister a modifier.
|
||||
*
|
||||
|
@ -116,27 +118,27 @@ public:
|
|||
* Returns: The key.
|
||||
* Throws std::runtime_error: No such key.
|
||||
*/
|
||||
keyboard_key& lookup_key(const std::string& name) throw(std::runtime_error);
|
||||
key& lookup_key(const std::string& name) throw(std::runtime_error);
|
||||
/**
|
||||
* Try lookup key by name.
|
||||
*
|
||||
* Parameter name: The name of the key.
|
||||
* Returns: The key, or NULL if not found.
|
||||
*/
|
||||
keyboard_key* try_lookup_key(const std::string& name) throw();
|
||||
key* try_lookup_key(const std::string& name) throw();
|
||||
/**
|
||||
* Look up all keys.
|
||||
*
|
||||
* Returns: The set of keys.
|
||||
*/
|
||||
std::list<keyboard_key*> all_keys() throw(std::bad_alloc);
|
||||
std::list<key*> all_keys() throw(std::bad_alloc);
|
||||
/**
|
||||
* Register a key.
|
||||
*
|
||||
* Parameter name: The name of the key.
|
||||
* Parameter mod: The key.
|
||||
*/
|
||||
void do_register_key(const std::string& name, keyboard_key& mod) throw(std::bad_alloc);
|
||||
void do_register_key(const std::string& name, key& mod) throw(std::bad_alloc);
|
||||
/**
|
||||
* Unregister a key.
|
||||
*
|
||||
|
@ -146,28 +148,28 @@ public:
|
|||
/**
|
||||
* Set exclusive listener for all keys at once.
|
||||
*/
|
||||
void set_exclusive(keyboard_event_listener* listener) throw();
|
||||
void set_exclusive(event_listener* listener) throw();
|
||||
/**
|
||||
* Set current key.
|
||||
*/
|
||||
void set_current_key(keyboard_key* key) throw();
|
||||
void set_current_key(key* key) throw();
|
||||
/**
|
||||
* Get current key.
|
||||
*/
|
||||
keyboard_key* get_current_key() throw();
|
||||
key* get_current_key() throw();
|
||||
private:
|
||||
keyboard(const keyboard&);
|
||||
keyboard& operator=(const keyboard&);
|
||||
std::map<std::string, keyboard_modifier*> modifiers;
|
||||
std::map<std::string, keyboard_key*> keys;
|
||||
std::map<std::string, modifier*> modifiers;
|
||||
std::map<std::string, key*> keys;
|
||||
mutex_class mutex;
|
||||
keyboard_key* current_key;
|
||||
key* current_key;
|
||||
};
|
||||
|
||||
/**
|
||||
* A modifier or group of modifiers.
|
||||
*/
|
||||
class keyboard_modifier
|
||||
class modifier
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -176,10 +178,10 @@ public:
|
|||
* Parameter keyb: The keyboard these will be on.
|
||||
* Parameter _name: The name of the modifier.
|
||||
*/
|
||||
keyboard_modifier(keyboard& keyb, const std::string& _name) throw(std::bad_alloc)
|
||||
modifier(keyboard& keyb, const std::string& _name) throw(std::bad_alloc)
|
||||
: kbd(keyb), name(_name)
|
||||
{
|
||||
register_queue<keyboard::_modifier_proxy, keyboard_modifier>::do_register(kbd.modifier_proxy, name,
|
||||
register_queue<keyboard::_modifier_proxy, modifier>::do_register(kbd.modifier_proxy, name,
|
||||
*this);
|
||||
}
|
||||
/**
|
||||
|
@ -189,18 +191,18 @@ public:
|
|||
* Parameter _name: The name of the modifier.
|
||||
* Parameter _link: The name of the modifier group this is in.
|
||||
*/
|
||||
keyboard_modifier(keyboard& keyb, const std::string& _name, const std::string& _link) throw(std::bad_alloc)
|
||||
modifier(keyboard& keyb, const std::string& _name, const std::string& _link) throw(std::bad_alloc)
|
||||
: kbd(keyb), name(_name), link(_link)
|
||||
{
|
||||
register_queue<keyboard::_modifier_proxy, keyboard_modifier>::do_register(kbd.modifier_proxy, name,
|
||||
register_queue<keyboard::_modifier_proxy, modifier>::do_register(kbd.modifier_proxy, name,
|
||||
*this);
|
||||
}
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_modifier() throw()
|
||||
~modifier() throw()
|
||||
{
|
||||
register_queue<keyboard::_modifier_proxy, keyboard_modifier>::do_unregister(kbd.modifier_proxy, name);
|
||||
register_queue<keyboard::_modifier_proxy, modifier>::do_unregister(kbd.modifier_proxy, name);
|
||||
}
|
||||
/**
|
||||
* Get associated keyboard.
|
||||
|
@ -221,7 +223,7 @@ public:
|
|||
*
|
||||
* Returns: The linked modifier, or NULL if none (or not initialized yet).
|
||||
*/
|
||||
keyboard_modifier* get_link() { return kbd.try_lookup_modifier(link); }
|
||||
modifier* get_link() { return kbd.try_lookup_modifier(link); }
|
||||
private:
|
||||
keyboard& kbd;
|
||||
std::string name;
|
||||
|
@ -231,7 +233,7 @@ private:
|
|||
/**
|
||||
* A set of modifier keys.
|
||||
*/
|
||||
class keyboard_modifier_set
|
||||
class modifier_set
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -241,7 +243,7 @@ public:
|
|||
* parameter really: If true, actually add the key. If false, do nothing.
|
||||
* throws std::bad_alloc: Not enough memory.
|
||||
*/
|
||||
void add(keyboard_modifier& mod, bool really = true) throw(std::bad_alloc);
|
||||
void add(modifier& mod, bool really = true) throw(std::bad_alloc);
|
||||
/**
|
||||
* Remove a modifier from the set.
|
||||
*
|
||||
|
@ -249,7 +251,7 @@ public:
|
|||
* parameter really: If true, actually remove the key. If false, do nothing.
|
||||
* throws std::bad_alloc: Not enough memory.
|
||||
*/
|
||||
void remove(keyboard_modifier& mod, bool really = true) throw(std::bad_alloc);
|
||||
void remove(modifier& mod, bool really = true) throw(std::bad_alloc);
|
||||
/**
|
||||
* Construct modifier set from comma-separated string.
|
||||
*
|
||||
|
@ -259,7 +261,7 @@ public:
|
|||
* throws std::bad_alloc: Not enough memory.
|
||||
* throws std::runtime_error: Illegal modifier or wrong syntax.
|
||||
*/
|
||||
static keyboard_modifier_set construct(keyboard& kbd, const std::string& modifiers) throw(std::bad_alloc,
|
||||
static modifier_set construct(keyboard& kbd, const std::string& modifiers) throw(std::bad_alloc,
|
||||
std::runtime_error);
|
||||
/**
|
||||
* Check modifier against its mask for validity.
|
||||
|
@ -272,7 +274,7 @@ public:
|
|||
* returns: True if set is valid, false if not.
|
||||
* throws std::bad_alloc: Not enough memory.
|
||||
*/
|
||||
bool valid(keyboard_modifier_set& mask) throw(std::bad_alloc);
|
||||
bool valid(modifier_set& mask) throw(std::bad_alloc);
|
||||
/**
|
||||
* Check if this modifier set triggers the action.
|
||||
*
|
||||
|
@ -282,7 +284,7 @@ public:
|
|||
* - Modifiers with this linkage group do not appear in either set nor trigger.
|
||||
*
|
||||
*/
|
||||
bool triggers(const keyboard_modifier_set& trigger, const keyboard_modifier_set& mask) throw(std::bad_alloc);
|
||||
bool triggers(const modifier_set& trigger, const modifier_set& mask) throw(std::bad_alloc);
|
||||
/**
|
||||
* Stringify.
|
||||
*/
|
||||
|
@ -293,14 +295,14 @@ public:
|
|||
* parameter m: Another set.
|
||||
* returns: True if two sets are equal, false if not.
|
||||
*/
|
||||
bool operator==(const keyboard_modifier_set& m) const throw();
|
||||
bool operator==(const modifier_set& m) const throw();
|
||||
/**
|
||||
* Less than check.
|
||||
*/
|
||||
bool operator<(const keyboard_modifier_set& m) const throw();
|
||||
bool operator<(const modifier_set& m) const throw();
|
||||
private:
|
||||
friend std::ostream& operator<<(std::ostream& os, const keyboard_modifier_set& m);
|
||||
std::set<keyboard_modifier*> set;
|
||||
friend std::ostream& operator<<(std::ostream& os, const modifier_set& m);
|
||||
std::set<modifier*> set;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -310,12 +312,12 @@ private:
|
|||
* parameter m: The modifier set to print.
|
||||
* returns: reference to os.
|
||||
*/
|
||||
std::ostream& operator<<(std::ostream& os, const keyboard_modifier_set& m);
|
||||
std::ostream& operator<<(std::ostream& os, const modifier_set& m);
|
||||
|
||||
/**
|
||||
* Type of key.
|
||||
*/
|
||||
enum keyboard_keytype
|
||||
enum keytype
|
||||
{
|
||||
/**
|
||||
* A simple key (pressed/released)
|
||||
|
@ -338,7 +340,7 @@ enum keyboard_keytype
|
|||
/**
|
||||
* Joystick axis calibration structure.
|
||||
*/
|
||||
struct keyboard_axis_calibration
|
||||
struct axis_calibration
|
||||
{
|
||||
/**
|
||||
* Mode: -1 => Disabled, 0 => Pressure-sentive button, 1 => Axis.
|
||||
|
@ -349,7 +351,7 @@ struct keyboard_axis_calibration
|
|||
/**
|
||||
* Mouse axis calibration structure.
|
||||
*/
|
||||
struct keyboard_mouse_calibration
|
||||
struct mouse_calibration
|
||||
{
|
||||
/**
|
||||
* The offset from left of screen area to left of game area.
|
||||
|
@ -364,7 +366,7 @@ struct keyboard_mouse_calibration
|
|||
/**
|
||||
* Superclass of key event data.
|
||||
*/
|
||||
class keyboard_event
|
||||
class event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -373,7 +375,7 @@ public:
|
|||
* Parameter _chngmask: The change mask.
|
||||
* Parameter _type: Type of the event.
|
||||
*/
|
||||
keyboard_event(uint32_t _chngmask, keyboard_keytype _type) throw()
|
||||
event(uint32_t _chngmask, keytype _type) throw()
|
||||
{
|
||||
chngmask = _chngmask;
|
||||
type = _type;
|
||||
|
@ -381,7 +383,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~keyboard_event() throw();
|
||||
virtual ~event() throw();
|
||||
/**
|
||||
* Get analog state. The format is dependent on key type.
|
||||
*/
|
||||
|
@ -395,16 +397,16 @@ public:
|
|||
/**
|
||||
* Get type of event.
|
||||
*/
|
||||
keyboard_keytype get_type() const throw() { return type; }
|
||||
keytype get_type() const throw() { return type; }
|
||||
private:
|
||||
uint32_t chngmask;
|
||||
keyboard_keytype type;
|
||||
keytype type;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple key event.
|
||||
*/
|
||||
class keyboard_event_key : public keyboard_event
|
||||
class event_key : public event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -412,11 +414,11 @@ public:
|
|||
*
|
||||
* Parameter chngmask: The change mask.
|
||||
*/
|
||||
keyboard_event_key(uint32_t chngmask);
|
||||
event_key(uint32_t chngmask);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_event_key() throw();
|
||||
~event_key() throw();
|
||||
/**
|
||||
* Get analog state.
|
||||
*
|
||||
|
@ -430,7 +432,7 @@ private:
|
|||
/**
|
||||
* An axis event.
|
||||
*/
|
||||
class keyboard_event_axis : public keyboard_event
|
||||
class event_axis : public event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -440,11 +442,11 @@ public:
|
|||
* Parameter chngmask: The change mask.
|
||||
* Parameter cal: The calibration structure.
|
||||
*/
|
||||
keyboard_event_axis(int32_t state, uint32_t chngmask);
|
||||
event_axis(int32_t state, uint32_t chngmask);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_event_axis() throw();
|
||||
~event_axis() throw();
|
||||
/**
|
||||
* Get analog state.
|
||||
*
|
||||
|
@ -453,13 +455,13 @@ public:
|
|||
int32_t get_state() const throw();
|
||||
private:
|
||||
int32_t state;
|
||||
keyboard_axis_calibration cal;
|
||||
axis_calibration cal;
|
||||
};
|
||||
|
||||
/**
|
||||
* A hat event.
|
||||
*/
|
||||
class keyboard_event_hat : public keyboard_event
|
||||
class event_hat : public event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -467,11 +469,11 @@ public:
|
|||
*
|
||||
* Parameter chngmask: The change mask to use.
|
||||
*/
|
||||
keyboard_event_hat(uint32_t chngmask);
|
||||
event_hat(uint32_t chngmask);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_event_hat() throw();
|
||||
~event_hat() throw();
|
||||
/**
|
||||
* Get analog state.
|
||||
*
|
||||
|
@ -483,7 +485,7 @@ public:
|
|||
/**
|
||||
* A mouse event.
|
||||
*/
|
||||
class keyboard_event_mouse : public keyboard_event
|
||||
class event_mouse : public event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -492,11 +494,11 @@ public:
|
|||
* Parameter state: The game-relative position to use.
|
||||
* Parameter cal: The calibration structure.
|
||||
*/
|
||||
keyboard_event_mouse(int32_t state, const keyboard_mouse_calibration& cal);
|
||||
event_mouse(int32_t state, const mouse_calibration& cal);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_event_mouse() throw();
|
||||
~event_mouse() throw();
|
||||
/**
|
||||
* Get analog state.
|
||||
*
|
||||
|
@ -506,22 +508,22 @@ public:
|
|||
/**
|
||||
* Get calibration data.
|
||||
*/
|
||||
keyboard_mouse_calibration get_calibration() { return cal; }
|
||||
mouse_calibration get_calibration() { return cal; }
|
||||
private:
|
||||
int32_t state;
|
||||
keyboard_mouse_calibration cal;
|
||||
mouse_calibration cal;
|
||||
};
|
||||
|
||||
/**
|
||||
* A keyboard event listener.
|
||||
*/
|
||||
class keyboard_event_listener
|
||||
class event_listener
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~keyboard_event_listener() throw();
|
||||
virtual ~event_listener() throw();
|
||||
/**
|
||||
* Receive a key event.
|
||||
*
|
||||
|
@ -529,13 +531,13 @@ public:
|
|||
* Parameter key: The key this event is about.
|
||||
* Parameter event: The event.
|
||||
*/
|
||||
virtual void on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event) = 0;
|
||||
virtual void on_key_event(modifier_set& mods, key& key, event& event) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* A (compound) key on keyboard.
|
||||
*/
|
||||
class keyboard_key
|
||||
class key
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -546,12 +548,12 @@ public:
|
|||
* Parameter clazz: The class of the key.
|
||||
* Parameter type: The type of key.
|
||||
*/
|
||||
keyboard_key(keyboard& keyb, const std::string& name, const std::string& clazz, keyboard_keytype type)
|
||||
key(keyboard& keyb, const std::string& name, const std::string& clazz, keytype type)
|
||||
throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~keyboard_key() throw();
|
||||
virtual ~key() throw();
|
||||
/**
|
||||
* Get class.
|
||||
*/
|
||||
|
@ -567,33 +569,33 @@ public:
|
|||
/**
|
||||
* Get key type.
|
||||
*/
|
||||
keyboard_keytype get_type() const throw() { return type; }
|
||||
keytype get_type() const throw() { return type; }
|
||||
/**
|
||||
* Add listener.
|
||||
*
|
||||
* Parameter listener: The listener.
|
||||
* Parameter analog: If true, also pass analog events.
|
||||
*/
|
||||
void add_listener(keyboard_event_listener& listener, bool analog) throw(std::bad_alloc);
|
||||
void add_listener(event_listener& listener, bool analog) throw(std::bad_alloc);
|
||||
/**
|
||||
* Remove listener.
|
||||
*
|
||||
* Parameter listener: The listener.
|
||||
*/
|
||||
void remove_listener(keyboard_event_listener& listener) throw();
|
||||
void remove_listener(event_listener& listener) throw();
|
||||
/**
|
||||
* Set exclusive listener.
|
||||
*
|
||||
* Parameter listener: The listener. NULL to ungrab key.
|
||||
*/
|
||||
void set_exclusive(keyboard_event_listener* listener) throw();
|
||||
void set_exclusive(event_listener* listener) throw();
|
||||
/**
|
||||
* Set analog state.
|
||||
*
|
||||
* Parameter mods: The current modifiers.
|
||||
* Parameter state: The new state. The format is dependent on key type.
|
||||
*/
|
||||
virtual void set_state(keyboard_modifier_set mods, int32_t state) throw() = 0;
|
||||
virtual void set_state(modifier_set mods, int32_t state) throw() = 0;
|
||||
/**
|
||||
* Get analog state. The format is dependent on key type.
|
||||
*/
|
||||
|
@ -609,11 +611,11 @@ public:
|
|||
/**
|
||||
* Dynamic cast to axis type.
|
||||
*/
|
||||
keyboard_key_axis* cast_axis() throw();
|
||||
key_axis* cast_axis() throw();
|
||||
/**
|
||||
* Dynamic cast to mouse type.
|
||||
*/
|
||||
keyboard_key_mouse* cast_mouse() throw();
|
||||
key_mouse* cast_mouse() throw();
|
||||
protected:
|
||||
/**
|
||||
* Call all event listeners on this key.
|
||||
|
@ -621,27 +623,27 @@ protected:
|
|||
* Parameter mods: The current modifiers.
|
||||
* Parameter event: The event to pass.
|
||||
*/
|
||||
void call_listeners(keyboard_modifier_set& mods, keyboard_event& event);
|
||||
void call_listeners(modifier_set& mods, event& event);
|
||||
/**
|
||||
* Mutex protecting state.
|
||||
*/
|
||||
mutable mutex_class mutex;
|
||||
private:
|
||||
keyboard_key(keyboard_key&);
|
||||
keyboard_key& operator=(keyboard_key&);
|
||||
key(key&);
|
||||
key& operator=(key&);
|
||||
keyboard& kbd;
|
||||
std::string clazz;
|
||||
std::string name;
|
||||
std::set<keyboard_event_listener*> digital_listeners;
|
||||
std::set<keyboard_event_listener*> analog_listeners;
|
||||
keyboard_event_listener* exclusive_listener;
|
||||
keyboard_keytype type;
|
||||
std::set<event_listener*> digital_listeners;
|
||||
std::set<event_listener*> analog_listeners;
|
||||
event_listener* exclusive_listener;
|
||||
keytype type;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple key on keyboard.
|
||||
*/
|
||||
class keyboard_key_key : public keyboard_key
|
||||
class key_key : public key
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -651,18 +653,18 @@ public:
|
|||
* Parameter name: The base name of the key.
|
||||
* Parameter clazz: The class of the key.
|
||||
*/
|
||||
keyboard_key_key(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
|
||||
key_key(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_key_key() throw();
|
||||
~key_key() throw();
|
||||
/**
|
||||
* Set analog state.
|
||||
*
|
||||
* Parameter mods: The current modifiers.
|
||||
* Parameter state: The new state. 1 for pressed, 0 for released.
|
||||
*/
|
||||
void set_state(keyboard_modifier_set mods, int32_t state) throw();
|
||||
void set_state(modifier_set mods, int32_t state) throw();
|
||||
/**
|
||||
* Get analog state. 1 for pressed, 0 for released.
|
||||
*/
|
||||
|
@ -676,15 +678,15 @@ public:
|
|||
*/
|
||||
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
|
||||
private:
|
||||
keyboard_key_key(keyboard_key_key&);
|
||||
keyboard_key_key& operator=(keyboard_key_key&);
|
||||
key_key(key_key&);
|
||||
key_key& operator=(key_key&);
|
||||
int32_t state;
|
||||
};
|
||||
|
||||
/**
|
||||
* A hat on keyboard.
|
||||
*/
|
||||
class keyboard_key_hat : public keyboard_key
|
||||
class key_hat : public key
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -694,18 +696,18 @@ public:
|
|||
* Parameter name: The base name of the key.
|
||||
* Parameter clazz: The class of the key.
|
||||
*/
|
||||
keyboard_key_hat(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
|
||||
key_hat(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_key_hat() throw();
|
||||
~key_hat() throw();
|
||||
/**
|
||||
* Set analog state.
|
||||
*
|
||||
* Parameter mods: The current modifiers.
|
||||
* Parameter state: The new state. 1 => up, 2 => right, 4 => down, 8 => left.
|
||||
*/
|
||||
void set_state(keyboard_modifier_set mods, int32_t state) throw();
|
||||
void set_state(modifier_set mods, int32_t state) throw();
|
||||
/**
|
||||
* Get analog state. 1 => up, 2 => right, 4 => down, 8 => left.
|
||||
*/
|
||||
|
@ -719,15 +721,15 @@ public:
|
|||
*/
|
||||
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
|
||||
private:
|
||||
keyboard_key_hat(keyboard_key_hat&);
|
||||
keyboard_key_hat& operator=(keyboard_key_hat&);
|
||||
key_hat(key_hat&);
|
||||
key_hat& operator=(key_hat&);
|
||||
int32_t state;
|
||||
};
|
||||
|
||||
/**
|
||||
* An axis on keyboard.
|
||||
*/
|
||||
class keyboard_key_axis : public keyboard_key
|
||||
class key_axis : public key
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -738,19 +740,19 @@ public:
|
|||
* Parameter clazz: The class of the key.
|
||||
* Parameter mode: Initial mode: -1 => disabled, 0 => axis, 1 => pressure
|
||||
*/
|
||||
keyboard_key_axis(keyboard& keyb, const std::string& name, const std::string& clazz, int mode)
|
||||
key_axis(keyboard& keyb, const std::string& name, const std::string& clazz, int mode)
|
||||
throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_key_axis() throw();
|
||||
~key_axis() throw();
|
||||
/**
|
||||
* Set analog state.
|
||||
*
|
||||
* Parameter mods: The current modifiers.
|
||||
* Parameter state: The new state. Uncalibrated analog position.
|
||||
*/
|
||||
void set_state(keyboard_modifier_set mods, int32_t state) throw();
|
||||
void set_state(modifier_set mods, int32_t state) throw();
|
||||
/**
|
||||
* Get analog state. -32767...32767 for axes, 0...32767 for pressure-sensitive buttons.
|
||||
*/
|
||||
|
@ -772,8 +774,8 @@ public:
|
|||
*/
|
||||
void set_mode(int mode, double tolerance) throw();
|
||||
private:
|
||||
keyboard_key_axis(keyboard_key_axis&);
|
||||
keyboard_key_axis& operator=(keyboard_key_axis&);
|
||||
key_axis(key_axis&);
|
||||
key_axis& operator=(key_axis&);
|
||||
int32_t rawstate;
|
||||
int digitalstate;
|
||||
double last_tolerance;
|
||||
|
@ -783,7 +785,7 @@ private:
|
|||
/**
|
||||
* A mouse axis on keyboard.
|
||||
*/
|
||||
class keyboard_key_mouse : public keyboard_key
|
||||
class key_mouse : public key
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -794,19 +796,19 @@ public:
|
|||
* Parameter clazz: The class of the key.
|
||||
* Parameter cal: Initial calibration.
|
||||
*/
|
||||
keyboard_key_mouse(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
keyboard_mouse_calibration cal) throw(std::bad_alloc);
|
||||
key_mouse(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
mouse_calibration cal) throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~keyboard_key_mouse() throw();
|
||||
~key_mouse() throw();
|
||||
/**
|
||||
* Set analog state.
|
||||
*
|
||||
* Parameter mods: The current modifiers.
|
||||
* Parameter state: The new state. Screen-relative analog position.
|
||||
*/
|
||||
void set_state(keyboard_modifier_set mods, int32_t state) throw();
|
||||
void set_state(modifier_set mods, int32_t state) throw();
|
||||
/**
|
||||
* Get analog state. Game-relative analog position.
|
||||
*/
|
||||
|
@ -822,16 +824,16 @@ public:
|
|||
/**
|
||||
* Get calibration.
|
||||
*/
|
||||
keyboard_mouse_calibration get_calibration() const throw();
|
||||
mouse_calibration get_calibration() const throw();
|
||||
/**
|
||||
* Set calibration.
|
||||
*/
|
||||
void set_calibration(keyboard_mouse_calibration cal) throw();
|
||||
void set_calibration(mouse_calibration cal) throw();
|
||||
private:
|
||||
keyboard_key_mouse(keyboard_key_mouse&);
|
||||
keyboard_key_mouse& operator=(keyboard_key_mouse&);
|
||||
key_mouse(key_mouse&);
|
||||
key_mouse& operator=(key_mouse&);
|
||||
int32_t rawstate;
|
||||
keyboard_mouse_calibration cal;
|
||||
mouse_calibration cal;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -15,7 +15,7 @@ extern lua_function_group lua_func_callback;
|
|||
extern lua_function_group lua_func_load;
|
||||
extern lua_function_group lua_func_zip;
|
||||
|
||||
void push_keygroup_parameters(lua_state& L, keyboard_key& p);
|
||||
void push_keygroup_parameters(lua_state& L, keyboard::key& p);
|
||||
extern lua_render_context* lua_render_ctx;
|
||||
extern controller_frame* lua_input_controllerdata;
|
||||
extern bool* lua_kill_frame;
|
||||
|
|
|
@ -28,7 +28,7 @@ void lua_callback_err_save(const std::string& name) throw();
|
|||
void lua_callback_post_save(const std::string& name, bool is_state) throw();
|
||||
void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw();
|
||||
void lua_callback_quit() throw();
|
||||
void lua_callback_keyhook(const std::string& key, keyboard_key& p) throw();
|
||||
void lua_callback_keyhook(const std::string& key, keyboard::key& p) throw();
|
||||
void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs, uint64_t ssecs, movie& mov, void* u);
|
||||
bool lua_callback_do_button(uint32_t port, uint32_t controller, uint32_t index, const char* type);
|
||||
void lua_callback_movie_lost(const char* what);
|
||||
|
|
|
@ -13,7 +13,7 @@ command::group lsnes_cmd;
|
|||
namespace
|
||||
{
|
||||
mutex_class alias_ibind_mutex;
|
||||
std::map<std::string, inverse_bind*> alias_binds;
|
||||
std::map<std::string, keyboard::invbind*> alias_binds;
|
||||
}
|
||||
|
||||
void refresh_alias_binds()
|
||||
|
@ -30,6 +30,6 @@ void refresh_alias_binds()
|
|||
if(i == "" || i[0] == '-')
|
||||
continue;
|
||||
if(!alias_binds.count(i) || alias_binds[i] == NULL)
|
||||
alias_binds[i] = new inverse_bind(lsnes_mapper, i, "Alias‣" + i);
|
||||
alias_binds[i] = new keyboard::invbind(lsnes_mapper, i, "Alias‣" + i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ namespace
|
|||
}
|
||||
};
|
||||
|
||||
std::map<std::string, inverse_bind*> macro_binds;
|
||||
std::map<std::string, inverse_bind*> macro_binds2;
|
||||
std::map<std::string, keyboard::invbind*> macro_binds;
|
||||
std::map<std::string, keyboard::invbind*> macro_binds2;
|
||||
std::map<std::string, controller_bind> all_buttons;
|
||||
std::map<std::string, active_bind> active_buttons;
|
||||
std::map<std::string, controller_key*> added_keys;
|
||||
std::map<std::string, keyboard::ctrlrkey*> added_keys;
|
||||
|
||||
//Promote stored key to active key.
|
||||
void promote_key(controller_key& k)
|
||||
void promote_key(keyboard::ctrlrkey& k)
|
||||
{
|
||||
std::string name = k.get_command();
|
||||
if(added_keys.count(name)) {
|
||||
|
@ -86,35 +86,35 @@ namespace
|
|||
//Allocate controller keys for specified button.
|
||||
void add_button(const std::string& name, const controller_bind& binding)
|
||||
{
|
||||
controller_key* k;
|
||||
keyboard::ctrlrkey* k;
|
||||
if(binding.mode == 0) {
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "+controller " << name).str(),
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "+controller " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name).str());
|
||||
promote_key(*k);
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "hold-controller " << name).str(),
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "hold-controller " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name << "‣hold").str());
|
||||
promote_key(*k);
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "type-controller " << name).str(),
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "type-controller " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name << "‣type").str());
|
||||
promote_key(*k);
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "+autofire-controller " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name << "‣autofire").str());
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "+autofire-controller "
|
||||
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
|
||||
<< binding.number << "‣" << binding.name << "‣autofire").str());
|
||||
promote_key(*k);
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "autofire-controller " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name << "‣autofire toggle").str());
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "autofire-controller "
|
||||
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
|
||||
<< binding.number << "‣" << binding.name << "‣autofire toggle").str());
|
||||
promote_key(*k);
|
||||
} else if(binding.mode == 1) {
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "designate-position " << name).str(),
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "designate-position " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name).str());
|
||||
promote_key(*k);
|
||||
} else if(binding.mode == 2) {
|
||||
k = new controller_key(lsnes_mapper, (stringfmt() << "controller-analog " << name).str(),
|
||||
k = new keyboard::ctrlrkey(lsnes_mapper, (stringfmt() << "controller-analog " << name).str(),
|
||||
(stringfmt() << "Controller‣" << binding.cclass << "‣#" << binding.number << "‣"
|
||||
<< binding.name << " (axis)").str(), true);
|
||||
promote_key(*k);
|
||||
|
@ -359,8 +359,8 @@ namespace
|
|||
if(mode < 3)
|
||||
do_button_action(name, state, mode);
|
||||
else if(mode == 3) {
|
||||
keyboard_key* mouse_x = lsnes_kbd.try_lookup_key("mouse_x");
|
||||
keyboard_key* mouse_y = lsnes_kbd.try_lookup_key("mouse_y");
|
||||
keyboard::key* mouse_x = lsnes_kbd.try_lookup_key("mouse_x");
|
||||
keyboard::key* mouse_y = lsnes_kbd.try_lookup_key("mouse_y");
|
||||
if(!mouse_x || !mouse_y) {
|
||||
messages << "Controller analog function not available without mouse" << std::endl;
|
||||
return;
|
||||
|
@ -575,8 +575,10 @@ void load_macros(controller_state& ctrlstate)
|
|||
for(auto i : s) {
|
||||
if(!macro_binds.count(i)) {
|
||||
//New macro, create inverse bind.
|
||||
macro_binds[i] = new inverse_bind(lsnes_mapper, "macro " + i , "Macro‣" + i + " (toggle)");
|
||||
macro_binds2[i] = new inverse_bind(lsnes_mapper, "+macro " + i , "Macro‣" + i + " (hold)");
|
||||
macro_binds[i] = new keyboard::invbind(lsnes_mapper, "macro " + i , "Macro‣" + i +
|
||||
" (toggle)");
|
||||
macro_binds2[i] = new keyboard::invbind(lsnes_mapper, "+macro " + i , "Macro‣" + i +
|
||||
" (hold)");
|
||||
}
|
||||
}
|
||||
for(auto i : macro_binds) {
|
||||
|
|
|
@ -214,15 +214,15 @@ void render_framebuffer()
|
|||
ri.rq.run(main_screen);
|
||||
notify_set_screen(main_screen);
|
||||
//We would want divide by 2, but we'll do it ourselves in order to do mouse.
|
||||
keyboard_key* mouse_x = lsnes_kbd.try_lookup_key("mouse_x");
|
||||
keyboard_key* mouse_y = lsnes_kbd.try_lookup_key("mouse_y");
|
||||
keyboard_mouse_calibration xcal;
|
||||
keyboard_mouse_calibration ycal;
|
||||
keyboard::key* mouse_x = lsnes_kbd.try_lookup_key("mouse_x");
|
||||
keyboard::key* mouse_y = lsnes_kbd.try_lookup_key("mouse_y");
|
||||
keyboard::mouse_calibration xcal;
|
||||
keyboard::mouse_calibration ycal;
|
||||
xcal.offset = ri.lgap;
|
||||
ycal.offset = ri.tgap;
|
||||
if(mouse_x && mouse_x->get_type() == KBD_KEYTYPE_MOUSE)
|
||||
if(mouse_x && mouse_x->get_type() == keyboard::KBD_KEYTYPE_MOUSE)
|
||||
mouse_x->cast_mouse()->set_calibration(xcal);
|
||||
if(mouse_y && mouse_y->get_type() == KBD_KEYTYPE_MOUSE)
|
||||
if(mouse_y && mouse_y->get_type() == keyboard::KBD_KEYTYPE_MOUSE)
|
||||
mouse_y->cast_mouse()->set_calibration(ycal);
|
||||
buffering.end_read();
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ namespace
|
|||
turboed = false;
|
||||
});
|
||||
|
||||
inverse_bind turboh(lsnes_mapper, "+turbo", "Speed‣Turbo hold");
|
||||
inverse_bind turbot(lsnes_mapper, "toggle-turbo", "Speed‣Turbo toggle");
|
||||
keyboard::invbind turboh(lsnes_mapper, "+turbo", "Speed‣Turbo hold");
|
||||
keyboard::invbind turbot(lsnes_mapper, "toggle-turbo", "Speed‣Turbo toggle");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1674,7 +1674,7 @@ out:
|
|||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
active_flag = false;
|
||||
});
|
||||
inverse_bind itangent(lsnes_mapper, "+tangent", "Movie‣Voice tangent");
|
||||
keyboard::invbind itangent(lsnes_mapper, "+tangent", "Movie‣Voice tangent");
|
||||
inthread_th* int_task;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
#include <sstream>
|
||||
#include <set>
|
||||
|
||||
keyboard lsnes_kbd;
|
||||
keyboard_mapper lsnes_mapper(lsnes_kbd, lsnes_cmd);
|
||||
keyboard::keyboard lsnes_kbd;
|
||||
keyboard::mapper lsnes_mapper(lsnes_kbd, lsnes_cmd);
|
||||
|
||||
hw_gamepad_set lsnes_gamepads;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard_key*> buttons;
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard_key*> axes;
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard_key*> hats;
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard::key*> buttons;
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard::key*> axes;
|
||||
std::map<std::pair<unsigned, unsigned>, keyboard::key*> hats;
|
||||
}
|
||||
|
||||
void lsnes_gamepads_init()
|
||||
|
@ -34,17 +34,17 @@ void lsnes_gamepads_init()
|
|||
lsnes_gamepads.set_button_cb([](unsigned jnum, unsigned num, bool val) {
|
||||
if(!buttons.count(std::make_pair(jnum, num)))
|
||||
return;
|
||||
platform::queue(keypress(keyboard_modifier_set(), *buttons[std::make_pair(jnum, num)], val));
|
||||
platform::queue(keypress(keyboard::modifier_set(), *buttons[std::make_pair(jnum, num)], val));
|
||||
});
|
||||
lsnes_gamepads.set_hat_cb([](unsigned jnum, unsigned num, unsigned val) {
|
||||
if(!hats.count(std::make_pair(jnum, num)))
|
||||
return;
|
||||
platform::queue(keypress(keyboard_modifier_set(), *hats[std::make_pair(jnum, num)], val));
|
||||
platform::queue(keypress(keyboard::modifier_set(), *hats[std::make_pair(jnum, num)], val));
|
||||
});
|
||||
lsnes_gamepads.set_axis_cb([](unsigned jnum, unsigned num, int16_t val) {
|
||||
if(!axes.count(std::make_pair(jnum, num)))
|
||||
return;
|
||||
platform::queue(keypress(keyboard_modifier_set(), *axes[std::make_pair(jnum, num)], val));
|
||||
platform::queue(keypress(keyboard::modifier_set(), *axes[std::make_pair(jnum, num)], val));
|
||||
});
|
||||
lsnes_gamepads.set_axismode_cb([](unsigned jnum, unsigned num, int mode, double tolerance) {
|
||||
if(!axes.count(std::make_pair(jnum, num)))
|
||||
|
@ -55,15 +55,15 @@ void lsnes_gamepads_init()
|
|||
if(type == 0) {
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "axis" << num).str();
|
||||
int mode = lsnes_gamepads[jnum].get_mode(num);
|
||||
axes[std::make_pair(jnum, num)] = new keyboard_key_axis(lsnes_kbd, name, "joystick", mode);
|
||||
axes[std::make_pair(jnum, num)] = new keyboard::key_axis(lsnes_kbd, name, "joystick", mode);
|
||||
//Axis.
|
||||
} else if(type == 1) {
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "button" << num).str();
|
||||
buttons[std::make_pair(jnum, num)] = new keyboard_key_key(lsnes_kbd, name, "joystick");
|
||||
buttons[std::make_pair(jnum, num)] = new keyboard::key_key(lsnes_kbd, name, "joystick");
|
||||
//Button.
|
||||
} else if(type == 2) {
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "hat" << num).str();
|
||||
hats[std::make_pair(jnum, num)] = new keyboard_key_hat(lsnes_kbd, name, "joystick");
|
||||
hats[std::make_pair(jnum, num)] = new keyboard::key_hat(lsnes_kbd, name, "joystick");
|
||||
//Hat.
|
||||
}
|
||||
});
|
||||
|
|
|
@ -897,92 +897,92 @@ namespace
|
|||
messages << "Macros are not held for next frame." << std::endl;
|
||||
});
|
||||
|
||||
inverse_bind imhold1(lsnes_mapper, "+hold-macro", "Macro‣Hold all macros");
|
||||
inverse_bind imhold2(lsnes_mapper, "hold-macro", "Macro‣Hold all macros (typed)");
|
||||
inverse_bind ipause_emulator(lsnes_mapper, "pause-emulator", "Speed‣(Un)pause");
|
||||
inverse_bind ijback(lsnes_mapper, "cycle-jukebox-backward", "Slot select‣Cycle backwards");
|
||||
inverse_bind ijforward(lsnes_mapper, "cycle-jukebox-forward", "Slot select‣Cycle forwards");
|
||||
inverse_bind iloadj(lsnes_mapper, "load-jukebox", "Load‣Selected slot");
|
||||
inverse_bind iloadjrw(lsnes_mapper, "load-jukebox-readwrite", "Load‣Selected slot (readwrite mode)");
|
||||
inverse_bind iloadjro(lsnes_mapper, "load-jukebox-readonly", "Load‣Selected slot (readonly mode)");
|
||||
inverse_bind iloadjp(lsnes_mapper, "load-jukebox-preserve", "Load‣Selected slot (preserve input)");
|
||||
inverse_bind iloadjm(lsnes_mapper, "load-jukebox-movie", "Load‣Selected slot (as movie)");
|
||||
inverse_bind isavej(lsnes_mapper, "save-jukebox", "Save‣Selected slot");
|
||||
inverse_bind iadvframe(lsnes_mapper, "+advance-frame", "Speed‣Advance frame");
|
||||
inverse_bind iadvsubframe(lsnes_mapper, "+advance-poll", "Speed‣Advance subframe");
|
||||
inverse_bind iskiplag(lsnes_mapper, "advance-skiplag", "Speed‣Advance poll");
|
||||
inverse_bind ireset(lsnes_mapper, "reset", "System‣Reset");
|
||||
inverse_bind iset_rwmode(lsnes_mapper, "set-rwmode", "Movie‣Switch to read/write");
|
||||
inverse_bind itoggle_romode(lsnes_mapper, "set-romode", "Movie‣Switch to read-only");
|
||||
inverse_bind itoggle_rwmode(lsnes_mapper, "toggle-rwmode", "Movie‣Toggle read-only");
|
||||
inverse_bind irepaint(lsnes_mapper, "repaint", "System‣Repaint screen");
|
||||
inverse_bind itogglepause(lsnes_mapper, "toggle-pause-on-end", "Movie‣Toggle pause-on-end");
|
||||
inverse_bind irewind_movie(lsnes_mapper, "rewind-movie", "Movie‣Rewind movie");
|
||||
inverse_bind icancel_saves(lsnes_mapper, "cancel-saves", "Save‣Cancel pending saves");
|
||||
inverse_bind iload1(lsnes_mapper, "load ${project}1.lsmv", "Load‣Slot 1");
|
||||
inverse_bind iload2(lsnes_mapper, "load ${project}2.lsmv", "Load‣Slot 2");
|
||||
inverse_bind iload3(lsnes_mapper, "load ${project}3.lsmv", "Load‣Slot 3");
|
||||
inverse_bind iload4(lsnes_mapper, "load ${project}4.lsmv", "Load‣Slot 4");
|
||||
inverse_bind iload5(lsnes_mapper, "load ${project}5.lsmv", "Load‣Slot 5");
|
||||
inverse_bind iload6(lsnes_mapper, "load ${project}6.lsmv", "Load‣Slot 6");
|
||||
inverse_bind iload7(lsnes_mapper, "load ${project}7.lsmv", "Load‣Slot 7");
|
||||
inverse_bind iload8(lsnes_mapper, "load ${project}8.lsmv", "Load‣Slot 8");
|
||||
inverse_bind iload9(lsnes_mapper, "load ${project}9.lsmv", "Load‣Slot 9");
|
||||
inverse_bind iload10(lsnes_mapper, "load ${project}10.lsmv", "Load‣Slot 10");
|
||||
inverse_bind iload11(lsnes_mapper, "load ${project}11.lsmv", "Load‣Slot 11");
|
||||
inverse_bind iload12(lsnes_mapper, "load ${project}12.lsmv", "Load‣Slot 12");
|
||||
inverse_bind iload13(lsnes_mapper, "load ${project}13.lsmv", "Load‣Slot 13");
|
||||
inverse_bind iload14(lsnes_mapper, "load ${project}14.lsmv", "Load‣Slot 14");
|
||||
inverse_bind iload15(lsnes_mapper, "load ${project}15.lsmv", "Load‣Slot 15");
|
||||
inverse_bind iload16(lsnes_mapper, "load ${project}16.lsmv", "Load‣Slot 16");
|
||||
inverse_bind iload17(lsnes_mapper, "load ${project}17.lsmv", "Load‣Slot 17");
|
||||
inverse_bind iload18(lsnes_mapper, "load ${project}18.lsmv", "Load‣Slot 18");
|
||||
inverse_bind iload19(lsnes_mapper, "load ${project}19.lsmv", "Load‣Slot 19");
|
||||
inverse_bind iload20(lsnes_mapper, "load ${project}20.lsmv", "Load‣Slot 20");
|
||||
inverse_bind iload21(lsnes_mapper, "load ${project}21.lsmv", "Load‣Slot 21");
|
||||
inverse_bind iload22(lsnes_mapper, "load ${project}22.lsmv", "Load‣Slot 22");
|
||||
inverse_bind iload23(lsnes_mapper, "load ${project}23.lsmv", "Load‣Slot 23");
|
||||
inverse_bind iload24(lsnes_mapper, "load ${project}24.lsmv", "Load‣Slot 24");
|
||||
inverse_bind iload25(lsnes_mapper, "load ${project}25.lsmv", "Load‣Slot 25");
|
||||
inverse_bind iload26(lsnes_mapper, "load ${project}26.lsmv", "Load‣Slot 26");
|
||||
inverse_bind iload27(lsnes_mapper, "load ${project}27.lsmv", "Load‣Slot 27");
|
||||
inverse_bind iload28(lsnes_mapper, "load ${project}28.lsmv", "Load‣Slot 28");
|
||||
inverse_bind iload29(lsnes_mapper, "load ${project}29.lsmv", "Load‣Slot 29");
|
||||
inverse_bind iload30(lsnes_mapper, "load ${project}30.lsmv", "Load‣Slot 30");
|
||||
inverse_bind iload31(lsnes_mapper, "load ${project}31.lsmv", "Load‣Slot 31");
|
||||
inverse_bind iload32(lsnes_mapper, "load ${project}32.lsmv", "Load‣Slot 32");
|
||||
inverse_bind isave1(lsnes_mapper, "save-state ${project}1.lsmv", "Save‣Slot 1");
|
||||
inverse_bind isave2(lsnes_mapper, "save-state ${project}2.lsmv", "Save‣Slot 2");
|
||||
inverse_bind isave3(lsnes_mapper, "save-state ${project}3.lsmv", "Save‣Slot 3");
|
||||
inverse_bind isave4(lsnes_mapper, "save-state ${project}4.lsmv", "Save‣Slot 4");
|
||||
inverse_bind isave5(lsnes_mapper, "save-state ${project}5.lsmv", "Save‣Slot 5");
|
||||
inverse_bind isave6(lsnes_mapper, "save-state ${project}6.lsmv", "Save‣Slot 6");
|
||||
inverse_bind isave7(lsnes_mapper, "save-state ${project}7.lsmv", "Save‣Slot 7");
|
||||
inverse_bind isave8(lsnes_mapper, "save-state ${project}8.lsmv", "Save‣Slot 8");
|
||||
inverse_bind isave9(lsnes_mapper, "save-state ${project}9.lsmv", "Save‣Slot 9");
|
||||
inverse_bind isave10(lsnes_mapper, "save-state ${project}10.lsmv", "Save‣Slot 10");
|
||||
inverse_bind isave11(lsnes_mapper, "save-state ${project}11.lsmv", "Save‣Slot 11");
|
||||
inverse_bind isave12(lsnes_mapper, "save-state ${project}12.lsmv", "Save‣Slot 12");
|
||||
inverse_bind isave13(lsnes_mapper, "save-state ${project}13.lsmv", "Save‣Slot 13");
|
||||
inverse_bind isave14(lsnes_mapper, "save-state ${project}14.lsmv", "Save‣Slot 14");
|
||||
inverse_bind isave15(lsnes_mapper, "save-state ${project}15.lsmv", "Save‣Slot 15");
|
||||
inverse_bind isave16(lsnes_mapper, "save-state ${project}16.lsmv", "Save‣Slot 16");
|
||||
inverse_bind isave17(lsnes_mapper, "save-state ${project}17.lsmv", "Save‣Slot 17");
|
||||
inverse_bind isave18(lsnes_mapper, "save-state ${project}18.lsmv", "Save‣Slot 18");
|
||||
inverse_bind isave19(lsnes_mapper, "save-state ${project}19.lsmv", "Save‣Slot 19");
|
||||
inverse_bind isave20(lsnes_mapper, "save-state ${project}20.lsmv", "Save‣Slot 20");
|
||||
inverse_bind isave21(lsnes_mapper, "save-state ${project}21.lsmv", "Save‣Slot 21");
|
||||
inverse_bind isave22(lsnes_mapper, "save-state ${project}22.lsmv", "Save‣Slot 22");
|
||||
inverse_bind isave23(lsnes_mapper, "save-state ${project}23.lsmv", "Save‣Slot 23");
|
||||
inverse_bind isave24(lsnes_mapper, "save-state ${project}24.lsmv", "Save‣Slot 24");
|
||||
inverse_bind isave25(lsnes_mapper, "save-state ${project}25.lsmv", "Save‣Slot 25");
|
||||
inverse_bind isave26(lsnes_mapper, "save-state ${project}26.lsmv", "Save‣Slot 26");
|
||||
inverse_bind isave27(lsnes_mapper, "save-state ${project}27.lsmv", "Save‣Slot 27");
|
||||
inverse_bind isave28(lsnes_mapper, "save-state ${project}28.lsmv", "Save‣Slot 28");
|
||||
inverse_bind isave29(lsnes_mapper, "save-state ${project}29.lsmv", "Save‣Slot 29");
|
||||
inverse_bind isave30(lsnes_mapper, "save-state ${project}30.lsmv", "Save‣Slot 30");
|
||||
inverse_bind isave31(lsnes_mapper, "save-state ${project}31.lsmv", "Save‣Slot 31");
|
||||
inverse_bind isave32(lsnes_mapper, "save-state ${project}32.lsmv", "Save‣Slot 32");
|
||||
keyboard::invbind imhold1(lsnes_mapper, "+hold-macro", "Macro‣Hold all macros");
|
||||
keyboard::invbind imhold2(lsnes_mapper, "hold-macro", "Macro‣Hold all macros (typed)");
|
||||
keyboard::invbind ipause_emulator(lsnes_mapper, "pause-emulator", "Speed‣(Un)pause");
|
||||
keyboard::invbind ijback(lsnes_mapper, "cycle-jukebox-backward", "Slot select‣Cycle backwards");
|
||||
keyboard::invbind ijforward(lsnes_mapper, "cycle-jukebox-forward", "Slot select‣Cycle forwards");
|
||||
keyboard::invbind iloadj(lsnes_mapper, "load-jukebox", "Load‣Selected slot");
|
||||
keyboard::invbind iloadjrw(lsnes_mapper, "load-jukebox-readwrite", "Load‣Selected slot (readwrite mode)");
|
||||
keyboard::invbind iloadjro(lsnes_mapper, "load-jukebox-readonly", "Load‣Selected slot (readonly mode)");
|
||||
keyboard::invbind iloadjp(lsnes_mapper, "load-jukebox-preserve", "Load‣Selected slot (preserve input)");
|
||||
keyboard::invbind iloadjm(lsnes_mapper, "load-jukebox-movie", "Load‣Selected slot (as movie)");
|
||||
keyboard::invbind isavej(lsnes_mapper, "save-jukebox", "Save‣Selected slot");
|
||||
keyboard::invbind iadvframe(lsnes_mapper, "+advance-frame", "Speed‣Advance frame");
|
||||
keyboard::invbind iadvsubframe(lsnes_mapper, "+advance-poll", "Speed‣Advance subframe");
|
||||
keyboard::invbind iskiplag(lsnes_mapper, "advance-skiplag", "Speed‣Advance poll");
|
||||
keyboard::invbind ireset(lsnes_mapper, "reset", "System‣Reset");
|
||||
keyboard::invbind iset_rwmode(lsnes_mapper, "set-rwmode", "Movie‣Switch to read/write");
|
||||
keyboard::invbind itoggle_romode(lsnes_mapper, "set-romode", "Movie‣Switch to read-only");
|
||||
keyboard::invbind itoggle_rwmode(lsnes_mapper, "toggle-rwmode", "Movie‣Toggle read-only");
|
||||
keyboard::invbind irepaint(lsnes_mapper, "repaint", "System‣Repaint screen");
|
||||
keyboard::invbind itogglepause(lsnes_mapper, "toggle-pause-on-end", "Movie‣Toggle pause-on-end");
|
||||
keyboard::invbind irewind_movie(lsnes_mapper, "rewind-movie", "Movie‣Rewind movie");
|
||||
keyboard::invbind icancel_saves(lsnes_mapper, "cancel-saves", "Save‣Cancel pending saves");
|
||||
keyboard::invbind iload1(lsnes_mapper, "load ${project}1.lsmv", "Load‣Slot 1");
|
||||
keyboard::invbind iload2(lsnes_mapper, "load ${project}2.lsmv", "Load‣Slot 2");
|
||||
keyboard::invbind iload3(lsnes_mapper, "load ${project}3.lsmv", "Load‣Slot 3");
|
||||
keyboard::invbind iload4(lsnes_mapper, "load ${project}4.lsmv", "Load‣Slot 4");
|
||||
keyboard::invbind iload5(lsnes_mapper, "load ${project}5.lsmv", "Load‣Slot 5");
|
||||
keyboard::invbind iload6(lsnes_mapper, "load ${project}6.lsmv", "Load‣Slot 6");
|
||||
keyboard::invbind iload7(lsnes_mapper, "load ${project}7.lsmv", "Load‣Slot 7");
|
||||
keyboard::invbind iload8(lsnes_mapper, "load ${project}8.lsmv", "Load‣Slot 8");
|
||||
keyboard::invbind iload9(lsnes_mapper, "load ${project}9.lsmv", "Load‣Slot 9");
|
||||
keyboard::invbind iload10(lsnes_mapper, "load ${project}10.lsmv", "Load‣Slot 10");
|
||||
keyboard::invbind iload11(lsnes_mapper, "load ${project}11.lsmv", "Load‣Slot 11");
|
||||
keyboard::invbind iload12(lsnes_mapper, "load ${project}12.lsmv", "Load‣Slot 12");
|
||||
keyboard::invbind iload13(lsnes_mapper, "load ${project}13.lsmv", "Load‣Slot 13");
|
||||
keyboard::invbind iload14(lsnes_mapper, "load ${project}14.lsmv", "Load‣Slot 14");
|
||||
keyboard::invbind iload15(lsnes_mapper, "load ${project}15.lsmv", "Load‣Slot 15");
|
||||
keyboard::invbind iload16(lsnes_mapper, "load ${project}16.lsmv", "Load‣Slot 16");
|
||||
keyboard::invbind iload17(lsnes_mapper, "load ${project}17.lsmv", "Load‣Slot 17");
|
||||
keyboard::invbind iload18(lsnes_mapper, "load ${project}18.lsmv", "Load‣Slot 18");
|
||||
keyboard::invbind iload19(lsnes_mapper, "load ${project}19.lsmv", "Load‣Slot 19");
|
||||
keyboard::invbind iload20(lsnes_mapper, "load ${project}20.lsmv", "Load‣Slot 20");
|
||||
keyboard::invbind iload21(lsnes_mapper, "load ${project}21.lsmv", "Load‣Slot 21");
|
||||
keyboard::invbind iload22(lsnes_mapper, "load ${project}22.lsmv", "Load‣Slot 22");
|
||||
keyboard::invbind iload23(lsnes_mapper, "load ${project}23.lsmv", "Load‣Slot 23");
|
||||
keyboard::invbind iload24(lsnes_mapper, "load ${project}24.lsmv", "Load‣Slot 24");
|
||||
keyboard::invbind iload25(lsnes_mapper, "load ${project}25.lsmv", "Load‣Slot 25");
|
||||
keyboard::invbind iload26(lsnes_mapper, "load ${project}26.lsmv", "Load‣Slot 26");
|
||||
keyboard::invbind iload27(lsnes_mapper, "load ${project}27.lsmv", "Load‣Slot 27");
|
||||
keyboard::invbind iload28(lsnes_mapper, "load ${project}28.lsmv", "Load‣Slot 28");
|
||||
keyboard::invbind iload29(lsnes_mapper, "load ${project}29.lsmv", "Load‣Slot 29");
|
||||
keyboard::invbind iload30(lsnes_mapper, "load ${project}30.lsmv", "Load‣Slot 30");
|
||||
keyboard::invbind iload31(lsnes_mapper, "load ${project}31.lsmv", "Load‣Slot 31");
|
||||
keyboard::invbind iload32(lsnes_mapper, "load ${project}32.lsmv", "Load‣Slot 32");
|
||||
keyboard::invbind isave1(lsnes_mapper, "save-state ${project}1.lsmv", "Save‣Slot 1");
|
||||
keyboard::invbind isave2(lsnes_mapper, "save-state ${project}2.lsmv", "Save‣Slot 2");
|
||||
keyboard::invbind isave3(lsnes_mapper, "save-state ${project}3.lsmv", "Save‣Slot 3");
|
||||
keyboard::invbind isave4(lsnes_mapper, "save-state ${project}4.lsmv", "Save‣Slot 4");
|
||||
keyboard::invbind isave5(lsnes_mapper, "save-state ${project}5.lsmv", "Save‣Slot 5");
|
||||
keyboard::invbind isave6(lsnes_mapper, "save-state ${project}6.lsmv", "Save‣Slot 6");
|
||||
keyboard::invbind isave7(lsnes_mapper, "save-state ${project}7.lsmv", "Save‣Slot 7");
|
||||
keyboard::invbind isave8(lsnes_mapper, "save-state ${project}8.lsmv", "Save‣Slot 8");
|
||||
keyboard::invbind isave9(lsnes_mapper, "save-state ${project}9.lsmv", "Save‣Slot 9");
|
||||
keyboard::invbind isave10(lsnes_mapper, "save-state ${project}10.lsmv", "Save‣Slot 10");
|
||||
keyboard::invbind isave11(lsnes_mapper, "save-state ${project}11.lsmv", "Save‣Slot 11");
|
||||
keyboard::invbind isave12(lsnes_mapper, "save-state ${project}12.lsmv", "Save‣Slot 12");
|
||||
keyboard::invbind isave13(lsnes_mapper, "save-state ${project}13.lsmv", "Save‣Slot 13");
|
||||
keyboard::invbind isave14(lsnes_mapper, "save-state ${project}14.lsmv", "Save‣Slot 14");
|
||||
keyboard::invbind isave15(lsnes_mapper, "save-state ${project}15.lsmv", "Save‣Slot 15");
|
||||
keyboard::invbind isave16(lsnes_mapper, "save-state ${project}16.lsmv", "Save‣Slot 16");
|
||||
keyboard::invbind isave17(lsnes_mapper, "save-state ${project}17.lsmv", "Save‣Slot 17");
|
||||
keyboard::invbind isave18(lsnes_mapper, "save-state ${project}18.lsmv", "Save‣Slot 18");
|
||||
keyboard::invbind isave19(lsnes_mapper, "save-state ${project}19.lsmv", "Save‣Slot 19");
|
||||
keyboard::invbind isave20(lsnes_mapper, "save-state ${project}20.lsmv", "Save‣Slot 20");
|
||||
keyboard::invbind isave21(lsnes_mapper, "save-state ${project}21.lsmv", "Save‣Slot 21");
|
||||
keyboard::invbind isave22(lsnes_mapper, "save-state ${project}22.lsmv", "Save‣Slot 22");
|
||||
keyboard::invbind isave23(lsnes_mapper, "save-state ${project}23.lsmv", "Save‣Slot 23");
|
||||
keyboard::invbind isave24(lsnes_mapper, "save-state ${project}24.lsmv", "Save‣Slot 24");
|
||||
keyboard::invbind isave25(lsnes_mapper, "save-state ${project}25.lsmv", "Save‣Slot 25");
|
||||
keyboard::invbind isave26(lsnes_mapper, "save-state ${project}26.lsmv", "Save‣Slot 26");
|
||||
keyboard::invbind isave27(lsnes_mapper, "save-state ${project}27.lsmv", "Save‣Slot 27");
|
||||
keyboard::invbind isave28(lsnes_mapper, "save-state ${project}28.lsmv", "Save‣Slot 28");
|
||||
keyboard::invbind isave29(lsnes_mapper, "save-state ${project}29.lsmv", "Save‣Slot 29");
|
||||
keyboard::invbind isave30(lsnes_mapper, "save-state ${project}30.lsmv", "Save‣Slot 30");
|
||||
keyboard::invbind isave31(lsnes_mapper, "save-state ${project}31.lsmv", "Save‣Slot 31");
|
||||
keyboard::invbind isave32(lsnes_mapper, "save-state ${project}32.lsmv", "Save‣Slot 32");
|
||||
|
||||
bool on_quit_prompt = false;
|
||||
class mywindowcallbacks : public information_dispatch
|
||||
|
|
|
@ -198,8 +198,8 @@ namespace
|
|||
update_movie_state();
|
||||
});
|
||||
|
||||
inverse_bind _mtback(lsnes_mapper, "rotate-multitrack-backwards", "Multitrack‣Rotate backwards");
|
||||
inverse_bind _mtfwd(lsnes_mapper, "rotate-multitrack", "Multitrack‣Rotate forward");
|
||||
keyboard::invbind _mtback(lsnes_mapper, "rotate-multitrack-backwards", "Multitrack‣Rotate backwards");
|
||||
keyboard::invbind _mtfwd(lsnes_mapper, "rotate-multitrack", "Multitrack‣Rotate forward");
|
||||
|
||||
function_ptr_luafun mtlua(lua_func_misc, "input.multitrack_state", [](lua_state& L, const std::string& fname)
|
||||
-> int {
|
||||
|
|
|
@ -42,7 +42,7 @@ keypress::keypress()
|
|||
value = 0;
|
||||
}
|
||||
|
||||
keypress::keypress(keyboard_modifier_set mod, keyboard_key& _key, short _value)
|
||||
keypress::keypress(keyboard::modifier_set mod, keyboard::key& _key, short _value)
|
||||
{
|
||||
modifiers = mod;
|
||||
key1 = &_key;
|
||||
|
@ -50,7 +50,7 @@ keypress::keypress(keyboard_modifier_set mod, keyboard_key& _key, short _value)
|
|||
value = _value;
|
||||
}
|
||||
|
||||
keypress::keypress(keyboard_modifier_set mod, keyboard_key& _key, keyboard_key& _key2, short _value)
|
||||
keypress::keypress(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value)
|
||||
{
|
||||
modifiers = mod;
|
||||
key1 = &_key;
|
||||
|
@ -90,8 +90,8 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
inverse_bind ienable_sound(lsnes_mapper, "enable-sound on", "Sound‣Enable");
|
||||
inverse_bind idisable_sound(lsnes_mapper, "enable-sound off", "Sound‣Disable");
|
||||
keyboard::invbind ienable_sound(lsnes_mapper, "enable-sound on", "Sound‣Enable");
|
||||
keyboard::invbind idisable_sound(lsnes_mapper, "enable-sound off", "Sound‣Disable");
|
||||
|
||||
emulator_status emustatus;
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include "keymapper.hpp"
|
||||
#include "keyboard-mapper.hpp"
|
||||
#include "register-queue.hpp"
|
||||
#include "string.hpp"
|
||||
|
||||
std::string keyboard_mapper::fixup_command_polarity(std::string cmd, bool polarity) throw(std::bad_alloc)
|
||||
namespace keyboard
|
||||
{
|
||||
std::string mapper::fixup_command_polarity(std::string cmd, bool polarity) throw(std::bad_alloc)
|
||||
{
|
||||
if(cmd == "" || cmd == "*")
|
||||
return "";
|
||||
|
@ -20,11 +22,11 @@ std::string keyboard_mapper::fixup_command_polarity(std::string cmd, bool polari
|
|||
return cmd;
|
||||
}
|
||||
|
||||
key_specifier::key_specifier() throw(std::bad_alloc)
|
||||
keyspec::keyspec() throw(std::bad_alloc)
|
||||
{
|
||||
}
|
||||
|
||||
key_specifier::key_specifier(const std::string& keyspec) throw(std::bad_alloc, std::runtime_error)
|
||||
keyspec::keyspec(const std::string& keyspec) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
regex_results r = regex("([^/]*)/([^|]*)\\|(.*)", keyspec, "Invalid keyspec");
|
||||
mod = r[1];
|
||||
|
@ -32,48 +34,48 @@ key_specifier::key_specifier(const std::string& keyspec) throw(std::bad_alloc, s
|
|||
key = r[3];
|
||||
}
|
||||
|
||||
key_specifier::operator std::string() throw(std::bad_alloc)
|
||||
keyspec::operator std::string() throw(std::bad_alloc)
|
||||
{
|
||||
return mod + "/" + mask + "|" + key;
|
||||
}
|
||||
|
||||
key_specifier::operator bool() throw()
|
||||
keyspec::operator bool() throw()
|
||||
{
|
||||
return (key != "");
|
||||
}
|
||||
|
||||
bool key_specifier::operator!() throw()
|
||||
bool keyspec::operator!() throw()
|
||||
{
|
||||
return (key == "");
|
||||
}
|
||||
|
||||
void key_specifier::clear() throw()
|
||||
void keyspec::clear() throw()
|
||||
{
|
||||
mod = "";
|
||||
mask = "";
|
||||
key = "";
|
||||
}
|
||||
|
||||
bool key_specifier::operator==(const key_specifier& keyspec)
|
||||
bool keyspec::operator==(const keyspec& keyspec)
|
||||
{
|
||||
return (mod == keyspec.mod && mask == keyspec.mask && key == keyspec.key);
|
||||
}
|
||||
|
||||
bool key_specifier::operator!=(const key_specifier& keyspec)
|
||||
bool keyspec::operator!=(const keyspec& keyspec)
|
||||
{
|
||||
return (mod != keyspec.mod || mask != keyspec.mask || key != keyspec.key);
|
||||
}
|
||||
|
||||
std::set<inverse_bind*> keyboard_mapper::get_inverses() throw(std::bad_alloc)
|
||||
std::set<invbind*> mapper::get_inverses() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::set<inverse_bind*> r;
|
||||
std::set<invbind*> r;
|
||||
for(auto i : ibinds)
|
||||
r.insert(i.second);
|
||||
return r;
|
||||
}
|
||||
|
||||
inverse_bind* keyboard_mapper::get_inverse(const std::string& command) throw(std::bad_alloc)
|
||||
invbind* mapper::get_inverse(const std::string& command) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(ibinds.count(command))
|
||||
|
@ -82,16 +84,16 @@ inverse_bind* keyboard_mapper::get_inverse(const std::string& command) throw(std
|
|||
return NULL;
|
||||
}
|
||||
|
||||
std::set<controller_key*> keyboard_mapper::get_controller_keys() throw(std::bad_alloc)
|
||||
std::set<ctrlrkey*> mapper::get_controller_keys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::set<controller_key*> r;
|
||||
std::set<ctrlrkey*> r;
|
||||
for(auto i : ckeys)
|
||||
r.insert(i.second);
|
||||
return r;
|
||||
}
|
||||
|
||||
controller_key* keyboard_mapper::get_controllerkey(const std::string& command) throw(std::bad_alloc)
|
||||
ctrlrkey* mapper::get_controllerkey(const std::string& command) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(ckeys.count(command))
|
||||
|
@ -100,7 +102,7 @@ controller_key* keyboard_mapper::get_controllerkey(const std::string& command) t
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void keyboard_mapper::do_register_inverse(const std::string& name, inverse_bind& ibind) throw(std::bad_alloc)
|
||||
void mapper::do_register_inverse(const std::string& name, invbind& ibind) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
ibinds[name] = &ibind;
|
||||
|
@ -112,64 +114,64 @@ void keyboard_mapper::do_register_inverse(const std::string& name, inverse_bind&
|
|||
}
|
||||
}
|
||||
|
||||
void keyboard_mapper::do_unregister_inverse(const std::string& name) throw(std::bad_alloc)
|
||||
void mapper::do_unregister_inverse(const std::string& name) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
ibinds.erase(name);
|
||||
}
|
||||
|
||||
void keyboard_mapper::do_register_ckey(const std::string& name, controller_key& ckey) throw(std::bad_alloc)
|
||||
void mapper::do_register_ckey(const std::string& name, ctrlrkey& ckey) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
ckeys[name] = &ckey;
|
||||
}
|
||||
|
||||
void keyboard_mapper::do_unregister_ckey(const std::string& name) throw(std::bad_alloc)
|
||||
void mapper::do_unregister_ckey(const std::string& name) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
ckeys.erase(name);
|
||||
}
|
||||
|
||||
keyboard& keyboard_mapper::get_keyboard() throw()
|
||||
keyboard& mapper::get_keyboard() throw()
|
||||
{
|
||||
return kbd;
|
||||
}
|
||||
|
||||
keyboard_mapper::keyboard_mapper(keyboard& _kbd, command::group& _domain) throw(std::bad_alloc)
|
||||
mapper::mapper(keyboard& _kbd, command::group& _domain) throw(std::bad_alloc)
|
||||
: inverse_proxy(*this), controllerkey_proxy(*this), kbd(_kbd), domain(_domain)
|
||||
{
|
||||
register_queue<_inverse_proxy, inverse_bind>::do_ready(inverse_proxy, true);
|
||||
register_queue<_controllerkey_proxy, controller_key>::do_ready(controllerkey_proxy, true);
|
||||
register_queue<_inverse_proxy, invbind>::do_ready(inverse_proxy, true);
|
||||
register_queue<_controllerkey_proxy, ctrlrkey>::do_ready(controllerkey_proxy, true);
|
||||
}
|
||||
|
||||
keyboard_mapper::~keyboard_mapper() throw()
|
||||
mapper::~mapper() throw()
|
||||
{
|
||||
register_queue<_inverse_proxy, inverse_bind>::do_ready(inverse_proxy, false);
|
||||
register_queue<_controllerkey_proxy, controller_key>::do_ready(controllerkey_proxy, false);
|
||||
register_queue<_inverse_proxy, invbind>::do_ready(inverse_proxy, false);
|
||||
register_queue<_controllerkey_proxy, ctrlrkey>::do_ready(controllerkey_proxy, false);
|
||||
}
|
||||
|
||||
keyboard_mapper::triplet::triplet(keyboard_modifier_set _mod, keyboard_modifier_set _mask, keyboard_key& _key,
|
||||
mapper::triplet::triplet(modifier_set _mod, modifier_set _mask, key& kkey,
|
||||
unsigned _subkey)
|
||||
{
|
||||
mod = _mod;
|
||||
mask = _mask;
|
||||
key = &_key;
|
||||
_key = &kkey;
|
||||
subkey = _subkey;
|
||||
index = false;
|
||||
}
|
||||
|
||||
keyboard_mapper::triplet::triplet(keyboard_key& _key, unsigned _subkey)
|
||||
mapper::triplet::triplet(key& kkey, unsigned _subkey)
|
||||
{
|
||||
key = &_key;
|
||||
_key = &kkey;
|
||||
subkey = _subkey;
|
||||
index = true;
|
||||
}
|
||||
|
||||
bool keyboard_mapper::triplet::operator<(const struct triplet& a) const
|
||||
bool mapper::triplet::operator<(const struct triplet& a) const
|
||||
{
|
||||
if((uint64_t)key < (uint64_t)a.key)
|
||||
if((uint64_t)_key < (uint64_t)a._key)
|
||||
return true;
|
||||
if((uint64_t)key > (uint64_t)a.key)
|
||||
if((uint64_t)_key > (uint64_t)a._key)
|
||||
return false;
|
||||
if(subkey < a.subkey)
|
||||
return true;
|
||||
|
@ -190,11 +192,11 @@ bool keyboard_mapper::triplet::operator<(const struct triplet& a) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool keyboard_mapper::triplet::operator==(const struct triplet& a) const
|
||||
bool mapper::triplet::operator==(const struct triplet& a) const
|
||||
{
|
||||
if(index != a.index)
|
||||
return false;
|
||||
if(key != a.key)
|
||||
if(_key != a._key)
|
||||
return false;
|
||||
if(subkey != a.subkey)
|
||||
return false;
|
||||
|
@ -205,37 +207,37 @@ bool keyboard_mapper::triplet::operator==(const struct triplet& a) const
|
|||
return true;
|
||||
}
|
||||
|
||||
key_specifier keyboard_mapper::triplet::as_keyspec() const throw(std::bad_alloc)
|
||||
keyspec mapper::triplet::as_keyspec() const throw(std::bad_alloc)
|
||||
{
|
||||
key_specifier k;
|
||||
keyspec k;
|
||||
k.mod = mod;
|
||||
k.mask = mask;
|
||||
auto s = key->get_subkeys();
|
||||
auto s = _key->get_subkeys();
|
||||
if(s.size() > subkey)
|
||||
k.key = key->get_name() + s[subkey];
|
||||
k.key = _key->get_name() + s[subkey];
|
||||
else
|
||||
k.key = key->get_name();
|
||||
k.key = _key->get_name();
|
||||
return k;
|
||||
}
|
||||
|
||||
std::list<key_specifier> keyboard_mapper::get_bindings() throw(std::bad_alloc)
|
||||
std::list<keyspec> mapper::get_bindings() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::list<key_specifier> r;
|
||||
std::list<keyspec> r;
|
||||
for(auto i : bindings)
|
||||
r.push_back(i.first.as_keyspec());
|
||||
return r;
|
||||
}
|
||||
|
||||
command::group& keyboard_mapper::get_command_group() throw()
|
||||
command::group& mapper::get_command_group() throw()
|
||||
{
|
||||
return domain;
|
||||
}
|
||||
|
||||
void keyboard_mapper::bind(std::string mod, std::string modmask, std::string keyname, std::string command)
|
||||
void mapper::bind(std::string mod, std::string modmask, std::string keyname, std::string command)
|
||||
throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
key_specifier spec;
|
||||
keyspec spec;
|
||||
spec.mod = mod;
|
||||
spec.mask = modmask;
|
||||
spec.key = keyname;
|
||||
|
@ -243,9 +245,9 @@ void keyboard_mapper::bind(std::string mod, std::string modmask, std::string key
|
|||
umutex_class u(mutex);
|
||||
if(bindings.count(t))
|
||||
throw std::runtime_error("Key is already bound");
|
||||
if(!listening.count(t.key)) {
|
||||
t.key->add_listener(*this, false);
|
||||
listening.insert(t.key);
|
||||
if(!listening.count(t._key)) {
|
||||
t._key->add_listener(*this, false);
|
||||
listening.insert(t._key);
|
||||
}
|
||||
std::string old_command;
|
||||
if(bindings.count(t))
|
||||
|
@ -254,10 +256,10 @@ void keyboard_mapper::bind(std::string mod, std::string modmask, std::string key
|
|||
change_command(spec, old_command, command);
|
||||
}
|
||||
|
||||
void keyboard_mapper::unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
|
||||
void mapper::unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
key_specifier spec;
|
||||
keyspec spec;
|
||||
spec.mod = mod;
|
||||
spec.mask = modmask;
|
||||
spec.key = keyname;
|
||||
|
@ -273,7 +275,7 @@ void keyboard_mapper::unbind(std::string mod, std::string modmask, std::string k
|
|||
change_command(spec, old_command, "");
|
||||
}
|
||||
|
||||
std::string keyboard_mapper::get(const key_specifier& keyspec) throw(std::bad_alloc)
|
||||
std::string mapper::get(const keyspec& keyspec) throw(std::bad_alloc)
|
||||
{
|
||||
triplet t(kbd, keyspec);
|
||||
umutex_class u(mutex);
|
||||
|
@ -282,7 +284,7 @@ std::string keyboard_mapper::get(const key_specifier& keyspec) throw(std::bad_al
|
|||
return bindings[t];
|
||||
}
|
||||
|
||||
void keyboard_mapper::change_command(const key_specifier& spec, const std::string& old, const std::string& newc)
|
||||
void mapper::change_command(const keyspec& spec, const std::string& old, const std::string& newc)
|
||||
{
|
||||
if(old != "" && ibinds.count(old)) {
|
||||
auto& i = ibinds[old];
|
||||
|
@ -303,14 +305,14 @@ void keyboard_mapper::change_command(const key_specifier& spec, const std::strin
|
|||
}
|
||||
}
|
||||
|
||||
void keyboard_mapper::set(const key_specifier& keyspec, const std::string& cmd) throw(std::bad_alloc,
|
||||
void mapper::set(const keyspec& keyspec, const std::string& cmd) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
triplet t(kbd, keyspec);
|
||||
umutex_class u(mutex);
|
||||
if(!listening.count(t.key)) {
|
||||
t.key->add_listener(*this, false);
|
||||
listening.insert(t.key);
|
||||
if(!listening.count(t._key)) {
|
||||
t._key->add_listener(*this, false);
|
||||
listening.insert(t._key);
|
||||
}
|
||||
std::string oldcmd;
|
||||
if(bindings.count(t))
|
||||
|
@ -319,7 +321,7 @@ void keyboard_mapper::set(const key_specifier& keyspec, const std::string& cmd)
|
|||
change_command(keyspec, oldcmd, cmd);
|
||||
}
|
||||
|
||||
void keyboard_mapper::on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event)
|
||||
void mapper::on_key_event(modifier_set& mods, key& key, event& event)
|
||||
{
|
||||
auto mask = event.get_change_mask();
|
||||
unsigned i = 0;
|
||||
|
@ -332,7 +334,7 @@ void keyboard_mapper::on_key_event(keyboard_modifier_set& mods, keyboard_key& ke
|
|||
}
|
||||
}
|
||||
|
||||
void keyboard_mapper::on_key_event_subkey(keyboard_modifier_set& mods, keyboard_key& key, unsigned skey,
|
||||
void mapper::on_key_event_subkey(modifier_set& mods, key& key, unsigned skey,
|
||||
bool polarity)
|
||||
{
|
||||
triplet llow(key, skey);
|
||||
|
@ -348,23 +350,23 @@ void keyboard_mapper::on_key_event_subkey(keyboard_modifier_set& mods, keyboard_
|
|||
}
|
||||
}
|
||||
|
||||
keyboard_mapper::triplet::triplet(keyboard& k, const key_specifier& spec)
|
||||
mapper::triplet::triplet(keyboard& k, const keyspec& spec)
|
||||
{
|
||||
mod = keyboard_modifier_set::construct(k, spec.mod);
|
||||
mask = keyboard_modifier_set::construct(k, spec.mask);
|
||||
mod = modifier_set::construct(k, spec.mod);
|
||||
mask = modifier_set::construct(k, spec.mask);
|
||||
if(!mod.valid(mask))
|
||||
throw std::runtime_error("Bad modifiers");
|
||||
auto g = keymapper_lookup_subkey(k, spec.key, false);
|
||||
key = g.first;
|
||||
_key = g.first;
|
||||
subkey = g.second;
|
||||
index = false;
|
||||
}
|
||||
|
||||
std::list<controller_key*> keyboard_mapper::get_controllerkeys_kbdkey(keyboard_key* kbdkey)
|
||||
std::list<ctrlrkey*> mapper::get_controllerkeys_kbdkey(key* kbdkey)
|
||||
throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::list<controller_key*> r;
|
||||
std::list<ctrlrkey*> r;
|
||||
for(auto i : ckeys) {
|
||||
for(unsigned j = 0;; j++) {
|
||||
auto k = i.second->get(j);
|
||||
|
@ -377,29 +379,29 @@ std::list<controller_key*> keyboard_mapper::get_controllerkeys_kbdkey(keyboard_k
|
|||
return r;
|
||||
}
|
||||
|
||||
inverse_bind::inverse_bind(keyboard_mapper& _mapper, const std::string& _command, const std::string& _name)
|
||||
invbind::invbind(mapper& kmapper, const std::string& _command, const std::string& _name)
|
||||
throw(std::bad_alloc)
|
||||
: mapper(_mapper), cmd(_command), oname(_name)
|
||||
: _mapper(kmapper), cmd(_command), oname(_name)
|
||||
{
|
||||
register_queue<keyboard_mapper::_inverse_proxy, inverse_bind>::do_register(mapper.inverse_proxy, cmd, *this);
|
||||
register_queue<mapper::_inverse_proxy, invbind>::do_register(_mapper.inverse_proxy, cmd, *this);
|
||||
}
|
||||
|
||||
inverse_bind::~inverse_bind() throw()
|
||||
invbind::~invbind() throw()
|
||||
{
|
||||
register_queue<keyboard_mapper::_inverse_proxy, inverse_bind>::do_unregister(mapper.inverse_proxy, cmd);
|
||||
register_queue<mapper::_inverse_proxy, invbind>::do_unregister(_mapper.inverse_proxy, cmd);
|
||||
}
|
||||
|
||||
key_specifier inverse_bind::get(unsigned index) throw(std::bad_alloc)
|
||||
keyspec invbind::get(unsigned index) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(index >= specs.size())
|
||||
return key_specifier();
|
||||
return keyspec();
|
||||
return specs[index];
|
||||
}
|
||||
|
||||
void inverse_bind::clear(unsigned index) throw(std::bad_alloc)
|
||||
void invbind::clear(unsigned index) throw(std::bad_alloc)
|
||||
{
|
||||
key_specifier unbind;
|
||||
keyspec unbind;
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(index >= specs.size())
|
||||
|
@ -407,43 +409,42 @@ void inverse_bind::clear(unsigned index) throw(std::bad_alloc)
|
|||
unbind = specs[index];
|
||||
}
|
||||
if(unbind)
|
||||
mapper.set(unbind, "");
|
||||
_mapper.set(unbind, "");
|
||||
}
|
||||
|
||||
void inverse_bind::append(const key_specifier& keyspec) throw(std::bad_alloc)
|
||||
void invbind::append(const keyspec& keyspec) throw(std::bad_alloc)
|
||||
{
|
||||
mapper.set(keyspec, cmd);
|
||||
_mapper.set(keyspec, cmd);
|
||||
}
|
||||
|
||||
std::string inverse_bind::getname() throw(std::bad_alloc)
|
||||
std::string invbind::getname() throw(std::bad_alloc)
|
||||
{
|
||||
return oname;
|
||||
}
|
||||
|
||||
controller_key::controller_key(keyboard_mapper& _mapper, const std::string& _command, const std::string& _name,
|
||||
ctrlrkey::ctrlrkey(mapper& kmapper, const std::string& _command, const std::string& _name,
|
||||
bool _axis) throw(std::bad_alloc)
|
||||
: mapper(_mapper), cmd(_command), oname(_name)
|
||||
: _mapper(kmapper), cmd(_command), oname(_name)
|
||||
{
|
||||
register_queue<keyboard_mapper::_controllerkey_proxy, controller_key>::do_register(mapper.controllerkey_proxy,
|
||||
register_queue<mapper::_controllerkey_proxy, ctrlrkey>::do_register(_mapper.controllerkey_proxy,
|
||||
cmd, *this);
|
||||
axis = _axis;
|
||||
}
|
||||
|
||||
controller_key::~controller_key() throw()
|
||||
ctrlrkey::~ctrlrkey() throw()
|
||||
{
|
||||
register_queue<keyboard_mapper::_controllerkey_proxy, controller_key>::do_unregister(
|
||||
mapper.controllerkey_proxy, cmd);
|
||||
register_queue<mapper::_controllerkey_proxy, ctrlrkey>::do_unregister(_mapper.controllerkey_proxy, cmd);
|
||||
}
|
||||
|
||||
std::pair<keyboard_key*, unsigned> controller_key::get(unsigned index) throw()
|
||||
std::pair<key*, unsigned> ctrlrkey::get(unsigned index) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(index >= keys.size())
|
||||
return std::make_pair(reinterpret_cast<keyboard_key*>(NULL), 0);
|
||||
return std::make_pair(reinterpret_cast<key*>(NULL), 0);
|
||||
return keys[index];
|
||||
}
|
||||
|
||||
std::string controller_key::get_string(unsigned index) throw(std::bad_alloc)
|
||||
std::string ctrlrkey::get_string(unsigned index) throw(std::bad_alloc)
|
||||
{
|
||||
auto k = get(index);
|
||||
if(!k.first)
|
||||
|
@ -454,11 +455,11 @@ std::string controller_key::get_string(unsigned index) throw(std::bad_alloc)
|
|||
return k.first->get_name() + s[k.second];
|
||||
}
|
||||
|
||||
void controller_key::append(keyboard_key* _key, unsigned _subkey) throw()
|
||||
void ctrlrkey::append(key* _key, unsigned _subkey) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
//Search for duplicates.
|
||||
std::pair<keyboard_key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
std::pair<key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
for(auto i : keys)
|
||||
if(i == mkey)
|
||||
return;
|
||||
|
@ -467,10 +468,10 @@ void controller_key::append(keyboard_key* _key, unsigned _subkey) throw()
|
|||
keys.push_back(mkey);
|
||||
}
|
||||
|
||||
void controller_key::remove(keyboard_key* _key, unsigned _subkey) throw()
|
||||
void ctrlrkey::remove(key* _key, unsigned _subkey) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::pair<keyboard_key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
std::pair<key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
for(auto i = keys.begin(); i != keys.end(); i++) {
|
||||
if(*i == mkey) {
|
||||
mkey.first->remove_listener(*this);
|
||||
|
@ -480,19 +481,19 @@ void controller_key::remove(keyboard_key* _key, unsigned _subkey) throw()
|
|||
}
|
||||
}
|
||||
|
||||
void controller_key::append(const std::string& _key) throw(std::bad_alloc, std::runtime_error)
|
||||
void ctrlrkey::append(const std::string& _key) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto g = keymapper_lookup_subkey(mapper.get_keyboard(), _key, axis);
|
||||
auto g = keymapper_lookup_subkey(_mapper.get_keyboard(), _key, axis);
|
||||
append(g.first, g.second);
|
||||
}
|
||||
|
||||
std::pair<keyboard_key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const std::string& name, bool axis)
|
||||
throw(std::bad_alloc, std::runtime_error)
|
||||
std::pair<key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const std::string& name,
|
||||
bool axis) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(name == "")
|
||||
return std::make_pair((keyboard_key*)NULL, 0);
|
||||
return std::make_pair((key*)NULL, 0);
|
||||
//Try direct lookup first.
|
||||
keyboard_key* key = kbd.try_lookup_key(name);
|
||||
key* key = kbd.try_lookup_key(name);
|
||||
if(key)
|
||||
return std::make_pair(key, 0);
|
||||
//Axes only do direct lookup.
|
||||
|
@ -511,11 +512,11 @@ std::pair<keyboard_key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const
|
|||
throw std::runtime_error("Invalid key");
|
||||
}
|
||||
|
||||
void controller_key::on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event)
|
||||
void ctrlrkey::on_key_event(modifier_set& mods, key& key, event& event)
|
||||
{
|
||||
if(axis) {
|
||||
//Axes work specially.
|
||||
mapper.get_command_group().invoke((stringfmt() << cmd << " " << event.get_state()).str());
|
||||
_mapper.get_command_group().invoke((stringfmt() << cmd << " " << event.get_state()).str());
|
||||
return;
|
||||
}
|
||||
auto mask = event.get_change_mask();
|
||||
|
@ -525,8 +526,9 @@ void controller_key::on_key_event(keyboard_modifier_set& mods, keyboard_key& key
|
|||
unsigned kmask = (mask >> (2 * i.second)) & 3;
|
||||
std::string cmd2;
|
||||
if(kmask & 2)
|
||||
cmd2 = keyboard_mapper::fixup_command_polarity(cmd, kmask == 3);
|
||||
cmd2 = mapper::fixup_command_polarity(cmd, kmask == 3);
|
||||
if(cmd2 != "")
|
||||
mapper.get_command_group().invoke(cmd2);
|
||||
_mapper.get_command_group().invoke(cmd2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
#include "keyboard.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void keyboard::do_register_modifier(const std::string& name, keyboard_modifier& mod) throw(std::bad_alloc)
|
||||
namespace keyboard
|
||||
{
|
||||
void keyboard::do_register_modifier(const std::string& name, modifier& mod) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
modifiers[name] = &mod;
|
||||
|
@ -13,15 +15,15 @@ void keyboard::do_unregister_modifier(const std::string& name) throw()
|
|||
modifiers.erase(name);
|
||||
}
|
||||
|
||||
keyboard_modifier& keyboard::lookup_modifier(const std::string& name) throw(std::runtime_error)
|
||||
modifier& keyboard::lookup_modifier(const std::string& name) throw(std::runtime_error)
|
||||
{
|
||||
keyboard_modifier* m = try_lookup_modifier(name);
|
||||
modifier* m = try_lookup_modifier(name);
|
||||
if(!m)
|
||||
throw std::runtime_error("No such modifier");
|
||||
return *m;
|
||||
}
|
||||
|
||||
keyboard_modifier* keyboard::try_lookup_modifier(const std::string& name) throw()
|
||||
modifier* keyboard::try_lookup_modifier(const std::string& name) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(!modifiers.count(name))
|
||||
|
@ -29,16 +31,16 @@ keyboard_modifier* keyboard::try_lookup_modifier(const std::string& name) throw(
|
|||
return modifiers[name];
|
||||
}
|
||||
|
||||
std::list<keyboard_modifier*> keyboard::all_modifiers() throw(std::bad_alloc)
|
||||
std::list<modifier*> keyboard::all_modifiers() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::list<keyboard_modifier*> r;
|
||||
std::list<modifier*> r;
|
||||
for(auto i : modifiers)
|
||||
r.push_back(i.second);
|
||||
return r;
|
||||
}
|
||||
|
||||
void keyboard::do_register_key(const std::string& name, keyboard_key& key) throw(std::bad_alloc)
|
||||
void keyboard::do_register_key(const std::string& name, key& key) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
keys[name] = &key;
|
||||
|
@ -50,15 +52,15 @@ void keyboard::do_unregister_key(const std::string& name) throw()
|
|||
keys.erase(name);
|
||||
}
|
||||
|
||||
keyboard_key& keyboard::lookup_key(const std::string& name) throw(std::runtime_error)
|
||||
key& keyboard::lookup_key(const std::string& name) throw(std::runtime_error)
|
||||
{
|
||||
keyboard_key* m = try_lookup_key(name);
|
||||
key* m = try_lookup_key(name);
|
||||
if(!m)
|
||||
throw std::runtime_error("No such key");
|
||||
return *m;
|
||||
}
|
||||
|
||||
keyboard_key* keyboard::try_lookup_key(const std::string& name) throw()
|
||||
key* keyboard::try_lookup_key(const std::string& name) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(!keys.count(name))
|
||||
|
@ -66,29 +68,29 @@ keyboard_key* keyboard::try_lookup_key(const std::string& name) throw()
|
|||
return keys[name];
|
||||
}
|
||||
|
||||
std::list<keyboard_key*> keyboard::all_keys() throw(std::bad_alloc)
|
||||
std::list<key*> keyboard::all_keys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::list<keyboard_key*> r;
|
||||
std::list<key*> r;
|
||||
for(auto i : keys)
|
||||
r.push_back(i.second);
|
||||
return r;
|
||||
}
|
||||
|
||||
void keyboard::set_exclusive(keyboard_event_listener* listener) throw()
|
||||
void keyboard::set_exclusive(event_listener* listener) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
for(auto i : keys)
|
||||
i.second->set_exclusive(listener);
|
||||
}
|
||||
|
||||
void keyboard::set_current_key(keyboard_key* key) throw()
|
||||
void keyboard::set_current_key(key* key) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
current_key = key;
|
||||
}
|
||||
|
||||
keyboard_key* keyboard::get_current_key() throw()
|
||||
key* keyboard::get_current_key() throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
return current_key;
|
||||
|
@ -97,32 +99,32 @@ keyboard_key* keyboard::get_current_key() throw()
|
|||
keyboard::keyboard() throw(std::bad_alloc)
|
||||
: modifier_proxy(*this), key_proxy(*this)
|
||||
{
|
||||
register_queue<keyboard::_modifier_proxy, keyboard_modifier>::do_ready(modifier_proxy, true);
|
||||
register_queue<keyboard::_key_proxy, keyboard_key>::do_ready(key_proxy, true);
|
||||
register_queue<keyboard::_modifier_proxy, modifier>::do_ready(modifier_proxy, true);
|
||||
register_queue<keyboard::_key_proxy, key>::do_ready(key_proxy, true);
|
||||
}
|
||||
|
||||
keyboard::~keyboard() throw()
|
||||
{
|
||||
register_queue<keyboard::_modifier_proxy, keyboard_modifier>::do_ready(modifier_proxy, false);
|
||||
register_queue<keyboard::_key_proxy, keyboard_key>::do_ready(key_proxy, false);
|
||||
register_queue<keyboard::_modifier_proxy, modifier>::do_ready(modifier_proxy, false);
|
||||
register_queue<keyboard::_key_proxy, key>::do_ready(key_proxy, false);
|
||||
}
|
||||
|
||||
void keyboard_modifier_set::add(keyboard_modifier& mod, bool really) throw(std::bad_alloc)
|
||||
void modifier_set::add(modifier& mod, bool really) throw(std::bad_alloc)
|
||||
{
|
||||
if(really)
|
||||
set.insert(&mod);
|
||||
}
|
||||
|
||||
void keyboard_modifier_set::remove(keyboard_modifier& mod, bool really) throw(std::bad_alloc)
|
||||
void modifier_set::remove(modifier& mod, bool really) throw(std::bad_alloc)
|
||||
{
|
||||
if(really)
|
||||
set.erase(&mod);
|
||||
}
|
||||
|
||||
keyboard_modifier_set keyboard_modifier_set::construct(keyboard& kbd, const std::string& _modifiers)
|
||||
modifier_set modifier_set::construct(keyboard& kbd, const std::string& _modifiers)
|
||||
throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
keyboard_modifier_set set;
|
||||
modifier_set set;
|
||||
std::string modifiers = _modifiers;
|
||||
while(modifiers != "") {
|
||||
std::string mod = modifiers;
|
||||
|
@ -138,29 +140,29 @@ keyboard_modifier_set keyboard_modifier_set::construct(keyboard& kbd, const std:
|
|||
return set;
|
||||
}
|
||||
|
||||
bool keyboard_modifier_set::valid(keyboard_modifier_set& mask) throw(std::bad_alloc)
|
||||
bool modifier_set::valid(modifier_set& mask) throw(std::bad_alloc)
|
||||
{
|
||||
//No element can be together with its linkage group.
|
||||
for(auto i : set) {
|
||||
keyboard_modifier* j = i->get_link();
|
||||
modifier* j = i->get_link();
|
||||
if(j && set.count(j))
|
||||
return false;
|
||||
}
|
||||
for(auto i : mask.set) {
|
||||
keyboard_modifier* j = i->get_link();
|
||||
modifier* j = i->get_link();
|
||||
if(j && mask.set.count(j))
|
||||
return false;
|
||||
}
|
||||
//For every element of set, it or its linkage group must be in mask.
|
||||
for(auto i : set) {
|
||||
keyboard_modifier* j = i->get_link();
|
||||
modifier* j = i->get_link();
|
||||
if(!mask.set.count(i) && !mask.set.count(j ? j : i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keyboard_modifier_set::operator==(const keyboard_modifier_set& m) const throw()
|
||||
bool modifier_set::operator==(const modifier_set& m) const throw()
|
||||
{
|
||||
for(auto i : set)
|
||||
if(!m.set.count(i))
|
||||
|
@ -171,7 +173,7 @@ bool keyboard_modifier_set::operator==(const keyboard_modifier_set& m) const thr
|
|||
return true;
|
||||
}
|
||||
|
||||
bool keyboard_modifier_set::operator<(const keyboard_modifier_set& m) const throw()
|
||||
bool modifier_set::operator<(const modifier_set& m) const throw()
|
||||
{
|
||||
auto i1 = set.begin();
|
||||
auto i2 = m.set.begin();
|
||||
|
@ -184,7 +186,7 @@ bool keyboard_modifier_set::operator<(const keyboard_modifier_set& m) const thro
|
|||
return (i2 != m.set.end());
|
||||
}
|
||||
|
||||
keyboard_modifier_set::operator std::string() const throw(std::bad_alloc)
|
||||
modifier_set::operator std::string() const throw(std::bad_alloc)
|
||||
{
|
||||
std::string r;
|
||||
for(auto i : set)
|
||||
|
@ -192,7 +194,7 @@ keyboard_modifier_set::operator std::string() const throw(std::bad_alloc)
|
|||
return r;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const keyboard_modifier_set& m)
|
||||
std::ostream& operator<<(std::ostream& os, const modifier_set& m)
|
||||
{
|
||||
os << "<modset:";
|
||||
for(auto i : m.set)
|
||||
|
@ -201,7 +203,7 @@ std::ostream& operator<<(std::ostream& os, const keyboard_modifier_set& m)
|
|||
return os;
|
||||
}
|
||||
|
||||
bool keyboard_modifier_set::triggers(const keyboard_modifier_set& trigger, const keyboard_modifier_set& mask)
|
||||
bool modifier_set::triggers(const modifier_set& trigger, const modifier_set& mask)
|
||||
throw(std::bad_alloc)
|
||||
{
|
||||
for(auto i : mask.set) {
|
||||
|
@ -241,51 +243,51 @@ bool keyboard_modifier_set::triggers(const keyboard_modifier_set& trigger, const
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t keyboard_mouse_calibration::get_calibrated_value(int32_t x) const throw()
|
||||
int32_t mouse_calibration::get_calibrated_value(int32_t x) const throw()
|
||||
{
|
||||
return x - offset;
|
||||
}
|
||||
|
||||
keyboard_event::~keyboard_event() throw() {}
|
||||
keyboard_event_key::~keyboard_event_key() throw() {}
|
||||
keyboard_event_axis::~keyboard_event_axis() throw() {}
|
||||
keyboard_event_hat::~keyboard_event_hat() throw() {}
|
||||
keyboard_event_mouse::~keyboard_event_mouse() throw() {}
|
||||
keyboard_event_listener::~keyboard_event_listener() throw() {}
|
||||
event::~event() throw() {}
|
||||
event_key::~event_key() throw() {}
|
||||
event_axis::~event_axis() throw() {}
|
||||
event_hat::~event_hat() throw() {}
|
||||
event_mouse::~event_mouse() throw() {}
|
||||
event_listener::~event_listener() throw() {}
|
||||
|
||||
keyboard_key::~keyboard_key() throw()
|
||||
key::~key() throw()
|
||||
{
|
||||
register_queue<keyboard::_key_proxy, keyboard_key>::do_unregister(kbd.key_proxy, name);
|
||||
register_queue<keyboard::_key_proxy, key>::do_unregister(kbd.key_proxy, name);
|
||||
}
|
||||
|
||||
keyboard_event_key::keyboard_event_key(uint32_t chngmask)
|
||||
: keyboard_event(chngmask, keyboard_keytype::KBD_KEYTYPE_KEY)
|
||||
event_key::event_key(uint32_t chngmask)
|
||||
: event(chngmask, keytype::KBD_KEYTYPE_KEY)
|
||||
{
|
||||
}
|
||||
|
||||
keyboard_event_axis::keyboard_event_axis(int32_t _state, uint32_t chngmask)
|
||||
: keyboard_event(chngmask, keyboard_keytype::KBD_KEYTYPE_AXIS)
|
||||
event_axis::event_axis(int32_t _state, uint32_t chngmask)
|
||||
: event(chngmask, keytype::KBD_KEYTYPE_AXIS)
|
||||
{
|
||||
state = _state;
|
||||
}
|
||||
|
||||
keyboard_event_hat::keyboard_event_hat(uint32_t chngmask)
|
||||
: keyboard_event(chngmask, keyboard_keytype::KBD_KEYTYPE_HAT)
|
||||
event_hat::event_hat(uint32_t chngmask)
|
||||
: event(chngmask, keytype::KBD_KEYTYPE_HAT)
|
||||
{
|
||||
}
|
||||
|
||||
keyboard_event_mouse::keyboard_event_mouse(int32_t _state, const keyboard_mouse_calibration& _cal)
|
||||
: keyboard_event(0, keyboard_keytype::KBD_KEYTYPE_MOUSE)
|
||||
event_mouse::event_mouse(int32_t _state, const mouse_calibration& _cal)
|
||||
: event(0, keytype::KBD_KEYTYPE_MOUSE)
|
||||
{
|
||||
state = _state;
|
||||
cal = _cal;
|
||||
}
|
||||
|
||||
int32_t keyboard_event_key::get_state() const throw() { return (get_change_mask() & 1) != 0; }
|
||||
int32_t keyboard_event_axis::get_state() const throw() { return state; }
|
||||
int32_t keyboard_event_mouse::get_state() const throw() { return state; }
|
||||
int32_t event_key::get_state() const throw() { return (get_change_mask() & 1) != 0; }
|
||||
int32_t event_axis::get_state() const throw() { return state; }
|
||||
int32_t event_mouse::get_state() const throw() { return state; }
|
||||
|
||||
int32_t keyboard_event_hat::get_state() const throw()
|
||||
int32_t event_hat::get_state() const throw()
|
||||
{
|
||||
int32_t r = 0;
|
||||
uint32_t m = get_change_mask();
|
||||
|
@ -296,15 +298,15 @@ int32_t keyboard_event_hat::get_state() const throw()
|
|||
return m;
|
||||
}
|
||||
|
||||
keyboard_key::keyboard_key(keyboard& keyb, const std::string& _name, const std::string& _clazz,
|
||||
keyboard_keytype _type) throw(std::bad_alloc)
|
||||
key::key(keyboard& keyb, const std::string& _name, const std::string& _clazz,
|
||||
keytype _type) throw(std::bad_alloc)
|
||||
: kbd(keyb), clazz(_clazz), name(_name), type(_type)
|
||||
{
|
||||
exclusive_listener = NULL;
|
||||
register_queue<keyboard::_key_proxy, keyboard_key>::do_register(kbd.key_proxy, name, *this);
|
||||
register_queue<keyboard::_key_proxy, key>::do_register(kbd.key_proxy, name, *this);
|
||||
}
|
||||
|
||||
void keyboard_key::add_listener(keyboard_event_listener& listener, bool analog) throw(std::bad_alloc)
|
||||
void key::add_listener(event_listener& listener, bool analog) throw(std::bad_alloc)
|
||||
{
|
||||
if(analog) {
|
||||
analog_listeners.insert(&listener);
|
||||
|
@ -314,19 +316,19 @@ void keyboard_key::add_listener(keyboard_event_listener& listener, bool analog)
|
|||
analog_listeners.erase(&listener);
|
||||
}
|
||||
}
|
||||
void keyboard_key::remove_listener(keyboard_event_listener& listener) throw()
|
||||
void key::remove_listener(event_listener& listener) throw()
|
||||
{
|
||||
digital_listeners.erase(&listener);
|
||||
analog_listeners.erase(&listener);
|
||||
}
|
||||
|
||||
void keyboard_key::set_exclusive(keyboard_event_listener* listener) throw()
|
||||
void key::set_exclusive(event_listener* listener) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
exclusive_listener = listener;
|
||||
}
|
||||
|
||||
void keyboard_key::call_listeners(keyboard_modifier_set& mods, keyboard_event& event)
|
||||
void key::call_listeners(modifier_set& mods, event& event)
|
||||
{
|
||||
kbd.set_current_key(this);
|
||||
bool digital = (event.get_change_mask() & 0xAAAAAAAAUL) != 0;
|
||||
|
@ -337,7 +339,7 @@ void keyboard_key::call_listeners(keyboard_modifier_set& mods, keyboard_event& e
|
|||
kbd.set_current_key(NULL);
|
||||
return;
|
||||
}
|
||||
keyboard_event_listener* itr = NULL;
|
||||
event_listener* itr = NULL;
|
||||
while(digital) {
|
||||
auto itr2 = digital_listeners.upper_bound(itr);
|
||||
if(itr2 == digital_listeners.end())
|
||||
|
@ -361,30 +363,30 @@ void keyboard_key::call_listeners(keyboard_modifier_set& mods, keyboard_event& e
|
|||
kbd.set_current_key(NULL);
|
||||
}
|
||||
|
||||
keyboard_key_axis* keyboard_key::cast_axis() throw()
|
||||
key_axis* key::cast_axis() throw()
|
||||
{
|
||||
if(type != KBD_KEYTYPE_AXIS)
|
||||
return NULL;
|
||||
return dynamic_cast<keyboard_key_axis*>(this);
|
||||
return dynamic_cast<key_axis*>(this);
|
||||
}
|
||||
|
||||
keyboard_key_mouse* keyboard_key::cast_mouse() throw()
|
||||
key_mouse* key::cast_mouse() throw()
|
||||
{
|
||||
if(type != KBD_KEYTYPE_MOUSE)
|
||||
return NULL;
|
||||
return dynamic_cast<keyboard_key_mouse*>(this);
|
||||
return dynamic_cast<key_mouse*>(this);
|
||||
}
|
||||
|
||||
keyboard_key_key::keyboard_key_key(keyboard& keyb, const std::string& name, const std::string& clazz)
|
||||
key_key::key_key(keyboard& keyb, const std::string& name, const std::string& clazz)
|
||||
throw(std::bad_alloc)
|
||||
: keyboard_key(keyb, name, clazz, keyboard_keytype::KBD_KEYTYPE_KEY)
|
||||
: key(keyb, name, clazz, keytype::KBD_KEYTYPE_KEY)
|
||||
{
|
||||
state = 0;
|
||||
}
|
||||
|
||||
keyboard_key_key::~keyboard_key_key() throw() {}
|
||||
key_key::~key_key() throw() {}
|
||||
|
||||
void keyboard_key_key::set_state(keyboard_modifier_set mods, int32_t _state) throw()
|
||||
void key_key::set_state(modifier_set mods, int32_t _state) throw()
|
||||
{
|
||||
uint32_t change = _state ? 1 : 0;
|
||||
bool edge = false;
|
||||
|
@ -396,30 +398,30 @@ void keyboard_key_key::set_state(keyboard_modifier_set mods, int32_t _state) thr
|
|||
}
|
||||
mutex.unlock();
|
||||
if(edge) {
|
||||
keyboard_event_key e(change);
|
||||
event_key e(change);
|
||||
call_listeners(mods, e);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t keyboard_key_key::get_state() const throw() { return state; }
|
||||
int32_t keyboard_key_key::get_state_digital() const throw() { return state; }
|
||||
int32_t key_key::get_state() const throw() { return state; }
|
||||
int32_t key_key::get_state_digital() const throw() { return state; }
|
||||
|
||||
std::vector<std::string> keyboard_key_key::get_subkeys() throw(std::bad_alloc)
|
||||
std::vector<std::string> key_key::get_subkeys() throw(std::bad_alloc)
|
||||
{
|
||||
std::vector<std::string> r;
|
||||
r.push_back("");
|
||||
return r;
|
||||
}
|
||||
|
||||
keyboard_key_hat::keyboard_key_hat(keyboard& keyb, const std::string& name, const std::string& clazz)
|
||||
key_hat::key_hat(keyboard& keyb, const std::string& name, const std::string& clazz)
|
||||
throw(std::bad_alloc)
|
||||
: keyboard_key(keyb, name, clazz, keyboard_keytype::KBD_KEYTYPE_HAT)
|
||||
: key(keyb, name, clazz, keytype::KBD_KEYTYPE_HAT)
|
||||
{
|
||||
state = 0;
|
||||
}
|
||||
keyboard_key_hat::~keyboard_key_hat() throw() {}
|
||||
key_hat::~key_hat() throw() {}
|
||||
|
||||
void keyboard_key_hat::set_state(keyboard_modifier_set mods, int32_t _state) throw()
|
||||
void key_hat::set_state(modifier_set mods, int32_t _state) throw()
|
||||
{
|
||||
state &= 15;
|
||||
uint32_t change = 0;
|
||||
|
@ -440,15 +442,15 @@ void keyboard_key_hat::set_state(keyboard_modifier_set mods, int32_t _state) thr
|
|||
}
|
||||
mutex.unlock();
|
||||
if(edge) {
|
||||
keyboard_event_hat e(change);
|
||||
event_hat e(change);
|
||||
call_listeners(mods, e);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t keyboard_key_hat::get_state() const throw() { return state; }
|
||||
int32_t keyboard_key_hat::get_state_digital() const throw() { return state; }
|
||||
int32_t key_hat::get_state() const throw() { return state; }
|
||||
int32_t key_hat::get_state_digital() const throw() { return state; }
|
||||
|
||||
std::vector<std::string> keyboard_key_hat::get_subkeys() throw(std::bad_alloc)
|
||||
std::vector<std::string> key_hat::get_subkeys() throw(std::bad_alloc)
|
||||
{
|
||||
std::vector<std::string> r;
|
||||
r.push_back("n");
|
||||
|
@ -458,24 +460,24 @@ std::vector<std::string> keyboard_key_hat::get_subkeys() throw(std::bad_alloc)
|
|||
return r;
|
||||
}
|
||||
|
||||
keyboard_key_axis::keyboard_key_axis(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
key_axis::key_axis(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
int mode) throw(std::bad_alloc)
|
||||
: keyboard_key(keyb, name, clazz, keyboard_keytype::KBD_KEYTYPE_AXIS)
|
||||
: key(keyb, name, clazz, keytype::KBD_KEYTYPE_AXIS)
|
||||
{
|
||||
rawstate = 0;
|
||||
digitalstate = 0;
|
||||
last_tolerance = 0.5;
|
||||
_mode = mode;
|
||||
}
|
||||
keyboard_key_axis::~keyboard_key_axis() throw() {}
|
||||
key_axis::~key_axis() throw() {}
|
||||
|
||||
int32_t keyboard_key_axis::get_state() const throw()
|
||||
int32_t key_axis::get_state() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
return rawstate;
|
||||
}
|
||||
|
||||
int32_t keyboard_key_axis::get_state_digital() const throw()
|
||||
int32_t key_axis::get_state_digital() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
if(rawstate <= -32768 * last_tolerance)
|
||||
|
@ -485,13 +487,13 @@ int32_t keyboard_key_axis::get_state_digital() const throw()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int keyboard_key_axis::get_mode() const throw()
|
||||
int key_axis::get_mode() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
return _mode;
|
||||
}
|
||||
|
||||
std::vector<std::string> keyboard_key_axis::get_subkeys() throw(std::bad_alloc)
|
||||
std::vector<std::string> key_axis::get_subkeys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
std::vector<std::string> r;
|
||||
|
@ -504,7 +506,7 @@ std::vector<std::string> keyboard_key_axis::get_subkeys() throw(std::bad_alloc)
|
|||
return r;
|
||||
}
|
||||
|
||||
void keyboard_key_axis::set_state(keyboard_modifier_set mods, int32_t _rawstate) throw()
|
||||
void key_axis::set_state(modifier_set mods, int32_t _rawstate) throw()
|
||||
{
|
||||
bool edge = false;
|
||||
int32_t state, ostate;
|
||||
|
@ -533,52 +535,52 @@ void keyboard_key_axis::set_state(keyboard_modifier_set mods, int32_t _rawstate)
|
|||
}
|
||||
mutex.unlock();
|
||||
if(edge) {
|
||||
keyboard_event_axis e(state, change);
|
||||
event_axis e(state, change);
|
||||
call_listeners(mods, e);
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_key_axis::set_mode(int mode, double tolerance) throw()
|
||||
void key_axis::set_mode(int mode, double tolerance) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
_mode = mode;
|
||||
last_tolerance = tolerance;
|
||||
}
|
||||
|
||||
keyboard_key_mouse::keyboard_key_mouse(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
keyboard_mouse_calibration _cal) throw(std::bad_alloc)
|
||||
: keyboard_key(keyb, name, clazz, keyboard_keytype::KBD_KEYTYPE_MOUSE)
|
||||
key_mouse::key_mouse(keyboard& keyb, const std::string& name, const std::string& clazz,
|
||||
mouse_calibration _cal) throw(std::bad_alloc)
|
||||
: key(keyb, name, clazz, keytype::KBD_KEYTYPE_MOUSE)
|
||||
{
|
||||
rawstate = 0;
|
||||
cal = _cal;
|
||||
}
|
||||
|
||||
keyboard_key_mouse::~keyboard_key_mouse() throw() {}
|
||||
int32_t keyboard_key_mouse::get_state_digital() const throw() { return 0; }
|
||||
key_mouse::~key_mouse() throw() {}
|
||||
int32_t key_mouse::get_state_digital() const throw() { return 0; }
|
||||
|
||||
int32_t keyboard_key_mouse::get_state() const throw()
|
||||
int32_t key_mouse::get_state() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
return cal.get_calibrated_value(rawstate);
|
||||
}
|
||||
|
||||
std::vector<std::string> keyboard_key_mouse::get_subkeys() throw(std::bad_alloc)
|
||||
std::vector<std::string> key_mouse::get_subkeys() throw(std::bad_alloc)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
keyboard_mouse_calibration keyboard_key_mouse::get_calibration() const throw()
|
||||
mouse_calibration key_mouse::get_calibration() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
keyboard_mouse_calibration tmp = cal;
|
||||
mouse_calibration tmp = cal;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void keyboard_key_mouse::set_state(keyboard_modifier_set mods, int32_t _rawstate) throw()
|
||||
void key_mouse::set_state(modifier_set mods, int32_t _rawstate) throw()
|
||||
{
|
||||
bool edge = false;
|
||||
int32_t state;
|
||||
keyboard_mouse_calibration _cal;
|
||||
mouse_calibration _cal;
|
||||
mutex.lock();
|
||||
if(rawstate != _rawstate) {
|
||||
rawstate = _rawstate;
|
||||
|
@ -588,18 +590,19 @@ void keyboard_key_mouse::set_state(keyboard_modifier_set mods, int32_t _rawstate
|
|||
}
|
||||
mutex.unlock();
|
||||
if(edge) {
|
||||
keyboard_event_mouse e(state, _cal);
|
||||
event_mouse e(state, _cal);
|
||||
call_listeners(mods, e);
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_key_mouse::set_calibration(keyboard_mouse_calibration _cal) throw()
|
||||
void key_mouse::set_calibration(mouse_calibration _cal) throw()
|
||||
{
|
||||
mutex.lock();
|
||||
cal = _cal;
|
||||
int32_t state = cal.get_calibrated_value(rawstate);
|
||||
mutex.unlock();
|
||||
keyboard_event_mouse e(state, _cal);
|
||||
keyboard_modifier_set mods;
|
||||
event_mouse e(state, _cal);
|
||||
modifier_set mods;
|
||||
call_listeners(mods, e);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ public:
|
|||
return ikey.getname();
|
||||
}
|
||||
private:
|
||||
inverse_bind ikey;
|
||||
keyboard::invbind ikey;
|
||||
};
|
||||
|
||||
class lua_command_binding : public command::base
|
||||
|
|
|
@ -184,9 +184,9 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
class _keyhook_listener : public keyboard_event_listener
|
||||
class _keyhook_listener : public keyboard::event_listener
|
||||
{
|
||||
void on_key_event(keyboard_modifier_set& modifiers, keyboard_key& key, keyboard_event& event)
|
||||
void on_key_event(keyboard::modifier_set& modifiers, keyboard::key& key, keyboard::event& event)
|
||||
{
|
||||
lua_callback_keyhook(key.get_name(), key);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ namespace
|
|||
bool state;
|
||||
std::string x = L.get_string(1, fname.c_str());
|
||||
state = L.get_bool(2, fname.c_str());
|
||||
keyboard_key* key = lsnes_kbd.try_lookup_key(x);
|
||||
keyboard::key* key = lsnes_kbd.try_lookup_key(x);
|
||||
if(!key)
|
||||
throw std::runtime_error("Invalid key name");
|
||||
bool ostate = hooked.count(x) > 0;
|
||||
|
|
|
@ -56,27 +56,27 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
void push_keygroup_parameters(lua_state& L, keyboard_key& p)
|
||||
void push_keygroup_parameters(lua_state& L, keyboard::key& p)
|
||||
{
|
||||
keyboard_mouse_calibration p2;
|
||||
keyboard_axis_calibration p3;
|
||||
keyboard::mouse_calibration p2;
|
||||
keyboard::axis_calibration p3;
|
||||
int mode;
|
||||
L.newtable();
|
||||
switch(p.get_type()) {
|
||||
case KBD_KEYTYPE_KEY:
|
||||
case keyboard::KBD_KEYTYPE_KEY:
|
||||
pushpair(L, "value", p.get_state());
|
||||
pushpair(L, "type", "key");
|
||||
break;
|
||||
case KBD_KEYTYPE_HAT:
|
||||
case keyboard::KBD_KEYTYPE_HAT:
|
||||
pushpair(L, "value", p.get_state());
|
||||
pushpair(L, "type", "hat");
|
||||
break;
|
||||
case KBD_KEYTYPE_MOUSE:
|
||||
case keyboard::KBD_KEYTYPE_MOUSE:
|
||||
p2 = p.cast_mouse()->get_calibration();
|
||||
pushpair(L, "value", p.get_state());
|
||||
pushpair(L, "type", "mouse");
|
||||
break;
|
||||
case KBD_KEYTYPE_AXIS:
|
||||
case keyboard::KBD_KEYTYPE_AXIS:
|
||||
mode = p.cast_axis()->get_mode();
|
||||
pushpair(L, "value", p.get_state());
|
||||
pushpair(L, "type", get_mode_str(mode));
|
||||
|
@ -90,7 +90,7 @@ bool lua_booted_flag = false;
|
|||
|
||||
namespace
|
||||
{
|
||||
int push_keygroup_parameters2(lua_state& L, keyboard_key* p)
|
||||
int push_keygroup_parameters2(lua_state& L, keyboard::key* p)
|
||||
{
|
||||
push_keygroup_parameters(L, *p);
|
||||
return 1;
|
||||
|
@ -428,7 +428,7 @@ void lua_callback_quit() throw()
|
|||
run_callback(on_quit);
|
||||
}
|
||||
|
||||
void lua_callback_keyhook(const std::string& key, keyboard_key& p) throw()
|
||||
void lua_callback_keyhook(const std::string& key, keyboard::key& p) throw()
|
||||
{
|
||||
run_callback(on_keyhook, lua_state::string_tag(key), lua_state::fnptr_tag(push_keygroup_parameters2, &p));
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace
|
|||
int mod;
|
||||
const char* name;
|
||||
const char* lname;
|
||||
keyboard_modifier* allocated;
|
||||
keyboard::modifier* allocated;
|
||||
} modifiers[] = {
|
||||
{ wxMOD_ALT, "alt", NULL, NULL },
|
||||
{ wxMOD_CONTROL, "ctrl", NULL, NULL },
|
||||
|
@ -37,7 +37,7 @@ namespace
|
|||
int keynum;
|
||||
const char* name;
|
||||
const char* clazz;
|
||||
keyboard_key_key* allocated;
|
||||
keyboard::key_key* allocated;
|
||||
} keys[] = {
|
||||
{ WXK_BACK, "back", "editing", NULL },
|
||||
{ WXK_TAB, "tab", "editing", NULL },
|
||||
|
@ -259,20 +259,20 @@ namespace
|
|||
{ 0, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
std::map<int, keyboard_modifier*> modifier_map;
|
||||
std::map<int, keyboard_key_key*> key_map;
|
||||
std::map<int, keyboard::modifier*> modifier_map;
|
||||
std::map<int, keyboard::key_key*> key_map;
|
||||
std::map<std::string, int> keys_allocated;
|
||||
std::set<int> keys_held;
|
||||
|
||||
struct keypress_request
|
||||
{
|
||||
keyboard_modifier_set mods;
|
||||
keyboard_key_key* key;
|
||||
keyboard::modifier_set mods;
|
||||
keyboard::key_key* key;
|
||||
bool polarity;
|
||||
};
|
||||
|
||||
//Request keypress event to happen.
|
||||
void do_keypress(keyboard_modifier_set mods, keyboard_key_key& key, bool polarity)
|
||||
void do_keypress(keyboard::modifier_set mods, keyboard::key_key& key, bool polarity)
|
||||
{
|
||||
struct keypress_request* req = new keypress_request;
|
||||
req->mods = mods;
|
||||
|
@ -307,7 +307,7 @@ void handle_wx_keyboard(wxKeyEvent& e, bool polarity)
|
|||
else
|
||||
wx_escape_count = 0;
|
||||
}
|
||||
keyboard_modifier_set mset;
|
||||
keyboard::modifier_set mset;
|
||||
modifier_entry* m = modifiers;
|
||||
while(m->name) {
|
||||
if((mods & m->mod) == m->mod) {
|
||||
|
@ -324,7 +324,7 @@ void handle_wx_keyboard(wxKeyEvent& e, bool polarity)
|
|||
} else
|
||||
keys_held.erase(keyc);
|
||||
key_entry* k = keys;
|
||||
keyboard_key_key* grp = NULL;
|
||||
keyboard::key_key* grp = NULL;
|
||||
while(k->name) {
|
||||
if(k->keynum == keyc) {
|
||||
grp = k->allocated;
|
||||
|
@ -345,16 +345,16 @@ void initialize_wx_keyboard()
|
|||
modifier_entry* m = modifiers;
|
||||
while(m->name) {
|
||||
if(m->lname)
|
||||
m->allocated = new keyboard_modifier(lsnes_kbd, m->name, m->lname);
|
||||
m->allocated = new keyboard::modifier(lsnes_kbd, m->name, m->lname);
|
||||
else
|
||||
m->allocated = new keyboard_modifier(lsnes_kbd, m->name);
|
||||
m->allocated = new keyboard::modifier(lsnes_kbd, m->name);
|
||||
modifier_map[m->mod] = m->allocated;
|
||||
m++;
|
||||
}
|
||||
key_entry* k = keys;
|
||||
while(k->name) {
|
||||
if(!keys_allocated.count(k->name)) {
|
||||
k->allocated = new keyboard_key_key(lsnes_kbd, k->name, k->clazz);
|
||||
k->allocated = new keyboard::key_key(lsnes_kbd, k->name, k->clazz);
|
||||
key_map[k->keynum] = k->allocated;
|
||||
keys_allocated[k->name] = k->keynum;
|
||||
} else
|
||||
|
|
|
@ -182,7 +182,7 @@ end:
|
|||
messages << r[1] << "/" << r[2] << " ";
|
||||
messages << r[3] << " bound to '" << r[4] << "'" << std::endl;
|
||||
} else if(r = regex("BUTTON[ \t]+([^ \t]+)[ \t](.*)", line)) {
|
||||
controller_key* ckey = lsnes_mapper.get_controllerkey(r[2]);
|
||||
keyboard::ctrlrkey* ckey = lsnes_mapper.get_controllerkey(r[2]);
|
||||
if(ckey) {
|
||||
ckey->append(r[1]);
|
||||
messages << r[1] << " bound (button) to " << r[2] << std::endl;
|
||||
|
|
|
@ -579,13 +579,13 @@ namespace
|
|||
emulation_thread->join();
|
||||
}
|
||||
|
||||
keyboard_mouse_calibration mouse_cal = {0};
|
||||
keyboard_key_mouse mouse_x(lsnes_kbd, "mouse_x", "mouse", mouse_cal);
|
||||
keyboard_key_mouse mouse_y(lsnes_kbd, "mouse_y", "mouse", mouse_cal);
|
||||
keyboard_key_key mouse_l(lsnes_kbd, "mouse_left", "mouse");
|
||||
keyboard_key_key mouse_m(lsnes_kbd, "mouse_center", "mouse");
|
||||
keyboard_key_key mouse_r(lsnes_kbd, "mouse_right", "mouse");
|
||||
keyboard_key_key mouse_i(lsnes_kbd, "mouse_inwindow", "mouse");
|
||||
keyboard::mouse_calibration mouse_cal = {0};
|
||||
keyboard::key_mouse mouse_x(lsnes_kbd, "mouse_x", "mouse", mouse_cal);
|
||||
keyboard::key_mouse mouse_y(lsnes_kbd, "mouse_y", "mouse", mouse_cal);
|
||||
keyboard::key_key mouse_l(lsnes_kbd, "mouse_left", "mouse");
|
||||
keyboard::key_key mouse_m(lsnes_kbd, "mouse_center", "mouse");
|
||||
keyboard::key_key mouse_r(lsnes_kbd, "mouse_right", "mouse");
|
||||
keyboard::key_key mouse_i(lsnes_kbd, "mouse_inwindow", "mouse");
|
||||
|
||||
std::pair<double, double> calc_scale_factors(double factor, bool ar,
|
||||
double par)
|
||||
|
@ -605,24 +605,24 @@ namespace
|
|||
{
|
||||
auto sfactors = calc_scale_factors(video_scale_factor, arcorrect_enabled,
|
||||
(our_rom.rtype) ? our_rom.rtype->get_PAR() : 1.0);
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_x, e.GetX() / sfactors.first));
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_y, e.GetY() / sfactors.second));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_x, e.GetX() / sfactors.first));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_y, e.GetY() / sfactors.second));
|
||||
if(e.Entering())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_i, 1));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_i, 1));
|
||||
if(e.Leaving())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_i, 0));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_i, 0));
|
||||
if(e.LeftDown())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_l, 1));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_l, 1));
|
||||
if(e.LeftUp())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_l, 0));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_l, 0));
|
||||
if(e.MiddleDown())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_m, 1));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_m, 1));
|
||||
if(e.MiddleUp())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_m, 0));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_m, 0));
|
||||
if(e.RightDown())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_r, 1));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_r, 1));
|
||||
if(e.RightUp())
|
||||
platform::queue(keypress(keyboard_modifier_set(), mouse_r, 0));
|
||||
platform::queue(keypress(keyboard::modifier_set(), mouse_r, 0));
|
||||
}
|
||||
|
||||
bool is_readonly_mode()
|
||||
|
|
|
@ -174,7 +174,7 @@ namespace
|
|||
int n = select->GetSelection();
|
||||
std::map<std::string, std::string> bind;
|
||||
std::vector<wxString> choices;
|
||||
std::list<key_specifier> a = lsnes_mapper.get_bindings();
|
||||
std::list<keyboard::keyspec> a = lsnes_mapper.get_bindings();
|
||||
for(auto i : a)
|
||||
bind[i] = lsnes_mapper.get(i);
|
||||
for(auto i : bind) {
|
||||
|
|
|
@ -63,11 +63,11 @@ namespace
|
|||
std::string pkey;
|
||||
std::function<void(std::string key)> keygrab_callback;
|
||||
|
||||
class keygrabber : public keyboard_event_listener
|
||||
class keygrabber : public keyboard::event_listener
|
||||
{
|
||||
public:
|
||||
keygrabber() { keygrab_active = false; }
|
||||
void on_key_event(keyboard_modifier_set& mods, keyboard_key& key, keyboard_event& event)
|
||||
void on_key_event(keyboard::modifier_set& mods, keyboard::key& key, keyboard::event& event)
|
||||
{
|
||||
if(!keygrab_active)
|
||||
return;
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace
|
|||
wxTreeCtrl* controls;
|
||||
std::map<string_list<char>, wxTreeItemId> items;
|
||||
std::map<string_list<char>, std::string> names;
|
||||
std::map<string_list<char>, controller_key*> realitems;
|
||||
std::map<string_list<char>, keyboard::ctrlrkey*> realitems;
|
||||
wxButton* set_button;
|
||||
wxButton* clear_button;
|
||||
void refresh();
|
||||
|
@ -114,7 +114,7 @@ namespace
|
|||
return;
|
||||
}
|
||||
try {
|
||||
controller_key* ik = realitems[sel];
|
||||
keyboard::ctrlrkey* ik = realitems[sel];
|
||||
if(!ik) {
|
||||
refresh();
|
||||
return;
|
||||
|
@ -143,7 +143,7 @@ namespace
|
|||
return;
|
||||
}
|
||||
try {
|
||||
controller_key* ik = realitems[sel];
|
||||
keyboard::ctrlrkey* ik = realitems[sel];
|
||||
if(!ik) {
|
||||
refresh();
|
||||
return;
|
||||
|
@ -187,7 +187,7 @@ namespace
|
|||
string_list<char> sel = get_selection();
|
||||
if(!realitems.count(sel))
|
||||
return;
|
||||
controller_key* ik = realitems[sel];
|
||||
keyboard::ctrlrkey* ik = realitems[sel];
|
||||
if(!ik)
|
||||
return;
|
||||
auto g = ik->get(e.GetId() - wxID_DROPKEY);
|
||||
|
@ -203,7 +203,7 @@ namespace
|
|||
string_list<char> sel = get_selection();
|
||||
if(!realitems.count(sel))
|
||||
return;
|
||||
controller_key* ik = realitems[sel];
|
||||
keyboard::ctrlrkey* ik = realitems[sel];
|
||||
if(!ik)
|
||||
return;
|
||||
|
||||
|
@ -227,7 +227,7 @@ namespace
|
|||
{
|
||||
if(closing())
|
||||
return;
|
||||
std::map<controller_key*, std::string> data;
|
||||
std::map<keyboard::ctrlrkey*, std::string> data;
|
||||
auto x = lsnes_mapper.get_controller_keys();
|
||||
realitems.clear();
|
||||
for(auto y : x) {
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace
|
|||
wxButton* sec_button;
|
||||
std::map<string_list<char>, wxTreeItemId> items;
|
||||
std::map<string_list<char>, std::string> names;
|
||||
std::map<string_list<char>, inverse_bind*> realitems;
|
||||
std::map<string_list<char>, keyboard::invbind*> realitems;
|
||||
void refresh();
|
||||
string_list<char> get_selection();
|
||||
wxTreeItemId get_item(const string_list<char>& i);
|
||||
|
@ -112,7 +112,7 @@ namespace
|
|||
return;
|
||||
}
|
||||
try {
|
||||
inverse_bind* ik = realitems[sel];
|
||||
keyboard::invbind* ik = realitems[sel];
|
||||
if(!ik) {
|
||||
refresh();
|
||||
return;
|
||||
|
@ -142,13 +142,13 @@ namespace
|
|||
return;
|
||||
}
|
||||
try {
|
||||
inverse_bind* ik = realitems[sel];
|
||||
keyboard::invbind* ik = realitems[sel];
|
||||
if(!ik) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
std::vector<wxString> dropchoices;
|
||||
key_specifier tmp;
|
||||
keyboard::keyspec tmp;
|
||||
unsigned idx = 0;
|
||||
while((tmp = (std::string)ik->get(idx++)))
|
||||
dropchoices.push_back(towxstring(clean_keystring(tmp)));
|
||||
|
@ -181,7 +181,7 @@ namespace
|
|||
string_list<char> sel = get_selection();
|
||||
if(!realitems.count(sel))
|
||||
return;
|
||||
inverse_bind* ik = realitems[sel];
|
||||
keyboard::invbind* ik = realitems[sel];
|
||||
if(!ik)
|
||||
return;
|
||||
ik->clear(e.GetId() - wxID_DROPKEY);
|
||||
|
@ -196,7 +196,7 @@ namespace
|
|||
string_list<char> sel = get_selection();
|
||||
if(!realitems.count(sel))
|
||||
return;
|
||||
inverse_bind* ik = realitems[sel];
|
||||
keyboard::invbind* ik = realitems[sel];
|
||||
if(!ik)
|
||||
return;
|
||||
|
||||
|
@ -206,7 +206,7 @@ namespace
|
|||
menu.Append(wxID_ADDKEY, towxstring("Add new key"));
|
||||
bool first = true;
|
||||
unsigned idx = 0;
|
||||
key_specifier tmp;
|
||||
keyboard::keyspec tmp;
|
||||
while((tmp = ik->get(idx++))) {
|
||||
if(first)
|
||||
menu.AppendSeparator();
|
||||
|
@ -220,14 +220,14 @@ namespace
|
|||
{
|
||||
if(closing())
|
||||
return;
|
||||
std::map<inverse_bind*, std::list<key_specifier>> data;
|
||||
std::map<keyboard::invbind*, std::list<keyboard::keyspec>> data;
|
||||
realitems.clear();
|
||||
auto x = lsnes_mapper.get_inverses();
|
||||
for(auto y : x) {
|
||||
string_list<char> key = split_on_codepoint(y->getname(), U'\u2023');
|
||||
names[key] = y->getname();
|
||||
realitems[key] = y;
|
||||
key_specifier tmp;
|
||||
keyboard::keyspec tmp;
|
||||
unsigned idx = 0;
|
||||
while((tmp = y->get(idx++)))
|
||||
data[y].push_back(tmp);
|
||||
|
|
|
@ -106,8 +106,8 @@ void press_button_dialog::dismiss_with(const std::string& _k)
|
|||
if(lch == '+' || lch == '-')
|
||||
k = k.substr(0, k.length() - 1);
|
||||
}
|
||||
keyboard_key& key = lsnes_kbd.lookup_key(k);
|
||||
if(key.get_type() != KBD_KEYTYPE_AXIS)
|
||||
keyboard::key& key = lsnes_kbd.lookup_key(k);
|
||||
if(key.get_type() != keyboard::KBD_KEYTYPE_AXIS)
|
||||
return;
|
||||
} catch(...) {
|
||||
return;
|
||||
|
@ -127,8 +127,8 @@ key_entry_dialog::key_entry_dialog(wxWindow* parent, const std::string& title, c
|
|||
wxString boxchoices[] = { wxT("Released"), wxT("Don't care"), wxT("Pressed") };
|
||||
std::vector<wxString> classeslist;
|
||||
wxString emptystring;
|
||||
std::list<keyboard_modifier*> mods;
|
||||
std::list<keyboard_key*> keys;
|
||||
std::list<keyboard::modifier*> mods;
|
||||
std::list<keyboard::key*> keys;
|
||||
|
||||
wtitle = title;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue