1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "ui/uidefs.h"
#include "ui/ui.h"
#include "globalincs/alphacolors.h"
void UI_RADIO::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group )
{
int _w, _h;
_w = 18;
_h = 18;
if (_text)
text = vm_strdup(_text);
else
text = NULL;
base_create( wnd, UI_KIND_RADIO, _x, _y, _w, _h );
position = 0;
pressed_down = 0;
flag = _state;
group = _group;
}
void UI_RADIO::destroy()
{
if (text)
vm_free(text);
UI_GADGET::destroy();
}
void UI_RADIO::draw()
{
int offset;
if ( uses_bmaps ) {
if ( disabled_flag ) {
if ( flag ) {
if ( bmap_ids[RADIO_DISABLED_MARKED] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_DISABLED_MARKED]);
gr_bitmap(x,y);
}
}
else {
if ( bmap_ids[RADIO_DISABLED_CLEAR] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_DISABLED_CLEAR]);
gr_bitmap(x,y);
}
}
}
else { // not disabled
if ( position == 0 ) { // up
if ( flag ) { // marked
if ( bmap_ids[RADIO_UP_MARKED] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_UP_MARKED]);
gr_bitmap(x,y);
}
}
else { // not marked
if ( bmap_ids[RADIO_UP_CLEAR] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_UP_CLEAR]);
gr_bitmap(x,y);
}
}
}
else { // down
if ( flag ) { // marked
if ( bmap_ids[RADIO_DOWN_MARKED] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_DOWN_MARKED]);
gr_bitmap(x,y);
}
}
else { // not marked
if ( bmap_ids[RADIO_DOWN_CLEAR] != -1 ) {
gr_set_bitmap(bmap_ids[RADIO_DOWN_CLEAR]);
gr_bitmap(x,y);
}
}
}
}
}
else {
gr_set_font(my_wnd->f_id);
gr_set_clip( x, y, w, h );
if (position == 0 ) {
ui_draw_box_out( 0, 0, w-1, h-1 );
offset = 0;
} else {
ui_draw_box_in( 0, 0, w-1, h-1 );
offset = 1;
}
if (disabled_flag)
gr_set_color_fast(&CDARK_GRAY);
else if (my_wnd->selected_gadget == this)
gr_set_color_fast(&CBRIGHT_GREEN);
else
gr_set_color_fast(&CGREEN);
if (flag) {
gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
} else {
gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
gr_set_color_fast( &CWHITE );
gr_circle( Middle(w)+offset, Middle(h)+offset, 4 );
}
if (disabled_flag)
gr_set_color_fast(&CDARK_GRAY);
else if (my_wnd->selected_gadget == this)
gr_set_color_fast(&CBRIGHT_GREEN);
else
gr_set_color_fast(&CGREEN);
if ( text ) {
gr_reset_clip();
gr_string( x+w+4, y+2, text );
}
}
}
void UI_RADIO::process(int focus)
{
int OnMe, oldposition;
if (disabled_flag) {
position = 0;
return;
}
if (my_wnd->selected_gadget == this)
focus = 1;
OnMe = is_mouse_on();
oldposition = position;
if (B1_PRESSED && OnMe) {
position = 1;
} else {
position = 0;
}
if (my_wnd->keypress == hotkey) {
position = 2;
my_wnd->last_keypress = 0;
}
if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
position = 2;
if (focus)
if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
position = 2;
pressed_down = 0;
if (position) {
if ( (oldposition == 1) && OnMe )
pressed_down = 1;
if ( (oldposition == 2) && focus )
pressed_down = 1;
}
if (pressed_down && user_function) {
user_function();
}
if (pressed_down && (flag == 0)) {
UI_GADGET *tmp = (UI_GADGET *) next;
UI_RADIO *tmpr;
while (tmp != this) {
if (tmp->kind == UI_KIND_RADIO) {
tmpr = (UI_RADIO *) tmp;
if ((tmpr->group == group) && tmpr->flag) {
tmpr->flag = 0;
tmpr->pressed_down = 0;
}
}
tmp = tmp->next;
}
flag = 1;
}
}
int UI_RADIO::changed()
{
return pressed_down;
}
int UI_RADIO::checked()
{
return flag;
}
|