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

List:       kde-commits
Subject:    playground/games/kolf-ng
From:       Huan Zeng <zh.issac () gmail ! com>
Date:       2009-08-13 9:07:58
Message-ID: 1250154478.216522.8574.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1010701 by hzeng:

heightmap are now shared between texture blender and heightmap editor, whenwe select \
to the texture blender's tab, if the heightmap/textures has been modified since the \
last time we selected texture blender, texture blender will reloaded the modified \
heightmap and recreate the texture.


 M  +1 -1      editor/blender-delegate.h  
 M  +7 -0      editor/blender-imageviewer.cpp  
 M  +7 -1      editor/blender-imageviewer.h  
 M  +17 -10    editor/blender-manager.cpp  
 M  +6 -2      editor/blender-manager.h  
 M  +3 -0      editor/blender-model.cpp  
 M  +4 -0      editor/blender-model.h  
 M  +1 -1      editor/blender-texturelistwidget.cpp  
 M  +7 -5      editor/hmcreator-drawingboard.cpp  
 M  +7 -3      editor/hmcreator-drawingboard.h  
 M  +9 -2      engine/game-editor.cpp  


--- trunk/playground/games/kolf-ng/editor/blender-delegate.h #1010700:1010701
@@ -26,6 +26,7 @@
 {
 	class TextureListDelegate : public QAbstractItemDelegate
 	{
+		Q_OBJECT
 		public:
 			TextureListDelegate( QObject *parent = 0 );
 			void paint( QPainter *painter,
@@ -45,7 +46,6 @@
 						  const QModelIndex &index) const;
 		protected:
 			bool eventFilter(QObject *obj, QEvent *event);
-	
 	};
 }
 #endif // KOLF_BLENDER_DELEGATE_H
--- trunk/playground/games/kolf-ng/editor/blender-imageviewer.cpp #1010700:1010701
@@ -44,6 +44,7 @@
 	QPixmap pixmap;
 	pixmap = QPixmap::fromImage(img);
 	m_image->setPixmap(pixmap);
+	m_image->update();
 }
 
 void Kolf::ImageViewer::setLeftText(const QString& text)
@@ -55,3 +56,9 @@
 {
 	m_rightText->setText(text);
 }
+
+
+void Kolf::ImageViewer::showEvent(QShowEvent* event)
+{
+	emit showed();
+}
--- trunk/playground/games/kolf-ng/editor/blender-imageviewer.h #1010700:1010701
@@ -26,17 +26,23 @@
 {
 	class ImageViewer : public GameUIPageWidget
 	{
+		Q_OBJECT
 		public:
 			ImageViewer();
 			void showImage(const QImage& img);
 			void setLeftText(const QString& text);
 			void setRightText(const QString& text);
+
+		Q_SIGNALS:
+			void showed();
+
+		protected:
+			virtual void showEvent(QShowEvent* event);
 	
 		private:
 			QLabel* m_image;
 			QLabel* m_leftText;
 			QLabel* m_rightText;
-	
 	};
 }
 #endif // KOLF_BLENDER_IMAGEVIEWER_H
--- trunk/playground/games/kolf-ng/editor/blender-manager.cpp #1010700:1010701
@@ -22,6 +22,7 @@
 #include "blender-model.h"
 #include "blender-manager.h"
 #include "blender-texture.h"
+#include "hmcreator-drawingboard.h"
 #include <KAction>
 #include <QFileDialog>
 #include <QListView>
@@ -36,12 +37,16 @@
 	, m_outputWidth(512)
 	, m_outputHeight(512)
 	, m_startBlendingAction(0)
+	, m_drawingBoard(0)
+	, m_texturesModified(false)
 {
 	m_view->setModel(m_model);
 	m_view->setItemDelegate(m_delegate);
 	m_view->setSelectionBehavior(QAbstractItemView::SelectRows);
 	m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 	m_imageViewer->setLeftText(tr("No heightmap loaded"));
+	connect(m_model, SIGNAL(texturesModified(bool)),
+		this, SLOT(setTexturesModified(bool)));
 }
 
 Kolf::BlenderManager::~BlenderManager()
@@ -94,13 +99,9 @@
 
 void Kolf::BlenderManager::startBlending()
 {
-	if(!m_isConfigurable)
+	setHeightmap();
+	if(!m_isConfigurable || !m_texturesModified)
 		return;
-	if(m_heightmap.isNull())
-		m_isConfigurable = true;
-	if(m_model->textureList().count() == 0)
-		m_isConfigurable = true;
-
 	m_isConfigurable = false;
 	m_blendResult = QImage(m_outputWidth, m_outputHeight, QImage::Format_ARGB32);
 
@@ -128,20 +129,27 @@
 		}
 	
 
+	m_texturesModified = false;
 	m_isConfigurable = true;
 	//changeBrightness() will make the blending result shown on the image viewer.
 	changeBrightness(0);
 }
 
