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, ePtr<gPixmap> &ptr)
219 setPixmap(bs, bp, *(ptr.operator->()));
222 void eWindowStyleSkinned::setPixmap(int bs, int bp, gPixmap &pixmap)
224 if ((bs >= bsMax) || (bs < 0))
228 for (int b = 1; b < bpMax; b <<= 1, ++i)
231 m_border[bs].m_pixmap[i] = &pixmap;
234 /* recalc border sizes */
235 m_border[bs].m_border_top = 0;
236 m_border[bs].m_border_left = 0;
237 m_border[bs].m_border_bottom = 0;
238 m_border[bs].m_border_right = 0;
240 for (int i = 0; i < 3; ++i)
241 if (m_border[bs].m_pixmap[i])
242 if (m_border[bs].m_border_top < m_border[bs].m_pixmap[i]->size().height())
243 m_border[bs].m_border_top = m_border[bs].m_pixmap[i]->size().height();
244 for (int i = 6; i < 9; ++i)
245 if (m_border[bs].m_pixmap[i])
246 if (m_border[bs].m_border_bottom < m_border[bs].m_pixmap[i]->size().height())
247 m_border[bs].m_border_bottom = m_border[bs].m_pixmap[i]->size().height();
249 if (m_border[bs].m_pixmap[3])
250 m_border[bs].m_border_left = m_border[bs].m_pixmap[3]->size().width();
252 m_border[bs].m_border_left = 0;
254 if (m_border[bs].m_pixmap[5])
255 m_border[bs].m_border_right = m_border[bs].m_pixmap[5]->size().width();
257 m_border[bs].m_border_right = 0;
259 /* eDebug("recalced border size for %d: %d:%d %d:%d",
261 m_border[bs].m_border_left, m_border[bs].m_border_top,
262 m_border[bs].m_border_right, m_border[bs].m_border_bottom); */
265 void eWindowStyleSkinned::setColor(int what, const gRGB &col)
267 if ((what < colMax) && (what >= 0))
271 void eWindowStyleSkinned::setTitleOffset(const eSize &offset)
273 m_title_offset = offset;
276 void eWindowStyleSkinned::setTitleFont(gFont *fnt)