1 #include <lib/gdi/sdl.h>
2 #include <lib/actions/action.h>
3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
5 #include <lib/driver/input_fake.h>
6 #include <lib/driver/rcsdl.h>
10 gSDLDC::gSDLDC() : m_pump(eApp, 1)
12 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
13 eWarning("Could not initialize SDL: %s", SDL_GetError());
17 setResolution(720, 576);
19 CONNECT(m_pump.recv_msg, gSDLDC::pumpEvent);
22 m_surface.clut.colors = 256;
23 m_surface.clut.data = new gRGB[m_surface.clut.colors];
25 m_pixmap = new gPixmap(&m_surface);
27 memset(m_surface.clut.data, 0, sizeof(*m_surface.clut.data)*m_surface.clut.colors);
39 void gSDLDC::keyEvent(const SDL_Event &event)
41 eSDLInputDriver *driver = eSDLInputDriver::getInstance();
43 eDebug("SDL Key %s: key=%d", (event.type == SDL_KEYDOWN) ? "Down" : "Up", event.key.keysym.sym);
46 driver->keyPressed(&event.key);
49 void gSDLDC::pumpEvent(const SDL_Event &event)
58 extern void quitMainloop(int exit_code);
64 void gSDLDC::pushEvent(enum event code, void *data1, void *data2)
68 event.type = SDL_USEREVENT;
69 event.user.code = code;
70 event.user.data1 = data1;
71 event.user.data2 = data2;
73 SDL_PushEvent(&event);
76 void gSDLDC::exec(const gOpcode *o)
89 void gSDLDC::setResolution(int xres, int yres)
91 pushEvent(EV_SET_VIDEO_MODE, (void *)xres, (void *)yres);
98 void gSDLDC::evSetVideoMode(unsigned long xres, unsigned long yres)
100 m_screen = SDL_SetVideoMode(xres, yres, 32, SDL_HWSURFACE);
102 eFatal("Could not create SDL surface: %s", SDL_GetError());
106 m_surface.x = m_screen->w;
107 m_surface.y = m_screen->h;
108 m_surface.bpp = m_screen->format->BitsPerPixel;
109 m_surface.bypp = m_screen->format->BytesPerPixel;
110 m_surface.stride = m_screen->pitch;
111 m_surface.data = m_screen->pixels;
113 SDL_EnableUNICODE(1);
116 void gSDLDC::evFlip()
121 void gSDLDC::thread()
128 if (SDL_WaitEvent(&event)) {
129 switch (event.type) {
136 switch (event.user.code) {
137 case EV_SET_VIDEO_MODE:
138 evSetVideoMode((unsigned long)event.user.data1, (unsigned long)event.user.data2);
153 eAutoInitPtr<gSDLDC> init_gSDLDC(eAutoInitNumbers::graphic-1, "gSDLDC");