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>
7 DEFINE_REF(eWindowStyleSkinned);
9 eWindowStyleSkinned::eWindowStyleSkinned()
11 // m_background_color = gRGB(0x808080);
13 // TODO: initialize colors!!
16 void eWindowStyleSkinned::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
18 // eDebug("handle new size: %d x %d", size.width(), size.height());
21 size.width() + m_border[bsWindow].m_border_left + m_border[bsWindow].m_border_right,
22 size.height() + m_border[bsWindow].m_border_top + m_border[bsWindow].m_border_bottom
25 offset = eSize(-m_border[bsWindow].m_border_left, -m_border[bsWindow].m_border_top);
27 eWidget *child = wnd->child();
29 wnd->m_clip_region = eRect(ePoint(0, 0), size);
31 child->move(ePoint(m_border[bsWindow].m_border_left, m_border[bsWindow].m_border_top));
32 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));
35 void eWindowStyleSkinned::paintWindowDecoration(eWindow *wnd, gPainter &painter, const std::string &title)
37 drawBorder(painter, eRect(ePoint(0, 0), wnd->size()), m_border[bsWindow], bpAll);
41 painter.setBackgroundColor(m_color[colWindowTitleBackground]);
42 painter.setForegroundColor(m_color[colWindowTitleForeground]);
43 painter.setFont(m_fnt);
44 painter.renderText(eRect(m_title_offset.width(), m_title_offset.height(), wnd->size().width() - m_title_offset.width(), m_border[bsWindow].m_border_top - m_title_offset.height()), title);
48 void eWindowStyleSkinned::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
50 painter.setBackgroundColor(m_color[colBackground]);
54 void eWindowStyleSkinned::setStyle(gPainter &painter, int what)
59 painter.setForegroundColor(m_color[colLabelForeground]);
61 case styleListboxSelected:
62 painter.setForegroundColor(m_color[colListboxSelectedForeground]);
63 painter.setBackgroundColor(m_color[colListboxSelectedBackground]);
65 case styleListboxNormal:
66 painter.setForegroundColor(m_color[colListboxForeground]);
67 painter.setBackgroundColor(m_color[colListboxBackground]);
69 case styleListboxMarked:
70 painter.setForegroundColor(m_color[colListboxMarkedForeground]);
71 painter.setBackgroundColor(m_color[colListboxMarkedBackground]);
73 case styleListboxMarkedAndSelected:
74 painter.setForegroundColor(m_color[colListboxMarkedAndSelectedForeground]);
75 painter.setBackgroundColor(m_color[colListboxMarkedAndSelectedBackground]);
80 void eWindowStyleSkinned::drawFrame(gPainter &painter, const eRect &frame, int what)
88 case frameListboxEntry:
92 eWarning("invalid frame style %d", what);
95 drawBorder(painter, frame, m_border[bs], bpAll);
98 void eWindowStyleSkinned::drawBorder(gPainter &painter, const eRect &pos, struct borderSet &border, int what)
100 int x = pos.left(), xm = pos.right();
103 &tl = border.m_pixmap[bpiTopLeft],
104 &t = border.m_pixmap[bpiTop],
105 &tr = border.m_pixmap[bpiTopRight],
106 &l = border.m_pixmap[bpiLeft],
107 &r = border.m_pixmap[bpiRight],
108 &bl = border.m_pixmap[bpiBottomLeft],
109 &b = border.m_pixmap[bpiBottom],
110 &br = border.m_pixmap[bpiBottomRight];
114 painter.blit(tl, ePoint(x, pos.top()));
115 x += tl->size().width();
120 xm -= tr->size().width();
121 painter.blit(tr, ePoint(xm, pos.top()), pos);
128 painter.blit(t, ePoint(x, pos.top()), eRect(x, pos.top(), xm - x, pos.height()));
129 x += t->size().width();
138 painter.blit(bl, ePoint(pos.left(), pos.bottom()-bl->size().height()));
139 x += bl->size().width();
144 xm -= br->size().width();
145 painter.blit(br, ePoint(xm, pos.bottom()-br->size().height()), eRect(x, pos.bottom()-br->size().height(), pos.width() - x, bl->size().height()));
152 painter.blit(b, ePoint(x, pos.bottom()-b->size().height()), eRect(x, pos.bottom()-b->size().height(), xm - x, pos.height()));
153 x += b->size().width();
159 y = tl->size().height();
163 int ym = pos.bottom();
165 ym -= bl->size().height();
171 painter.blit(l, ePoint(pos.left(), y), eRect(pos.left(), y, pos.width(), ym - y));
172 y += l->size().height();
179 y = tr->size().height();
185 ym -= br->size().height();
191 painter.blit(r, ePoint(pos.right() - r->size().width(), y), eRect(pos.right()-r->size().width(), y, r->size().width(), ym - y));
192 y += r->size().height();
197 RESULT eWindowStyleSkinned::getFont(int what, ePtr<gFont> &fnt)
203 fnt = new gFont("Regular", 12);
206 fnt = new gFont("Regular", 20);
209 fnt = new gFont("Regular", 25);
217 void eWindowStyleSkinned::setPixmap(int bs, int bp, gPixmap &pixmap)
219 if ((bs >= bsMax) || (bs < 0))
223 for (int b = 1; b < bpMax; b <<= 1, ++i)
226 m_border[bs].m_pixmap[i] = &pixmap;
229 /* recalc border sizes */
230 m_border[bs].m_border_top = 0;
231 m_border[bs].m_border_left = 0;
232 m_border[bs].m_border_bottom = 0;
233 m_border[bs].m_border_right = 0;
235 for (int i = 0; i < 3; ++i)
236 if (m_border[bs].m_pixmap[i])
237 if (m_border[bs].m_border_top < m_border[bs].m_pixmap[i]->size().height())
238 m_border[bs].m_border_top = m_border[bs].m_pixmap[i]->size().height();
239 for (int i = 6; i < 9; ++i)
240 if (m_border[bs].m_pixmap[i])
241 if (m_border[bs].m_border_bottom < m_border[bs].m_pixmap[i]->size().height())
242 m_border[bs].m_border_bottom = m_border[bs].m_pixmap[i]->size().height();
244 if (m_border[bs].m_pixmap[3])
245 m_border[bs].m_border_left = m_border[bs].m_pixmap[3]->size().width();
247 m_border[bs].m_border_left = 0;
249 if (m_border[bs].m_pixmap[5])
250 m_border[bs].m_border_right = m_border[bs].m_pixmap[5]->size().width();
252 m_border[bs].m_border_right = 0;
254 eDebug("recalced border size for %d: %d:%d %d:%d",
256 m_border[bs].m_border_left, m_border[bs].m_border_top,
257 m_border[bs].m_border_right, m_border[bs].m_border_bottom);
260 void eWindowStyleSkinned::setColor(int what, const gRGB &col)
262 if ((what < colMax) && (what >= 0))
266 void eWindowStyleSkinned::setTitleOffset(const eSize &offset)
268 m_title_offset = offset;
271 void eWindowStyleSkinned::setTitleFont(gFont *fnt)