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()
112 void BC_Button::disable()
120 void BC_Button::set_underline(int number)
122 this->underline_number = number;
125 int BC_Button::set_images(VFrame **data)
127 for(int i = 0; i < 3; i++)
129 if(images[i]) delete images[i];
130 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
136 w = images[BUTTON_UP]->get_w();
138 h = images[BUTTON_UP]->get_h();
142 int BC_Button::draw_face(int flush)
144 draw_top_background(parent_window, 0, 0, w, h);
145 pixmap->draw_pixmap(images[status],
156 int BC_Button::repeat_event(int64_t duration)
158 if( status == BUTTON_UPHI && tooltip_text && tooltip_text[0] != 0 &&
159 duration == top_level->get_resources()->tooltip_delay )
167 int BC_Button::cursor_enter_event()
169 if(is_event_win() && enabled)
171 if(top_level->button_down) {
172 status = BUTTON_DOWNHI;
175 if(status == BUTTON_UP) status = BUTTON_UPHI;
181 int BC_Button::cursor_leave_event()
183 if(status == BUTTON_UPHI)
195 int BC_Button::button_press_event()
197 if(is_event_win() && get_buttonpress() == 1 && enabled)
200 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
207 int BC_Button::button_release_event()
212 if(status == BUTTON_DOWNHI)
214 status = BUTTON_UPHI;
227 int BC_Button::cursor_motion_event()
229 if(top_level->button_down &&
231 status == BUTTON_DOWNHI &&
240 int BC_Button::get_status()
255 BC_OKButton::BC_OKButton(int x, int y)
257 BC_WindowBase::get_resources()->ok_images)
261 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window, VFrame **images)
263 parent_window->get_h() - images[0]->get_h() - 10,
266 set_tooltip(_("OK"));
269 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
271 parent_window->get_h() - BC_WindowBase::get_resources()->ok_images[0]->get_h() - 10,
272 BC_WindowBase::get_resources()->ok_images)
274 set_tooltip(_("OK"));
277 int BC_OKButton::handle_event()
279 get_top_level()->set_done(0);
283 int BC_OKButton::resize_event(int w, int h)
285 reposition_window(10,
286 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
290 int BC_OKButton::keypress_event()
292 if(get_keypress() == RETURN) return handle_event();
296 int BC_OKButton::calculate_h()
298 return BC_WindowBase::get_resources()->ok_images[0]->get_h();
301 int BC_OKButton::calculate_w()
303 return BC_WindowBase::get_resources()->ok_images[0]->get_w();
318 BC_CancelButton::BC_CancelButton(int x, int y)
320 BC_WindowBase::get_resources()->cancel_images)
322 set_tooltip(_("Cancel"));
325 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
326 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
327 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
328 BC_WindowBase::get_resources()->cancel_images)
330 set_tooltip(_("Cancel"));
333 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window, VFrame **images)
334 : BC_Button(parent_window->get_w() - images[0]->get_w() - 10,
335 parent_window->get_h() - images[0]->get_h() - 10,
338 set_tooltip(_("Cancel"));
341 int BC_CancelButton::handle_event()
343 get_top_level()->set_done(1);
347 int BC_CancelButton::resize_event(int w,int h)
349 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
350 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
354 int BC_CancelButton::keypress_event()
356 if(get_keypress() == ESC) return handle_event();
360 int BC_CancelButton::calculate_h()
362 return BC_WindowBase::get_resources()->cancel_images[0]->get_h();
365 int BC_CancelButton::calculate_w()
367 return BC_WindowBase::get_resources()->cancel_images[0]->get_w();
389 BC_GenericButton::BC_GenericButton(int x, int y,
390 const char *text, VFrame **data, int color)
392 data ? data : BC_WindowBase::get_resources()->generic_button_images)
394 strcpy(this->text, text);
398 BC_GenericButton::BC_GenericButton(int x, int y,
399 int w, const char *text, VFrame **data, int color)
401 data ? data : BC_WindowBase::get_resources()->generic_button_images)
403 strcpy(this->text, text);
407 int BC_GenericButton::set_images(VFrame **data)
409 BC_Resources *resources = get_resources();
410 for(int i = 0; i < 3; i++)
412 if(images[i]) delete images[i];
413 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
419 w = get_text_width(MEDIUMFONT, text) +
420 resources->generic_button_margin * 2;
423 h = images[BUTTON_UP]->get_h();
427 void BC_GenericButton::text_color(int color)
432 int BC_GenericButton::calculate_w(BC_WindowBase *gui, const char *text)
434 BC_Resources *resources = gui->get_resources();
435 return gui->get_text_width(MEDIUMFONT, text) +
436 resources->generic_button_margin * 2;
439 int BC_GenericButton::calculate_h()
441 BC_Resources *resources = BC_WindowBase::get_resources();
442 return resources->generic_button_images[0]->get_h();
445 int BC_GenericButton::draw_face(int flush)
447 draw_top_background(parent_window, 0, 0, get_w(), get_h());
448 draw_3segmenth(0, 0, get_w(), images[status]);
450 BC_Resources *resources = get_resources();
454 set_color(resources->default_text_color);
456 set_color(resources->disabled_text_color);
457 set_font(MEDIUMFONT);
460 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
461 w = get_text_width(current_font, text, strlen(text)) +
462 resources->generic_button_margin * 2;
463 x = get_w() / 2 - w / 2 + resources->generic_button_margin;
464 if(status == BUTTON_DOWNHI) { x++; y++; }
465 draw_text(x, y, text);
467 if(underline_number >= 0)
470 int x1 = get_text_width(current_font, text, underline_number) +
472 int x2 = get_text_width(current_font, text, underline_number + 1) +
475 draw_line(x1, y, x2, y);
476 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);
487 BC_OKTextButton::BC_OKTextButton(BC_WindowBase *parent_window)
488 : BC_GenericButton(10,
489 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
492 this->parent_window = parent_window;
495 int BC_OKTextButton::resize_event(int w, int h)
497 reposition_window(10,
498 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
502 int BC_OKTextButton::handle_event()
504 get_top_level()->set_done(0);
508 int BC_OKTextButton::keypress_event()
510 if(get_keypress() == RETURN) return handle_event();
516 BC_CancelTextButton::BC_CancelTextButton(BC_WindowBase *parent_window)
517 : BC_GenericButton(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
518 parent_window->get_h() - BC_GenericButton::calculate_h() - 10,
521 this->parent_window = parent_window;
524 int BC_CancelTextButton::resize_event(int w, int h)
526 reposition_window(parent_window->get_w() - BC_GenericButton::calculate_w(parent_window, _("Cancel")) - 10,
527 parent_window->get_h() - BC_GenericButton::calculate_h() - 10);
531 int BC_CancelTextButton::handle_event()
533 get_top_level()->set_done(1);
537 int BC_CancelTextButton::keypress_event()
539 if(get_keypress() == ESC) return handle_event();