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.
14 #pragma off (unreferenced)
15 static char rcsid[] = "$Id: checkbox.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
16 #pragma on (unreferenced)
29 #define Middle(x) ((2*(x)+1)/4)
31 void ui_draw_checkbox( UI_GADGET_CHECKBOX * checkbox )
34 if ((checkbox->status==1) || (checkbox->position != checkbox->oldposition))
39 gr_set_current_canvas( checkbox->canvas );
41 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)checkbox)
42 gr_set_fontcolor( CRED, -1 );
44 gr_set_fontcolor( CBLACK, -1 );
46 if (checkbox->position == 0 )
48 ui_draw_box_out( 0, 0, checkbox->width-1, checkbox->height-1 );
50 ui_string_centered( Middle(checkbox->width), Middle(checkbox->height), "X" );
52 ui_string_centered( Middle(checkbox->width), Middle(checkbox->height), " " );
54 ui_draw_box_in( 0, 0, checkbox->width-1, checkbox->height-1 );
56 ui_string_centered( Middle(checkbox->width)+1, Middle(checkbox->height)+1, "X" );
58 ui_string_centered( Middle(checkbox->width)+1, Middle(checkbox->height)+1, " " );
61 gr_ustring( checkbox->width+4, 2, checkbox->text );
68 UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
70 UI_GADGET_CHECKBOX * checkbox;
72 checkbox = (UI_GADGET_CHECKBOX *)ui_gadget_add( wnd, 5, x, y, x+w-1, y+h-1 );
74 checkbox->text = malloc(strlen(text)+5);
75 strcpy(checkbox->text,text);
78 checkbox->position = 0;
79 checkbox->oldposition = 0;
80 checkbox->pressed = 0;
82 checkbox->group = group;
89 void ui_checkbox_do( UI_GADGET_CHECKBOX * checkbox, int keypress )
91 int OnMe, ButtonLastSelected;
95 OnMe = ui_mouse_on_gadget( (UI_GADGET *)checkbox );
97 checkbox->oldposition = checkbox->position;
99 if ((selected_gadget != NULL) && (selected_gadget->kind !=5))
100 ButtonLastSelected = 0;
102 ButtonLastSelected = 1;
104 if ( B1_PRESSED && OnMe && ButtonLastSelected )
106 checkbox->position = 1;
108 checkbox->position = 0;
112 if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
113 checkbox->position = 2;
115 if ((checkbox->position==0) && (checkbox->oldposition==1) && OnMe )
116 checkbox->pressed = 1;
117 else if ((checkbox->position==0) && (checkbox->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) )
118 checkbox->pressed = 1;
120 checkbox->pressed = 0;
122 if (checkbox->pressed == 1)
125 ui_draw_checkbox( checkbox );