1 /* $Id: keypad.c,v 1.5 2005-02-26 00:47:08 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
39 #define MAX_NUM_PADS 20
41 static UI_GADGET_BUTTON * Pad[17];
42 static UI_KEYPAD * KeyPad[MAX_NUM_PADS];
43 static int active_pad;
45 static int desc_x, desc_y;
47 static int HotKey[17];
48 static int HotKey1[17];
50 #define REMOVE_EOL(s) (*(strstr( (s), "\n" ))='\0')
52 int ui_pad_get_current()
61 for (i=0; i< MAX_NUM_PADS; i++ )
71 for (i=0; i< MAX_NUM_PADS; i++ )
75 free(KeyPad[i]->buttontext[j]);
83 void LineParse( int n, char * dest, char * source )
85 int i = 0, j=0, cn = 0;
87 // Go to the n'th line
89 if ((unsigned char) source[i++] == 179)
92 // Read up until the next comma
93 while ((unsigned char) source[i] != 179)
95 dest[j] = source[i++];
103 void ui_pad_activate( UI_WINDOW * wnd, int x, int y )
110 gr_set_current_canvas( wnd->canvas );
111 ui_draw_box_in( x, y, x+(bw*4)+10 + 200, y+(bh*5)+45 );
119 n=0; row = 0; col = 0; w = 1; h = 1;
120 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
121 Pad[n]->canvas->cv_font = ui_small_font;
122 n=1; row = 0; col = 1; w = 1; h = 1;
123 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
124 Pad[n]->canvas->cv_font = ui_small_font;
125 n=2; row = 0; col = 2; w = 1; h = 1;
126 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
127 Pad[n]->canvas->cv_font = ui_small_font;
128 n=3; row = 0; col = 3; w = 1; h = 1;
129 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
130 Pad[n]->canvas->cv_font = ui_small_font;
131 n=4; row = 1; col = 0; w = 1; h = 1;
132 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
133 Pad[n]->canvas->cv_font = ui_small_font;
134 n=5; row = 1; col = 1; w = 1; h = 1;
135 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
136 Pad[n]->canvas->cv_font = ui_small_font;
137 n=6; row = 1; col = 2; w = 1; h = 1;
138 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
139 Pad[n]->canvas->cv_font = ui_small_font;
140 n=7; row = 1; col = 3; w = 1; h = 2;
141 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
142 Pad[n]->canvas->cv_font = ui_small_font;
143 n=8; row = 2; col = 0; w = 1; h = 1;
144 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
145 Pad[n]->canvas->cv_font = ui_small_font;
146 n=9; row = 2; col = 1; w = 1; h = 1;
147 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
148 Pad[n]->canvas->cv_font = ui_small_font;
149 n=10; row = 2; col = 2; w = 1; h = 1;
150 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
151 Pad[n]->canvas->cv_font = ui_small_font;
152 n=11; row = 3; col = 0; w = 1; h = 1;
153 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
154 Pad[n]->canvas->cv_font = ui_small_font;
155 n=12; row = 3; col = 1; w = 1; h = 1;
156 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
157 Pad[n]->canvas->cv_font = ui_small_font;
158 n=13; row = 3; col = 2; w = 1; h = 1;
159 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
160 Pad[n]->canvas->cv_font = ui_small_font;
161 n=14; row = 3; col = 3; w = 1; h = 2;
162 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
163 Pad[n]->canvas->cv_font = ui_small_font;
164 n=15; row = 4; col = 0; w = 2; h = 1;
165 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
166 Pad[n]->canvas->cv_font = ui_small_font;
167 n=16; row = 4; col = 2; w = 1; h = 1;
168 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
169 Pad[n]->canvas->cv_font = ui_small_font;
171 HotKey[0] = KEY_CTRLED + KEY_NUMLOCK;
172 HotKey[1] = KEY_CTRLED + KEY_PADDIVIDE;
173 HotKey[2] = KEY_CTRLED + KEY_PADMULTIPLY;
174 HotKey[3] = KEY_CTRLED + KEY_PADMINUS;
175 HotKey[4] = KEY_CTRLED + KEY_PAD7;
176 HotKey[5] = KEY_CTRLED + KEY_PAD8;
177 HotKey[6] = KEY_CTRLED + KEY_PAD9;
178 HotKey[7] = KEY_CTRLED + KEY_PADPLUS;
179 HotKey[8] = KEY_CTRLED + KEY_PAD4;
180 HotKey[9] = KEY_CTRLED + KEY_PAD5;
181 HotKey[10] = KEY_CTRLED + KEY_PAD6;
182 HotKey[11] = KEY_CTRLED + KEY_PAD1;
183 HotKey[12] = KEY_CTRLED + KEY_PAD2;
184 HotKey[13] = KEY_CTRLED + KEY_PAD3;
185 HotKey[14] = KEY_CTRLED + KEY_PADENTER;
186 HotKey[15] = KEY_CTRLED + KEY_PAD0;
187 HotKey[16] = KEY_CTRLED + KEY_PADPERIOD;
189 HotKey1[0] = KEY_SHIFTED + KEY_CTRLED + KEY_NUMLOCK;
190 HotKey1[1] = KEY_SHIFTED + KEY_CTRLED + KEY_PADDIVIDE;
191 HotKey1[2] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMULTIPLY;
192 HotKey1[3] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMINUS;
193 HotKey1[4] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD7;
194 HotKey1[5] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD8;
195 HotKey1[6] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD9;
196 HotKey1[7] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPLUS;
197 HotKey1[8] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD4;
198 HotKey1[9] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD5;
199 HotKey1[10] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD6;
200 HotKey1[11] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD1;
201 HotKey1[12] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD2;
202 HotKey1[13] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD3;
203 HotKey1[14] = KEY_SHIFTED + KEY_CTRLED + KEY_PADENTER;
204 HotKey1[15] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD0;
205 HotKey1[16] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPERIOD;
212 void ui_pad_deactivate()
216 for (i=0; i<17; i++ )
222 static void ui_pad_set_active( int n )
230 gr_set_current_canvas( NULL );
231 gr_setcolor( CWHITE );
232 gr_urect( desc_x, desc_y, desc_x+ 56*4-1, desc_y+15 );
233 gr_set_fontcolor( CBLACK, CWHITE );
234 gr_ustring( desc_x, desc_y, KeyPad[n]->description );
236 for (i=0; i<17; i++ )
238 Pad[i]->text = KeyPad[n]->buttontext[i];
240 Pad[i]->user_function = NULL;
241 Pad[i]->dim_if_no_function = 1;
244 for (j=0; j< KeyPad[n]->numkeys; j++ )
246 if (HotKey[i] == KeyPad[n]->keycode[j] )
248 Pad[i]->hotkey = HotKey[i];
249 Pad[i]->user_function = func_nget( KeyPad[n]->function_number[j], &np, &name );
251 if (HotKey1[i] == KeyPad[n]->keycode[j] )
253 Pad[i]->hotkey1 = HotKey1[i];
254 Pad[i]->user_function1 = func_nget( KeyPad[n]->function_number[j], &np, &name );
262 void ui_pad_goto(int n)
264 if ( KeyPad[n] != NULL )
265 ui_pad_set_active(n);
268 void ui_pad_goto_next()
275 while( KeyPad[i]==NULL )
278 if (i >= MAX_NUM_PADS)
283 ui_pad_set_active(i);
286 void ui_pad_goto_prev()
290 if (active_pad == -1 )
291 active_pad = MAX_NUM_PADS;
294 if (i<0) i= MAX_NUM_PADS - 1;
297 while( KeyPad[i]==NULL )
302 if (i == active_pad )
305 ui_pad_set_active(i);
308 void ui_pad_read( int n, char * filename )
316 int keycode, functionnumber;
318 infile = fopen( filename, "rt" );
320 Warning( "Couldn't find %s", filename );
324 MALLOC( KeyPad[n], UI_KEYPAD, 1 );
326 for (i=0; i < 17; i++ ) {
327 MALLOC( KeyPad[n]->buttontext[i], char, 100 );
330 KeyPad[n]->numkeys = 0;
332 for (i=0; i<100; i++ )
334 KeyPad[n]->keycode[i] = -1;
335 KeyPad[n]->function_number[i] = 0;
338 while ( linenumber < 22)
340 fgets( buffer, 100, infile );
341 REMOVE_EOL( buffer );
343 switch( linenumber+1 )
346 strncpy( KeyPad[n]->description, buffer, 100 );
348 //===================== ROW 0 ==============================
350 LineParse( 1, text, buffer );
351 sprintf( KeyPad[n]->buttontext[0], "%s\n", text );
352 LineParse( 2, text, buffer );
353 sprintf( KeyPad[n]->buttontext[1], "%s\n", text );
354 LineParse( 3, text, buffer );
355 sprintf( KeyPad[n]->buttontext[2], "%s\n", text );
356 LineParse( 4, text, buffer );
357 sprintf( KeyPad[n]->buttontext[3], "%s\n", text );
360 LineParse( 1, text, buffer );
361 sprintf( KeyPad[n]->buttontext[0], "%s%s\n", KeyPad[n]->buttontext[0],text );
362 LineParse( 2, text, buffer );
363 sprintf( KeyPad[n]->buttontext[1], "%s%s\n", KeyPad[n]->buttontext[1],text );
364 LineParse( 3, text, buffer );
365 sprintf( KeyPad[n]->buttontext[2], "%s%s\n", KeyPad[n]->buttontext[2],text );
366 LineParse( 4, text, buffer );
367 sprintf( KeyPad[n]->buttontext[3], "%s%s\n", KeyPad[n]->buttontext[3],text );
370 LineParse( 1, text, buffer );
371 sprintf( KeyPad[n]->buttontext[0], "%s%s", KeyPad[n]->buttontext[0],text );
372 LineParse( 2, text, buffer );
373 sprintf( KeyPad[n]->buttontext[1], "%s%s", KeyPad[n]->buttontext[1],text );
374 LineParse( 3, text, buffer );
375 sprintf( KeyPad[n]->buttontext[2], "%s%s", KeyPad[n]->buttontext[2],text );
376 LineParse( 4, text, buffer );
377 sprintf( KeyPad[n]->buttontext[3], "%s%s", KeyPad[n]->buttontext[3],text );
379 //===================== ROW 1 ==============================
381 LineParse( 1, text, buffer );
382 sprintf( KeyPad[n]->buttontext[4], "%s\n", text );
383 LineParse( 2, text, buffer );
384 sprintf( KeyPad[n]->buttontext[5], "%s\n", text );
385 LineParse( 3, text, buffer);
386 sprintf( KeyPad[n]->buttontext[6], "%s\n", text );
387 LineParse( 4, text, buffer );
388 sprintf( KeyPad[n]->buttontext[7], "%s\n", text );
391 LineParse( 1, text, buffer );
392 sprintf( KeyPad[n]->buttontext[4], "%s%s\n", KeyPad[n]->buttontext[4],text );
393 LineParse( 2, text, buffer );
394 sprintf( KeyPad[n]->buttontext[5], "%s%s\n", KeyPad[n]->buttontext[5],text );
395 LineParse( 3, text, buffer );
396 sprintf( KeyPad[n]->buttontext[6], "%s%s\n", KeyPad[n]->buttontext[6],text );
397 LineParse( 4, text, buffer );
398 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
401 LineParse( 1, text, buffer );
402 sprintf( KeyPad[n]->buttontext[4], "%s%s", KeyPad[n]->buttontext[4],text );
403 LineParse( 2, text, buffer );
404 sprintf( KeyPad[n]->buttontext[5], "%s%s", KeyPad[n]->buttontext[5],text );
405 LineParse( 3, text, buffer );
406 sprintf( KeyPad[n]->buttontext[6], "%s%s", KeyPad[n]->buttontext[6],text );
407 LineParse( 4, text, buffer );
408 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
411 ptr = strrchr( buffer, 179 );
413 ptr = strrchr( buffer, 180 ); ptr++;
414 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],ptr );
416 //======================= ROW 2 ==============================
418 LineParse( 1, text, buffer );
419 sprintf( KeyPad[n]->buttontext[8], "%s\n", text );
420 LineParse( 2, text, buffer );
421 sprintf( KeyPad[n]->buttontext[9], "%s\n", text );
422 LineParse( 3, text, buffer);
423 sprintf( KeyPad[n]->buttontext[10], "%s\n", text );
424 LineParse( 4, text, buffer );
425 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
428 LineParse( 1, text, buffer );
429 sprintf( KeyPad[n]->buttontext[8], "%s%s\n", KeyPad[n]->buttontext[8],text );
430 LineParse( 2, text, buffer );
431 sprintf( KeyPad[n]->buttontext[9], "%s%s\n", KeyPad[n]->buttontext[9],text );
432 LineParse( 3, text, buffer );
433 sprintf( KeyPad[n]->buttontext[10], "%s%s\n", KeyPad[n]->buttontext[10],text );
434 LineParse( 4, text, buffer );
435 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
438 LineParse( 1, text, buffer );
439 sprintf( KeyPad[n]->buttontext[8], "%s%s", KeyPad[n]->buttontext[8],text );
440 LineParse( 2, text, buffer );
441 sprintf( KeyPad[n]->buttontext[9], "%s%s", KeyPad[n]->buttontext[9],text );
442 LineParse( 3, text, buffer );
443 sprintf( KeyPad[n]->buttontext[10], "%s%s", KeyPad[n]->buttontext[10],text );
444 LineParse( 4, text, buffer );
445 sprintf( KeyPad[n]->buttontext[7], "%s%s", KeyPad[n]->buttontext[7],text );
447 // ====================== ROW 3 =========================
449 LineParse( 1, text, buffer );
450 sprintf( KeyPad[n]->buttontext[11], "%s\n", text );
451 LineParse( 2, text, buffer );
452 sprintf( KeyPad[n]->buttontext[12], "%s\n", text );
453 LineParse( 3, text, buffer);
454 sprintf( KeyPad[n]->buttontext[13], "%s\n", text );
455 LineParse( 4, text, buffer );
456 sprintf( KeyPad[n]->buttontext[14], "%s\n", text );
459 LineParse( 1, text, buffer );
460 sprintf( KeyPad[n]->buttontext[11], "%s%s\n", KeyPad[n]->buttontext[11],text );
461 LineParse( 2, text, buffer );
462 sprintf( KeyPad[n]->buttontext[12], "%s%s\n", KeyPad[n]->buttontext[12],text );
463 LineParse( 3, text, buffer );
464 sprintf( KeyPad[n]->buttontext[13], "%s%s\n", KeyPad[n]->buttontext[13],text );
465 LineParse( 4, text, buffer );
466 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
469 LineParse( 1, text, buffer );
470 sprintf( KeyPad[n]->buttontext[11], "%s%s", KeyPad[n]->buttontext[11],text );
471 LineParse( 2, text, buffer );
472 sprintf( KeyPad[n]->buttontext[12], "%s%s", KeyPad[n]->buttontext[12],text );
473 LineParse( 3, text, buffer );
474 sprintf( KeyPad[n]->buttontext[13], "%s%s", KeyPad[n]->buttontext[13],text );
475 LineParse( 4, text, buffer );
476 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
479 ptr = strrchr( buffer, 179 );
481 ptr = strrchr( buffer, 180 ); ptr++;
482 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14], ptr );
484 //======================= ROW 4 =========================
486 LineParse( 1, text, buffer );
487 sprintf( KeyPad[n]->buttontext[15], "%s\n", text );
488 LineParse( 2, text, buffer );
489 sprintf( KeyPad[n]->buttontext[16], "%s\n", text );
490 LineParse( 3, text, buffer );
491 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
494 LineParse( 1, text, buffer );
495 sprintf( KeyPad[n]->buttontext[15], "%s%s\n", KeyPad[n]->buttontext[15],text );
496 LineParse( 2, text, buffer );
497 sprintf( KeyPad[n]->buttontext[16], "%s%s\n", KeyPad[n]->buttontext[16],text );
498 LineParse( 3, text, buffer );
499 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
502 LineParse( 1, text, buffer );
503 sprintf( KeyPad[n]->buttontext[15], "%s%s", KeyPad[n]->buttontext[15],text );
504 LineParse( 2, text, buffer );
505 sprintf( KeyPad[n]->buttontext[16], "%s%s", KeyPad[n]->buttontext[16],text );
506 LineParse( 3, text, buffer );
507 sprintf( KeyPad[n]->buttontext[14], "%s%s", KeyPad[n]->buttontext[14],text );
514 // Get the keycodes...
516 while (fscanf( infile, " %s %s ", text, buffer )!=EOF)
518 keycode = DecodeKeyText(text);
519 functionnumber = func_get_index(buffer);
520 if (functionnumber==-1)
522 Error( "Unknown function, %s, in %s\n", buffer, filename );
523 } else if (keycode==-1)
525 Error( "Unknown keystroke, %s, in %s\n", text, filename );
526 //MessageBox( -2, -2, 1, buffer, "Ok" );
529 KeyPad[n]->keycode[KeyPad[n]->numkeys] = keycode;
530 KeyPad[n]->function_number[KeyPad[n]->numkeys] = functionnumber;
531 KeyPad[n]->numkeys++;