1 #include <lib/gui/epixmap.h>
2 #include <lib/gdi/epng.h>
3 #include <lib/gui/ewidgetdesktop.h>
5 ePixmap::ePixmap(eWidget *parent)
6 :eWidget(parent), m_alphatest(false), m_scale(false), m_have_border_color(false), m_border_width(0)
10 void ePixmap::setAlphatest(int alphatest)
12 m_alphatest = alphatest;
13 setTransparent(alphatest);
16 void ePixmap::setScale(int scale)
25 void ePixmap::setPixmap(gPixmap *pixmap)
28 event(evtChangedPixmap);
31 void ePixmap::setPixmap(ePtr<gPixmap> &pixmap)
34 event(evtChangedPixmap);
37 void ePixmap::setPixmapFromFile(const char *filename)
39 loadPNG(m_pixmap, filename);
43 eDebug("ePixmap::setPixmapFromFile: loadPNG failed");
47 // TODO: This only works for desktop 0
48 getDesktop(0)->makeCompatiblePixmap(*m_pixmap);
49 event(evtChangedPixmap);
52 void ePixmap::setBorderWidth(int pixel)
58 void ePixmap::setBorderColor(const gRGB &color)
61 m_have_border_color=true;
65 void ePixmap::checkSize()
67 /* when we have no pixmap, or a pixmap of different size, we need
68 to enable transparency in any case. */
69 if (m_pixmap && m_pixmap->size() == size() && !m_alphatest)
76 int ePixmap::event(int event, void *data, void *data2)
82 ePtr<eWindowStyle> style;
87 // we don't clear the background before because of performance reasons.
88 // when the pixmap is too small to fit the whole widget area, the widget is
89 // transparent anyway, so the background is already painted.
90 // eWidget::event(event, data, data2);
92 gPainter &painter = *(gPainter*)data2;
98 else if (m_alphatest == 1)
99 flags = gPainter::BT_ALPHATEST;
100 else if (m_alphatest == 2)
101 flags = gPainter::BT_ALPHABLEND;
103 painter.blitScale(m_pixmap, eRect(ePoint(0, 0), size()), eRect(), flags);
105 painter.blit(m_pixmap, ePoint(0, 0), eRect(), flags);
109 if (m_have_border_color)
110 painter.setForegroundColor(m_border_color);
111 painter.fill(eRect(0, 0, s.width(), m_border_width));
112 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
113 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
114 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
118 case evtChangedPixmap:
126 return eWidget::event(event, data, data2);