2 #include "bcresources.h"
15 #define BUTTON_DOWNHI 2
17 BC_Button::BC_Button(int x,
20 : BC_SubWindow(x, y, 0, 0, -1)
23 for(int i = 0; i < 3; i++) images[i] = 0;
24 if(!data) printf("BC_Button::BC_Button data == 0\n");
27 underline_number = -1;
30 BC_Button::BC_Button(int x,
34 : BC_SubWindow(x, y, 0, 0, -1)
38 for(int i = 0; i < 3; i++) images[i] = 0;
39 if(!data) printf("BC_Button::BC_Button data == 0\n");
41 underline_number = -1;
45 BC_Button::~BC_Button()
47 for(int i = 0; i < 3; i++) if(images[i]) delete images[i];
52 int BC_Button::initialize()
57 // Create the subwindow
58 BC_SubWindow::initialize();
65 int BC_Button::reposition_window(int x, int y)
67 BC_WindowBase::reposition_window(x, y);
73 int BC_Button::update_bitmaps(VFrame **data)
77 draw_top_background(parent_window, 0, 0, w, h);
82 void BC_Button::set_underline(int number)
84 this->underline_number = number;
87 int BC_Button::set_images(VFrame **data)
89 for(int i = 0; i < 3; i++)
91 if(images[i]) delete images[i];
92 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
98 w = images[BUTTON_UP]->get_w();
100 h = images[BUTTON_UP]->get_h();
104 int BC_Button::draw_face()
106 draw_top_background(parent_window, 0, 0, w, h);
107 images[status]->write_drawable(pixmap,
118 int BC_Button::repeat_event(int64_t duration)
120 if(duration == top_level->get_resources()->tooltip_delay &&
121 tooltip_text[0] != 0 &&
122 status == BUTTON_UPHI &&
132 int BC_Button::cursor_enter_event()
134 if(top_level->event_win == win)
137 if(top_level->button_down)
139 status = BUTTON_DOWNHI;
142 if(status == BUTTON_UP) status = BUTTON_UPHI;
148 int BC_Button::cursor_leave_event()
150 if(status == BUTTON_UPHI)
159 int BC_Button::button_press_event()
161 if(top_level->event_win == win)
163 top_level->hide_tooltip();
164 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
171 int BC_Button::button_release_event()
173 //printf("BC_Button::button_release_event 1\n");
174 if(top_level->event_win == win)
177 //printf("BC_Button::button_release_event 2\n");
178 if(status == BUTTON_DOWNHI)
180 //printf("BC_Button::button_release_event 3\n");
181 status = BUTTON_UPHI;
186 //printf("BC_Button::button_release_event 4\n");
195 int BC_Button::cursor_motion_event()
197 if(top_level->button_down && top_level->event_win == win &&
198 status == BUTTON_DOWNHI && !cursor_inside())
207 BC_OKButton::BC_OKButton(int x, int y)
209 BC_WindowBase::get_resources()->ok_images)
213 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
215 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
216 BC_WindowBase::get_resources()->ok_images)
220 int BC_OKButton::handle_event()
222 get_top_level()->set_done(0);
226 int BC_OKButton::resize_event(int w, int h)
228 reposition_window(10,
229 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
233 int BC_OKButton::keypress_event()
235 if(get_keypress() == RETURN) return handle_event();
239 BC_CancelButton::BC_CancelButton(int x, int y)
241 BC_WindowBase::get_resources()->cancel_images)
245 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
246 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
247 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
248 BC_WindowBase::get_resources()->cancel_images)
252 int BC_CancelButton::handle_event()
254 get_top_level()->set_done(1);
258 int BC_CancelButton::resize_event(int w,int h)
260 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
261 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
265 int BC_CancelButton::keypress_event()
267 if(get_keypress() == ESC) return handle_event();
284 BC_GenericButton::BC_GenericButton(int x, int y, char *text, VFrame **data)
287 data ? data : BC_WindowBase::get_resources()->generic_button_images)
289 strcpy(this->text, text);
292 BC_GenericButton::BC_GenericButton(int x, int y, int w, char *text, VFrame **data)
296 data ? data : BC_WindowBase::get_resources()->generic_button_images)
298 strcpy(this->text, text);
301 int BC_GenericButton::set_images(VFrame **data)
303 for(int i = 0; i < 3; i++)
305 if(images[i]) delete images[i];
306 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
312 w = get_text_width(MEDIUMFONT, text) + images[BUTTON_UP]->get_w() / 3;
315 h = images[BUTTON_UP]->get_h();
319 int BC_GenericButton::draw_face()
322 draw_top_background(parent_window, 0, 0, get_w(), get_h());
323 draw_3segmenth(0, 0, get_w(), images[status]);
326 set_font(MEDIUMFONT);
327 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
328 w = get_text_width(current_font, text, strlen(text));
329 x = get_w() / 2 - w / 2;
334 if(underline_number >= 0)
337 int x1 = get_text_width(current_font, text, underline_number) + x;
338 int x2 = get_text_width(current_font, text, underline_number + 1) + x;
339 draw_line(x1, y, x2, y);
340 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);