[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-10 18:33:10
Message-ID: 1249929190.583383.1232.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1009726 by hzeng:
added two actions for blender, the remained ones will add later.
M +1 -0 CMakeLists.txt
M +68 -3 editor/blender-manager.cpp
M +3 -1 editor/blender-manager.h
M +2 -3 editor/blender-texturelistwidget.cpp
M +2 -1 editor/blender-texturelistwidget.h
M +49 -1 engine/game-editor.cpp
M +2 -3 engine/kolf-editorui.rc
--- trunk/playground/games/kolf-ng/CMakeLists.txt #1009725:1009726
@@ -21,6 +21,7 @@
editor/blender-manager.cpp
editor/blender-model.cpp
editor/blender-texture.cpp
+ editor/blender-texturelistwidget.cpp
editor/hmcreator-drawingboard.cpp
editor/hmcreator-ellipseselectbutton.cpp
editor/hmcreator-eraserbutton.cpp
--- trunk/playground/games/kolf-ng/editor/blender-manager.cpp #1009725:1009726
@@ -25,13 +25,13 @@
#include <QFileDialog>
#include <QListView>
-Kolf::BlenderManager::BlenderManager(QObject* parent)
+Kolf::BlenderManager::BlenderManager(ImageViewer* imageViewer, QObject* parent)
: QObject(parent)
, m_model(new TextureListModel())
, m_delegate(new TextureListDelegate())
, m_view(new QListView())
, m_heightmap(0)
- , m_imageViewer(0)
+ , m_imageViewer(imageViewer)
, m_isConfigurable(true)
, m_outputWidth(512)
, m_outputHeight(512)
@@ -40,6 +40,7 @@
m_view->setItemDelegate(m_delegate);
m_view->setSelectionBehavior(QAbstractItemView::SelectRows);
m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ m_imageViewer->setLeftText(tr("No heightmap loaded"));
}
Kolf::BlenderManager::~BlenderManager()
@@ -47,6 +48,22 @@
delete m_heightmap;
}
+void Kolf::BlenderManager::addTextures()
+{
+ if(!m_isConfigurable)
+ return;
+ m_isConfigurable = false;
+
+ QStringList fileNames;
+ fileNames = QFileDialog::getOpenFileNames(m_imageViewer,
+ tr("Open Image"), "./", tr("Image Files (*.png *.jpg *.bmp)"));
+ m_model->insertRows(fileNames, 0);
+
+ //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_isConfigurable = true;
+
+}
+
void Kolf::BlenderManager::addTextures(const QStringList& fileNames)
{
if(!m_isConfigurable)
@@ -59,7 +76,6 @@
void Kolf::BlenderManager::delTextures()
{
- //m_model->removeRows(m_view->currentIndex().row(), 1);
QModelIndexList indexes = m_view->selectionModel()->selectedIndexes();
foreach (const QModelIndex& index, indexes)
{
@@ -113,9 +129,41 @@
m_isConfigurable = true;
+ //changeBrightness() will make the blending result shown on the image viewer.
changeBrightness(0);
}
+void Kolf::BlenderManager::loadHeightmap()
+{
+ if(!m_isConfigurable)
+ return;
+ m_isConfigurable = false;
+
+ delete m_heightmap;
+ m_heightmap = 0;
+ QString fileName;
+ fileName = QFileDialog::getOpenFileName(m_imageViewer,
+ tr("Open Image"), "./", tr("Image Files (*.png *.jpg *.bmp)"));
+ if(!fileName.isEmpty())
+ {
+ m_heightmap = new Heightmap(fileName);
+ m_imageViewer->showImage(*m_heightmap);
+ int width = m_heightmap->width();
+ int height = m_heightmap->height();
+ int min = 255, max = 0;
+ for(int x = 0; x < width; ++x)
+ for(int y = 0; y < height; ++y)
+ {
+ max = qMax(m_heightmap->pixel(x, y), max);
+ min = qMin(m_heightmap->pixel(x, y), min);
+ }
+ m_imageViewer->setLeftText(QString("Heightmap loaded\nHeight range: \
(%1,%2)").arg(min).arg(max)); + }
+ //m_showHeightmapAction->setEnabled(m_heightmap != 0);
+ //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_isConfigurable = true;
+}
+
void Kolf::BlenderManager::loadHeightmap(Heightmap* heightmap)
{
if(!m_isConfigurable)
@@ -123,6 +171,20 @@
m_isConfigurable = false;
delete m_heightmap;
m_heightmap = heightmap;
+ if(m_heightmap)
+ {
+ m_imageViewer->showImage(*m_heightmap);
+ int width = m_heightmap->width();
+ int height = m_heightmap->height();
+ int min = 255, max = 0;
+ for(int x = 0; x < width; ++x)
+ for(int y = 0; y < height; ++y)
+ {
+ max = qMax(m_heightmap->pixel(x, y), max);
+ min = qMin(m_heightmap->pixel(x, y), min);
+ }
+ m_imageViewer->setLeftText(QString("Heightmap loaded\nHeight range: \
(%1,%2)").arg(min).arg(max)); + }
//m_showHeightmapAction->setEnabled(m_heightmap != 0);
//m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); m_isConfigurable = true;
@@ -147,17 +209,20 @@
color.setRgb(r, g, b);
m_brightEffect.setPixel(x, y, color.rgb());
}
+ m_imageViewer->showImage(m_brightEffect);
m_isConfigurable = true;
}
void Kolf::BlenderManager::setOutputWidth(int width)
{
m_outputWidth = width;
+ m_imageViewer->setRightText(QString("Output texture\n size: \
(%1,%2)").arg(m_outputWidth).arg(m_outputHeight)); }
void Kolf::BlenderManager::setOutputHeight(int height)
{
m_outputHeight = height;
+ m_imageViewer->setRightText(QString("Output texture\n size: \
(%1,%2)").arg(m_outputWidth).arg(m_outputHeight)); }
#include "blender-manager.moc"
--- trunk/playground/games/kolf-ng/editor/blender-manager.h #1009725:1009726
@@ -33,7 +33,7 @@
{
Q_OBJECT
public:
- BlenderManager(QObject* parent = 0);
+ BlenderManager(ImageViewer* imageViewer, QObject* parent = 0);
~BlenderManager();
Heightmap* heightmap() const {return m_heightmap;}
int outputWidth() const {return m_outputWidth;}
@@ -44,9 +44,11 @@
void setImageViewer(ImageViewer* imageViewer) {m_imageViewer = imageViewer;}
private Q_SLOTS:
+ void addTextures();
void addTextures(const QStringList& fileNames);
void delTextures();
void startBlending();
+ void loadHeightmap();
void loadHeightmap(Heightmap* heightmap);
void changeBrightness(int value);
void setOutputWidth(int width);
--- trunk/playground/games/kolf-ng/editor/blender-texturelistwidget.cpp \
#1009725:1009726 @@ -23,12 +23,11 @@
Kolf::TextureListWidget::TextureListWidget(ImageViewer* imageViewer)
: GameUIDockWidget(i18n("Texture list"))
- , m_blendManager(new BlenderManager(this))
+ , m_blenderManager(new BlenderManager(imageViewer, this))
{
setObjectName("TextureListWidget");
setPreferredArea(Qt::RightDockWidgetArea);
- m_blendManager->setImageViewer(imageViewer);
- setWidget(m_blendManager->view());
+ setWidget(m_blenderManager->view());
}
Kolf::TextureListWidget::~TextureListWidget()
--- trunk/playground/games/kolf-ng/editor/blender-texturelistwidget.h \
#1009725:1009726 @@ -30,8 +30,9 @@
public:
TextureListWidget(ImageViewer* imageViewer);
~TextureListWidget();
+ BlenderManager* blenderManager() {return m_blenderManager;}
private:
- BlenderManager* m_blendManager;
+ BlenderManager* m_blenderManager;
};
}
#endif
--- trunk/playground/games/kolf-ng/engine/game-editor.cpp #1009725:1009726
@@ -21,6 +21,8 @@
#include "course.h"
#include "player.h"
#include "../editor/blender-imageviewer.h"
+#include "../editor/blender-manager.h"
+#include "../editor/blender-texturelistwidget.h"
#include "../editor/hmcreator-drawingboard.h"
#include "../editor/hmcreator-toolbox.h"
#include "../elements/ball.h"
@@ -58,10 +60,56 @@
connect(nextAct, SIGNAL(triggered()), this, SIGNAL(actionGoToNextHole()));
//page widgets: basic views
addPageWidget(new Kolf::View2DComponent);
- addPageWidget(new Kolf::ImageViewer);
+ Kolf::ImageViewer* imageViewer = new Kolf::ImageViewer;
+ addPageWidget(imageViewer);
+ Kolf::TextureListWidget* textureListWidget = new \
Kolf::TextureListWidget(imageViewer); + addDockWidget(textureListWidget);
Kolf::DrawingBoard* drawingBoard = new Kolf::DrawingBoard;
addPageWidget(drawingBoard);
addDockWidget(new Kolf::ToolBox(drawingBoard));
+
+ //Action: texture blender -- add textures
+ KAction* addTexAction = new KAction(KIcon("archive-insert"),i18n("&Add texture"), \
actionCollection()); + addTexAction->setShortcut(i18n("Ctrl+I"));
+ addTexAction->setStatusTip(i18n("Add a new texture"));
+ addTexAction->setToolTip(i18n("Add a new texture, Ctrl+I"));
+ actionCollection()->addAction("blender-addTexture", addTexAction);
+ connect(addTexAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(addTextures())); +
+ KAction* delTexAction = new KAction(KIcon("archive-remove"), i18n("&Delete \
texture"), actionCollection()); + delTexAction->setShortcut(i18n("Ctrl+D"));
+ delTexAction->setStatusTip(i18n("Delete a texture in the list"));
+ delTexAction->setToolTip(i18n("Delete a texture in the list, Ctrl+D"));
+ actionCollection()->addAction("blender-delTexture", delTexAction);
+ connect(delTexAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(delTextures())); +
+/*
+ m_loadHeightmapAction = new KAction(KIcon("document-open"),tr("&Load \
heightmap"),this); + m_loadHeightmapAction->setShortcut(tr("Ctrl+L"));
+ m_loadHeightmapAction->setStatusTip(tr("Load the heightmap"));
+ m_loadHeightmapAction->setToolTip(tr("Load the heightmap, Ctrl+L"));
+ connect(m_loadHeightmapAction, SIGNAL(triggered()), this, SLOT(loadHeightmap()));
+
+ m_showHeightmapAction = new KAction(KIcon("games-config-board"),tr("S&how \
heightmap"),this); + m_showHeightmapAction->setShortcut(tr("Ctrl+H"));
+ m_showHeightmapAction->setStatusTip(tr("Show the heightmap"));
+ m_showHeightmapAction->setToolTip(tr("Show the heightmap, Ctrl+H"));
+ m_showHeightmapAction->setEnabled(false); //will become available when a heightmap \
is loaded + connect(m_showHeightmapAction, SIGNAL(triggered()), this, \
SLOT(showHeightmap())); +
+ m_startAction = new KAction(KIcon("run-build"),tr("Start &Blending"),this);
+ m_startAction->setShortcut(tr("Ctrl+B"));
+ m_startAction->setStatusTip(tr("Start blending"));
+ m_startAction->setToolTip(tr("start blending"));
+ m_startAction->setEnabled(false); //will become available when a heightmap and \
textures are loaded + connect(m_startAction, SIGNAL(triggered()), this, \
SLOT(start())); +
+ m_saveAction = new KAction(KIcon("document-save"),tr("&Save"),this);
+ m_saveAction->setShortcut(tr("Ctrl+S"));
+ m_saveAction->setStatusTip(tr("Save texture"));
+ m_saveAction->setToolTip(tr("Save the result"));
+ connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save()));
+*/
}
void Kolf::EditorGameUI::setCleanDispatcher(bool clean)
--- trunk/playground/games/kolf-ng/engine/kolf-editorui.rc #1009725:1009726
@@ -10,9 +10,8 @@
<Separator/>
<Action name="edit_undo" />
<Action name="edit_redo" />
- <!--
<Separator/>
- <Action name="kolf_take_snapshot" />
- -->
+ <Action name="blender-addTexture" />
+ <Action name="blender-delTexture" />
</ToolBar>
</gui>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic