]> git.mxchange.org Git - flightgear.git/blob - src/Input/FGCommonInput.cxx
Advanced input subsystem - Step2: Split up current input subsystem
[flightgear.git] / src / Input / FGCommonInput.cxx
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 #include "FGCommonInput.hxx"
26 #include <Main/globals.hxx>
27 #include <Main/fg_os.hxx>
28
29 void FGCommonInput::read_bindings (const SGPropertyNode * node, binding_list_t * binding_list, int modifiers, string & module )
30 {
31   SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
32   vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
33   string nasal = "nasal";
34   for (unsigned int i = 0; i < bindings.size(); i++) {
35     const char *cmd = bindings[i]->getStringValue("command");
36     SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding " << cmd);
37     if (nasal.compare(cmd) == 0 && !module.empty())
38       bindings[i]->setStringValue("module", module.c_str());
39     binding_list[modifiers].push_back(new SGBinding(bindings[i], globals->get_props()));
40   }
41
42                                 // Read nested bindings for modifiers
43   if (node->getChild("mod-up") != 0)
44     read_bindings(node->getChild("mod-up"), binding_list,
45                    modifiers|KEYMOD_RELEASED, module);
46
47   if (node->getChild("mod-shift") != 0)
48     read_bindings(node->getChild("mod-shift"), binding_list,
49                    modifiers|KEYMOD_SHIFT, module);
50
51   if (node->getChild("mod-ctrl") != 0)
52     read_bindings(node->getChild("mod-ctrl"), binding_list,
53                    modifiers|KEYMOD_CTRL, module);
54
55   if (node->getChild("mod-alt") != 0)
56     read_bindings(node->getChild("mod-alt"), binding_list,
57                    modifiers|KEYMOD_ALT, module);
58
59   if (node->getChild("mod-meta") != 0)
60     read_bindings(node->getChild("mod-meta"), binding_list,
61                    modifiers|KEYMOD_META, module);
62
63   if (node->getChild("mod-super") != 0)
64     read_bindings(node->getChild("mod-super"), binding_list,
65                    modifiers|KEYMOD_SUPER, module);
66
67   if (node->getChild("mod-hyper") != 0)
68     read_bindings(node->getChild("mod-hyper"), binding_list,
69                    modifiers|KEYMOD_HYPER, module);
70 }
71