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