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: button.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 #define BUTTON_EXTRA_WIDTH 15
32 #define BUTTON_EXTRA_HEIGHT 2
34 int ui_button_any_drawn = 0;
36 void ui_get_button_size( char * text, int * width, int * height )
40 gr_get_string_size(text, width, height, &avg );
42 *width += BUTTON_EXTRA_WIDTH*2;
45 *height += BUTTON_EXTRA_HEIGHT*2;
51 void ui_draw_button( UI_GADGET_BUTTON * button )
55 if ((button->status==1) || (button->position != button->oldposition))
57 ui_button_any_drawn = 1;
59 gr_set_current_canvas( button->canvas );
60 color = button->canvas->cv_color;
62 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)button)
63 gr_set_fontcolor( CRED, -1 );
66 if ((button->user_function==NULL) && button->dim_if_no_function )
67 gr_set_fontcolor( CGREY, -1 );
69 gr_set_fontcolor( CBLACK, -1 );
73 if (button->position == 0 )
76 ui_draw_box_out( 0, 0, button->width-1, button->height-1 );
77 ui_string_centered( Middle(button->width), Middle(button->height), button->text );
79 gr_setcolor( CBLACK );
80 gr_rect( 0, 0, button->width, button->height );
82 gr_rect( 1, 1, button->width-1, button->height-1 );
86 ui_draw_box_in( 0, 0, button->width-1, button->height-1 );
87 ui_string_centered( Middle(button->width)+1, Middle(button->height)+1, button->text );
89 gr_setcolor( CBLACK );
90 gr_rect( 0, 0, button->width, button->height );
92 gr_rect( 2, 2, button->width, button->height );
95 button->canvas->cv_color = color;
101 UI_GADGET_BUTTON * ui_add_gadget_button( UI_WINDOW * wnd, short x, short y, short w, short h, char * text, int (*function_to_call)(void) )
103 UI_GADGET_BUTTON * button;
105 button = (UI_GADGET_BUTTON *)ui_gadget_add( wnd, 1, x, y, x+w-1, y+h-1 );
109 MALLOC( button->text, char, strlen(text)+1 );
110 strcpy( button->text, text );
116 button->position = 0;
117 button->oldposition = 0;
119 button->user_function = function_to_call;
120 button->user_function1 = NULL;
122 button->dim_if_no_function = 0;
129 void ui_button_do( UI_GADGET_BUTTON * button, int keypress )
132 int OnMe, ButtonLastSelected;
134 OnMe = ui_mouse_on_gadget( (UI_GADGET *)button );
136 button->oldposition = button->position;
138 if (selected_gadget != NULL)
140 if (selected_gadget->kind==1)
141 ButtonLastSelected = 1;
143 ButtonLastSelected = 0;
145 ButtonLastSelected = 1;
148 if ( B1_PRESSED && OnMe && ButtonLastSelected )
151 button->position = 1;
153 button->position = 0;
156 if (keypress == button->hotkey )
158 button->position = 2;
162 if ((keypress == button->hotkey1) && button->user_function1 )
164 result = button->user_function1();
169 //if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
170 // button->position = 2;
172 if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && ((keypress==KEY_SPACEBAR) || (keypress==KEY_ENTER)) )
173 button->position = 2;
175 if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)button)
176 if ((button->oldposition==2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
177 button->position = 2;
181 if (button->position==0) {
182 if ( (button->oldposition==1) && OnMe )
184 if ( (button->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) )
188 ui_draw_button( button );
190 if (button->pressed && button->user_function )
192 result = button->user_function();