FlightGear next
FGCommonInput.cxx
Go to the documentation of this file.
1// FGCommonInput.cxx -- common functions for all Input subsystems
2//
3// Written by Torsten Dreyer, started August 2009
4// Based on work from David Megginson, started May 2001.
5//
6// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
7// Copyright (C) 2001 David Megginson, david@megginson.com
8//
9// This program is free software; you can redistribute it and/or
10// modify it under the terms of the GNU General Public License as
11// published by the Free Software Foundation; either version 2 of the
12// License, or (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22//
23// $Id$
24
25#ifdef HAVE_CONFIG_H
26# include <config.h>
27#endif
28
29#include "FGCommonInput.hxx"
30#include <Main/globals.hxx>
31#include <Main/fg_os.hxx>
32
33using simgear::PropertyList;
34using std::string;
35
36void FGCommonInput::read_bindings (const SGPropertyNode * node, binding_list_t * binding_list, int modifiers, const string & module )
37{
38 PropertyList bindings = node->getChildren("binding");
39 static string nasal = "nasal";
40 for (unsigned int i = 0; i < bindings.size(); i++) {
41 std::string cmd = bindings[i]->getStringValue("command");
42 if (nasal.compare(cmd) == 0 && !module.empty())
43 bindings[i]->setStringValue("module", module.c_str());
44 binding_list[modifiers].push_back(new SGBinding(bindings[i], globals->get_props()));
45 }
46
47 // Read nested bindings for modifiers
48 if (node->getChild("mod-up") != 0)
49 read_bindings(node->getChild("mod-up"), binding_list,
50 modifiers|KEYMOD_RELEASED, module);
51
52 if (node->getChild("mod-shift") != 0)
53 read_bindings(node->getChild("mod-shift"), binding_list,
54 modifiers|KEYMOD_SHIFT, module);
55
56 if (node->getChild("mod-ctrl") != 0)
57 read_bindings(node->getChild("mod-ctrl"), binding_list,
58 modifiers|KEYMOD_CTRL, module);
59
60 if (node->getChild("mod-alt") != 0)
61 read_bindings(node->getChild("mod-alt"), binding_list,
62 modifiers|KEYMOD_ALT, module);
63
64 if (node->getChild("mod-meta") != 0)
65 read_bindings(node->getChild("mod-meta"), binding_list,
66 modifiers|KEYMOD_META, module);
67
68 if (node->getChild("mod-super") != 0)
69 read_bindings(node->getChild("mod-super"), binding_list,
70 modifiers|KEYMOD_SUPER, module);
71
72 if (node->getChild("mod-hyper") != 0)
73 read_bindings(node->getChild("mod-hyper"), binding_list,
74 modifiers|KEYMOD_HYPER, module);
75}
76
#define i(x)
static void read_bindings(const SGPropertyNode *base, binding_list_t *binding_list, int modifiers, const std::string &module)
SGBindingList binding_list_t
@ KEYMOD_SUPER
Definition fg_os.hxx:30
@ KEYMOD_CTRL
Definition fg_os.hxx:27
@ KEYMOD_HYPER
Definition fg_os.hxx:31
@ KEYMOD_ALT
Definition fg_os.hxx:28
@ KEYMOD_META
Definition fg_os.hxx:29
@ KEYMOD_RELEASED
Definition fg_os.hxx:25
@ KEYMOD_SHIFT
Definition fg_os.hxx:26
FGGlobals * globals
Definition globals.cxx:142