2 #include "bcresources.h"
13 BC_Toggle::BC_Toggle(int x, int y,
20 : BC_SubWindow(x, y, 0, 0, -1)
23 for(int i = 0; i < 5; i++)
26 status = value ? BC_Toggle::TOGGLE_CHECKED : BC_Toggle::TOGGLE_UP;
28 strcpy(this->caption, caption);
29 this->bottom_justify = bottom_justify;
34 this->color = get_resources()->default_text_color;
42 BC_Toggle::~BC_Toggle()
44 for(int i = 0; i < 5; i++) if(images[i]) delete images[i];
49 int BC_Toggle::initialize()
53 calculate_extents(this,
65 has_caption() ? caption : 0);
67 // Create the subwindow
68 BC_SubWindow::initialize();
69 set_cursor(UPRIGHT_ARROW_CURSOR);
76 void BC_Toggle::calculate_extents(BC_WindowBase *gui,
90 BC_Resources *resources = get_resources();
91 VFrame *frame = images[0];
103 *text_w = gui->get_text_width(MEDIUMFONT, caption);
104 *text_h = gui->get_text_height(MEDIUMFONT);
106 if(resources->toggle_highlight_bg)
108 *text_w += resources->toggle_text_margin * 2;
109 *text_h = MAX(*text_h, resources->toggle_highlight_bg->get_h());
114 *toggle_y = (*text_h - *h) >> 1;
118 *text_y = (*h - *text_h) >> 1;
122 *text_y = *h - *text_h;
123 *text_line = *h - gui->get_text_descent(MEDIUMFONT);
126 *text_line = *text_y + gui->get_text_ascent(MEDIUMFONT);
128 *w = *text_x + *text_w;
135 int BC_Toggle::set_images(VFrame **data)
139 for(int i = 0; i < 5; i++)
141 if(images[i]) delete images[i];
142 images[i] = new BC_Pixmap(top_level, data[i], PIXMAP_ALPHA);
144 BC_Resources *resources = get_resources();
145 if(resources->toggle_highlight_bg)
147 bg_image = new BC_Pixmap(top_level,
148 resources->toggle_highlight_bg,
154 void BC_Toggle::set_underline(int number)
156 this->underline = number;
160 void BC_Toggle::set_select_drag(int value)
162 this->select_drag = value;
165 int BC_Toggle::draw_face()
167 BC_Resources *resources = get_resources();
168 draw_top_background(parent_window, 0, 0, get_w(), get_h());
172 (status == BC_Toggle::TOGGLE_UPHI ||
173 status == BC_Toggle::TOGGLE_DOWN ||
174 status == BC_Toggle::TOGGLE_CHECKEDHI))
176 // Draw highlight image
180 int y = text_line - get_text_ascent(MEDIUMFONT) / 2 -
181 bg_image->get_h() / 2;
193 text_line - get_text_ascent(MEDIUMFONT),
195 get_text_height(MEDIUMFONT));
205 draw_text(text_x + resources->toggle_text_margin,
212 int x = text_x + resources->toggle_text_margin;
213 int y = text_line + 1;
214 int x1 = get_text_width(current_font, caption, underline) + x;
215 int x2 = get_text_width(current_font, caption, underline + 1) + x;
216 draw_line(x1, y, x2, y);
217 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
221 draw_pixmap(images[status]);
226 void BC_Toggle::enable()
229 if(parent_window) draw_face();
232 void BC_Toggle::disable()
235 if(parent_window) draw_face();
238 void BC_Toggle::set_status(int value)
240 this->status = value;
244 int BC_Toggle::repeat_event(int64_t duration)
246 if(duration == top_level->get_resources()->tooltip_delay &&
247 tooltip_text[0] != 0 &&
248 (status == BC_Toggle::TOGGLE_UPHI || status == BC_Toggle::TOGGLE_CHECKEDHI) &&
258 int BC_Toggle::cursor_enter_event()
260 if(top_level->event_win == win && enabled)
263 if(top_level->button_down)
264 status = BC_Toggle::TOGGLE_DOWN;
266 status = value ? BC_Toggle::TOGGLE_CHECKEDHI : BC_Toggle::TOGGLE_UPHI;
272 int BC_Toggle::cursor_leave_event()
275 if(!value && status == BC_Toggle::TOGGLE_UPHI)
277 status = BC_Toggle::TOGGLE_UP;
281 if(status == BC_Toggle::TOGGLE_CHECKEDHI)
283 status = BC_Toggle::TOGGLE_CHECKED;
289 int BC_Toggle::button_press_event()
292 if(top_level->event_win == win && get_buttonpress() == 1 && enabled)
294 status = BC_Toggle::TOGGLE_DOWN;
296 // Change value now for select drag mode.
297 // Radial always goes to 1
304 top_level->toggle_drag = 1;
305 top_level->toggle_value = value;
315 int BC_Toggle::button_release_event()
320 if(top_level->event_win == win)
322 // Keep value regardless of status if drag mode.
326 status = BC_Toggle::TOGGLE_CHECKEDHI;
328 status = BC_Toggle::TOGGLE_UPHI;
329 top_level->toggle_drag = 0;
332 // Change value only if button down for default mode.
333 if(status == BC_Toggle::TOGGLE_DOWN)
335 // Radial always goes to 1.
336 if(!value || is_radial)
338 status = BC_Toggle::TOGGLE_CHECKEDHI;
343 status = BC_Toggle::TOGGLE_UPHI;
346 result = handle_event();
354 int BC_Toggle::cursor_motion_event()
356 if(top_level->button_down &&
357 top_level->event_win == win &&
360 if(status == BC_Toggle::TOGGLE_DOWN)
363 status = BC_Toggle::TOGGLE_CHECKED;
365 status = BC_Toggle::TOGGLE_UP;
369 if(status == BC_Toggle::TOGGLE_UPHI)
371 status = BC_Toggle::TOGGLE_CHECKEDHI;
378 int BC_Toggle::get_value()
383 int BC_Toggle::set_value(int value, int draw)
385 if(value != this->value)
392 case BC_Toggle::TOGGLE_UP:
393 status = BC_Toggle::TOGGLE_CHECKED;
395 case BC_Toggle::TOGGLE_UPHI:
396 status = BC_Toggle::TOGGLE_CHECKEDHI;
403 case BC_Toggle::TOGGLE_CHECKED:
404 status = BC_Toggle::TOGGLE_UP;
406 case BC_Toggle::TOGGLE_CHECKEDHI:
407 status = BC_Toggle::TOGGLE_UPHI;
410 if(draw) draw_face();
415 int BC_Toggle::update(int value, int draw)
417 return set_value(value, draw);
420 void BC_Toggle::reposition_window(int x, int y)
422 BC_WindowBase::reposition_window(x, y);
427 int BC_Toggle::has_caption()
429 return (caption != 0 && caption[0] != 0);
432 BC_Radial::BC_Radial(int x,
440 BC_WindowBase::get_resources()->radial_images,
450 BC_CheckBox::BC_CheckBox(int x,
458 BC_WindowBase::get_resources()->checkbox_images,
468 BC_CheckBox::BC_CheckBox(int x,
476 BC_WindowBase::get_resources()->checkbox_images,
486 int BC_CheckBox::handle_event()
488 *value = get_value();
494 BC_Label::BC_Label(int x,
501 BC_WindowBase::get_resources()->label_images,