src/video/sdl_v.cpp
changeset 7170 923946ec324f
parent 7019 09e090048a59
child 7310 eed5036fee1f
equal deleted inserted replaced
7169:314b046af3a1 7170:923946ec324f
    15 #include "../variables.h"
    15 #include "../variables.h"
    16 #include "../blitter/factory.hpp"
    16 #include "../blitter/factory.hpp"
    17 #include "sdl_v.h"
    17 #include "sdl_v.h"
    18 #include <SDL.h>
    18 #include <SDL.h>
    19 
    19 
       
    20 static FVideoDriver_SDL iFVideoDriver_SDL;
       
    21 
    20 static SDL_Surface *_sdl_screen;
    22 static SDL_Surface *_sdl_screen;
    21 static bool _all_modes;
    23 static bool _all_modes;
    22 
    24 
    23 #define MAX_DIRTY_RECTS 100
    25 #define MAX_DIRTY_RECTS 100
    24 static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
    26 static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
    25 static int _num_dirty_rects;
    27 static int _num_dirty_rects;
    26 
    28 
    27 static void SdlVideoMakeDirty(int left, int top, int width, int height)
    29 void VideoDriver_SDL::MakeDirty(int left, int top, int width, int height)
    28 {
    30 {
    29 	if (_num_dirty_rects < MAX_DIRTY_RECTS) {
    31 	if (_num_dirty_rects < MAX_DIRTY_RECTS) {
    30 		_dirty_rects[_num_dirty_rects].x = left;
    32 		_dirty_rects[_num_dirty_rects].x = left;
    31 		_dirty_rects[_num_dirty_rects].y = top;
    33 		_dirty_rects[_num_dirty_rects].y = top;
    32 		_dirty_rects[_num_dirty_rects].w = width;
    34 		_dirty_rects[_num_dirty_rects].w = width;
   413 		}
   415 		}
   414 	}
   416 	}
   415 	return -1;
   417 	return -1;
   416 }
   418 }
   417 
   419 
   418 static const char *SdlVideoStart(const char * const *parm)
   420 const char *VideoDriver_SDL::Start(const char * const *parm)
   419 {
   421 {
   420 	char buf[30];
   422 	char buf[30];
   421 
   423 
   422 	const char *s = SdlOpen(SDL_INIT_VIDEO);
   424 	const char *s = SdlOpen(SDL_INIT_VIDEO);
   423 	if (s != NULL) return s;
   425 	if (s != NULL) return s;
   432 	SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
   434 	SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
   433 	SDL_CALL SDL_EnableUNICODE(1);
   435 	SDL_CALL SDL_EnableUNICODE(1);
   434 	return NULL;
   436 	return NULL;
   435 }
   437 }
   436 
   438 
   437 static void SdlVideoStop()
   439 void VideoDriver_SDL::Stop()
   438 {
   440 {
   439 	SdlClose(SDL_INIT_VIDEO);
   441 	SdlClose(SDL_INIT_VIDEO);
   440 }
   442 }
   441 
   443 
   442 static void SdlVideoMainLoop()
   444 void VideoDriver_SDL::MainLoop()
   443 {
   445 {
   444 	uint32 cur_ticks = SDL_CALL SDL_GetTicks();
   446 	uint32 cur_ticks = SDL_CALL SDL_GetTicks();
   445 	uint32 last_cur_ticks = cur_ticks;
   447 	uint32 last_cur_ticks = cur_ticks;
   446 	uint32 next_tick = cur_ticks + 30;
   448 	uint32 next_tick = cur_ticks + 30;
   447 	uint32 pal_tick = 0;
   449 	uint32 pal_tick = 0;
   503 			DrawSurfaceToScreen();
   505 			DrawSurfaceToScreen();
   504 		}
   506 		}
   505 	}
   507 	}
   506 }
   508 }
   507 
   509 
   508 static bool SdlVideoChangeRes(int w, int h)
   510 bool VideoDriver_SDL::ChangeResolution(int w, int h)
   509 {
   511 {
   510 	return CreateMainSurface(w, h);
   512 	return CreateMainSurface(w, h);
   511 }
   513 }
   512 
   514 
   513 static void SdlVideoFullScreen(bool full_screen)
   515 void VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
   514 {
   516 {
   515 	_fullscreen = full_screen;
   517 	_fullscreen = fullscreen;
   516 	GetVideoModes(); // get the list of available video modes
   518 	GetVideoModes(); // get the list of available video modes
   517 	if (_num_resolutions == 0 || !_video_driver->change_resolution(_cur_resolution[0], _cur_resolution[1])) {
   519 	if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution[0], _cur_resolution[1])) {
   518 		// switching resolution failed, put back full_screen to original status
   520 		// switching resolution failed, put back full_screen to original status
   519 		_fullscreen ^= true;
   521 		_fullscreen ^= true;
   520 	}
   522 	}
   521 }
   523 }
   522 
   524 
   523 const HalVideoDriver _sdl_video_driver = {
       
   524 	SdlVideoStart,
       
   525 	SdlVideoStop,
       
   526 	SdlVideoMakeDirty,
       
   527 	SdlVideoMainLoop,
       
   528 	SdlVideoChangeRes,
       
   529 	SdlVideoFullScreen,
       
   530 };
       
   531 
       
   532 #endif /* WITH_SDL */
   525 #endif /* WITH_SDL */