4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcresources.h"
25 #include "bcsignals.h"
37 BC_Button::BC_Button(int x,
40 : BC_SubWindow(x, y, 0, 0, -1)
43 for(int i = 0; i < 3; i++) images[i] = 0;
44 if(!data) printf("BC_Button::BC_Button data == 0\n");
47 underline_number = -1;
51 BC_Button::BC_Button(int x,
55 : BC_SubWindow(x, y, 0, 0, -1)
59 for(int i = 0; i < 3; i++) images[i] = 0;
60 if(!data) printf("BC_Button::BC_Button data == 0\n");
62 underline_number = -1;
67 BC_Button::~BC_Button()
69 for(int i = 0; i < 3; i++) if(images[i]) delete images[i];
74 int BC_Button::initialize()
79 // Create the subwindow
80 BC_SubWindow::initialize();
88 int BC_Button::reposition_window(int x, int y)
90 BC_WindowBase::reposition_window(x, y);
96 int BC_Button::update_bitmaps(VFrame **data)
100 draw_top_background(parent_window, 0, 0, w, h);
105 void BC_Button::enable()
111 void BC_Button::disable()
119 void BC_Button::set_underline(int number)
121 this->underline_number = number;
124 int BC_Button::set_images(VFrame **data)
126 for(int i = 0; i < 3; i++)
128 if(images[i]) delete images[i];
129 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
135 w = images[BUTTON_UP]->get_w();
137 h = images[BUTTON_UP]->get_h();
141 int BC_Button::draw_face(int flush)
143 draw_top_background(parent_window, 0, 0, w, h);
144 pixmap->draw_pixmap(images[status],
155 int BC_Button::repeat_event(int64_t duration)
157 if( status == BUTTON_UPHI && !tooltip_done &&
158 tooltip_text && tooltip_text[0] != 0 &&
159 duration == top_level->get_resources()->tooltip_delay )
168 int BC_Button::cursor_enter_event()
170 if(is_event_win() && enabled)
173 if(top_level->button_down)
175 status = BUTTON_DOWNHI;
178 if(status == BUTTON_UP) status = BUTTON_UPHI;
184 int BC_Button::cursor_leave_event()
186 if(status == BUTTON_UPHI)
198 int BC_Button::button_press_event()
200 if(is_event_win() && get_buttonpress() == 1 && enabled)
203 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
210 int BC_Button::button_release_event()
215 if(status == BUTTON_DOWNHI)
217 status = BUTTON_UPHI;
230 int BC_Button::cursor_motion_event()
232 if(top_level->button_down &&
234 status == BUTTON_DOWNHI &&
243 int BC_Button::get_status()
258 BC_OKButton::BC_OKButton(int x, int y)
260 BC_WindowBase::get_resources()->ok_images)
264 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
266 parent_window->get_h() - images[0]->get_h() - 10,
269 set_tooltip(_("OK"));
272 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
274 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
275 BC_WindowBase::get_resources()->ok_images)
277 set_tooltip(_("OK"));
280 int BC_OKButton::handle_event()
282 get_top_level()->set_done(0);
286 int BC_OKButton::resize_event(int w, int h)
288 reposition_window(10,
289 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
293 int BC_OKButton::keypress_event()
295 if(get_keypress() == RETURN) return handle_event();
299 int BC_OKButton::calculate_h()
301 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
304 int BC_OKButton::calculate_w()
306 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
321 BC_CancelButton::BC_CancelButton(int x, int y)
323 BC_WindowBase::get_resources()->cancel_images)
325 set_tooltip(_("Cancel"));
328 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
329 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
330 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
331 BC_WindowBase::get_resources()->cancel_images)
333 set_tooltip(_("Cancel"));
336 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
337 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
338 parent_window->get_h() - images[0]->get_h() - 10,
341 set_tooltip(_("Cancel"));
344 int BC_CancelButton::handle_event()
346 get_top_level()->set_done(1);
350 int BC_CancelButton::resize_event(int w,int h)
352 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
353 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
357 int BC_CancelButton::keypress_event()
359 if(get_keypress() == ESC) return handle_event();
363 int BC_CancelButton::calculate_h()
365 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
368 int BC_CancelButton::calculate_w()
370 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
392 BC_GenericButton::BC_GenericButton(int x, int y,
393 const char *text, VFrame **data, int color)
395 data ? data : BC_WindowBase::get_resources()->generic_button_images)
397 strcpy(this->text, text);
401 BC_GenericButton::BC_GenericButton(int x, int y,
402 int w, const char *text, VFrame **data, int color)
404 data ? data : BC_WindowBase::get_resources()->generic_button_images)
406 strcpy(this->text, text);
410 int BC_GenericButton::set_images(VFrame **data)
412 BC_Resources *resources = get_resources();
413 for(int i = 0; i < 3; i++)
415 if(images[i]) delete images[i];
416 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
422 w = get_text_width(MEDIUMFONT, text) +
423 resources->generic_button_margin * 2;
426 h = images[BUTTON_UP]->get_h();
430 void BC_GenericButton::text_color(int color)
435 int BC_GenericButton::calculate_w(BC_WindowBase *gui, const char *text)
437 BC_Resources *resources = gui->get_resources();
438 return gui->get_text_width(MEDIUMFONT, text) +
439 resources->generic_button_margin * 2;
442 int BC_GenericButton::calculate_h()
444 BC_Resources *resources = BC_WindowBase::get_resources();
445 return resources->generic_button_images[0]->get_h();
448 int BC_GenericButton::draw_face(int flush)
450 draw_top_background(parent_window, 0, 0, get_w(), get_h());
451 draw_3segmenth(0, 0, get_w(), images[status]);
453 BC_Resources *resources = get_resources();
457 set_color(resources->default_text_color);
459 set_color(resources->disabled_text_color);
460 set_font(MEDIUMFONT);
463 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
464 w = get_text_width(current_font, text, strlen(text)) +
465 resources->generic_button_margin * 2;
466 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
467 if(status == BUTTON_DOWNHI) { x++; y++; }
468 draw_text(x, y, text);
470 if(underline_number >= 0)
473 int x1 = get_text_width(current_font, text, underline_number) +
475 int x2 = get_text_width(current_font, text, underline_number + 1) +
478 draw_line(x1, y, x2, y);
479 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
490 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
491 : BC_GenericButton(10,
492 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
495 this->parent_window = parent_window;
498 int BC_OKTextButton::resize_event(int w, int h)
500 reposition_window(10,
501 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
505 int BC_OKTextButton::handle_event()
507 get_top_level()->set_done(0);
511 int BC_OKTextButton::keypress_event()
513 if(get_keypress() == RETURN) return handle_event();
519 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
520 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
521 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
524 this->parent_window = parent_window;
527 int BC_CancelTextButton::resize_event(int w, int h)
529 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
530 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
534 int BC_CancelTextButton::handle_event()
536 get_top_level()->set_done(1);
540 int BC_CancelTextButton::keypress_event()
542 if(get_keypress() == ESC) return handle_event();