ultimatepp/uppsrc/upt/SDLCore.upt
mdelfede d2b54f7989 changed svn layout
git-svn-id: svn://ultimatepp.org/upp/trunk@281 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2008-06-07 22:31:27 +00:00

98 lines
2.1 KiB
Text

template "SDL with Core package" main;
option "Create header" header;
option "Initialize video" video;
option "Double buffering" doublebuff;
option "Full screen" fullscreen;
option "Event loop" loop;
@@<:PACKAGE:>.h
??header
#ifndef _<:PACKAGE:>_<:PACKAGE:>_h
#define _<:PACKAGE:>_<:PACKAGE:>_h
#include <Core/Core.h>
#include <SDL.h>
using namespace Upp;
#endif
@@<:PACKAGE:>.cpp
<:?header:>#include "<:PACKAGE:>.h"
<:/:>#include <Core/Core.h>
#include <plugin/SDL/SDL.h><:.:>
<:?video:>
SDL_Surface * OpenScreen(const int width, const int height, const int bpp, const int flags)
{
SDL_Surface * screen = SDL_SetVideoMode(width, height, bpp, flags);
if(!screen)
{
Cout() << Format("Couldn't set display mode: %s\n", SDL_GetError());
return NULL;
}
return screen;
}
<:.:><:(loop && video ? "
void Paint(SDL_Surface * surface)
{
/* Put your painting code here */
}
" : ""):>
CONSOLE_APP_MAIN
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
return;
<:?video:>
int videoflags = SDL_HWSURFACE | SDL_HWACCEL<:(fullscreen || doublebuff ? fullscreen ? doublebuff ? " | SDL_FULLSCREEN | SDL_DOUBLEBUF" : " | SDL_FULLSCREEN" : doublebuff ? " | SDL_DOUBLEBUF" : "" : ""):>;
SDL_Surface * screen = OpenScreen(1024, 768, 32, videoflags);
if(!screen)
return;
<:.:><:?loop:>
SDL_Event event;
bool done = false;
while(!done)
{
if(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_LALT || event.key.keysym.sym == SDLK_TAB)
break;
<:(video ? "if(event.key.keysym.sym == SDLK_RETURN)
{
videoflags ^= SDL_FULLSCREEN;
screen = OpenScreen(screen->w, screen->h, screen->format->BitsPerPixel, videoflags);
if(!screen)
done = true;
break;
}" : ""):>
case SDL_QUIT:
done = true;
break;
default:
break;
}
}
<:(video ? "else
{
Paint(screen);
SDL_Flip(screen);
}" : ""):>
}<:.:><:?video:>
SDL_FreeSurface(screen);<:.:>
SDL_Quit();
}
@@<:PACKAGE:>.upp
uses
Core;
file <:?header:>"<:PACKAGE:>.h",<:.:>
"<:PACKAGE:>.cpp";
library(MSC) "SDL SDLmain";
library(GCC WIN32) "SDL.dll SDLmain";
mainconfig
"" = "";