| 1 |
#include <ClanLib/display.h> |
| 2 |
#include <ClanLib/gl.h> |
| 3 |
|
| 4 |
#include "window_zz.h" |
| 5 |
#include "stylemanager_zz.h" |
| 6 |
|
| 7 |
CL_Window_ZZ::CL_Window_ZZ( |
| 8 |
CL_Window *window, |
| 9 |
CL_StyleManager_ZZ *style) |
| 10 |
: |
| 11 |
CL_ComponentStyle(window), |
| 12 |
window(window), |
| 13 |
style(style), |
| 14 |
move_handler(0), |
| 15 |
resources(style->get_resources()), |
| 16 |
title_font(0), |
| 17 |
first_paint(true) |
| 18 |
{ |
| 19 |
slot_paint = window->sig_paint().connect(this, &CL_Window_ZZ::on_paint); |
| 20 |
|
| 21 |
button_quit = new CL_Button(CL_Rect(window->get_width() - 12, 3, window->get_width(), 15), "X", window, style); |
| 22 |
|
| 23 |
title_font = new CL_Font("Window/font", resources); |
| 24 |
|
| 25 |
rc_title = CL_Rect(0, 0,title_font->get_width(window->get_title()) + 16, |
| 26 |
title_font->get_height(window->get_title()) + 10); |
| 27 |
|
| 28 |
move_handler = new CL_ComponentMoveHandler(rc_title, window); |
| 29 |
rc_main = CL_Rect(12, 12, window->get_width(), window->get_height()); |
| 30 |
|
| 31 |
slot_quit = button_quit->sig_clicked().connect(this, &CL_Window_ZZ::on_quit); |
| 32 |
} |
| 33 |
|
| 34 |
CL_Window_ZZ::~CL_Window_ZZ() |
| 35 |
{ |
| 36 |
delete title_font; |
| 37 |
delete move_handler; |
| 38 |
delete button_quit; |
| 39 |
} |
| 40 |
|
| 41 |
void CL_Window_ZZ::on_paint() |
| 42 |
{ |
| 43 |
rc_title = CL_Rect(0, 0,title_font->get_width(window->get_title()) + 16, |
| 44 |
title_font->get_height(window->get_title()) + 10); |
| 45 |
|
| 46 |
rc_main = CL_Rect(12, 12, window->get_width(), window->get_height()); |
| 47 |
|
| 48 |
if (first_paint) |
| 49 |
{ |
| 50 |
button_quit->set_position(CL_Rect(window->get_width() - 12,3, |
| 51 |
window->get_width(),15)); |
| 52 |
|
| 53 |
delete move_handler; |
| 54 |
move_handler = new CL_ComponentMoveHandler(rc_title, window); |
| 55 |
|
| 56 |
window->get_client_area()->set_position(CL_Rect(rc_main.left, rc_main.top, |
| 57 |
window->get_width(), window->get_height())); |
| 58 |
|
| 59 |
first_paint = false; |
| 60 |
} |
| 61 |
|
| 62 |
int width = window->get_width(); |
| 63 |
int height = window->get_height(); |
| 64 |
|
| 65 |
// Fill |
| 66 |
//------- |
| 67 |
CL_Color clr_background(100, 120, 100, 180); |
| 68 |
style->fill_rounded_rect(window->client_to_screen(rc_main), clr_background); |
| 69 |
|
| 70 |
// Outline |
| 71 |
CL_Color clr_outline(175, 205, 148); |
| 72 |
style->draw_rounded_rect(window->client_to_screen(rc_main), clr_outline); |
| 73 |
|
| 74 |
|
| 75 |
CL_Color clr_title_bgnd(93, 156, 39); |
| 76 |
// title |
| 77 |
style->fill_rounded_rect(window->client_to_screen(rc_title), clr_title_bgnd); |
| 78 |
style->draw_rounded_rect(window->client_to_screen(rc_title), clr_outline); |
| 79 |
|
| 80 |
// draw title text |
| 81 |
CL_Point title_coord = window->client_to_screen(CL_Point(rc_title.left + 8, rc_title.top + 6)); |
| 82 |
title_font->draw(title_coord.x, title_coord.y, window->get_title()); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
void CL_Window_ZZ::on_quit() |
| 87 |
{ |
| 88 |
if (window->is_modal()) |
| 89 |
window->quit(); |
| 90 |
else |
| 91 |
window->close(); |
| 92 |
} |