]> icculus.org git repositories - taylor/freespace2.git/blob - src/ui/keytrap.cpp
Initial revision
[taylor/freespace2.git] / src / ui / keytrap.cpp
1 /*
2  * $Logfile: /Freespace2/code/UI/KEYTRAP.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines for gadgets that trap keypresses.
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:11  root
11  * Initial revision
12  *
13  * 
14  * 2     10/07/98 10:54a Dave
15  * Initial checkin.
16  * 
17  * 1     10/07/98 10:51a Dave
18  * 
19  * 2     1/14/98 6:43p Hoffoss
20  * Massive changes to UI code.  A lot cleaner and better now.  Did all
21  * this to get the new UI_DOT_SLIDER to work properly, which the old code
22  * wasn't flexible enough to handle.
23  * 
24  * 1     11/14/96 6:55p John
25  *
26  * $NoKeywords: $
27  */
28
29 #include "uidefs.h"
30 #include "ui.h"
31
32
33 void UI_KEYTRAP::create(UI_WINDOW *wnd, int key, void (*_user_function)(void) )
34 {
35         base_create( wnd, UI_KIND_BUTTON, 0, 0, 0, 0 );
36
37         pressed_down = 0;
38         set_hotkey(key);
39         set_callback(_user_function);
40
41         parent = this;          // Ugly.  This keeps KEYTRAPS from getting keyboard control.
42 };
43
44 void UI_KEYTRAP::draw()
45 {
46 }
47
48 void UI_KEYTRAP::process(int focus)
49 {
50         pressed_down = 0;
51
52         if (disabled_flag) {
53                 return;
54         }
55
56         if (my_wnd->keypress == hotkey) {
57                 pressed_down = 1;
58                 my_wnd->last_keypress = 0;
59         }
60
61         if (pressed_down && user_function)      {
62                 user_function();
63         }
64 }
65
66 int UI_KEYTRAP::pressed()
67 {
68         return pressed_down;
69 }