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;
31 BC_Button::BC_Button(int x,
35 : BC_SubWindow(x, y, 0, 0, -1)
39 for(int i = 0; i < 3; i++) images[i] = 0;
40 if(!data) printf("BC_Button::BC_Button data == 0\n");
42 underline_number = -1;
47 BC_Button::~BC_Button()
49 for(int i = 0; i < 3; i++) if(images[i]) delete images[i];
54 int BC_Button::initialize()
59 // Create the subwindow
60 BC_SubWindow::initialize();
67 int BC_Button::reposition_window(int x, int y)
69 BC_WindowBase::reposition_window(x, y);
75 int BC_Button::update_bitmaps(VFrame **data)
79 draw_top_background(parent_window, 0, 0, w, h);
84 void BC_Button::enable()
90 void BC_Button::disable()
97 void BC_Button::set_underline(int number)
99 this->underline_number = number;
102 int BC_Button::set_images(VFrame **data)
104 for(int i = 0; i < 3; i++)
106 if(images[i]) delete images[i];
107 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
113 w = images[BUTTON_UP]->get_w();
115 h = images[BUTTON_UP]->get_h();
119 int BC_Button::draw_face()
121 draw_top_background(parent_window, 0, 0, w, h);
122 images[status]->write_drawable(pixmap,
134 int BC_Button::repeat_event(int64_t duration)
136 if(duration == top_level->get_resources()->tooltip_delay &&
137 tooltip_text[0] != 0 &&
138 status == BUTTON_UPHI &&
148 int BC_Button::cursor_enter_event()
150 if(top_level->event_win == win && enabled)
153 if(top_level->button_down)
155 status = BUTTON_DOWNHI;
158 if(status == BUTTON_UP) status = BUTTON_UPHI;
164 int BC_Button::cursor_leave_event()
166 if(status == BUTTON_UPHI)
175 int BC_Button::button_press_event()
177 if(top_level->event_win == win && get_buttonpress() == 1 && enabled)
180 if(status == BUTTON_UPHI || status == BUTTON_UP) status = BUTTON_DOWNHI;
187 int BC_Button::button_release_event()
189 //printf("BC_Button::button_release_event 1\n");
190 if(top_level->event_win == win)
193 //printf("BC_Button::button_release_event 2\n");
194 if(status == BUTTON_DOWNHI)
196 //printf("BC_Button::button_release_event 3\n");
197 status = BUTTON_UPHI;
202 //printf("BC_Button::button_release_event 4\n");
211 int BC_Button::cursor_motion_event()
213 if(top_level->button_down && top_level->event_win == win &&
214 status == BUTTON_DOWNHI && !cursor_inside())
223 BC_OKButton::BC_OKButton(int x, int y)
225 BC_WindowBase::get_resources()->ok_images)
229 BC_OKButton::BC_OKButton(BC_WindowBase *parent_window)
231 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
232 BC_WindowBase::get_resources()->ok_images)
236 int BC_OKButton::handle_event()
238 get_top_level()->set_done(0);
242 int BC_OKButton::resize_event(int w, int h)
244 reposition_window(10,
245 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
249 int BC_OKButton::keypress_event()
251 if(get_keypress() == RETURN) return handle_event();
255 BC_CancelButton::BC_CancelButton(int x, int y)
257 BC_WindowBase::get_resources()->cancel_images)
261 BC_CancelButton::BC_CancelButton(BC_WindowBase *parent_window)
262 : BC_Button(parent_window->get_w() - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
263 parent_window->get_h() - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10,
264 BC_WindowBase::get_resources()->cancel_images)
268 int BC_CancelButton::handle_event()
270 get_top_level()->set_done(1);
274 int BC_CancelButton::resize_event(int w,int h)
276 reposition_window(w - BC_WindowBase::get_resources()->cancel_images[0]->get_w() - 10,
277 h - BC_WindowBase::get_resources()->cancel_images[0]->get_h() - 10);
281 int BC_CancelButton::keypress_event()
283 if(get_keypress() == ESC) return handle_event();
300 BC_GenericButton::BC_GenericButton(int x, int y, char *text, VFrame **data)
303 data ? data : BC_WindowBase::get_resources()->generic_button_images)
305 strcpy(this->text, text);
308 BC_GenericButton::BC_GenericButton(int x, int y, int w, char *text, VFrame **data)
312 data ? data : BC_WindowBase::get_resources()->generic_button_images)
314 strcpy(this->text, text);
317 int BC_GenericButton::set_images(VFrame **data)
319 for(int i = 0; i < 3; i++)
321 if(images[i]) delete images[i];
322 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
328 w = get_text_width(MEDIUMFONT, text) + images[BUTTON_UP]->get_w() / 3;
331 h = images[BUTTON_UP]->get_h();
335 int BC_GenericButton::draw_face()
338 draw_top_background(parent_window, 0, 0, get_w(), get_h());
339 draw_3segmenth(0, 0, get_w(), images[status]);
345 set_font(MEDIUMFONT);
346 y = (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2);
347 w = get_text_width(current_font, text, strlen(text));
348 x = get_w() / 2 - w / 2;
353 if(underline_number >= 0)
356 int x1 = get_text_width(current_font, text, underline_number) + x;
357 int x2 = get_text_width(current_font, text, underline_number + 1) + x;
358 draw_line(x1, y, x2, y);
359 draw_line(x1, y + 1, (x2 + x1) / 2, y + 1);