- create DCs for buffered mode
[enigma2.git] / main / enigma.cpp
1 #undef WITH_SDL
2 #ifdef WITH_SDL
3 #error
4 #define SDLDC
5 #endif
6 #include <stdio.h>
7 #include <libsig_comp.h>
8 #include <lib/base/ebase.h>
9 #include <lib/base/eerror.h>
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12
13 #include <unistd.h>
14
15 #include <lib/gdi/grc.h>
16 #include <lib/gdi/gfbdc.h>
17 #ifdef WITH_SDL
18 #error
19 #include <lib/gdi/sdl.h>
20 #endif
21 #include <lib/gdi/font.h> 
22
23 #include <lib/gui/ewidget.h>
24 #include <lib/gui/ewidgetdesktop.h>
25 #include <lib/gui/elabel.h>
26 #include <lib/gui/ebutton.h>
27
28 #include <lib/gui/ewindow.h>
29
30 #include <lib/python/python.h>
31 #include <lib/python/connections.h>
32
33 #include <lib/gui/elistboxcontent.h>
34
35 #include <lib/driver/rc.h>
36
37 #include <lib/actions/action.h>
38
39 #include <lib/gdi/epng.h>
40
41 #ifdef OBJECT_DEBUG
42 int object_total_remaining;
43
44 void object_dump()
45 {
46         printf("%d items left\n", object_total_remaining);
47 }
48 #endif
49
50 void dumpRegion(const gRegion &region)
51 {
52         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
53                 region.extends.left(), region.extends.top(),
54                 region.extends.right(), region.extends.bottom(), region.rects.size());
55         for (int y=0; y<region.extends.bottom(); ++y)
56         {
57                 for (int x=0; x<region.extends.right(); ++x)
58                 {
59                         unsigned char res = ' ';
60                         for (unsigned int i=0; i < region.rects.size(); ++i)
61                                 if (region.rects[i].contains(ePoint(x, y)))
62                                         res = '0' + i;
63                         fprintf(stderr, "%c", res);
64                 }
65                 fprintf(stderr, "\n");
66         }
67 }
68
69 eWidgetDesktop *wdsk;
70
71 // typedef struct _object PyObject;
72
73 void print(int i)
74 {
75         printf("C++ says: it's a %d!!!\n", i);
76 }
77
78 PSignal1<void,int> keyPressed;
79
80 PSignal1<void,int> &keyPressedSignal()
81 {
82         return keyPressed;
83 }
84
85 void keyEvent(const eRCKey &key)
86 {
87         ePtr<eActionMap> ptr;
88         eActionMap::getInstance(ptr);
89         ptr->keyPressed(0, key.code, key.flags);
90 //      if (!key.flags)
91 //              keyPressed(key.code);
92 }
93
94 /************************************************/
95 #include <unistd.h>
96 #include <lib/components/scan.h>
97 #include <lib/dvb/idvb.h>
98 #include <lib/dvb/dvb.h>
99 #include <lib/dvb/db.h>
100 #include <lib/dvb/dvbtime.h>
101 #include <lib/dvb/epgcache.h>
102
103 class eMain: public eApplication, public Object
104 {
105         eInit init;
106         
107         ePtr<eDVBResourceManager> m_mgr;
108         ePtr<eDVBDB> m_dvbdb;
109         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
110         ePtr<eComponentScan> m_scan;
111         ePtr<eEPGCache> m_epgcache;
112
113 public:
114         eMain()
115         {
116                 init.setRunlevel(eAutoInitNumbers::main);
117
118                                 /* TODO: put into init */
119                 m_dvbdb = new eDVBDB();
120                 m_mgr = new eDVBResourceManager();
121                 m_locale_time_handler = new eDVBLocalTimeHandler();
122                 m_epgcache = new eEPGCache();
123                 m_mgr->setChannelList(m_dvbdb);
124                 
125 //              m_scan = new eComponentScan();
126 //              m_scan->start();
127
128         }
129         
130         ~eMain()
131         {
132                 m_scan = 0;
133         }
134 };
135
136 /************************************************/
137
138
139 int main(int argc, char **argv)
140 {
141 #ifdef OBJECT_DEBUG
142         atexit(object_dump);
143 #endif
144
145
146         ePython python;
147         eMain main;
148
149 #if 1
150 #ifdef SDLDC
151         ePtr<gSDLDC> my_dc;
152         gSDLDC::getInstance(my_dc);
153 #else
154         ePtr<gFBDC> my_dc;
155         gFBDC::getInstance(my_dc);
156 #endif
157
158         fontRenderClass::getInstance()->AddFont(FONTDIR "/arial.ttf", "Arial", 100);
159
160         eWidgetDesktop dsk(eSize(720, 576));
161         
162         wdsk = &dsk;
163
164
165         dsk.setDC(my_dc);
166
167         ePtr<gPixmap> m_pm;
168         loadPNG(m_pm, "data/pal.png");
169         if (!m_pm)
170         {
171                 eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
172         } else
173                 dsk.setPalette(*m_pm);
174
175         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
176 #endif
177
178                 /* redrawing is done in an idle-timer, so we have to set the context */
179         dsk.setRedrawTask(main);
180         
181         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
182         
183         printf("executing main\n");
184
185         python.execute("mytest", "__main__");
186
187 //      eApp->exec();
188
189         return 0;
190 }
191
192 eWidgetDesktop *getDesktop()
193 {
194         return wdsk;
195 }
196
197 void runMainloop()
198 {
199         eApp->exec();
200 }
201
202 void quitMainloop()
203 {
204         eApp->quit(0);
205 }