TheXception's patch:
authorunc0rr
Thu, 23 Apr 2009 13:54:25 +0000
changeset 2012 76fff564246b
parent 2011 40a168fb6f1b
child 2013 64be1ad497ca
TheXception's patch: - Animated stars in frontend's background
QTfrontend/CMakeLists.txt
QTfrontend/bgwidget.cpp
QTfrontend/bgwidget.h
QTfrontend/hedgewars.qrc
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/res/Star.png
--- a/QTfrontend/CMakeLists.txt	Mon Apr 20 17:45:01 2009 +0000
+++ b/QTfrontend/CMakeLists.txt	Thu Apr 23 13:54:25 2009 +0000
@@ -6,6 +6,7 @@
 set(QT_USE_QTNETWORK TRUE)
 set(QT_USE_QTSVG TRUE)
 set(QT_USE_QTXML TRUE)
+# set(QT_USE_QTOPENGL TRUE)
 set(QT_USE_QTMAIN TRUE)
 
 find_package(Qt4 REQUIRED)
@@ -87,6 +88,7 @@
 	misc.cpp
 	ammoSchemeModel.cpp
 	togglebutton.cpp
+	bgwidget.cpp
 	)
 
 if(MINGW)
@@ -137,6 +139,7 @@
 	misc.h
 	ammoSchemeModel.h
 	togglebutton.h
+	bgwidget.h
 	)
 
 set(hwfr_hdrs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/bgwidget.cpp	Thu Apr 23 13:54:25 2009 +0000
@@ -0,0 +1,139 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2009 Kristian Lehmann <email@thexception.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "bgwidget.h"
+
+SpritePosition::SpritePosition(QWidget * parent, int sh)
+{
+	wParent = parent;
+	iSpriteHeight = sh;
+	reset();
+}
+
+SpritePosition::~SpritePosition()
+{
+}
+
+void SpritePosition::move()
+{
+	fX += fXMov;
+	fY += fYMov;
+	iAngle += 4;
+	if (iAngle >= 360) iAngle = 0;
+	if (fY > wParent->height()) reset();
+}
+
+void SpritePosition::reset()
+{
+	fY = -1 * iSpriteHeight;
+	fX = (qrand() % ((int)(wParent->width() * 1.5))) - wParent->width()/2;
+	fYMov = ((qrand() % 400)+300) / 100.0f;
+	fXMov = fYMov * 0.5f;
+	iAngle = qrand() % 360;
+}
+
+QPoint SpritePosition::pos()
+{
+	return QPoint((int)fX,(int)fY);
+}
+
+int SpritePosition::getAngle()
+{
+	return iAngle;
+}
+
+void SpritePosition::init()
+{
+	fY = qrand() % (wParent->height() + 1);
+	fX = qrand() % (wParent->width() + 1);
+}
+
+BGWidget::BGWidget(QWidget * parent) : QWidget(parent)
+{
+	sprite.load(":/res/Star.png");
+	
+	setAutoFillBackground(false);
+
+	for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height());
+	
+	for (int i = 0; i < 360; i++)
+	{
+		rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
+		rotatedSprites[i]->fill(0);
+
+		QPoint translate(sprite.width()/2, sprite.height()/2);
+
+		QPainter p;
+		p.begin(rotatedSprites[i]);
+		p.setRenderHint(QPainter::Antialiasing);
+		p.setRenderHint(QPainter::SmoothPixmapTransform);
+		p.translate(translate.x(), translate.y());
+		p.rotate(i);
+		p.translate(-1*translate.x(), -1*translate.y());
+		p.drawImage(0, 0, sprite);
+
+	}
+
+	timerAnimation = new QTimer();
+	connect(timerAnimation, SIGNAL(timeout()), this, SLOT(animate()));
+	timerAnimation->setInterval(ANIMATION_INTERVAL);
+}
+
+BGWidget::~BGWidget()
+{
+	for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i];
+	for (int i = 0; i < 360; i++) delete rotatedSprites[i];
+	delete timerAnimation;
+}
+
+void BGWidget::paintEvent(QPaintEvent *event)
+{
+	QPainter p;
+	p.begin(this);
+	//p.setRenderHint(QPainter::Antialiasing);
+	for (int i = 0; i < SPRITE_MAX; i++)
+	{
+		QPoint point = spritePositions[i]->pos();
+		p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()]);
+	}
+	p.end();
+}
+
+void BGWidget::animate()
+{
+	repaint();
+	for (int i = 0; i < SPRITE_MAX; i++)
+	{
+		spritePositions[i]->move();
+	}
+}
+
+void BGWidget::startAnimation()
+{
+	timerAnimation->start();
+}
+
+void BGWidget::stopAnimation()
+{
+	timerAnimation->stop();
+}
+
+void BGWidget::init()
+{
+	for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i]->init();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/bgwidget.h	Thu Apr 23 13:54:25 2009 +0000
@@ -0,0 +1,75 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2009 Kristian Lehmann <email@thexception.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef BGWIDGET_H
+#define BGWIDGET_H
+
+#include <QWidget>
+//#include <QGLWidget>
+#include <QPainter>
+#include <QTimer>
+#include <QPaintEvent>
+#include <QTime>
+#include <QPoint>
+
+#define SPRITE_MAX 12
+
+#define ANIMATION_INTERVAL 40
+
+class SpritePosition
+{
+public:
+	SpritePosition(QWidget * parent, int sh);
+	~SpritePosition();
+private:
+	float fX;
+	float fY;
+	float fXMov;
+	float fYMov;
+	int iAngle; 
+	QWidget * wParent;
+	int iSpriteHeight;
+public:
+	void move();
+	void reset();
+	QPoint pos();
+	int getAngle();
+	void init();
+};
+
+class BGWidget : public QWidget
+{
+	Q_OBJECT
+public:
+	BGWidget(QWidget * parent);
+	~BGWidget();
+	void startAnimation();
+	void stopAnimation();
+	void init();
+private:
+	QImage sprite;
+	QTimer * timerAnimation;
+	SpritePosition * spritePositions[SPRITE_MAX];
+	QImage * rotatedSprites[360];
+protected:
+	void paintEvent(QPaintEvent * event);
+private slots:
+	void animate();
+};
+
+#endif // BGWIDGET_H
--- a/QTfrontend/hedgewars.qrc	Mon Apr 20 17:45:01 2009 +0000
+++ b/QTfrontend/hedgewars.qrc	Thu Apr 23 13:54:25 2009 +0000
@@ -59,5 +59,6 @@
     <file>res/iconDamage.png</file>
     <file>res/iconTime.png</file>
     <file>res/dice.png</file>
+    <file>res/Star.png</file>
 </qresource>
 </RCC>
--- a/QTfrontend/hwform.cpp	Mon Apr 20 17:45:01 2009 +0000
+++ b/QTfrontend/hwform.cpp	Thu Apr 23 13:54:25 2009 +0000
@@ -53,6 +53,7 @@
 #include "playrecordpage.h"
 #include "input_ip.h"
 #include "ammoSchemeModel.h"
+#include "bgwidget.h"
 
 HWForm::HWForm(QWidget *parent)
   : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
@@ -166,6 +167,12 @@
 	ui.pageScheme->setModel(ammoSchemeModel);
 	ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
 
+	wBackground = new BGWidget(this);
+	wBackground->setFixedSize(this->width(), this->height());
+	wBackground->lower();
+	wBackground->init();
+	wBackground->startAnimation();
+
 	PagesStack.push(ID_PAGE_MAIN);
 	GoBack();
 }
@@ -731,6 +738,7 @@
 	switch(gameState) {
 		case gsStarted: {
 			Music(false);
+			if (wBackground) wBackground->stopAnimation();	
 			GoToPage(ID_PAGE_INGAME);
 			ui.pageGameStats->clear();
 			if (pRegisterServer)
@@ -743,6 +751,7 @@
 		case gsFinished: {
 			GoBack();
 			Music(ui.pageOptions->CBEnableMusic->isChecked());
+			if (wBackground) wBackground->startAnimation();	
 			GoToPage(ID_PAGE_GAMESTATS);
 			if (hwnet) hwnet->gameFinished();
 			break;
@@ -752,6 +761,7 @@
 			if (id == ID_PAGE_INGAME) {
 				GoBack();
 				Music(ui.pageOptions->CBEnableMusic->isChecked());
+				if (wBackground) wBackground->startAnimation();	
 				if (hwnet) hwnet->gameFinished();
 			}
 		};
@@ -892,3 +902,11 @@
 	else
 		qWarning("Left room while not in room");
 }
+
+void HWForm::resizeEvent(QResizeEvent * event)
+{
+	int w = event->size().width();
+	int h = event->size().height();
+	wBackground->setFixedSize(w, h);
+	wBackground->move(0, 0);
+}
--- a/QTfrontend/hwform.h	Mon Apr 20 17:45:01 2009 +0000
+++ b/QTfrontend/hwform.h	Thu Apr 23 13:54:25 2009 +0000
@@ -27,6 +27,7 @@
 #include "game.h"
 #include "ui_hwform.h"
 #include "SDLs.h"
+#include "bgwidget.h"
 
 class HWGame;
 class HWTeam;
@@ -105,6 +106,7 @@
 	void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo);
 	void closeEvent(QCloseEvent *event);
 	void CustomizePalettes();
+	void resizeEvent(QResizeEvent * event);
 	
 	enum PageIDs {
 		ID_PAGE_SETUP_TEAM      =  0,
@@ -138,6 +140,7 @@
 	QStack<quint8> PagesStack;
 	QTime eggTimer;
 	SDLInteraction sdli;
+	BGWidget * wBackground;
 	void OnPageShown(quint8 id, quint8 lastid=0);
 };
 
Binary file QTfrontend/res/Star.png has changed