4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_INPUT_CONFIG_HPP
25 #define XCSOAR_INPUT_CONFIG_HPP
27 #include "InputQueue.hpp"
28 #include "Menu/MenuData.hpp"
29 #include "Util/RadixTree.hpp"
30 #include "Util/StaticString.hpp"
31 #include "Util/TrivialArray.hpp"
43 #elif defined(USE_EGL)
51 typedef void (*pt2Event
)(const TCHAR
*);
53 // Events - What do you want to DO
55 // Which function to call (can be any, but should be here)
59 // Next in event list - eg: Macros
63 /** Map mode to location */
64 TrivialArray
<StaticString
<MAX_MODE_STRING
>, MAX_MODE
> modes
;
66 // Key map to Event - Keys (per mode) mapped to events
67 unsigned short Key2Event
[MAX_MODE
][MAX_KEY
]; // Points to Events location
69 RadixTree
<unsigned> Gesture2Event
;
71 // Glide Computer Events
72 unsigned short GC2Event
[GCE_COUNT
];
74 // NMEA Triggered Events
75 unsigned short N2Event
[NE_COUNT
];
77 TrivialArray
<Event
, MAX_EVENTS
> events
;
84 int LookupMode(const TCHAR
*name
) const {
85 for (unsigned i
= 0, size
= modes
.size(); i
< size
; ++i
)
92 int AppendMode(const TCHAR
*name
) {
96 modes
.append() = name
;
97 return modes
.size() - 1;
101 int MakeMode(const TCHAR
*name
) {
102 int mode
= LookupMode(name
);
104 mode
= AppendMode(name
);
109 unsigned AppendEvent(pt2Event handler
, const TCHAR
*misc
,
114 Event
&event
= events
.append();
115 event
.event
= handler
;
119 return events
.size() - 1;
122 void AppendMenu(unsigned mode_id
, const TCHAR
* label
,
123 unsigned location
, unsigned event_id
) {
124 assert(mode_id
< MAX_MODE
);
126 menus
[mode_id
].Add(label
, location
, event_id
);
130 unsigned GetKeyEvent(unsigned mode
, unsigned key_code
) const {
131 assert(mode
< MAX_MODE
);
133 if (key_code
>= MAX_KEY
)
136 if (mode
> 0 && Key2Event
[mode
][key_code
] != 0)
137 return Key2Event
[mode
][key_code
];
139 /* fall back to the default mode */
140 return Key2Event
[0][key_code
];
144 const MenuItem
&GetMenuItem(unsigned mode
, unsigned location
) const {
145 assert(mode
< MAX_MODE
);
146 assert(location
< Menu::MAX_ITEMS
);
148 return menus
[mode
][location
];