-void Kolf::BlenderManager::loadHeightmap(const Kolf::Heightmap& heightmap)
+void Kolf::BlenderManager::setHeightmap()
 {
 	if(!m_isConfigurable)
 		return;
+	if(!m_drawingBoard || m_drawingBoard->pixmap().isNull())
+		return;
+	if(!m_drawingBoard->isEditedFromLastBlending())
+		return;
 	m_isConfigurable = false;
-	m_heightmap = heightmap;
+	m_heightmap = Heightmap(m_drawingBoard->pixmap().toImage());
+	//set Kolf::DrawinngBoard::isEditedFromLastBlending to false.
+	m_drawingBoard->setEditFlag(false);
 	if(!m_heightmap.isNull())
 	{
-		m_imageViewer->showImage(m_heightmap);
+	//	m_imageViewer->showImage(m_heightmap);
 		int width = m_heightmap.width();
 		int height = m_heightmap.height();
 		int min = 255, max = 0;
@@ -155,7 +163,6 @@
 	}
 	m_startBlendingAction->setEnabled(m_model->textureList().count() != 0 && \
!m_heightmap.isNull());  m_isConfigurable = true;
-	startBlending();
 }
 
 void Kolf::BlenderManager::showHeightmap()
--- trunk/playground/games/kolf-ng/editor/blender-manager.h #1010700:1010701
@@ -26,6 +26,7 @@
 class QListView;
 namespace Kolf
 {
+	class DrawingBoard;
 	class ImageViewer;
 	class TextureListModel;
 	class TextureListDelegate;
@@ -44,10 +45,11 @@
 			QImage& blendingResult() {return m_brightEffect;}
 			void setImageViewer(ImageViewer* imageViewer) {m_imageViewer = imageViewer;}
 			void setStartBlendingAction(KAction* action) {m_startBlendingAction = action;}
+			void setDrawingBoard(DrawingBoard* board) {m_drawingBoard = board;}
 
 		public Q_SLOTS:
-			void loadHeightmap(const Kolf::Heightmap& heightmap);
-
+			void setHeightmap();
+			void setTexturesModified(bool flag) {m_texturesModified = flag;}
 		private Q_SLOTS:
 			void addTextures();
 			void addTextures(const QStringList& fileNames);
@@ -72,6 +74,8 @@
 			int m_outputWidth;
 			int m_outputHeight;
 			KAction* m_startBlendingAction;
+			DrawingBoard* m_drawingBoard;
+			bool m_texturesModified;
 	};
 }
 
--- trunk/playground/games/kolf-ng/editor/blender-model.cpp #1010700:1010701
@@ -59,6 +59,7 @@
 	}
 
 	endInsertRows();
+	emit texturesModified(true);
 	return true;
 }
 
@@ -72,6 +73,7 @@
 	}
 	
 	endRemoveRows();
+	emit texturesModified(true);
 	return true;
 }
 
@@ -97,6 +99,7 @@
 		texture->range()[1] = range[1].toInt();
 		texture->range()[2] = range[2].toInt();
 		emit dataChanged(index, index);
+		emit texturesModified(true);
 		return true;
 	}
 
--- trunk/playground/games/kolf-ng/editor/blender-model.h #1010700:1010701
@@ -44,6 +44,10 @@
 	
 		private:
 			QList<BlenderTexture*> m_textureList;
+
+		Q_SIGNALS:
+			///This signal is used to let blender manager to avoid no needed reblending.
+			void texturesModified(bool flag);
 	};
 }
 #endif // KOLF_BLENDER_MODEL_H
--- trunk/playground/games/kolf-ng/editor/blender-texturelistwidget.cpp \
#1010700:1010701 @@ -26,7 +26,7 @@
 	, m_blenderManager(new BlenderManager(imageViewer, this))
 {
 	setObjectName("TextureListWidget");
-	setPreferredArea(Qt::RightDockWidgetArea);
+	setPreferredArea(Qt::LeftDockWidgetArea);
 	setWidget(m_blenderManager->view());
 }
 
--- trunk/playground/games/kolf-ng/editor/hmcreator-drawingboard.cpp #1010700:1010701
@@ -32,6 +32,7 @@
 Kolf::DrawingBoard::DrawingBoard()
 	: GameUIPageWidget(i18n("Terrain heightmap"))
 	, m_currentToolButton(0)
+	, m_isEditedFromLastBlending(false)
 {
 	initializePixmap();
 }
@@ -51,8 +52,9 @@
 	{
 		const Kolf::TerrainGeometry* geometry = object->terrainGeometry();
 		const Kolf::HeightmapRenderer& heightmapRenderer = geometry->heightmapRenderer();
-		fromHeightmapRenderer(heightmapRenderer);
-		emit heightmapChanged(Kolf::Heightmap(heightmapRenderer));
+		m_workingImage = fromHeightmapRenderer(heightmapRenderer);
+		storePixmap();
+		emit heightmapChanged();
 		update();
 	}
 }
