]> icculus.org git repositories - btb/d2x.git/blob - unused/ui/checkbox.c
comments/formatting
[btb/d2x.git] / unused / ui / checkbox.c
1 /*
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.
12 */
13
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)
17
18
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "mem.h"
23 #include "fix.h"
24 #include "types.h"
25 #include "gr.h"
26 #include "ui.h"
27 #include "key.h"
28
29 #define Middle(x) ((2*(x)+1)/4)
30
31 void ui_draw_checkbox( UI_GADGET_CHECKBOX * checkbox )
32 {
33
34         if ((checkbox->status==1) || (checkbox->position != checkbox->oldposition))
35         {
36                 checkbox->status = 0;
37
38                 ui_mouse_hide();
39                 gr_set_current_canvas( checkbox->canvas );
40
41                 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)checkbox)
42                         gr_set_fontcolor( CRED, -1 );
43                 else
44                         gr_set_fontcolor( CBLACK, -1 );
45
46                 if (checkbox->position == 0 )
47                 {
48                         ui_draw_box_out( 0, 0, checkbox->width-1, checkbox->height-1 );
49                         if (checkbox->flag)
50                                 ui_string_centered(  Middle(checkbox->width), Middle(checkbox->height), "X" );
51                         else
52                                 ui_string_centered(  Middle(checkbox->width), Middle(checkbox->height), " " );
53                 } else {
54                         ui_draw_box_in( 0, 0, checkbox->width-1, checkbox->height-1 );
55                         if (checkbox->flag)
56                                 ui_string_centered(  Middle(checkbox->width)+1, Middle(checkbox->height)+1, "X" );
57                         else
58                                 ui_string_centered(  Middle(checkbox->width)+1, Middle(checkbox->height)+1, " " );
59                 }
60
61                 gr_ustring( checkbox->width+4, 2, checkbox->text );
62
63                 ui_mouse_show();
64         }
65 }
66
67
68 UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
69 {
70         UI_GADGET_CHECKBOX * checkbox;
71
72         checkbox = (UI_GADGET_CHECKBOX *)ui_gadget_add( wnd, 5, x, y, x+w-1, y+h-1 );
73
74         checkbox->text = malloc(strlen(text)+5);
75         strcpy(checkbox->text,text);
76         checkbox->width = w;
77         checkbox->height = h;
78         checkbox->position = 0;
79         checkbox->oldposition = 0;
80         checkbox->pressed = 0;
81         checkbox->flag = 0;
82         checkbox->group = group;
83
84         return checkbox;
85
86 }
87
88
89 void ui_checkbox_do( UI_GADGET_CHECKBOX * checkbox, int keypress )
90 {
91         int OnMe, ButtonLastSelected;
92
93         keypress = keypress;
94
95         OnMe = ui_mouse_on_gadget( (UI_GADGET *)checkbox );
96
97         checkbox->oldposition = checkbox->position;
98
99         if ((selected_gadget != NULL) && (selected_gadget->kind !=5))
100                 ButtonLastSelected = 0;
101         else
102                 ButtonLastSelected = 1;
103
104         if ( B1_PRESSED && OnMe && ButtonLastSelected )
105         {
106                 checkbox->position = 1;
107         } else  {
108                 checkbox->position = 0;
109         }
110
111
112         if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
113                 checkbox->position = 2;
114
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;
119         else
120                 checkbox->pressed = 0;
121
122         if (checkbox->pressed == 1)
123                 checkbox->flag ^= 1;
124
125         ui_draw_checkbox( checkbox );
126
127 }