1 /* $Id: keypad.c,v 1.2 2004-12-19 15:21:11 btb 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.
42 #define MAX_NUM_PADS 20
44 static UI_GADGET_BUTTON * Pad[17];
45 static UI_KEYPAD * KeyPad[MAX_NUM_PADS];
46 static int active_pad;
48 static int desc_x, desc_y;
50 static int HotKey[17];
51 static int HotKey1[17];
53 #define REMOVE_EOL(s) (*(strstr( (s), "\n" ))='\0')
55 int ui_pad_get_current()
64 for (i=0; i< MAX_NUM_PADS; i++ )
74 for (i=0; i< MAX_NUM_PADS; i++ )
78 free(KeyPad[i]->buttontext[j]);
86 void LineParse( int n, char * dest, char * source )
88 int i = 0, j=0, cn = 0;
90 // Go to the n'th line
92 if (source[i++] == 179 )
95 // Read up until the next comma
96 while ( source[i] != 179 )
98 dest[j] = source[i++];
106 void ui_pad_activate( UI_WINDOW * wnd, int x, int y )
113 gr_set_current_canvas( wnd->canvas );
114 ui_draw_box_in( x, y, x+(bw*4)+10 + 200, y+(bh*5)+45 );
122 n=0; row = 0; col = 0; 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=1; row = 0; col = 1; 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=2; row = 0; col = 2; 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=3; row = 0; col = 3; 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=4; row = 1; col = 0; 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=5; row = 1; col = 1; 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=6; row = 1; col = 2; w = 1; h = 1;
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=7; row = 1; col = 3; w = 1; h = 2;
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=8; row = 2; col = 0; 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=9; row = 2; col = 1; 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=10; row = 2; col = 2; 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=11; row = 3; col = 0; 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=12; row = 3; col = 1; 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=13; row = 3; col = 2; w = 1; h = 1;
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=14; row = 3; col = 3; w = 1; h = 2;
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=15; row = 4; col = 0; w = 2; 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;
170 n=16; row = 4; col = 2; w = 1; h = 1;
171 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
172 Pad[n]->canvas->cv_font = ui_small_font;
174 HotKey[0] = KEY_CTRLED + KEY_NUMLOCK;
175 HotKey[1] = KEY_CTRLED + KEY_PADDIVIDE;
176 HotKey[2] = KEY_CTRLED + KEY_PADMULTIPLY;
177 HotKey[3] = KEY_CTRLED + KEY_PADMINUS;
178 HotKey[4] = KEY_CTRLED + KEY_PAD7;
179 HotKey[5] = KEY_CTRLED + KEY_PAD8;
180 HotKey[6] = KEY_CTRLED + KEY_PAD9;
181 HotKey[7] = KEY_CTRLED + KEY_PADPLUS;
182 HotKey[8] = KEY_CTRLED + KEY_PAD4;
183 HotKey[9] = KEY_CTRLED + KEY_PAD5;
184 HotKey[10] = KEY_CTRLED + KEY_PAD6;
185 HotKey[11] = KEY_CTRLED + KEY_PAD1;
186 HotKey[12] = KEY_CTRLED + KEY_PAD2;
187 HotKey[13] = KEY_CTRLED + KEY_PAD3;
188 HotKey[14] = KEY_CTRLED + KEY_PADENTER;
189 HotKey[15] = KEY_CTRLED + KEY_PAD0;
190 HotKey[16] = KEY_CTRLED + KEY_PADPERIOD;
192 HotKey1[0] = KEY_SHIFTED + KEY_CTRLED + KEY_NUMLOCK;
193 HotKey1[1] = KEY_SHIFTED + KEY_CTRLED + KEY_PADDIVIDE;
194 HotKey1[2] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMULTIPLY;
195 HotKey1[3] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMINUS;
196 HotKey1[4] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD7;
197 HotKey1[5] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD8;
198 HotKey1[6] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD9;
199 HotKey1[7] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPLUS;
200 HotKey1[8] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD4;
201 HotKey1[9] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD5;
202 HotKey1[10] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD6;
203 HotKey1[11] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD1;
204 HotKey1[12] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD2;
205 HotKey1[13] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD3;
206 HotKey1[14] = KEY_SHIFTED + KEY_CTRLED + KEY_PADENTER;
207 HotKey1[15] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD0;
208 HotKey1[16] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPERIOD;
215 void ui_pad_deactivate()
219 for (i=0; i<17; i++ )
225 static void ui_pad_set_active( int n )
233 gr_set_current_canvas( NULL );
234 gr_setcolor( CWHITE );
235 gr_urect( desc_x, desc_y, desc_x+ 56*4-1, desc_y+15 );
236 gr_set_fontcolor( CBLACK, CWHITE );
237 gr_ustring( desc_x, desc_y, KeyPad[n]->description );
239 for (i=0; i<17; i++ )
241 Pad[i]->text = KeyPad[n]->buttontext[i];
243 Pad[i]->user_function = NULL;
244 Pad[i]->dim_if_no_function = 1;
247 for (j=0; j< KeyPad[n]->numkeys; j++ )
249 if (HotKey[i] == KeyPad[n]->keycode[j] )
251 Pad[i]->hotkey = HotKey[i];
252 Pad[i]->user_function = func_nget( KeyPad[n]->function_number[j], &np, &name );
254 if (HotKey1[i] == KeyPad[n]->keycode[j] )
256 Pad[i]->hotkey1 = HotKey1[i];
257 Pad[i]->user_function1 = func_nget( KeyPad[n]->function_number[j], &np, &name );
265 void ui_pad_goto(int n)
267 if ( KeyPad[n] != NULL )
268 ui_pad_set_active(n);
271 void ui_pad_goto_next()
278 while( KeyPad[i]==NULL )
281 if (i >= MAX_NUM_PADS)
286 ui_pad_set_active(i);
289 void ui_pad_goto_prev()
293 if (active_pad == -1 )
294 active_pad = MAX_NUM_PADS;
297 if (i<0) i= MAX_NUM_PADS - 1;
300 while( KeyPad[i]==NULL )
305 if (i == active_pad )
308 ui_pad_set_active(i);
311 void ui_pad_read( int n, char * filename )
319 int keycode, functionnumber;
321 infile = fopen( filename, "rt" );
323 Warning( "Couldn't find %s", filename );
327 MALLOC( KeyPad[n], UI_KEYPAD, 1 );
329 for (i=0; i < 17; i++ ) {
330 MALLOC( KeyPad[n]->buttontext[i], char, 100 );
333 KeyPad[n]->numkeys = 0;
335 for (i=0; i<100; i++ )
337 KeyPad[n]->keycode[i] = -1;
338 KeyPad[n]->function_number[i] = 0;
341 while ( linenumber < 22)
343 fgets( buffer, 100, infile );
344 REMOVE_EOL( buffer );
346 switch( linenumber+1 )
349 strncpy( KeyPad[n]->description, buffer, 100 );
351 //===================== ROW 0 ==============================
353 LineParse( 1, text, buffer );
354 sprintf( KeyPad[n]->buttontext[0], "%s\n", text );
355 LineParse( 2, text, buffer );
356 sprintf( KeyPad[n]->buttontext[1], "%s\n", text );
357 LineParse( 3, text, buffer );
358 sprintf( KeyPad[n]->buttontext[2], "%s\n", text );
359 LineParse( 4, text, buffer );
360 sprintf( KeyPad[n]->buttontext[3], "%s\n", text );
363 LineParse( 1, text, buffer );
364 sprintf( KeyPad[n]->buttontext[0], "%s%s\n", KeyPad[n]->buttontext[0],text );
365 LineParse( 2, text, buffer );
366 sprintf( KeyPad[n]->buttontext[1], "%s%s\n", KeyPad[n]->buttontext[1],text );
367 LineParse( 3, text, buffer );
368 sprintf( KeyPad[n]->buttontext[2], "%s%s\n", KeyPad[n]->buttontext[2],text );
369 LineParse( 4, text, buffer );
370 sprintf( KeyPad[n]->buttontext[3], "%s%s\n", KeyPad[n]->buttontext[3],text );
373 LineParse( 1, text, buffer );
374 sprintf( KeyPad[n]->buttontext[0], "%s%s", KeyPad[n]->buttontext[0],text );
375 LineParse( 2, text, buffer );
376 sprintf( KeyPad[n]->buttontext[1], "%s%s", KeyPad[n]->buttontext[1],text );
377 LineParse( 3, text, buffer );
378 sprintf( KeyPad[n]->buttontext[2], "%s%s", KeyPad[n]->buttontext[2],text );
379 LineParse( 4, text, buffer );
380 sprintf( KeyPad[n]->buttontext[3], "%s%s", KeyPad[n]->buttontext[3],text );
382 //===================== ROW 1 ==============================
384 LineParse( 1, text, buffer );
385 sprintf( KeyPad[n]->buttontext[4], "%s\n", text );
386 LineParse( 2, text, buffer );
387 sprintf( KeyPad[n]->buttontext[5], "%s\n", text );
388 LineParse( 3, text, buffer);
389 sprintf( KeyPad[n]->buttontext[6], "%s\n", text );
390 LineParse( 4, text, buffer );
391 sprintf( KeyPad[n]->buttontext[7], "%s\n", text );
394 LineParse( 1, text, buffer );
395 sprintf( KeyPad[n]->buttontext[4], "%s%s\n", KeyPad[n]->buttontext[4],text );
396 LineParse( 2, text, buffer );
397 sprintf( KeyPad[n]->buttontext[5], "%s%s\n", KeyPad[n]->buttontext[5],text );
398 LineParse( 3, text, buffer );
399 sprintf( KeyPad[n]->buttontext[6], "%s%s\n", KeyPad[n]->buttontext[6],text );
400 LineParse( 4, text, buffer );
401 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
404 LineParse( 1, text, buffer );
405 sprintf( KeyPad[n]->buttontext[4], "%s%s", KeyPad[n]->buttontext[4],text );
406 LineParse( 2, text, buffer );
407 sprintf( KeyPad[n]->buttontext[5], "%s%s", KeyPad[n]->buttontext[5],text );
408 LineParse( 3, text, buffer );
409 sprintf( KeyPad[n]->buttontext[6], "%s%s", KeyPad[n]->buttontext[6],text );
410 LineParse( 4, text, buffer );
411 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
414 ptr = strrchr( buffer, 179 );
416 ptr = strrchr( buffer, 180 ); ptr++;
417 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],ptr );
419 //======================= ROW 2 ==============================
421 LineParse( 1, text, buffer );
422 sprintf( KeyPad[n]->buttontext[8], "%s\n", text );
423 LineParse( 2, text, buffer );
424 sprintf( KeyPad[n]->buttontext[9], "%s\n", text );
425 LineParse( 3, text, buffer);
426 sprintf( KeyPad[n]->buttontext[10], "%s\n", text );
427 LineParse( 4, text, buffer );
428 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
431 LineParse( 1, text, buffer );
432 sprintf( KeyPad[n]->buttontext[8], "%s%s\n", KeyPad[n]->buttontext[8],text );
433 LineParse( 2, text, buffer );
434 sprintf( KeyPad[n]->buttontext[9], "%s%s\n", KeyPad[n]->buttontext[9],text );
435 LineParse( 3, text, buffer );
436 sprintf( KeyPad[n]->buttontext[10], "%s%s\n", KeyPad[n]->buttontext[10],text );
437 LineParse( 4, text, buffer );
438 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
441 LineParse( 1, text, buffer );
442 sprintf( KeyPad[n]->buttontext[8], "%s%s", KeyPad[n]->buttontext[8],text );
443 LineParse( 2, text, buffer );
444 sprintf( KeyPad[n]->buttontext[9], "%s%s", KeyPad[n]->buttontext[9],text );
445 LineParse( 3, text, buffer );
446 sprintf( KeyPad[n]->buttontext[10], "%s%s", KeyPad[n]->buttontext[10],text );
447 LineParse( 4, text, buffer );
448 sprintf( KeyPad[n]->buttontext[7], "%s%s", KeyPad[n]->buttontext[7],text );
450 // ====================== ROW 3 =========================
452 LineParse( 1, text, buffer );
453 sprintf( KeyPad[n]->buttontext[11], "%s\n", text );
454 LineParse( 2, text, buffer );
455 sprintf( KeyPad[n]->buttontext[12], "%s\n", text );
456 LineParse( 3, text, buffer);
457 sprintf( KeyPad[n]->buttontext[13], "%s\n", text );
458 LineParse( 4, text, buffer );
459 sprintf( KeyPad[n]->buttontext[14], "%s\n", text );
462 LineParse( 1, text, buffer );
463 sprintf( KeyPad[n]->buttontext[11], "%s%s\n", KeyPad[n]->buttontext[11],text );
464 LineParse( 2, text, buffer );
465 sprintf( KeyPad[n]->buttontext[12], "%s%s\n", KeyPad[n]->buttontext[12],text );
466 LineParse( 3, text, buffer );
467 sprintf( KeyPad[n]->buttontext[13], "%s%s\n", KeyPad[n]->buttontext[13],text );
468 LineParse( 4, text, buffer );
469 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
472 LineParse( 1, text, buffer );
473 sprintf( KeyPad[n]->buttontext[11], "%s%s", KeyPad[n]->buttontext[11],text );
474 LineParse( 2, text, buffer );
475 sprintf( KeyPad[n]->buttontext[12], "%s%s", KeyPad[n]->buttontext[12],text );
476 LineParse( 3, text, buffer );
477 sprintf( KeyPad[n]->buttontext[13], "%s%s", KeyPad[n]->buttontext[13],text );
478 LineParse( 4, text, buffer );
479 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
482 ptr = strrchr( buffer, 179 );
484 ptr = strrchr( buffer, 180 ); ptr++;
485 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14], ptr );
487 //======================= ROW 4 =========================
489 LineParse( 1, text, buffer );
490 sprintf( KeyPad[n]->buttontext[15], "%s\n", text );
491 LineParse( 2, text, buffer );
492 sprintf( KeyPad[n]->buttontext[16], "%s\n", text );
493 LineParse( 3, text, buffer );
494 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
497 LineParse( 1, text, buffer );
498 sprintf( KeyPad[n]->buttontext[15], "%s%s\n", KeyPad[n]->buttontext[15],text );
499 LineParse( 2, text, buffer );
500 sprintf( KeyPad[n]->buttontext[16], "%s%s\n", KeyPad[n]->buttontext[16],text );
501 LineParse( 3, text, buffer );
502 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
505 LineParse( 1, text, buffer );
506 sprintf( KeyPad[n]->buttontext[15], "%s%s", KeyPad[n]->buttontext[15],text );
507 LineParse( 2, text, buffer );
508 sprintf( KeyPad[n]->buttontext[16], "%s%s", KeyPad[n]->buttontext[16],text );
509 LineParse( 3, text, buffer );
510 sprintf( KeyPad[n]->buttontext[14], "%s%s", KeyPad[n]->buttontext[14],text );
517 // Get the keycodes...
519 while (fscanf( infile, " %s %s ", text, buffer )!=EOF)
521 keycode = DecodeKeyText(text);
522 functionnumber = func_get_index(buffer);
523 if (functionnumber==-1)
525 Error( "Unknown function, %s, in %s\n", buffer, filename );
526 } else if (keycode==-1)
528 Error( "Unknown keystroke, %s, in %s\n", text, filename );
529 //MessageBox( -2, -2, 1, buffer, "Ok" );
532 KeyPad[n]->keycode[KeyPad[n]->numkeys] = keycode;
533 KeyPad[n]->function_number[KeyPad[n]->numkeys] = functionnumber;
534 KeyPad[n]->numkeys++;