@@ -132,6 +134,7 @@
 void Kolf::DrawingBoard::storePixmap()
 {
 	m_storeIamge = m_workingImage;
+	m_isEditedFromLastBlending = true;
 }
 
 void Kolf::DrawingBoard::restorePixmap()
@@ -144,10 +147,9 @@
 	return Kolf::HeightmapRenderer(m_workingImage.toImage());
 }
 
-void Kolf::DrawingBoard::fromHeightmapRenderer(const Kolf::HeightmapRenderer& \
heightmapRenderer) +QPixmap Kolf::DrawingBoard::fromHeightmapRenderer(const \
Kolf::HeightmapRenderer& heightmapRenderer)  {
-	m_workingImage = QPixmap::fromImage(heightmapRenderer);
-	storePixmap();
+	return QPixmap::fromImage(heightmapRenderer);
 }
 
 void Kolf::DrawingBoard::clearPixmap()
--- trunk/playground/games/kolf-ng/editor/hmcreator-drawingboard.h #1010700:1010701
@@ -50,12 +50,15 @@
 			///Converts the current pixmap into Kolf::HeightmapRenderer, then we can use this \
Kolf::HeightmapRenderer to render 3d view.  HeightmapRenderer toHeightmapRenderer();
 			///Sets the current pixmap from a Kolf::HeightmapRenderer.
-			void fromHeightmapRenderer(const Kolf::HeightmapRenderer& heightmapRenderer);
+			QPixmap fromHeightmapRenderer(const Kolf::HeightmapRenderer& heightmapRenderer);
 
 			static const QPen HelperLinesPen;
 
+			void setEditFlag(bool flag) {m_isEditedFromLastBlending = flag;}
+			bool isEditedFromLastBlending() {return m_isEditedFromLastBlending;}
+
 		Q_SIGNALS:
-			void heightmapChanged(const Kolf::Heightmap& heightmap);
+			void heightmapChanged();
 
 		public Q_SLOTS:
 			///Sets the current heightmap which we want to edit it.
@@ -90,7 +93,8 @@
 			QPixmap m_storeIamge;
 			QPainterPath m_selection;
 			Kolf::ToolButton* m_currentToolButton;
-//			Kolf::Heightmap m_heightmap;
+			///Uses this flag to decide if need to reset the heightmap in \
Kolf::BlenderManger. +			bool m_isEditedFromLastBlending;
 	};
 }
 #endif //KOLF_HMCREATOR_DRAWINGBOARD_H
--- trunk/playground/games/kolf-ng/engine/game-editor.cpp #1010700:1010701
@@ -60,18 +60,24 @@
 	nextAct->setToolTip(i18n("Go to next hole"));
 	actionCollection()->addAction("kolf_level_next", nextAct);
 	connect(nextAct, SIGNAL(triggered()), this, SIGNAL(actionGoToNextHole()));
+
 	//page widgets: basic views
 	addPageWidget(new Kolf::View2DComponent);
+	//Blender's part
 	Kolf::ImageViewer* imageViewer = new Kolf::ImageViewer;
 	addPageWidget(imageViewer);
 	Kolf::TextureListWidget* textureListWidget = new \
Kolf::TextureListWidget(imageViewer);  addDockWidget(textureListWidget);
 	addDockWidget(new Kolf::BlenderConfigWidget(textureListWidget->blenderManager()));
+	//Heightmap creator's part
 	Kolf::DrawingBoard* drawingBoard = new Kolf::DrawingBoard;
 	addPageWidget(drawingBoard);
 	addDockWidget(new Kolf::ToolBox(drawingBoard));
-	connect(drawingBoard, SIGNAL(heightmapChanged(const Kolf::Heightmap&)),
-		textureListWidget->blenderManager(), SLOT(loadHeightmap(const Kolf::Heightmap&)));
+	textureListWidget->blenderManager()->setDrawingBoard(drawingBoard);
+	connect(drawingBoard, SIGNAL(heightmapChanged()),
+		textureListWidget->blenderManager(), SLOT(setHeightmap()));
+	connect(imageViewer, SIGNAL(showed()), 
+		textureListWidget->blenderManager(), SLOT(startBlending()));
 
  	//Action: texture blender -- add textures
  	KAction* addTexAction = new KAction(KIcon("archive-insert"),i18n("&Add texture"), \
actionCollection()); @@ -106,6 +112,7 @@
 	saveAction->setToolTip(i18n("Save the result"));
 	actionCollection()->addAction("blender-saveResult", saveAction);
 	connect(saveAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(saveResult())); +
 }
 
 void Kolf::EditorGameUI::setCleanDispatcher(bool clean)


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

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