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_text && tooltip_text[0] != 0 &&
158 duration == top_level->get_resources()->tooltip_delay )
166 int BC_Button::cursor_enter_event()
168 if(is_event_win() && enabled)
170 if(top_level->button_down) {
171 status = BUTTON_DOWNHI;
174 if(status == BUTTON_UP) status = BUTTON_UPHI;
180 int BC_Button::cursor_leave_event()
182 if(status == BUTTON_UPHI)
194 int BC_Button::button_press_event()
196 if(is_event_win() && get_buttonpress() == 1 && enabled)
199 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
206 int BC_Button::button_release_event()
211 if(status == BUTTON_DOWNHI)
213 status = BUTTON_UPHI;
226 int BC_Button::cursor_motion_event()
228 if(top_level->button_down &&
230 status == BUTTON_DOWNHI &&
239 int BC_Button::get_status()
254 BC_OKButton::BC_OKButton(int x, int y)
256 BC_WindowBase::get_resources()->ok_images)
260 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
262 parent_window->get_h() - images[0]->get_h() - 10,
265 set_tooltip(_("OK"));
268 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
270 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
271 BC_WindowBase::get_resources()->ok_images)
273 set_tooltip(_("OK"));
276 int BC_OKButton::handle_event()
278 get_top_level()->set_done(0);
282 int BC_OKButton::resize_event(int w, int h)
284 reposition_window(10,
285 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
289 int BC_OKButton::keypress_event()
291 if(get_keypress() == RETURN) return handle_event();
295 int BC_OKButton::calculate_h()
297 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
300 int BC_OKButton::calculate_w()
302 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
317 BC_CancelButton::BC_CancelButton(int x, int y)
319 BC_WindowBase::get_resources()->cancel_images)
321 set_tooltip(_("Cancel"));
324 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
325 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
326 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
327 BC_WindowBase::get_resources()->cancel_images)
329 set_tooltip(_("Cancel"));
332 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
333 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
334 parent_window->get_h() - images[0]->get_h() - 10,
337 set_tooltip(_("Cancel"));
340 int BC_CancelButton::handle_event()
342 get_top_level()->set_done(1);
346 int BC_CancelButton::resize_event(int w,int h)
348 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
349 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
353 int BC_CancelButton::keypress_event()
355 if(get_keypress() == ESC) return handle_event();
359 int BC_CancelButton::calculate_h()
361 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
364 int BC_CancelButton::calculate_w()
366 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
388 BC_GenericButton::BC_GenericButton(int x, int y,
389 const char *text, VFrame **data, int color)
391 data ? data : BC_WindowBase::get_resources()->generic_button_images)
393 strcpy(this->text, text);
397 BC_GenericButton::BC_GenericButton(int x, int y,
398 int w, const char *text, VFrame **data, int color)
400 data ? data : BC_WindowBase::get_resources()->generic_button_images)
402 strcpy(this->text, text);
406 int BC_GenericButton::set_images(VFrame **data)
408 BC_Resources *resources = get_resources();
409 for(int i = 0; i < 3; i++)
411 if(images[i]) delete images[i];
412 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
418 w = get_text_width(MEDIUMFONT, text) +
419 resources->generic_button_margin * 2;
422 h = images[BUTTON_UP]->get_h();
426 void BC_GenericButton::text_color(int color)
431 int BC_GenericButton::calculate_w(BC_WindowBase *gui, const char *text)
433 BC_Resources *resources = gui->get_resources();
434 return gui->get_text_width(MEDIUMFONT, text) +
435 resources->generic_button_margin * 2;
438 int BC_GenericButton::calculate_h()
440 BC_Resources *resources = BC_WindowBase::get_resources();
441 return resources->generic_button_images[0]->get_h();
444 int BC_GenericButton::draw_face(int flush)
446 draw_top_background(parent_window, 0, 0, get_w(), get_h());
447 draw_3segmenth(0, 0, get_w(), images[status]);
449 BC_Resources *resources = get_resources();
453 set_color(resources->default_text_color);
455 set_color(resources->disabled_text_color);
456 set_font(MEDIUMFONT);
459 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
460 w = get_text_width(current_font, text, strlen(text)) +
461 resources->generic_button_margin * 2;
462 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
463 if(status == BUTTON_DOWNHI) { x++; y++; }
464 draw_text(x, y, text);
466 if(underline_number >= 0)
469 int x1 = get_text_width(current_font, text, underline_number) +
471 int x2 = get_text_width(current_font, text, underline_number + 1) +
474 draw_line(x1, y, x2, y);
475 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
486 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
487 : BC_GenericButton(10,
488 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
491 this->parent_window = parent_window;
494 int BC_OKTextButton::resize_event(int w, int h)
496 reposition_window(10,
497 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
501 int BC_OKTextButton::handle_event()
503 get_top_level()->set_done(0);
507 int BC_OKTextButton::keypress_event()
509 if(get_keypress() == RETURN) return handle_event();
515 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
516 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
517 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
520 this->parent_window = parent_window;
523 int BC_CancelTextButton::resize_event(int w, int h)
525 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
526 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
530 int BC_CancelTextButton::handle_event()
532 get_top_level()->set_done(1);
536 int BC_CancelTextButton::keypress_event()
538 if(get_keypress() == ESC) return handle_event();