[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/kolf-ng
From:       Stefan Majewsky <majewsky () gmx ! net>
Date:       2009-09-21 11:18:26
Message-ID: 1253531906.996683.10880.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1026299 by majewsky:

Reduce the connection between BlenderManager and DrawingBoard to one signal-slot \
connection that transfers the heightmap.

 M  +8 -13     editor/blender-manager.cpp  
 M  +3 -5      editor/blender-manager.h  
 M  +20 -1     editor/hmcreator-drawingboard.cpp  
 M  +4 -2      editor/hmcreator-drawingboard.h  
 M  +3 -3      engine/game-editor.cpp  


--- trunk/playground/games/kolf-ng/editor/blender-manager.cpp #1026298:1026299
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright 2009 Zeng Huan <zh.issac@gmail.com>
+ *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
  *
  *   This program is free software; you can redistribute it and/or
  *   modify it under the terms of the GNU General Public
@@ -40,7 +41,6 @@
 	, m_delegate(new TextureListDelegate())
 	, m_view(new QListView())
 	, m_outputSize(512, 512)
-	, m_drawingBoard(0)
 	, m_texturesModified(false)
 {
 	m_blendThread = new BlendThread(this);
@@ -112,9 +112,9 @@
 	m_model->appendItems(textureList);
 }
 
-void Kolf::BlenderManager::startBlending()
+void Kolf::BlenderManager::startBlending(bool force)
 {
-	if(setHeightmap() || m_texturesModified)
+	if (force || m_texturesModified)
 	{
 		m_blendThread->process();
 		m_texturesModified = false;
@@ -150,17 +150,12 @@
 		}
 }
 
-bool Kolf::BlenderManager::setHeightmap()
+void Kolf::BlenderManager::setHeightmap(const Kolf::Heightmap& heightmap)
 {
-	QMutexLocker locker(&m_mutex);
-	if(!m_drawingBoard || m_drawingBoard->image().isNull())
-		return false;
-	if(!m_drawingBoard->isEditedFromLastBlending())
-		return false;
-	m_heightmap = Heightmap(m_drawingBoard->image().toImage());
-	//set Kolf::DrawingBoard::isEditedFromLastBlending to false.
-	m_drawingBoard->setEditFlag(false);
-	return true;
+	m_mutex.lock();
+	m_heightmap = heightmap;
+	m_mutex.unlock();
+	startBlending(true);
 }
 
 #include "blender-manager.moc"
--- trunk/playground/games/kolf-ng/editor/blender-manager.h #1026298:1026299
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright 2009 Zeng Huan <zh.issac@gmail.com>
+ *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
  *
  *   This program is free software; you can redistribute it and/or
  *   modify it under the terms of the GNU General Public
@@ -29,7 +30,6 @@
 namespace Kolf
 {
 	class BlendThread;
-	class DrawingBoard;
 	class TextureListModel;
 	class TextureListDelegate;
 
@@ -41,12 +41,11 @@
 			~BlenderManager();
 			Heightmap heightmap() const {return m_heightmap;}
 			QListView* view() const {return m_view;}
-			void setDrawingBoard(DrawingBoard* board) {m_drawingBoard = board;}
 			QMutex& mutex() {return m_mutex;}
 			QImage blendResult() const {return m_blendResult;}
 
 		public Q_SLOTS:
-			bool setHeightmap();
+			void setHeightmap(const Kolf::Heightmap& heightmap);
 			void setTexturesModified(bool flag) {m_texturesModified = flag;}
 		Q_SIGNALS:
 			void blendingFinished();
@@ -55,7 +54,7 @@
 			void addTextures(const QStringList& fileNames);
 			void delTextures();
 			void loadDefaultTextureSet();
-			void startBlending();
+			void startBlending(bool force = false);
 			void processBlending();
 
 			friend class BlendThread;
@@ -68,7 +67,6 @@
 
 			QImage m_blendResult;
 			QSize m_outputSize;
-			DrawingBoard* m_drawingBoard;
 			bool m_texturesModified;
 			BlendThread* m_blendThread;
 			QMutex m_mutex;
--- trunk/playground/games/kolf-ng/editor/hmcreator-drawingboard.cpp #1026298:1026299
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright 2009 Zeng Huan <zh.issac@gmail.com>
+ *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
  *
  *   This program is free software; you can redistribute it and/or
  *   modify it under the terms of the GNU General Public
@@ -37,6 +38,13 @@
 	initializeImage();
 }
 
+void Kolf::DrawingBoard::setImage(const QPixmap& image)
+{
+	m_workingImage = image;
+	emit heightmapChanged(image.toImage());
+	storeImage();
+}
+
 void Kolf::DrawingBoard::setSelection(const QPainterPath& selection)
 {
 	 m_selection = selection;
@@ -54,11 +62,22 @@
 		const Kolf::HeightmapRenderer& heightmapRenderer = geometry->heightmapRenderer();
 		m_workingImage = fromHeightmapRenderer(heightmapRenderer);
 		storeImage();
-		emit heightmapChanged();
+		emit heightmapChanged(heightmapRenderer);
 		update();
 	}
 }
 
