Debian Codegraph @

Examples/GUIStyle/ZZ_Theme/stylemanager_zz.cpp

raw
1 #include <ClanLib/gl.h>
2
3 #include "stylemanager_zz.h"
4 #include "button_zz.h"
5 #include "checkbox_zz.h"
6 #include "frame_zz.h"
7 #include "inputbox_zz.h"
8 #include "window_zz.h"
9 #include "listbox_zz.h"
10 #include "scrollbar_zz.h"
11 #include "label_zz.h"
12
13 #pragma warning ( push, 1 )
14 #pragma warning ( disable: 4244 ) // conversion from 'int' to 'float', possible loss of data
15
16
17 // Construction:
18
19 CL_StyleManager_ZZ::CL_StyleManager_ZZ(CL_ResourceManager *resources)
20 : CL_StyleManager(resources)
21 {
22 }
23
24 CL_StyleManager_ZZ::~CL_StyleManager_ZZ()
25 {
26 }
27
28 // Attributes:
29
30 // Operations:
31
32 void CL_StyleManager_ZZ::fill_rect(
33 int x1, int y1, int x2, int y2,
34 float r, float g, float b,
35 float a0, float a1, float a2, float a3)
36 {
37 glDisable(GL_TEXTURE_2D);
38 glBegin(GL_QUADS);
39 glColor4f(r,g,b,a0);
40 glVertex2i(x1, y1);
41 glColor4f(r,g,b,a1);
42 glVertex2i(x2, y1);
43 glColor4f(r,g,b,a2);
44 glVertex2i(x2, y2);
45 glColor4f(r,g,b,a3);
46 glVertex2i(x1, y2);
47 glEnd();
48 glEnable(GL_TEXTURE_2D);
49 }
50
51 void CL_StyleManager_ZZ::fill_rect(
52 int x1, int y1, int x2, int y2,
53 float r0, float g0, float b0,
54 float r1, float g1, float b1,
55 float r2, float g2, float b2,
56 float r3, float g3, float b3,
57 float a)
58 {
59 glDisable(GL_TEXTURE_2D);
60 glBegin(GL_QUADS);
61 glColor4f(r0,g0,b0,a);
62 glVertex2i(x1, y1);
63 glColor4f(r1,g1,b1,a);
64 glVertex2i(x2, y1);
65 glColor4f(r2,g2,b2,a);
66 glVertex2i(x2, y2);
67 glColor4f(r3,g3,b3,a);
68 glVertex2i(x1, y2);
69 glEnd();
70 glEnable(GL_TEXTURE_2D);
71 }
72
73 // Overridables:
74
75 void CL_StyleManager_ZZ::connect_styles(
76 const std::string &type,
77 CL_Component *owner)
78 {
79 if (type == "button")
80 {
81 CL_Button *button = (CL_Button *) owner;
82 button->set_style(new CL_Button_ZZ(button, this));
83 }
84 else if (type == "window")
85 {
86 CL_Window *window = (CL_Window *) owner;
87 window->set_style(new CL_Window_ZZ(window, this));
88 }
89 else if (type == "frame")
90 {
91 CL_Frame *frame = (CL_Frame *) owner;
92 frame->set_style(new CL_Frame_ZZ(frame, this));
93 }
94 else if (type == "inputbox")
95 {
96 CL_InputBox *inputbox = (CL_InputBox *) owner;
97 inputbox->set_style(new CL_InputBox_ZZ(inputbox, this));
98 }
99 else if (type == "listbox")
100 {
101 CL_ListBox *listbox = (CL_ListBox *) owner;
102 listbox->set_style(new CL_ListBox_ZZ(listbox, this));
103 }
104 else if (type == "scrollbar")
105 {
106 CL_ScrollBar *scrollbar = (CL_ScrollBar *) owner;
107 scrollbar->set_style(new CL_ScrollBar_ZZ(scrollbar, this));
108 }
109 else if (type == "checkbox")
110 {
111 CL_CheckBox *checkbox = (CL_CheckBox *) owner;
112 checkbox->set_style(new CL_CheckBox_ZZ(checkbox, this));
113 }
114 else if (type == "label")
115 {
116 CL_Label *label = (CL_Label *) owner;
117 label->set_style(new CL_Label_ZZ(label, this));
118 }
119 // else
120 // {
121 // CL_StyleManager::connect_styles(type, owner);
122 // }
123 }
124
125 void CL_StyleManager_ZZ::draw_rounded_rect(CL_Rect const & rc, CL_Color const & clr)
126 {
127 CL_Display::draw_line(rc.left + 6, rc.top, rc.right - 6, rc.top, clr);
128 CL_Display::draw_line(rc.left + 6, rc.bottom - 1, rc.right - 6, rc.bottom - 1, clr);
129
130 CL_Display::draw_line(rc.left + 0, rc.top + 6, rc.left, rc.bottom - 6, clr);
131 CL_Display::draw_line(rc.right - 1, rc.top + 6, rc.right - 1, rc.bottom - 6, clr);
132
133 // left
134 {
135 CL_Display::draw_line(rc.left + 1, rc.top + 6, rc.left + 1, rc.top + 4, clr);
136 CL_Display::draw_pixel(rc.left + 2, rc.top + 3, clr);
137 CL_Display::draw_pixel(rc.left + 3, rc.top + 2, clr);
138 CL_Display::draw_line(rc.left + 4, rc.top + 1, rc.left + 6, rc.top + 1, clr);
139
140
141 CL_Display::draw_line(rc.left + 1, rc.bottom - 1 - 5, rc.left + 1, rc.bottom - 1 - 3, clr);
142 CL_Display::draw_pixel(rc.left + 2, rc.bottom - 1 - 3, clr);
143 CL_Display::draw_pixel(rc.left + 3, rc.bottom - 1 - 2, clr);
144 CL_Display::draw_line(rc.left + 4, rc.bottom - 1 - 1, rc.left + 6, rc.bottom - 1 - 1, clr);
145 }
146 // right
147 {
148 CL_Display::draw_line(rc.right - 1 - 1, rc.top + 4, rc.right - 1 - 1, rc.top + 6, clr);
149 CL_Display::draw_pixel(rc.right - 1 - 2, rc.top + 3, clr);
150 CL_Display::draw_pixel(rc.right - 1 - 3, rc.top + 2, clr);
151 CL_Display::draw_line(rc.right - 1 - 3, rc.top + 1, rc.right - 1 - 5, rc.top + 1, clr);
152
153
154 CL_Display::draw_line(rc.right - 1 - 1, rc.bottom - 1 - 5, rc.right - 1 - 1, rc.bottom - 1 - 3, clr);
155 CL_Display::draw_pixel(rc.right - 1 - 2, rc.bottom - 1 - 3, clr);
156 CL_Display::draw_pixel(rc.right - 1 - 3, rc.bottom - 1 - 2, clr);
157 CL_Display::draw_line(rc.right - 1 - 3, rc.bottom - 1 - 1, rc.right - 1 - 5, rc.bottom - 1 - 1, clr);
158 }
159 }
160
161 void CL_StyleManager_ZZ::fill_rounded_rect(CL_Rect const & rc, CL_Color const & clr)
162 {
163 // main
164 CL_Display::fill_rect(CL_Rect(rc.left + 6, rc.top, rc.right - 6, rc.bottom - 1), clr);
165
166 // left
167 {
168 CL_Display::draw_line(rc.left, rc.top + 6, rc.left, rc.bottom - 6 - 1, clr);
169 CL_Display::draw_line(rc.left + 1, rc.top + 6 - 2, rc.left + 1, rc.bottom - 6 - 1 + 2, clr);
170 CL_Display::draw_line(rc.left + 2, rc.top + 6 - 3, rc.left + 2, rc.bottom - 6 - 1 + 3, clr);
171 CL_Display::draw_line(rc.left + 3, rc.top + 6 - 4, rc.left + 3, rc.bottom - 6 - 1 + 4, clr);
172 CL_Display::draw_line(rc.left + 4, rc.top + 6 - 5, rc.left + 4, rc.bottom - 6 - 1 + 5, clr);
173 CL_Display::draw_line(rc.left + 5, rc.top + 6 - 5, rc.left + 5, rc.bottom - 6 - 1 + 5, clr);
174 }
175 // right
176 {
177 CL_Display::draw_line(rc.right - 1, rc.top + 6, rc.right - 1, rc.bottom - 6 - 1, clr);
178 CL_Display::draw_line(rc.right - 1 - 1, rc.top + 6 - 2, rc.right - 1 - 1, rc.bottom - 6 - 1 + 2, clr);
179 CL_Display::draw_line(rc.right - 1 - 2, rc.top + 6 - 3, rc.right - 1 - 2, rc.bottom - 6 - 1 + 3, clr);
180 CL_Display::draw_line(rc.right - 1 - 3, rc.top + 6 - 4, rc.right - 1 - 3, rc.bottom - 6 - 1 + 4, clr);
181 CL_Display::draw_line(rc.right - 1 - 4, rc.top + 6 - 5, rc.right - 1 - 4, rc.bottom - 6 - 1 + 5, clr);
182 CL_Display::draw_line(rc.right - 1 - 5, rc.top + 6 - 5, rc.right - 1 - 5, rc.bottom - 6 - 1 + 5, clr);
183 }
184 }
185
186 #pragma warning ( pop )