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.
38 #define MAX_NUM_PADS 20
40 static UI_GADGET_BUTTON * Pad[17];
41 static UI_KEYPAD * KeyPad[MAX_NUM_PADS];
42 static int active_pad;
44 static int desc_x, desc_y;
46 static int HotKey[17];
47 static int HotKey1[17];
49 #define REMOVE_EOL(s) (*(strstr( (s), "\n" ))='\0')
51 int ui_pad_get_current()
60 for (i=0; i< MAX_NUM_PADS; i++ )
70 for (i=0; i< MAX_NUM_PADS; i++ )
74 d_free(KeyPad[i]->buttontext[j]);
82 void LineParse( int n, char * dest, char * source )
84 int i = 0, j=0, cn = 0;
86 // Go to the n'th line
88 if ((unsigned char) source[i++] == 179)
91 // Read up until the next comma
92 while ((unsigned char) source[i] != 179)
94 dest[j] = source[i++];
102 void ui_pad_activate( UI_WINDOW * wnd, int x, int y )
109 gr_set_current_canvas( wnd->canvas );
110 ui_draw_box_in( x, y, x+(bw*4)+10 + 200, y+(bh*5)+45 );
118 n=0; row = 0; col = 0; w = 1; h = 1;
119 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
120 Pad[n]->canvas->cv_font = ui_small_font;
121 n=1; row = 0; col = 1; w = 1; h = 1;
122 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
123 Pad[n]->canvas->cv_font = ui_small_font;
124 n=2; row = 0; col = 2; w = 1; h = 1;
125 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
126 Pad[n]->canvas->cv_font = ui_small_font;
127 n=3; row = 0; col = 3; w = 1; h = 1;
128 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
129 Pad[n]->canvas->cv_font = ui_small_font;
130 n=4; row = 1; col = 0; w = 1; h = 1;
131 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
132 Pad[n]->canvas->cv_font = ui_small_font;
133 n=5; row = 1; col = 1; w = 1; h = 1;
134 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
135 Pad[n]->canvas->cv_font = ui_small_font;
136 n=6; row = 1; col = 2; w = 1; h = 1;
137 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
138 Pad[n]->canvas->cv_font = ui_small_font;
139 n=7; row = 1; col = 3; w = 1; h = 2;
140 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
141 Pad[n]->canvas->cv_font = ui_small_font;
142 n=8; row = 2; col = 0; w = 1; h = 1;
143 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
144 Pad[n]->canvas->cv_font = ui_small_font;
145 n=9; row = 2; col = 1; w = 1; h = 1;
146 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
147 Pad[n]->canvas->cv_font = ui_small_font;
148 n=10; row = 2; col = 2; w = 1; h = 1;
149 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
150 Pad[n]->canvas->cv_font = ui_small_font;
151 n=11; row = 3; col = 0; w = 1; h = 1;
152 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
153 Pad[n]->canvas->cv_font = ui_small_font;
154 n=12; row = 3; col = 1; w = 1; h = 1;
155 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
156 Pad[n]->canvas->cv_font = ui_small_font;
157 n=13; row = 3; col = 2; w = 1; h = 1;
158 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
159 Pad[n]->canvas->cv_font = ui_small_font;
160 n=14; row = 3; col = 3; w = 1; h = 2;
161 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
162 Pad[n]->canvas->cv_font = ui_small_font;
163 n=15; row = 4; col = 0; w = 2; h = 1;
164 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
165 Pad[n]->canvas->cv_font = ui_small_font;
166 n=16; row = 4; col = 2; w = 1; h = 1;
167 Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
168 Pad[n]->canvas->cv_font = ui_small_font;
170 HotKey[0] = KEY_CTRLED + KEY_NUMLOCK;
171 HotKey[1] = KEY_CTRLED + KEY_PADDIVIDE;
172 HotKey[2] = KEY_CTRLED + KEY_PADMULTIPLY;
173 HotKey[3] = KEY_CTRLED + KEY_PADMINUS;
174 HotKey[4] = KEY_CTRLED + KEY_PAD7;
175 HotKey[5] = KEY_CTRLED + KEY_PAD8;
176 HotKey[6] = KEY_CTRLED + KEY_PAD9;
177 HotKey[7] = KEY_CTRLED + KEY_PADPLUS;
178 HotKey[8] = KEY_CTRLED + KEY_PAD4;
179 HotKey[9] = KEY_CTRLED + KEY_PAD5;
180 HotKey[10] = KEY_CTRLED + KEY_PAD6;
181 HotKey[11] = KEY_CTRLED + KEY_PAD1;
182 HotKey[12] = KEY_CTRLED + KEY_PAD2;
183 HotKey[13] = KEY_CTRLED + KEY_PAD3;
184 HotKey[14] = KEY_CTRLED + KEY_PADENTER;
185 HotKey[15] = KEY_CTRLED + KEY_PAD0;
186 HotKey[16] = KEY_CTRLED + KEY_PADPERIOD;
188 HotKey1[0] = KEY_SHIFTED + KEY_CTRLED + KEY_NUMLOCK;
189 HotKey1[1] = KEY_SHIFTED + KEY_CTRLED + KEY_PADDIVIDE;
190 HotKey1[2] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMULTIPLY;
191 HotKey1[3] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMINUS;
192 HotKey1[4] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD7;
193 HotKey1[5] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD8;
194 HotKey1[6] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD9;
195 HotKey1[7] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPLUS;
196 HotKey1[8] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD4;
197 HotKey1[9] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD5;
198 HotKey1[10] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD6;
199 HotKey1[11] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD1;
200 HotKey1[12] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD2;
201 HotKey1[13] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD3;
202 HotKey1[14] = KEY_SHIFTED + KEY_CTRLED + KEY_PADENTER;
203 HotKey1[15] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD0;
204 HotKey1[16] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPERIOD;
211 void ui_pad_deactivate()
215 for (i=0; i<17; i++ )
221 static void ui_pad_set_active( int n )
229 gr_set_current_canvas( NULL );
230 gr_setcolor( CWHITE );
231 gr_urect( desc_x, desc_y, desc_x+ 56*4-1, desc_y+15 );
232 gr_set_fontcolor( CBLACK, CWHITE );
233 gr_ustring( desc_x, desc_y, KeyPad[n]->description );
235 for (i=0; i<17; i++ )
237 Pad[i]->text = KeyPad[n]->buttontext[i];
239 Pad[i]->user_function = NULL;
240 Pad[i]->dim_if_no_function = 1;
243 for (j=0; j< KeyPad[n]->numkeys; j++ )
245 if (HotKey[i] == KeyPad[n]->keycode[j] )
247 Pad[i]->hotkey = HotKey[i];
248 Pad[i]->user_function = func_nget( KeyPad[n]->function_number[j], &np, &name );
250 if (HotKey1[i] == KeyPad[n]->keycode[j] )
252 Pad[i]->hotkey1 = HotKey1[i];
253 Pad[i]->user_function1 = func_nget( KeyPad[n]->function_number[j], &np, &name );
261 void ui_pad_goto(int n)
263 if ( KeyPad[n] != NULL )
264 ui_pad_set_active(n);
267 void ui_pad_goto_next()
274 while( KeyPad[i]==NULL )
277 if (i >= MAX_NUM_PADS)
282 ui_pad_set_active(i);
285 void ui_pad_goto_prev()
289 if (active_pad == -1 )
290 active_pad = MAX_NUM_PADS;
293 if (i<0) i= MAX_NUM_PADS - 1;
296 while( KeyPad[i]==NULL )
301 if (i == active_pad )
304 ui_pad_set_active(i);
307 void ui_pad_read( int n, char * filename )
312 char line_buffer[200];
316 int keycode, functionnumber;
318 infile = cfopen( 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 cfgets( buffer, 100, infile );
342 switch( linenumber+1 )
345 strncpy( KeyPad[n]->description, buffer, 100 );
347 //===================== ROW 0 ==============================
349 LineParse( 1, text, buffer );
350 sprintf( KeyPad[n]->buttontext[0], "%s\n", text );
351 LineParse( 2, text, buffer );
352 sprintf( KeyPad[n]->buttontext[1], "%s\n", text );
353 LineParse( 3, text, buffer );
354 sprintf( KeyPad[n]->buttontext[2], "%s\n", text );
355 LineParse( 4, text, buffer );
356 sprintf( KeyPad[n]->buttontext[3], "%s\n", text );
359 LineParse( 1, text, buffer );
360 sprintf( KeyPad[n]->buttontext[0], "%s%s\n", KeyPad[n]->buttontext[0],text );
361 LineParse( 2, text, buffer );
362 sprintf( KeyPad[n]->buttontext[1], "%s%s\n", KeyPad[n]->buttontext[1],text );
363 LineParse( 3, text, buffer );
364 sprintf( KeyPad[n]->buttontext[2], "%s%s\n", KeyPad[n]->buttontext[2],text );
365 LineParse( 4, text, buffer );
366 sprintf( KeyPad[n]->buttontext[3], "%s%s\n", KeyPad[n]->buttontext[3],text );
369 LineParse( 1, text, buffer );
370 sprintf( KeyPad[n]->buttontext[0], "%s%s", KeyPad[n]->buttontext[0],text );
371 LineParse( 2, text, buffer );
372 sprintf( KeyPad[n]->buttontext[1], "%s%s", KeyPad[n]->buttontext[1],text );
373 LineParse( 3, text, buffer );
374 sprintf( KeyPad[n]->buttontext[2], "%s%s", KeyPad[n]->buttontext[2],text );
375 LineParse( 4, text, buffer );
376 sprintf( KeyPad[n]->buttontext[3], "%s%s", KeyPad[n]->buttontext[3],text );
378 //===================== ROW 1 ==============================
380 LineParse( 1, text, buffer );
381 sprintf( KeyPad[n]->buttontext[4], "%s\n", text );
382 LineParse( 2, text, buffer );
383 sprintf( KeyPad[n]->buttontext[5], "%s\n", text );
384 LineParse( 3, text, buffer);
385 sprintf( KeyPad[n]->buttontext[6], "%s\n", text );
386 LineParse( 4, text, buffer );
387 sprintf( KeyPad[n]->buttontext[7], "%s\n", text );
390 LineParse( 1, text, buffer );
391 sprintf( KeyPad[n]->buttontext[4], "%s%s\n", KeyPad[n]->buttontext[4],text );
392 LineParse( 2, text, buffer );
393 sprintf( KeyPad[n]->buttontext[5], "%s%s\n", KeyPad[n]->buttontext[5],text );
394 LineParse( 3, text, buffer );
395 sprintf( KeyPad[n]->buttontext[6], "%s%s\n", KeyPad[n]->buttontext[6],text );
396 LineParse( 4, text, buffer );
397 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
400 LineParse( 1, text, buffer );
401 sprintf( KeyPad[n]->buttontext[4], "%s%s", KeyPad[n]->buttontext[4],text );
402 LineParse( 2, text, buffer );
403 sprintf( KeyPad[n]->buttontext[5], "%s%s", KeyPad[n]->buttontext[5],text );
404 LineParse( 3, text, buffer );
405 sprintf( KeyPad[n]->buttontext[6], "%s%s", KeyPad[n]->buttontext[6],text );
406 LineParse( 4, text, buffer );
407 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
410 ptr = strrchr( buffer, (char) 179 );
412 ptr = strrchr( buffer, (char) 180 ); ptr++;
413 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],ptr );
415 //======================= ROW 2 ==============================
417 LineParse( 1, text, buffer );
418 sprintf( KeyPad[n]->buttontext[8], "%s\n", text );
419 LineParse( 2, text, buffer );
420 sprintf( KeyPad[n]->buttontext[9], "%s\n", text );
421 LineParse( 3, text, buffer);
422 sprintf( KeyPad[n]->buttontext[10], "%s\n", text );
423 LineParse( 4, text, buffer );
424 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
427 LineParse( 1, text, buffer );
428 sprintf( KeyPad[n]->buttontext[8], "%s%s\n", KeyPad[n]->buttontext[8],text );
429 LineParse( 2, text, buffer );
430 sprintf( KeyPad[n]->buttontext[9], "%s%s\n", KeyPad[n]->buttontext[9],text );
431 LineParse( 3, text, buffer );
432 sprintf( KeyPad[n]->buttontext[10], "%s%s\n", KeyPad[n]->buttontext[10],text );
433 LineParse( 4, text, buffer );
434 sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
437 LineParse( 1, text, buffer );
438 sprintf( KeyPad[n]->buttontext[8], "%s%s", KeyPad[n]->buttontext[8],text );
439 LineParse( 2, text, buffer );
440 sprintf( KeyPad[n]->buttontext[9], "%s%s", KeyPad[n]->buttontext[9],text );
441 LineParse( 3, text, buffer );
442 sprintf( KeyPad[n]->buttontext[10], "%s%s", KeyPad[n]->buttontext[10],text );
443 LineParse( 4, text, buffer );
444 sprintf( KeyPad[n]->buttontext[7], "%s%s", KeyPad[n]->buttontext[7],text );
446 // ====================== ROW 3 =========================
448 LineParse( 1, text, buffer );
449 sprintf( KeyPad[n]->buttontext[11], "%s\n", text );
450 LineParse( 2, text, buffer );
451 sprintf( KeyPad[n]->buttontext[12], "%s\n", text );
452 LineParse( 3, text, buffer);
453 sprintf( KeyPad[n]->buttontext[13], "%s\n", text );
454 LineParse( 4, text, buffer );
455 sprintf( KeyPad[n]->buttontext[14], "%s\n", text );
458 LineParse( 1, text, buffer );
459 sprintf( KeyPad[n]->buttontext[11], "%s%s\n", KeyPad[n]->buttontext[11],text );
460 LineParse( 2, text, buffer );
461 sprintf( KeyPad[n]->buttontext[12], "%s%s\n", KeyPad[n]->buttontext[12],text );
462 LineParse( 3, text, buffer );
463 sprintf( KeyPad[n]->buttontext[13], "%s%s\n", KeyPad[n]->buttontext[13],text );
464 LineParse( 4, text, buffer );
465 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
468 LineParse( 1, text, buffer );
469 sprintf( KeyPad[n]->buttontext[11], "%s%s", KeyPad[n]->buttontext[11],text );
470 LineParse( 2, text, buffer );
471 sprintf( KeyPad[n]->buttontext[12], "%s%s", KeyPad[n]->buttontext[12],text );
472 LineParse( 3, text, buffer );
473 sprintf( KeyPad[n]->buttontext[13], "%s%s", KeyPad[n]->buttontext[13],text );
474 LineParse( 4, text, buffer );
475 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
478 ptr = strrchr( buffer, (char) 179 );
480 ptr = strrchr( buffer, (char) 180 ); ptr++;
481 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14], ptr );
483 //======================= ROW 4 =========================
485 LineParse( 1, text, buffer );
486 sprintf( KeyPad[n]->buttontext[15], "%s\n", text );
487 LineParse( 2, text, buffer );
488 sprintf( KeyPad[n]->buttontext[16], "%s\n", text );
489 LineParse( 3, text, buffer );
490 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
493 LineParse( 1, text, buffer );
494 sprintf( KeyPad[n]->buttontext[15], "%s%s\n", KeyPad[n]->buttontext[15],text );
495 LineParse( 2, text, buffer );
496 sprintf( KeyPad[n]->buttontext[16], "%s%s\n", KeyPad[n]->buttontext[16],text );
497 LineParse( 3, text, buffer );
498 sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
501 LineParse( 1, text, buffer );
502 sprintf( KeyPad[n]->buttontext[15], "%s%s", KeyPad[n]->buttontext[15],text );
503 LineParse( 2, text, buffer );
504 sprintf( KeyPad[n]->buttontext[16], "%s%s", KeyPad[n]->buttontext[16],text );
505 LineParse( 3, text, buffer );
506 sprintf( KeyPad[n]->buttontext[14], "%s%s", KeyPad[n]->buttontext[14],text );
513 // Get the keycodes...
515 while (cfgets(line_buffer, 200, infile))
517 sscanf(line_buffer, " %s %s ", text, buffer);
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++;