view data/model/SDLWidget.cpp @ 132:e236ce53a2e7

(none)
author benoitrigolleau
date Thu, 08 Nov 2007 14:42:12 +0000
parents
children 3b2b790e47e5
line wrap: on
line source
#include <vector>
#include <cstdlib>
#include <ctime>
#include "SDLWidget.h"

SDLWidget::SDLWidget()
	:windowInitialized(false), screen(0)
	{
		setAttribute(Qt::WA_PaintOnScreen);
		setAttribute(Qt::WA_NoSystemBackground);
		setMinimumSize(320,240);
		resize(320, 240);
	}

SDLWidget::~SDLWidget()
	{
		SDL_Quit();
	}

void SDLWidget::showEvent(QShowEvent *e)
	{
		(void)e;
		if(!windowInitialized)
		{
			// it's here the link between SDL and QT
			char windowid[64];
#ifdef Q_WS_WIN
			sprintf(windowid, "SDL_WINDOWID=0x%lx", reinterpret_cast<qlonglong>(winId()));
#elif defined Q_WS_X11
			sprintf(windowid, "SDL_WINDOWID=0x%lx", winId());
#else
			qFatal("uncorrect window ID");
#endif
			SDL_putenv(windowid);

			//SDL_Init(SDL_INIT_VIDEO);
			//screen = SDL_SetVideoMode(width(), height(), 32, SDL_SWSURFACE);
			windowInitialized = true;
		}
	}