2 #include "bcresources.h"
8 BC_Toggle::BC_Toggle(int x, int y,
15 : BC_SubWindow(x, y, 0, 0, -1)
18 images[0] = images[1] = images[2] = images[3] = images[4] = 0;
19 status = value ? TOGGLE_CHECKED : TOGGLE_UP;
21 this->caption = caption;
22 this->bottom_justify = bottom_justify;
29 BC_Toggle::~BC_Toggle()
39 int BC_Toggle::initialize()
43 w = images[0]->get_w();
44 h = images[0]->get_h();
50 // Expand subwindow for text
53 text_w = get_text_width(MEDIUMFONT, caption);
54 text_h = get_text_height(MEDIUMFONT);
57 toggle_y = (text_h - h) >> 1;
61 text_y = (h - text_h) >> 1;
66 text_line = h - get_text_descent(MEDIUMFONT);
69 text_line = text_y + get_text_ascent(MEDIUMFONT);
74 // Create the subwindow
75 BC_SubWindow::initialize();
82 int BC_Toggle::set_images(VFrame **data)
93 images[0] = new BC_Pixmap(top_level, data[0], PIXMAP_ALPHA);
94 images[1] = new BC_Pixmap(top_level, data[1], PIXMAP_ALPHA);
95 images[2] = new BC_Pixmap(top_level, data[2], PIXMAP_ALPHA);
96 images[3] = new BC_Pixmap(top_level, data[3], PIXMAP_ALPHA);
97 images[4] = new BC_Pixmap(top_level, data[4], PIXMAP_ALPHA);
101 void BC_Toggle::set_select_drag(int value)
103 this->select_drag = value;
106 int BC_Toggle::draw_face()
108 draw_top_background(parent_window, 0, 0, get_w(), get_h());
111 if(status == TOGGLE_UPHI || status == TOGGLE_DOWN || status == TOGGLE_CHECKEDHI)
114 draw_box(text_x, text_line - get_text_ascent(MEDIUMFONT), get_w() - text_x, get_text_height(MEDIUMFONT));
118 set_color(get_resources()->text_default);
121 draw_text(text_x, text_line, caption);
124 draw_pixmap(images[status]);
130 int BC_Toggle::repeat_event(int64_t duration)
132 if(duration == top_level->get_resources()->tooltip_delay &&
133 tooltip_text[0] != 0 &&
134 (status == TOGGLE_UPHI || status == TOGGLE_CHECKEDHI) &&
144 int BC_Toggle::cursor_enter_event()
146 if(top_level->event_win == win)
149 if(top_level->button_down)
150 status = TOGGLE_DOWN;
152 status = value ? TOGGLE_CHECKEDHI : TOGGLE_UPHI;
158 int BC_Toggle::cursor_leave_event()
168 status = TOGGLE_CHECKED;
174 int BC_Toggle::button_press_event()
177 if(top_level->event_win == win && get_buttonpress() == 1)
179 status = TOGGLE_DOWN;
180 top_level->toggle_value = !this->value;
187 int BC_Toggle::button_release_event()
190 if(top_level->event_win == win && status == TOGGLE_DOWN)
194 status = TOGGLE_CHECKEDHI;
199 status = TOGGLE_UPHI;
204 return handle_event();
209 int BC_Toggle::cursor_motion_event()
211 if(select_drag) return 0;
212 if(top_level->button_down && top_level->event_win == win && !cursor_inside())
214 if(status == TOGGLE_DOWN)
220 if(status == TOGGLE_UPHI)
222 status = TOGGLE_CHECKEDHI;
229 int BC_Toggle::get_value()
234 int BC_Toggle::set_value(int value, int draw)
236 if(value != this->value)
244 status = TOGGLE_CHECKED;
247 status = TOGGLE_CHECKEDHI;
257 case TOGGLE_CHECKEDHI:
258 status = TOGGLE_UPHI;
261 if(draw) draw_face();
266 int BC_Toggle::update(int value, int draw)
268 return set_value(value, draw);
271 void BC_Toggle::reposition_window(int x, int y)
273 BC_WindowBase::reposition_window(x, y);
278 int BC_Toggle::has_caption()
280 return (caption != 0 && caption[0] != 0);
283 BC_Radial::BC_Radial(int x,
291 BC_WindowBase::get_resources()->radial_images,
300 BC_CheckBox::BC_CheckBox(int x,
308 BC_WindowBase::get_resources()->checkbox_images,
318 BC_CheckBox::BC_CheckBox(int x,
326 BC_WindowBase::get_resources()->checkbox_images,
336 int BC_CheckBox::handle_event()
338 *value = get_value();
345 BC_Label::BC_Label(int x,
352 BC_WindowBase::get_resources()->label_images,