]> git.mxchange.org Git - flightgear.git/blob - src/Main/keyboard.cxx
- removed bfi.cxx and bfi.hxx
[flightgear.git] / src / Main / keyboard.cxx
1 // keyboard.cxx -- handle GLUT keyboard events
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997 - 1999  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef HAVE_WINDOWS_H
29 #  include <windows.h>                     
30 #endif
31
32 #include <GL/glut.h>
33
34 #include <plib/pu.h>
35
36 #include <simgear/compiler.h>
37
38 #include <Input/input.hxx>
39
40 #include "keyboard.hxx"
41
42
43 /**
44  * Construct the modifiers.
45  */
46 static inline int get_mods ()
47 {
48   int glut_modifiers = glutGetModifiers();
49   int modifiers = 0;
50
51   if (glut_modifiers & GLUT_ACTIVE_SHIFT)
52     modifiers |= FGInput::FG_MOD_SHIFT;
53   if (glut_modifiers & GLUT_ACTIVE_CTRL)
54     modifiers |= FGInput::FG_MOD_CTRL;
55   if (glut_modifiers & GLUT_ACTIVE_ALT)
56     modifiers |= FGInput::FG_MOD_ALT;
57
58   return modifiers;
59 }
60
61
62 /**
63  * Key-down event handler for Glut.
64  *
65  * <p>Pass the value on to the FGInput module unless PUI wants it.</p>
66  *
67  * @param k The integer value for the key pressed.
68  * @param x (unused)
69  * @param y (unused)
70  */
71 void GLUTkey(unsigned char k, int x, int y)
72 {
73                                 // Give PUI a chance to grab it first.
74   if (!puKeyboard(k, PU_DOWN))
75     current_input.doKey(k, get_mods(), x, y);
76 }
77
78
79 /**
80  * Key-up event handler for GLUT.
81  *
82  * <p>PUI doesn't use this, so always pass it to the input manager.</p>
83  *
84  * @param k The integer value for the key pressed.
85  * @param x (unused)
86  * @param y (unused)
87  */
88 void GLUTkeyup(unsigned char k, int x, int y)
89 {
90   current_input.doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
91 }
92
93
94 /**
95  * Special key-down handler for Glut.
96  *
97  * <p>Pass the value on to the FGInput module unless PUI wants it.
98  * The key value will have 256 added to it.</p>
99  *
100  * @param k The integer value for the key pressed (will have 256 added
101  * to it).
102  * @param x (unused)
103  * @param y (unused)
104  */
105 void GLUTspecialkey(int k, int x, int y)
106 {
107                                 // Give PUI a chance to grab it first.
108   if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN))
109     current_input.doKey(k + 256, get_mods(), x, y);
110 }
111
112
113 /**
114  * Special key-up handler for Glut.
115  *
116  * @param k The integer value for the key pressed (will have 256 added
117  * to it).
118  * @param x (unused)
119  * @param y (unused)
120  */
121 void GLUTspecialkeyup(int k, int x, int y)
122 {
123   current_input.doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
124 }
125
126
127 // end of keyboard.cxx