lib/dvb/frontend.cpp: DTV frontend api support is now working (DVB-S2 is also working...
[enigma2.git] / lib / gui / epixmap.cpp
1 #include <lib/gui/epixmap.h>
2 #include <lib/gdi/epng.h>
3 #include <lib/gui/ewidgetdesktop.h>
4
5 ePixmap::ePixmap(eWidget *parent)
6         :eWidget(parent), m_alphatest(false), m_scale(false)
7 {
8 }
9
10 void ePixmap::setAlphatest(int alphatest)
11 {
12         m_alphatest = alphatest;
13         setTransparent(alphatest);
14 }
15
16 void ePixmap::setScale(int scale)
17 {
18         if (m_scale != scale)
19         {
20                 m_scale = scale;
21                 invalidate();
22         }
23 }
24
25 void ePixmap::setPixmap(gPixmap *pixmap)
26 {
27         m_pixmap = pixmap;
28         event(evtChangedPixmap);
29 }
30
31 void ePixmap::setPixmap(ePtr<gPixmap> &pixmap)
32 {
33         m_pixmap = pixmap;
34         event(evtChangedPixmap);
35 }
36
37 void ePixmap::setPixmapFromFile(const char *filename)
38 {
39         loadPNG(m_pixmap, filename);
40         
41         if (!m_pixmap)
42         {
43                 eDebug("ePixmap::setPixmapFromFile: loadPNG failed");
44                 return;
45         }
46         
47                 // TODO: This only works for desktop 0
48         getDesktop(0)->makeCompatiblePixmap(*m_pixmap);
49         event(evtChangedPixmap);
50 }
51
52 void ePixmap::checkSize()
53 {
54                         /* when we have no pixmap, or a pixmap of different size, we need 
55            to enable transparency in any case. */
56         if (m_pixmap && m_pixmap->size() == size() && !m_alphatest)
57                 setTransparent(0);
58         else
59                 setTransparent(1);
60                 /* fall trough. */
61 }
62
63 int ePixmap::event(int event, void *data, void *data2)
64 {
65         switch (event)
66         {
67         case evtPaint:
68         {
69                 ePtr<eWindowStyle> style;
70                 
71                 getStyle(style);
72
73 //      we don't clear the background before because of performance reasons.
74 //      when the pixmap is too small to fit the whole widget area, the widget is
75 //      transparent anyway, so the background is already painted.
76 //              eWidget::event(event, data, data2); 
77
78                 gPainter &painter = *(gPainter*)data2;
79                 if (m_pixmap)
80                 {
81                         int flags = 0;
82                         if (m_alphatest == 0)
83                                 flags = 0;
84                         else if (m_alphatest == 1)
85                                 flags = gPainter::BT_ALPHATEST;
86                         else if (m_alphatest == 2)
87                                 flags = gPainter::BT_ALPHABLEND;
88                         if (m_scale)
89                                 painter.blitScale(m_pixmap, eRect(ePoint(0, 0), size()), eRect(), flags);
90                         else
91                                 painter.blit(m_pixmap, ePoint(0, 0), eRect(), flags);
92                 }
93
94                 return 0;
95         }
96         case evtChangedPixmap:
97                 checkSize();
98                 invalidate();
99                 return 0;
100         case evtChangedSize:
101                 checkSize();
102                         /* fall trough. */
103         default:
104                 return eWidget::event(event, data, data2);
105         }
106 }