changeset 132:e236ce53a2e7

(none)
author benoitrigolleau
date Thu, 08 Nov 2007 14:42:12 +0000
parents b5087d5a7814
children 894b45c9b787
files data/model/SDLWidget.cpp data/model/SDLWidget.h
diffstat 2 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/model/SDLWidget.cpp	Thu Nov 08 14:42:12 2007 +0000
@@ -0,0 +1,40 @@
+#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;
+		}
+	}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/model/SDLWidget.h	Thu Nov 08 14:42:12 2007 +0000
@@ -0,0 +1,32 @@
+#ifndef _SDL_WIDGET_H
+#define _SDL_WIDGET_H
+#include <QWidget>
+#include <QShowEvent>
+#include <QTimer>
+
+#ifdef WIN32
+#include <SDL.h>
+#endif
+#ifdef __unix__
+#include <SDL/SDL.h>
+#endif
+#undef main
+
+class SDLWidget : public QWidget
+{
+	Q_OBJECT
+
+public:
+	SDLWidget();
+	virtual ~SDLWidget();
+
+protected:
+
+	bool windowInitialized;
+	SDL_Surface *screen;
+
+	virtual void showEvent(QShowEvent *e);
+};
+
+
+#endif