- reenable lcd support
[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 #include <lib/gdi/glcddc.h>
18 #ifdef WITH_SDL
19 #error
20 #include <lib/gdi/sdl.h>
21 #endif
22 #include <lib/gdi/font.h> 
23
24 #include <lib/gui/ewidget.h>
25 #include <lib/gui/ewidgetdesktop.h>
26 #include <lib/gui/elabel.h>
27 #include <lib/gui/ebutton.h>
28
29 #include <lib/gui/ewindow.h>
30
31 #include <lib/python/python.h>
32 #include <lib/python/connections.h>
33
34 #include <lib/gui/elistboxcontent.h>
35
36 #include <lib/driver/rc.h>
37
38 #include <lib/actions/action.h>
39
40 #include <lib/gdi/epng.h>
41
42 #ifdef OBJECT_DEBUG
43 int object_total_remaining;
44
45 void object_dump()
46 {
47         printf("%d items left\n", object_total_remaining);
48 }
49 #endif
50
51 void dumpRegion(const gRegion &region)
52 {
53         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
54                 region.extends.left(), region.extends.top(),
55                 region.extends.right(), region.extends.bottom(), region.rects.size());
56 #if 0
57         for (int y=0; y<region.extends.bottom(); ++y)
58         {
59                 for (int x=0; x<region.extends.right(); ++x)
60                 {
61                         unsigned char res = ' ';
62                         for (unsigned int i=0; i < region.rects.size(); ++i)
63                                 if (region.rects[i].contains(ePoint(x, y)))
64                                         res = '0' + i;
65                         fprintf(stderr, "%c", res);
66                 }
67                 fprintf(stderr, "\n");
68         }
69 #endif
70
71 }
72
73 eWidgetDesktop *wdsk, *lcddsk;
74
75 // typedef struct _object PyObject;
76
77 void print(int i)
78 {
79         printf("C++ says: it's a %d!!!\n", i);
80 }
81
82 PSignal1<void,int> keyPressed;
83
84 PSignal1<void,int> &keyPressedSignal()
85 {
86         return keyPressed;
87 }
88
89 void keyEvent(const eRCKey &key)
90 {
91         ePtr<eActionMap> ptr;
92         eActionMap::getInstance(ptr);
93         ptr->keyPressed(0, key.code, key.flags);
94 //      if (!key.flags)
95 //              keyPressed(key.code);
96 }
97
98 /************************************************/
99 #include <unistd.h>
100 #include <lib/components/scan.h>
101 #include <lib/dvb/idvb.h>
102 #include <lib/dvb/dvb.h>
103 #include <lib/dvb/db.h>
104 #include <lib/dvb/dvbtime.h>
105 #include <lib/dvb/epgcache.h>
106
107 class eMain: public eApplication, public Object
108 {
109         eInit init;
110         
111         ePtr<eDVBResourceManager> m_mgr;
112         ePtr<eDVBDB> m_dvbdb;
113         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
114         ePtr<eComponentScan> m_scan;
115 //      ePtr<eEPGCache> m_epgcache;
116
117 public:
118         eMain()
119         {
120                 init.setRunlevel(eAutoInitNumbers::main);
121
122                                 /* TODO: put into init */
123                 m_dvbdb = new eDVBDB();
124                 m_mgr = new eDVBResourceManager();
125                 m_locale_time_handler = new eDVBLocalTimeHandler();
126 //              m_epgcache = new eEPGCache();
127                 m_mgr->setChannelList(m_dvbdb);
128                 
129 //              m_scan = new eComponentScan();
130 //              m_scan->start();
131
132         }
133         
134         ~eMain()
135         {
136                 m_scan = 0;
137         }
138 };
139
140 /************************************************/
141
142
143 int main(int argc, char **argv)
144 {
145 #ifdef OBJECT_DEBUG
146         atexit(object_dump);
147 #endif
148
149
150         ePython python;
151         eMain main;
152         
153         int double_buffer = 0;
154
155 #if 1
156 #ifdef SDLDC
157         ePtr<gSDLDC> my_dc;
158         gSDLDC::getInstance(my_dc);
159 #else
160         ePtr<gFBDC> my_dc;
161         gFBDC::getInstance(my_dc);
162         
163         double_buffer = my_dc->haveDoubleBuffering();
164 #endif
165
166         ePtr<gLCDDC> my_lcd_dc;
167         gLCDDC::getInstance(my_lcd_dc);
168
169         fontRenderClass::getInstance()->AddFont(FONTDIR "/arial.ttf", "Arial", 100);
170
171         eWidgetDesktop dsk(eSize(720, 576));
172         eWidgetDesktop dsk_lcd(eSize(132, 64));
173         
174         if (double_buffer)
175         {
176                 eDebug(" - double buffering found, enable buffered graphics mode.");
177                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
178         }
179         
180         wdsk = &dsk;
181         lcddsk = &dsk_lcd;
182
183         dsk.setDC(my_dc);
184         dsk_lcd.setDC(my_lcd_dc);
185
186         ePtr<gPixmap> m_pm;
187         loadPNG(m_pm, "data/pal.png");
188         if (!m_pm)
189         {
190                 eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
191         } else
192                 dsk.setPalette(*m_pm);
193
194         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
195 #endif
196
197                 /* redrawing is done in an idle-timer, so we have to set the context */
198         dsk.setRedrawTask(main);
199         dsk_lcd.setRedrawTask(main);
200
201         eWindow *lcd_win = new eWindow(&dsk_lcd);
202         
203         lcd_win->setFlag(eWindow::wfNoBorder);
204         
205         lcd_win->move(ePoint(0, 0));
206         lcd_win->resize(eSize(132, 64));
207         
208         eLabel *lcd_label = new eLabel(lcd_win);
209         lcd_label->move(ePoint(0, 0));
210         lcd_label->resize(eSize(132, 64));
211         lcd_label->setText("bla bla bla, this lcd\nSUCKS!");
212
213         lcd_win->show();
214         
215         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
216         
217         printf("executing main\n");
218
219         python.execute("mytest", "__main__");
220
221 //      eApp->exec();
222
223         return 0;
224 }
225
226 eWidgetDesktop *getDesktop()
227 {
228         return wdsk;
229 }
230
231 void runMainloop()
232 {
233         eApp->exec();
234 }
235
236 void quitMainloop()
237 {
238         eApp->quit(0);
239 }