- sdl is now default output
[enigma2.git] / lib / gui / ewindowstyleskinned.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/gdi/esize.h>
3 #include <lib/gui/ewindow.h>
4 #include <lib/gui/ewindowstyle.h>
5 #include <lib/gui/ewindowstyleskinned.h>
6
7 DEFINE_REF(eWindowStyleSkinned);
8
9 eWindowStyleSkinned::eWindowStyleSkinned()
10 {
11         m_background_color = gRGB(0x808080);
12 }
13
14 void eWindowStyleSkinned::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
15 {
16 //      eDebug("handle new size: %d x %d", size.width(), size.height());
17         
18         size = eSize(
19                         size.width() + m_border[bsWindow].m_border_left + m_border[bsWindow].m_border_right,
20                         size.height() + m_border[bsWindow].m_border_top + m_border[bsWindow].m_border_bottom
21                 );
22         
23         offset = eSize(-m_border[bsWindow].m_border_left, -m_border[bsWindow].m_border_top);
24         
25         eWidget *child = wnd->child();
26         
27         wnd->m_clip_region = eRect(ePoint(0, 0), size);
28         
29         child->move(ePoint(m_border[bsWindow].m_border_left, m_border[bsWindow].m_border_top));
30         child->resize(eSize(size.width() - m_border[bsWindow].m_border_left - m_border[bsWindow].m_border_right, size.height() - m_border[bsWindow].m_border_top - m_border[bsWindow].m_border_bottom));
31 }
32
33 void eWindowStyleSkinned::paintWindowDecoration(eWindow *wnd, gPainter &painter, const std::string &title)
34 {
35         drawBorder(painter, eRect(ePoint(0, 0), wnd->size()), m_border[bsWindow], bpAll);
36 }
37
38 void eWindowStyleSkinned::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
39 {
40         painter.setBackgroundColor(m_background_color);
41         painter.clear();
42 }
43
44 void eWindowStyleSkinned::setStyle(gPainter &painter, int what)
45 {
46         switch (what)
47         {
48         case styleLabel:
49                 painter.setForegroundColor(gColor(0x1F));
50                 break;
51         case styleListboxSelected:
52                 painter.setForegroundColor(gColor(0x1F));
53                 painter.setBackgroundColor(gColor(0x1A));
54                 break;
55         case styleListboxNormal:
56                 painter.setForegroundColor(gColor(0x1C));
57                 painter.setBackgroundColor(m_background_color);
58                 break;
59         case styleListboxMarked:
60                 painter.setForegroundColor(gColor(0x2F));
61                 painter.setBackgroundColor(gColor(0x2A));
62                 break;
63         }
64 }
65
66 void eWindowStyleSkinned::drawFrame(gPainter &painter, const eRect &frame, int what)
67 {
68         int bs;
69         switch (what)
70         {
71         case frameButton:
72                 bs = bsButton;
73                 break;
74         case frameListboxEntry:
75                 bs = bsListboxEntry;
76                 break;
77         default:
78                 eWarning("invalid frame style %d", what);
79                 return;
80         }
81         drawBorder(painter, frame, m_border[bs], bpAll);
82 }
83
84 void eWindowStyleSkinned::drawBorder(gPainter &painter, const eRect &pos, struct borderSet &border, int what)
85 {
86         int x = pos.left(), xm = pos.right();
87         
88         ePtr<gPixmap> 
89                 &tl = border.m_pixmap[bpiTopLeft],
90                 &t  = border.m_pixmap[bpiTop],
91                 &tr = border.m_pixmap[bpiTopRight],
92                 &l  = border.m_pixmap[bpiLeft],
93                 &r  = border.m_pixmap[bpiRight],
94                 &bl = border.m_pixmap[bpiBottomLeft],
95                 &b  = border.m_pixmap[bpiBottom],
96                 &br = border.m_pixmap[bpiBottomRight];
97         
98         if (tl)
99         {
100                 painter.blit(tl, ePoint(x, pos.top()));
101                 x += tl->size().width();
102         }
103         
104         if (tr)
105         {
106                 xm -= tr->size().width();
107                 painter.blit(tr, ePoint(xm, pos.top()), pos);
108         }
109
110         if (t)
111         {
112                 while (x < xm)
113                 {
114                         painter.blit(t, ePoint(x, pos.top()), eRect(x, pos.top(), xm - x, pos.height()));
115                         x += t->size().width();
116                 }
117         }
118         
119         x = pos.left();
120         xm = pos.right();
121         
122         if (bl)
123         {
124                 painter.blit(bl, ePoint(pos.left(), pos.bottom()-bl->size().height()));
125                 x += bl->size().width();
126         }
127         
128         if (br)
129         {
130                 xm -= br->size().width();
131                 painter.blit(br, ePoint(xm, pos.bottom()-br->size().height()), eRect(x, pos.bottom()-br->size().height(), pos.width() - x, bl->size().height()));
132         }
133         
134         if (b)
135         {
136                 while (x < xm)
137                 {
138                         painter.blit(b, ePoint(x, pos.bottom()-b->size().height()), eRect(x, pos.bottom()-b->size().height(), xm - x, pos.height()));
139                         x += b->size().width();
140                 }
141         }
142         
143         int y = 0;
144         if (tl)
145                 y = tl->size().height();
146         
147         y += pos.top();
148         
149         int ym = pos.bottom();
150         if (bl)
151                 ym -= bl->size().height();
152         
153         if (l)
154         {
155                 while (y < ym)
156                 {
157                         painter.blit(l, ePoint(pos.left(), y), eRect(pos.left(), y, pos.width(), ym - y));
158                         y += l->size().height();
159                 }
160         }
161         
162         y = 0;
163         
164         if (tr)
165                 y = tr->size().height();
166         
167         y += pos.top();
168         
169         ym = pos.bottom();
170         if (br)
171                 ym -= br->size().height();
172         
173         if (r)
174         {
175                 while (y < ym)
176                 {
177                         painter.blit(r, ePoint(pos.right() - r->size().width(), y), eRect(pos.right()-r->size().width(), y, r->size().width(), ym - y));
178                         y += r->size().height();
179                 }
180         }
181 }
182
183 RESULT eWindowStyleSkinned::getFont(int what, ePtr<gFont> &fnt)
184 {
185         fnt = 0;
186         switch (what)
187         {
188         case fontStatic:
189                 fnt = new gFont("Arial", 12);
190                 break;
191         case fontButton:
192                 fnt = new gFont("Arial", 20);
193                 break;
194         case fontTitlebar:
195                 fnt = new gFont("Arial", 25);
196                 break;
197         default:
198                 return -1;
199         }
200         return 0;
201 }
202
203 void eWindowStyleSkinned::setPixmap(int bs, int bp, gPixmap &pixmap)
204 {
205         if ((bs >= bsMax) || (bs < 0))
206                 return;
207         
208         int i = 0;
209         for (int b = 1; b < bpMax; b <<= 1, ++i)
210         {
211                 if (bp & b)
212                         m_border[bs].m_pixmap[i] = &pixmap;
213         }
214         
215                 /* recalc border sizes */
216         m_border[bs].m_border_top = 0;
217         m_border[bs].m_border_left = 0;
218         m_border[bs].m_border_bottom = 0;
219         m_border[bs].m_border_right = 0;
220         
221         for (int i = 0; i < 3; ++i)
222                 if (m_border[bs].m_pixmap[i])
223                         if (m_border[bs].m_border_top < m_border[bs].m_pixmap[i]->size().height())
224                                 m_border[bs].m_border_top = m_border[bs].m_pixmap[i]->size().height();
225         for (int i = 6; i < 9; ++i)
226                 if (m_border[bs].m_pixmap[i])
227                         if (m_border[bs].m_border_bottom < m_border[bs].m_pixmap[i]->size().height())
228                                 m_border[bs].m_border_bottom = m_border[bs].m_pixmap[i]->size().height();
229         for (int i = 0; i < 9; i += 3)
230                 if (m_border[bs].m_pixmap[i])
231                         if (m_border[bs].m_border_left < m_border[bs].m_pixmap[i]->size().width())
232                                 m_border[bs].m_border_left = m_border[bs].m_pixmap[i]->size().width();
233         for (int i = 2; i < 9; i += 3)
234                 if (m_border[bs].m_pixmap[i])
235                         if (m_border[bs].m_border_right < m_border[bs].m_pixmap[i]->size().width())
236                                 m_border[bs].m_border_right = m_border[bs].m_pixmap[i]->size().width();
237         eDebug("recalced border size for %d: %d:%d %d:%d",
238                 bs, 
239                 m_border[bs].m_border_left, m_border[bs].m_border_top, 
240                 m_border[bs].m_border_right, m_border[bs].m_border_bottom); 
241 }
242
243 void eWindowStyleSkinned::setDefaultBackgroundColor(const gRGB &back)
244 {
245         m_background_color = back;
246         eDebug("set default background color!");
247 }
248