Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 2ebb56836f5fa850d48d2d5cbf5ddd089bbb6bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
   client/keyboard.h
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CLIENT_KEYBOARD_H__
#define __INCLUDED_CLIENT_KEYBOARD_H__

#include <string>
#include <map>
#include <list>

#include "SDL2/SDL.h"

#include "client/action.h"
#include "client/key.h"

namespace client
{

class Keyboard
{
public:	
	typedef std::map<unsigned int, Key *> Keys;

	typedef std::list<Action *> Actions;

	Keyboard();
	~Keyboard();

	/// find a key by scancode
	Key *find(unsigned int scancode);

	/// find a key by name
	Key *find(std::string const & name);

	/// bind a string to a key, if str is empty, just list
	void bind(std::string const &name, const std::string str);

	/// clear the string bound to a key
	void unbind(std::string const &name);

	/// celar all key binds
	void unbindall();
	
	/// reset key states
	void reset();

	/// list keyboard key names
	void list_keys() const;

	/// list actions
	void list_actions() const;

	/// list keyboard binds
	void list_binds() const;

	/// load keyboard binds
	void load_binds() const;

	/// save keyboard binds
	void save_binds() const;

	/// a key has been pressed
	Key *press(const unsigned int scancode);

	/// a key has been pressed
	Key *press(Key *key);

	/// a key has been pressed
	Key *release(const unsigned int scancode);

	/// convert SDL_keysym to a keystroke
	static unsigned int translate_keysym(const unsigned int keysym, const int modifiers);
	
	inline Keys & keys()
	{
		return _keys;
	}

private:
	Key *add_key(const unsigned int scancode, const char *name, const char ascii = 0, const char *bind = 0);

	Action *add_action(const char *name, Action::Identifier id, const char *description = 0);

	Keys 			_keys;
	Actions 		_actions;
};

}

#endif // __INCLUDED_CLIENT_KEYBOARD_H__