?? renderthread.cpp
字號:
#include "renderthread.h"
RenderThread::RenderThread()
{
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
::exit(0);
}
atexit(SDL_Quit);
p_ptrScreen = SDL_SetVideoMode( 640, 480, 0, SDL_SWSURFACE );
if ( p_ptrScreen == NULL )
{
fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
::exit(0);
}
p_ptrBMP = SDL_LoadBMP( "test.bmp" );
if (SDL_MUSTLOCK(p_ptrScreen))
if (SDL_LockSurface(p_ptrScreen) < 0)
return;
p_ptrBMP = SDL_LoadBMP( "test.bmp" );
if (p_ptrBMP == NULL)
{
fprintf(stderr, "Unable to load image: %s\n", SDL_GetError());
::exit(0);
}
if (SDL_MUSTLOCK(p_ptrScreen))
SDL_UnlockSurface(p_ptrScreen);
p_rctPosition.x = 0;
p_rctPosition.y = 0;
p_rctPosition.w = p_ptrBMP->w;
p_rctPosition.h = p_ptrBMP->h;
}
RenderThread::~RenderThread()
{
qDebug( "Cleaning up the mess" );
SDL_FreeSurface( p_ptrBMP );
SDL_Quit();
}
void RenderThread::run()
{
SDL_Event event;
bool bRunning = false;
while( 1 )
{
if( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
if( event.key.keysym.sym == SDLK_ESCAPE )
{
::exit( 0 );
return;
}
else if( event.key.keysym.sym == SDLK_SPACE )
{
bRunning = bRunning == true ? false : true;
}
}
}
if( bRunning )
{
move();
}
SDL_FillRect( p_ptrScreen, 0, 0 );
SDL_BlitSurface( p_ptrBMP, 0, p_ptrScreen, &p_rctPosition );
SDL_Flip( p_ptrScreen );
// Limit to 25 fps
SDL_Delay( 40 );
}
::exit(1);
}
void RenderThread::move()
{
p_rctPosition.x += 5;
if( p_rctPosition.x + p_rctPosition.w >= p_ptrScreen->w )
{
p_rctPosition.x = 0;
p_rctPosition.y += 5;
}
if( p_rctPosition.y + p_rctPosition.h >= p_ptrScreen->h )
{
p_rctPosition.x = 0;
p_rctPosition.y = 0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -