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