rotor turning with measure input power is now working
[enigma2.git] / lib / gdi / sdl.cpp
1 #include <lib/gdi/sdl.h>
2
3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
5
6 #include <SDL.h>
7
8 gSDLDC *gSDLDC::m_instance;
9
10 gSDLDC::gSDLDC()
11 {
12         if (SDL_Init(SDL_INIT_VIDEO) < 0)
13         {
14                 eWarning("Could not initialize SDL: %s", SDL_GetError());
15                 return;
16         }
17         
18         m_screen = SDL_SetVideoMode(720, 576, 32, SDL_HWSURFACE);
19         if (!m_screen)
20         {
21                 eWarning("Could not create SDL surface: %s", SDL_GetError());
22                 return;
23         }
24
25         m_instance=this;
26         
27         m_surface.type = 0;
28         m_surface.x = m_screen->w;
29         m_surface.y = m_screen->h;
30         m_surface.bpp = m_screen->format->BitsPerPixel;
31         m_surface.bypp = m_screen->format->BytesPerPixel;
32         m_surface.stride = m_screen->pitch;
33         m_surface.data = m_screen->pixels;
34         m_surface.clut.colors=256;
35         m_surface.clut.data=new gRGB[m_surface.clut.colors];
36         
37         m_pixmap = new gPixmap(&m_surface);
38         
39         memset(m_surface.clut.data, 0, sizeof(*m_surface.clut.data)*m_surface.clut.colors);
40 }
41
42 gSDLDC::~gSDLDC()
43 {
44         SDL_Quit();
45         m_instance=0;
46 }
47
48 void gSDLDC::setPalette()
49 {
50         if (!m_surface.clut.data)
51                 return;
52         
53 /*      for (int i=0; i<256; ++i)
54         {
55                 fb->CMAP()->red[i]=ramp[m_surface.clut.data[i].r]<<8;
56                 fb->CMAP()->green[i]=ramp[m_surface.clut.data[i].g]<<8;
57                 fb->CMAP()->blue[i]=ramp[m_surface.clut.data[i].b]<<8;
58                 fb->CMAP()->transp[i]=rampalpha[m_surface.clut.data[i].a]<<8;
59                 if (!fb->CMAP()->red[i])
60                         fb->CMAP()->red[i]=0x100;
61         }
62         fb->PutCMAP(); */
63 }
64
65 void gSDLDC::exec(gOpcode *o)
66 {
67         switch (o->opcode)
68         {
69         case gOpcode::setPalette:
70         {
71                 gDC::exec(o);
72                 setPalette();
73                 break;
74         }
75         case gOpcode::flush:
76                 SDL_Flip(m_screen);
77                 eDebug("FLUSH");
78                 break;
79         default:
80                 gDC::exec(o);
81                 break;
82         }
83 }
84
85 eAutoInitPtr<gSDLDC> init_gSDLDC(eAutoInitNumbers::graphic-1, "gSDLDC");