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()
118 void BC_Button::set_underline(int number)
120 this->underline_number = number;
123 int BC_Button::set_images(VFrame **data)
125 for(int i = 0; i < 3; i++)
127 if(images[i]) delete images[i];
128 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
134 w = images[BUTTON_UP]->get_w();
136 h = images[BUTTON_UP]->get_h();
140 int BC_Button::draw_face(int flush)
142 draw_top_background(parent_window, 0, 0, w, h);
143 pixmap->draw_pixmap(images[status],
154 int BC_Button::repeat_event(int64_t duration)
156 if( status == BUTTON_UPHI && !tooltip_done &&
157 tooltip_text && tooltip_text[0] != 0 &&
158 duration == top_level->get_resources()->tooltip_delay )
167 int BC_Button::cursor_enter_event()
169 if(is_event_win() && enabled)
172 if(top_level->button_down)
174 status = BUTTON_DOWNHI;
177 if(status == BUTTON_UP) status = BUTTON_UPHI;
183 int BC_Button::cursor_leave_event()
185 if(status == BUTTON_UPHI)
197 int BC_Button::button_press_event()
199 if(is_event_win() && get_buttonpress() == 1 && enabled)
202 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
209 int BC_Button::button_release_event()
214 if(status == BUTTON_DOWNHI)
216 status = BUTTON_UPHI;
229 int BC_Button::cursor_motion_event()
231 if(top_level->button_down &&
233 status == BUTTON_DOWNHI &&
242 int BC_Button::get_status()
257 BC_OKButton::BC_OKButton(int x, int y)
259 BC_WindowBase::get_resources()->ok_images)
263 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
265 parent_window->get_h() - images[0]->get_h() - 10,
268 set_tooltip(_("OK"));
271 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
273 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
274 BC_WindowBase::get_resources()->ok_images)
276 set_tooltip(_("OK"));
279 int BC_OKButton::handle_event()
281 get_top_level()->set_done(0);
285 int BC_OKButton::resize_event(int w, int h)
287 reposition_window(10,
288 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
292 int BC_OKButton::keypress_event()
294 if(get_keypress() == RETURN) return handle_event();
298 int BC_OKButton::calculate_h()
300 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
303 int BC_OKButton::calculate_w()
305 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
320 BC_CancelButton::BC_CancelButton(int x, int y)
322 BC_WindowBase::get_resources()->cancel_images)
324 set_tooltip(_("Cancel"));
327 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
328 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
329 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
330 BC_WindowBase::get_resources()->cancel_images)
332 set_tooltip(_("Cancel"));
335 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
336 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
337 parent_window->get_h() - images[0]->get_h() - 10,
340 set_tooltip(_("Cancel"));
343 int BC_CancelButton::handle_event()
345 get_top_level()->set_done(1);
349 int BC_CancelButton::resize_event(int w,int h)
351 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
352 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
356 int BC_CancelButton::keypress_event()
358 if(get_keypress() == ESC) return handle_event();
362 int BC_CancelButton::calculate_h()
364 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
367 int BC_CancelButton::calculate_w()
369 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
391 BC_GenericButton::BC_GenericButton(int x, int y,
392 const char *text, VFrame **data, int color)
394 data ? data : BC_WindowBase::get_resources()->generic_button_images)
396 strcpy(this->text, text);
400 BC_GenericButton::BC_GenericButton(int x, int y,
401 int w, const char *text, VFrame **data, int color)
403 data ? data : BC_WindowBase::get_resources()->generic_button_images)
405 strcpy(this->text, text);
409 int BC_GenericButton::set_images(VFrame **data)
411 BC_Resources *resources = get_resources();
412 for(int i = 0; i < 3; i++)
414 if(images[i]) delete images[i];
415 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
421 w = get_text_width(MEDIUMFONT, text) +
422 resources->generic_button_margin * 2;
425 h = images[BUTTON_UP]->get_h();
429 void BC_GenericButton::text_color(int color)
434 int BC_GenericButton::calculate_w(BC_WindowBase *gui, const char *text)
436 BC_Resources *resources = gui->get_resources();
437 return gui->get_text_width(MEDIUMFONT, text) +
438 resources->generic_button_margin * 2;
441 int BC_GenericButton::calculate_h()
443 BC_Resources *resources = BC_WindowBase::get_resources();
444 return resources->generic_button_images[0]->get_h();
447 int BC_GenericButton::draw_face(int flush)
449 draw_top_background(parent_window, 0, 0, get_w(), get_h());
450 draw_3segmenth(0, 0, get_w(), images[status]);
452 BC_Resources *resources = get_resources();
456 set_color(resources->default_text_color);
458 set_color(resources->disabled_text_color);
459 set_font(MEDIUMFONT);
462 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
463 w = get_text_width(current_font, text, strlen(text)) +
464 resources->generic_button_margin * 2;
465 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
466 if(status == BUTTON_DOWNHI) { x++; y++; }
467 draw_text(x, y, text);
469 if(underline_number >= 0)
472 int x1 = get_text_width(current_font, text, underline_number) +
474 int x2 = get_text_width(current_font, text, underline_number + 1) +
477 draw_line(x1, y, x2, y);
478 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
489 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
490 : BC_GenericButton(10,
491 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
494 this->parent_window = parent_window;
497 int BC_OKTextButton::resize_event(int w, int h)
499 reposition_window(10,
500 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
504 int BC_OKTextButton::handle_event()
506 get_top_level()->set_done(0);
510 int BC_OKTextButton::keypress_event()
512 if(get_keypress() == RETURN) return handle_event();
518 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
519 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
520 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
523 this->parent_window = parent_window;
526 int BC_CancelTextButton::resize_event(int w, int h)
528 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
529 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
533 int BC_CancelTextButton::handle_event()
535 get_top_level()->set_done(1);
539 int BC_CancelTextButton::keypress_event()
541 if(get_keypress() == ESC) return handle_event();