+void Kolf::DrawingBoard::hideEvent(QHideEvent* event)
+{
+	Q_UNUSED(event)
+	if (m_isEditedFromLastBlending && !m_workingImage.isNull())
+	{
+		emit heightmapChanged(m_workingImage.toImage());
+		m_isEditedFromLastBlending = false;
+	}
+	Kolf::GameUIPageWidget::hideEvent(event);
+}
+
 void Kolf::DrawingBoard::mousePressEvent(QMouseEvent* event)
 {
 
--- trunk/playground/games/kolf-ng/editor/hmcreator-drawingboard.h #1026298:1026299
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright 2009 Zeng Huan <zh.issac@gmail.com>
+ *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
  *
  *   This program is free software; you can redistribute it and/or
  *   modify it under the terms of the GNU General Public
@@ -40,7 +41,7 @@
 			DrawingBoard();
 			QPointF lastPoint() const {return m_lastPoint;}
 			QPixmap &image() {return m_workingImage;}
-			void setImage(const QPixmap &image) {m_workingImage = image; restoreImage();}
+			void setImage(const QPixmap& image);
 			QPainterPath selection() const {return m_selection;}
 			void setSelection(const QPainterPath& selection);
 			///Stores the current pixmap.
@@ -58,10 +59,11 @@
 			bool isEditedFromLastBlending() {return m_isEditedFromLastBlending;}
 
 		Q_SIGNALS:
-			void heightmapChanged();
+			void heightmapChanged(const Kolf::Heightmap& heightmap);
 
 		protected:
 			virtual void currentSceneChanged(Kolf::Scene* oldScene, Kolf::Scene* newScene);
+			virtual void hideEvent(QHideEvent* event);
 			///We always record the position of the mouse, it might be the leftTop point of a \
selectoin or a point in a painting path.  virtual void mousePressEvent(QMouseEvent* \
event);  ///If the m_currentToolButton represents a selecting action, then we want to \
draw a dynamic selection; If the m_currentToolButton represents a painting tool, we \
                want to do some real painting.
--- trunk/playground/games/kolf-ng/engine/game-editor.cpp #1026298:1026299
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
+ *   Copyright 2009 Zeng Huan <zh.issac@gmail.com>
  *
  *   This program is free software; you can redistribute it and/or
  *   modify it under the terms of the GNU General Public
@@ -70,9 +71,8 @@
 	Kolf::DrawingBoard* drawingBoard = new Kolf::DrawingBoard;
 	addPageWidget(drawingBoard);
 	addDockWidget(new Kolf::ToolBox(drawingBoard));
-	blenderWidget->manager()->setDrawingBoard(drawingBoard);
-	connect(drawingBoard, SIGNAL(heightmapChanged()),
-		blenderWidget->manager(), SLOT(setHeightmap()));
+	connect(drawingBoard, SIGNAL(heightmapChanged(const Kolf::Heightmap&)),
+		blenderWidget->manager(), SLOT(setHeightmap(const Kolf::Heightmap&)));
 
  	//Action: texture blender -- add textures
  	KAction* addTexAction = new KAction(KIcon("archive-insert"),i18n("Add texture"), \
actionCollection());


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic