3 #include "bcresources.h"
17 #define BUTTON_DOWNHI 2
19 BC_Button::BC_Button(int x,
22 : BC_SubWindow(x, y, 0, 0, -1)
25 for(int i = 0; i < 3; i++) images[i] = 0;
26 if(!data) printf("BC_Button::BC_Button data == 0\n");
29 underline_number = -1;
33 BC_Button::BC_Button(int x,
37 : BC_SubWindow(x, y, 0, 0, -1)
41 for(int i = 0; i < 3; i++) images[i] = 0;
42 if(!data) printf("BC_Button::BC_Button data == 0\n");
44 underline_number = -1;
49 BC_Button::~BC_Button()
51 for(int i = 0; i < 3; i++) if(images[i]) delete images[i];
56 int BC_Button::initialize()
61 // Create the subwindow
62 BC_SubWindow::initialize();
69 int BC_Button::reposition_window(int x, int y, int w, int h)
71 BC_WindowBase::reposition_window(x, y, w, h);
77 int BC_Button::update_bitmaps(VFrame **data)
81 draw_top_background(parent_window, 0, 0, w, h);
86 void BC_Button::enable()
92 void BC_Button::disable()
99 void BC_Button::set_underline(int number)
101 this->underline_number = number;
104 int BC_Button::set_images(VFrame **data)
106 for(int i = 0; i < 3; i++)
108 if(images[i]) delete images[i];
109 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
115 w = images[BUTTON_UP]->get_w();
117 h = images[BUTTON_UP]->get_h();
121 int BC_Button::draw_face()
123 draw_top_background(parent_window, 0, 0, w, h);
124 pixmap->draw_pixmap(images[status],
135 int BC_Button::repeat_event(int64_t duration)
137 if(duration == top_level->get_resources()->tooltip_delay &&
138 tooltip_text[0] != 0 &&
139 status == BUTTON_UPHI &&
149 int BC_Button::cursor_enter_event()
151 if(top_level->event_win == win && enabled)
154 if(top_level->button_down)
156 status = BUTTON_DOWNHI;
159 if(status == BUTTON_UP) status = BUTTON_UPHI;
165 int BC_Button::cursor_leave_event()
167 if(status == BUTTON_UPHI)
179 int BC_Button::button_press_event()
181 if(top_level->event_win == win && get_buttonpress() == 1 && enabled)
184 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
191 int BC_Button::button_release_event()
193 if(top_level->event_win == win)
196 if(status == BUTTON_DOWNHI)
198 status = BUTTON_UPHI;
211 int BC_Button::cursor_motion_event()
213 if(top_level->button_down && top_level->event_win == win &&
214 status == BUTTON_DOWNHI && !cursor_inside())
232 BC_OKButton::BC_OKButton(int x, int y)
234 BC_WindowBase::get_resources()->ok_images)
238 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
240 parent_window->get_h() - images[0]->get_h() - 10,
246 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
248 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
249 BC_WindowBase::get_resources()->ok_images)
254 int BC_OKButton::handle_event()
256 get_top_level()->set_done(0);
260 int BC_OKButton::resize_event(int w, int h)
262 reposition_window(10,
263 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
267 int BC_OKButton::keypress_event()
269 if(get_keypress() == RETURN) return handle_event();
273 int BC_OKButton::calculate_h()
275 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
278 int BC_OKButton::calculate_w()
280 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
295 BC_CancelButton::BC_CancelButton(int x, int y)
297 BC_WindowBase::get_resources()->cancel_images)
299 set_tooltip("Cancel");
302 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
303 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
304 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
305 BC_WindowBase::get_resources()->cancel_images)
307 set_tooltip("Cancel");
310 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
311 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
312 parent_window->get_h() - images[0]->get_h() - 10,
315 set_tooltip("Cancel");
318 int BC_CancelButton::handle_event()
320 get_top_level()->set_done(1);
324 int BC_CancelButton::resize_event(int w,int h)
326 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
327 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
331 int BC_CancelButton::keypress_event()
333 if(get_keypress() == ESC) return handle_event();
337 int BC_CancelButton::calculate_h()
339 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
342 int BC_CancelButton::calculate_w()
344 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
366 BC_GenericButton::BC_GenericButton(int x, int y, char *text, VFrame **data)
369 data ? data : BC_WindowBase::get_resources()->generic_button_images)
371 strcpy(this->text, text);
374 BC_GenericButton::BC_GenericButton(int x, int y, int w, char *text, VFrame **data)
378 data ? data : BC_WindowBase::get_resources()->generic_button_images)
380 strcpy(this->text, text);
383 int BC_GenericButton::set_images(VFrame **data)
385 BC_Resources *resources = get_resources();
386 for(int i = 0; i < 3; i++)
388 if(images[i]) delete images[i];
389 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
395 w = get_text_width(MEDIUMFONT, text) +
396 resources->generic_button_margin * 2;
399 h = images[BUTTON_UP]->get_h();
403 int BC_GenericButton::calculate_w(BC_WindowBase *gui, char *text)
405 BC_Resources *resources = gui->get_resources();
406 return gui->get_text_width(MEDIUMFONT, text) +
407 resources->generic_button_margin * 2;
410 int BC_GenericButton::calculate_h()
412 BC_Resources *resources = BC_WindowBase::get_resources();
413 return resources->generic_button_images[0]->get_h();
416 int BC_GenericButton::draw_face()
418 draw_top_background(parent_window, 0, 0, get_w(), get_h());
419 draw_3segmenth(0, 0, get_w(), images[status]);
422 set_color(get_resources()->default_text_color);
424 set_color(get_resources()->disabled_text_color);
425 set_font(MEDIUMFONT);
428 BC_Resources *resources = get_resources();
429 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
430 w = get_text_width(current_font, text, strlen(text)) +
431 resources->generic_button_margin * 2;
432 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
433 if(status == BUTTON_DOWNHI)
442 if(underline_number >= 0)
445 int x1 = get_text_width(current_font, text, underline_number) +
447 resources->toggle_text_margin;
448 int x2 = get_text_width(current_font, text, underline_number + 1) +
450 resources->toggle_text_margin;
451 draw_line(x1, y, x2, y);
452 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
463 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
464 : BC_GenericButton(10,
465 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
468 this->parent_window = parent_window;
471 int BC_OKTextButton::resize_event(int w, int h)
473 reposition_window(10,
474 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
478 int BC_OKTextButton::handle_event()
480 get_top_level()->set_done(0);
484 int BC_OKTextButton::keypress_event()
486 if(get_keypress() == RETURN) return handle_event();
492 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
493 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
494 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
497 this->parent_window = parent_window;
500 int BC_CancelTextButton::resize_event(int w, int h)
502 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
503 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
507 int BC_CancelTextButton::handle_event()
509 get_top_level()->set_done(1);
513 int BC_CancelTextButton::keypress_event()
515 if(get_keypress() == ESC) return handle_event();
527 // c-file-style: "linux"