]> icculus.org git repositories - btb/d2x.git/blob - ui/keypress.c
remove rcs tags
[btb/d2x.git] / ui / keypress.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include "conf.h"
16 #endif
17
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include <string.h>
21
22 #include "fix.h"
23 #include "pstypes.h"
24 #include "gr.h"
25 #include "ui.h"
26 #include "key.h"
27
28 char * KeyDesc[256] = {         \
29 "","{Esc}","{1}","{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}","{0}","{-}",           \
30 "{=}","{Backspace}","{Tab}","{Q}","{W}","{E}","{R}","{T}","{Y}","{U}","{I}","{O}",      \
31 "{P}","{[}","{]}","{Enter}","{LeftCtrl}","{A}","{S}","{D}","{F}",        \
32 "{G}","{H}","{J}","{K}","{L}","{;}","{'}","{`}",        \
33 "{RightShift}","{\\}","{Z}","{X}","{C}","{V}","{B}","{N}","{M}","{,}",      \
34 "{.}","{/}","{LeftShift}","{Pad*}","{LeftAlt}","{Spacebar}",      \
35 "{CapsLock}","{F1}","{F2}","{F3}","{F4}","{F5}","{F6}","{F7}","{F8}","{F9}",        \
36 "{F10}","{NumLock}","{ScrollLock}","{Pad7}","{Pad8}","{Pad9}","{Pad-}",   \
37 "{Pad4}","{Pad5}","{Pad6}","{Pad+}","{Pad1}","{Pad2}","{Pad3}","{Pad0}", \
38 "{Pad.}","","","","{F11}","{F12}","","","","","","","","","",         \
39 "","","","","","","","","","","","","","","","","","","","",     \
40 "","","","","","","","","","","","","","","","","","","","",     \
41 "","","","","","","","","","","","","","","","","","",           \
42 "{PadEnter}","{RightCtrl}","","","","","","","","","","","","","", \
43 "","","","","","","","","","","{Pad/}","","","{RightAlt}","",      \
44 "","","","","","","","","","","","","","{Home}","{Up}","{PageUp}",     \
45 "","{Left}","","{Right}","","{End}","{Down}","{PageDown}","{Insert}",       \
46 "{Delete}","","","","","","","","","","","","","","","","","",     \
47 "","","","","","","","","","","","","","","","","","","","",     \
48 "","","","","","","" };
49
50
51
52
53 void GetKeyDescription( char * text, int keypress )
54 {
55         char Ctrl[10];
56         char Alt[10];
57         char Shift[10];
58
59         if (keypress & KEY_CTRLED)
60                 strcpy( Ctrl, "{Ctrl}");
61         else
62                 strcpy( Ctrl, "");
63
64         if (keypress & KEY_ALTED)
65                 strcpy( Alt, "{Alt}");
66         else
67                 strcpy( Alt, "");
68
69         if (keypress & KEY_SHIFTED)
70                 strcpy( Shift, "{Shift}");
71         else
72                 strcpy( Shift, "");
73
74         sprintf( text, "%s%s%s%s", Ctrl, Alt, Shift, KeyDesc[keypress & 255 ]  );
75 }
76
77
78 int DecodeKeyText( char * text )
79 {
80         int i, code = 0;
81
82         if (strstr(text, "{Ctrl}") )
83                 code |= KEY_CTRLED;
84         if (strstr(text, "{Alt}") )
85                 code |= KEY_ALTED;
86         if (strstr(text, "{Shift}") )
87                 code |= KEY_SHIFTED;
88
89         for (i=0; i<256; i++ )
90         {
91                 if ( strlen(KeyDesc[i])>0 && strstr(text, KeyDesc[i]) )
92                 {
93                         code |= i;
94                         return code;
95                 }
96         }
97         return -1;
98 }
99
100
101
102
103 int GetKeyCode(char * text)
104 {
105         UI_WINDOW * wnd;
106         UI_GADGET_BUTTON * DoneButton;
107         char temp_text[100];
108
109         text = text;
110
111         wnd = ui_open_window( 200, 200, 400, 200, WIN_DIALOG );
112
113         DoneButton = ui_add_gadget_button( wnd, 170, 165, 60, 25, "Ok", NULL );
114
115         ui_gadget_calc_keys(wnd);
116
117         //key_flush();
118
119         wnd->keyboard_focus_gadget = (UI_GADGET *)DoneButton;
120
121         while(1)
122         {
123                 ui_mega_process();
124                 ui_window_do_gadgets(wnd);
125
126                 if (last_keypress > 0)
127                 {
128                         GetKeyDescription( temp_text, last_keypress );
129                         ui_wprintf_at( wnd, 10, 100, "%s     ", temp_text  );
130                 }
131
132                 if (DoneButton->pressed)
133                         break;
134
135                 gr_update();
136         }
137
138         ui_close_window(wnd);
139
140         return 0;
141 }
142