Debian Codegraph @

Examples/GUIStyle/ZZ_Theme/checkbox_zz.cpp

raw
1 #include <ClanLib/display.h>
2 #include <ClanLib/gl.h>
3
4 #include "checkbox_zz.h"
5 #include "stylemanager_zz.h"
6
7 CL_CheckBox_ZZ::CL_CheckBox_ZZ(
8 CL_CheckBox *checkbox,
9 CL_StyleManager_ZZ *style)
10 :
11 CL_ComponentStyle(checkbox),
12 style(style),
13 checkbox(checkbox)
14 {
15 resources = style->get_resources();
16
17 font = new CL_Font("CheckBox/font", resources);
18
19 surface_left = new CL_Surface("CheckBox/left", resources);
20 surface_right = new CL_Surface("CheckBox/right", resources);
21 surface_ticker = new CL_Surface("CheckBox/ticker", resources);
22
23 slot_paint = checkbox->sig_paint().connect_virtual(
24 this, &CL_CheckBox_ZZ::on_paint);
25 slot_get_preferred_size = checkbox->sig_get_preferred_size().connect(
26 this, &CL_CheckBox_ZZ::on_get_preferred_size);
27 }
28
29 CL_CheckBox_ZZ::~CL_CheckBox_ZZ()
30 {
31 }
32
33 void CL_CheckBox_ZZ::on_get_preferred_size(CL_Size &size)
34 {
35 size.width = font->get_width(checkbox->get_text()) + 28;
36 size.height = 35;
37 }
38
39 void CL_CheckBox_ZZ::on_paint(CL_SlotParent_v0 &super)
40 {
41 surface_left->draw(0, 0);
42 surface_right->draw(16, 0);
43
44 int checkbox_width = checkbox->get_width();
45 int checkbox_height = checkbox->get_height();
46
47 if(checkbox->is_down())
48 surface_ticker->draw(-3, -10);
49
50 int x_pos = 28;
51 int text_height = font->get_height();
52 int y_pos = (checkbox_height - text_height) / 2 - 4;
53
54 font->draw(checkbox->get_screen_x() + x_pos, checkbox->get_screen_x() + y_pos, checkbox->get_text());
55 }