2 #include "bcresources.h"
16 #define BUTTON_DOWNHI 2
18 BC_Button::BC_Button(int x,
21 : BC_SubWindow(x, y, 0, 0, -1)
24 for(int i = 0; i < 3; i++) images[i] = 0;
25 if(!data) printf("BC_Button::BC_Button data == 0\n");
28 underline_number = -1;
32 BC_Button::BC_Button(int x,
36 : BC_SubWindow(x, y, 0, 0, -1)
40 for(int i = 0; i < 3; i++) images[i] = 0;
41 if(!data) printf("BC_Button::BC_Button data == 0\n");
43 underline_number = -1;
48 BC_Button::~BC_Button()
50 for(int i = 0; i < 3; i++) if(images[i]) delete images[i];
55 int BC_Button::initialize()
60 // Create the subwindow
61 BC_SubWindow::initialize();
68 int BC_Button::reposition_window(int x, int y)
70 BC_WindowBase::reposition_window(x, y);
76 int BC_Button::update_bitmaps(VFrame **data)
80 draw_top_background(parent_window, 0, 0, w, h);
85 void BC_Button::enable()
91 void BC_Button::disable()
98 void BC_Button::set_underline(int number)
100 this->underline_number = number;
103 int BC_Button::set_images(VFrame **data)
105 for(int i = 0; i < 3; i++)
107 if(images[i]) delete images[i];
108 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
114 w = images[BUTTON_UP]->get_w();
116 h = images[BUTTON_UP]->get_h();
120 int BC_Button::draw_face()
122 draw_top_background(parent_window, 0, 0, w, h);
123 images[status]->write_drawable(pixmap,
134 int BC_Button::repeat_event(int64_t duration)
136 if(duration == top_level->get_resources()->tooltip_delay &&
137 tooltip_text[0] != 0 &&
138 status == BUTTON_UPHI &&
148 int BC_Button::cursor_enter_event()
150 if(top_level->event_win == win && enabled)
153 if(top_level->button_down)
155 status = BUTTON_DOWNHI;
158 if(status == BUTTON_UP) status = BUTTON_UPHI;
164 int BC_Button::cursor_leave_event()
166 if(status == BUTTON_UPHI)
178 int BC_Button::button_press_event()
180 if(top_level->event_win == win && get_buttonpress() == 1 && enabled)
183 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
190 int BC_Button::button_release_event()
192 //printf("BC_Button::button_release_event 1\n");
193 if(top_level->event_win == win)
196 //printf("BC_Button::button_release_event 2\n");
197 if(status == BUTTON_DOWNHI)
199 //printf("BC_Button::button_release_event 3\n");
200 status = BUTTON_UPHI;
205 //printf("BC_Button::button_release_event 4\n");
214 int BC_Button::cursor_motion_event()
216 if(top_level->button_down && top_level->event_win == win &&
217 status == BUTTON_DOWNHI && !cursor_inside())
235 BC_OKButton::BC_OKButton(int x, int y)
237 BC_WindowBase::get_resources()->ok_images)
241 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
243 parent_window->get_h() - images[0]->get_h() - 10,
249 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
251 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
252 BC_WindowBase::get_resources()->ok_images)
257 int BC_OKButton::handle_event()
259 get_top_level()->set_done(0);
263 int BC_OKButton::resize_event(int w, int h)
265 reposition_window(10,
266 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
270 int BC_OKButton::keypress_event()
272 if(get_keypress() == RETURN) return handle_event();
276 int BC_OKButton::calculate_h()
278 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
281 int BC_OKButton::calculate_w()
283 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
298 BC_CancelButton::BC_CancelButton(int x, int y)
300 BC_WindowBase::get_resources()->cancel_images)
302 set_tooltip("Cancel");
305 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
306 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
307 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
308 BC_WindowBase::get_resources()->cancel_images)
310 set_tooltip("Cancel");
313 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
314 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
315 parent_window->get_h() - images[0]->get_h() - 10,
318 set_tooltip("Cancel");
321 int BC_CancelButton::handle_event()
323 get_top_level()->set_done(1);
327 int BC_CancelButton::resize_event(int w,int h)
329 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
330 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
334 int BC_CancelButton::keypress_event()
336 if(get_keypress() == ESC) return handle_event();
340 int BC_CancelButton::calculate_h()
342 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
345 int BC_CancelButton::calculate_w()
347 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
369 BC_GenericButton::BC_GenericButton(int x, int y, char *text, VFrame **data)
372 data ? data : BC_WindowBase::get_resources()->generic_button_images)
374 strcpy(this->text, text);
377 BC_GenericButton::BC_GenericButton(int x, int y, int w, char *text, VFrame **data)
381 data ? data : BC_WindowBase::get_resources()->generic_button_images)
383 strcpy(this->text, text);
386 int BC_GenericButton::set_images(VFrame **data)
388 BC_Resources *resources = get_resources();
389 for(int i = 0; i < 3; i++)
391 if(images[i]) delete images[i];
392 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
398 w = get_text_width(MEDIUMFONT, text) +
399 resources->generic_button_margin * 2;
402 h = images[BUTTON_UP]->get_h();
406 int BC_GenericButton::calculate_w(BC_WindowBase *gui, char *text)
408 BC_Resources *resources = gui->get_resources();
409 return gui->get_text_width(MEDIUMFONT, text) +
410 resources->generic_button_margin * 2;
413 int BC_GenericButton::calculate_h()
415 BC_Resources *resources = BC_WindowBase::get_resources();
416 return resources->generic_button_images[0]->get_h();
419 int BC_GenericButton::draw_face()
421 draw_top_background(parent_window, 0, 0, get_w(), get_h());
422 draw_3segmenth(0, 0, get_w(), images[status]);
425 set_color(get_resources()->default_text_color);
427 set_color(get_resources()->disabled_text_color);
428 set_font(MEDIUMFONT);
431 BC_Resources *resources = get_resources();
432 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
433 w = get_text_width(current_font, text, strlen(text)) +
434 resources->generic_button_margin * 2;
435 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
436 if(status == BUTTON_DOWNHI)
445 if(underline_number >= 0)
448 int x1 = get_text_width(current_font, text, underline_number) +
450 resources->toggle_text_margin;
451 int x2 = get_text_width(current_font, text, underline_number + 1) +
453 resources->toggle_text_margin;
454 draw_line(x1, y, x2, y);
455 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
466 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
467 : BC_GenericButton(10,
468 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
471 this->parent_window = parent_window;
474 int BC_OKTextButton::resize_event(int w, int h)
476 reposition_window(10,
477 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
481 int BC_OKTextButton::handle_event()
483 get_top_level()->set_done(0);
487 int BC_OKTextButton::keypress_event()
489 if(get_keypress() == RETURN) return handle_event();
495 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
496 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
497 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
500 this->parent_window = parent_window;
503 int BC_CancelTextButton::resize_event(int w, int h)
505 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
506 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
510 int BC_CancelTextButton::handle_event()
512 get_top_level()->set_done(1);
516 int BC_CancelTextButton::keypress_event()
518 if(get_keypress() == ESC) return handle_event();