Changeset - r15414:a26136a8c645
[Not reviewed]
master
0 3 0
yexo - 14 years ago 2010-07-03 20:14:56
yexo@openttd.org
(svn r20067) -Add: special modifier (GLOBAL) to mark hotkeys as global hotkeys
3 files changed with 9 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/gfx_type.h
Show inline comments
 
@@ -29,13 +29,15 @@ struct PalSpriteID {
 
enum WindowKeyCodes {
 
	WKC_SHIFT = 0x8000,
 
	WKC_CTRL  = 0x4000,
 
	WKC_ALT   = 0x2000,
 
	WKC_META  = 0x1000,
 

	
 
	WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META,
 
	WKC_GLOBAL_HOTKEY = 0x0800, ///< Fake keycode bit to indicate global hotkeys
 

	
 
	WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
 

	
 
	/* Special ones */
 
	WKC_NONE        =  0,
 
	WKC_ESC         =  1,
 
	WKC_BACKSPACE   =  2,
 
	WKC_INSERT      =  3,
src/hotkeys.cpp
Show inline comments
 
@@ -27,12 +27,13 @@ struct KeycodeNames {
 
/** Array of non-standard keycodes that can be used in the hotkeys config file. */
 
static const KeycodeNames _keycode_to_name[] = {
 
	{"SHIFT", WKC_SHIFT},
 
	{"CTRL", WKC_CTRL},
 
	{"ALT", WKC_ALT},
 
	{"META", WKC_META},
 
	{"GLOBAL", WKC_GLOBAL_HOTKEY},
 
	{"ESC", WKC_ESC},
 
	{"DEL", WKC_DELETE},
 
	{"RETURN", WKC_RETURN},
 
	{"BACKQUOTE", WKC_BACKQUOTE},
 
	{"F1", WKC_F1},
 
	{"F2", WKC_F2},
src/hotkeys.h
Show inline comments
 
@@ -49,13 +49,13 @@ struct Hotkey {
 
	{
 
		if (callback == NULL) {
 
			this->callback = NULL;
 
		} else {
 
			this->callback = new CallbackWrapper(callback);
 
		}
 
		if (default_keycode != 0) *this->keycodes.Append() = default_keycode;
 
		if (default_keycode != 0) this->AddKeycode(default_keycode);
 
	}
 

	
 
	/**
 
	 * Create a new Hotkey object with multiple default keycodes.
 
	 * @param default_keycodes An array of default keycodes terminated with 0.
 
	 * @param name The name of this hotkey.
 
@@ -71,13 +71,13 @@ struct Hotkey {
 
		} else {
 
			this->callback = new CallbackWrapper(callback);
 
		}
 

	
 
		const uint16 *keycode = default_keycodes;
 
		while (*keycode != 0) {
 
			this->keycodes.Include(*keycode);
 
			this->AddKeycode(*keycode);
 
			keycode++;
 
		}
 
	}
 

	
 
	~Hotkey()
 
	{
 
@@ -104,19 +104,20 @@ struct Hotkey {
 

	
 
/**
 
 * Check if a keycode is bound to something.
 
 * @param list The list with hotkeys to check
 
 * @param keycode The keycode that was pressed
 
 * @param w The window-pointer to give to the callback function (if any).
 
 * @param global_only Limit the search to hotkeys defined as 'global'.
 
 * @return The number of the matching hotkey or -1.
 
 */
 
template<class T>
 
int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w)
 
int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w, bool global_only = false)
 
{
 
	while (list->num != -1) {
 
		if (list->keycodes.Contains(keycode)) {
 
		if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
 
			if (list->callback != NULL) (w->*(list->callback->callback))(-1);
 
			return list->num;
 
		}
 
		list++;
 
	}
 
	return -1;
0 comments (0 inline, 0 general)