FS2_Open
Open source remastering of the Freespace 2 engine
keytrap.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "ui/ui.h"
13 #include "ui/uidefs.h"
14 
15 
16 
17 void UI_KEYTRAP::create(UI_WINDOW *wnd, int key, void (*_user_function)(void) )
18 {
19  base_create( wnd, UI_KIND_BUTTON, 0, 0, 0, 0 );
20 
21  pressed_down = 0;
22  set_hotkey(key);
23  set_callback(_user_function);
24 
25  parent = this; // Ugly. This keeps KEYTRAPS from getting keyboard control.
26 }
27 
28 void UI_KEYTRAP::draw()
29 {
30 }
31 
32 void UI_KEYTRAP::process(int focus)
33 {
34  pressed_down = 0;
35 
36  if (disabled_flag) {
37  return;
38  }
39 
40  if (my_wnd->keypress == hotkey) {
41  pressed_down = 1;
42  my_wnd->last_keypress = 0;
43  }
44 
45  if (pressed_down && user_function) {
46  user_function();
47  }
48 }
49 
51 {
52  return pressed_down;
53 }
int hotkey
Definition: ui.h:78
UI_WINDOW * my_wnd
Definition: ui.h:111
void base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
Definition: gadget.cpp:244
int pressed()
Definition: keytrap.cpp:50
void set_callback(void(*_user_function)(void))
Definition: gadget.cpp:288
int key
#define UI_KIND_BUTTON
Definition: ui.h:18
void set_hotkey(int keycode)
Definition: gadget.cpp:280
int disabled_flag
Definition: ui.h:82
UI_GADGET * parent
Definition: ui.h:100
int last_keypress
Definition: ui.h:650
Definition: ui.h:584
void create(UI_WINDOW *wnd, int key, void(*_user_function)(void))
Definition: keytrap.cpp:17
void(* user_function)(void)
Definition: ui.h:81
int keypress
Definition: ui.h:622