Commit 251e00e0 authored by Ian Wadham's avatar Ian Wadham

In KGameRenderer extract the KGoldrunner theme-parameters and use the...

In KGameRenderer extract the KGoldrunner theme-parameters and use the QGraphicsScene to set the border color. In g.h and g.cpp change the tile-coordinate system to be in line with KGoldrunner internal grid-coordinates. In kgoldrunner.cpp, comment out an erroneous reference to KGameRenderer.

svn path=/branches/work/kgoldrunner-qgv/; revision=1298234
parent 933714a4
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
struct Tile {const int i; const int j; const char type; }; struct Tile {const int i; const int j; const char type; };
static const Tile test[] = { static const Tile test[] = {
{2, 2, BRICK}, // One brick at each corner of the level-layout. {1, 1, BRICK}, // One brick at each corner of the level-layout.
{2, 21, BRICK}, {1, 20, BRICK},
{29, 2, BRICK}, {28, 1, BRICK},
{29, 21, BRICK}, {28, 20, BRICK},
{10, 10, BRICK}, // A block of 12 bricks. {10, 10, BRICK}, // A block of 12 bricks.
{10, 11, BRICK}, {10, 11, BRICK},
{10, 12, BRICK}, {10, 12, BRICK},
...@@ -61,39 +61,40 @@ static const Tile test[] = { ...@@ -61,39 +61,40 @@ static const Tile test[] = {
{21, 11, BAR}, {21, 11, BAR},
{22, 11, BAR}, {22, 11, BAR},
{23, 11, BAR}, {23, 11, BAR},
{20, 13, LADDER}, // A 6-piece ladder. {20, 12, LADDER}, // A 6-piece ladder.
{20, 13, LADDER},
{20, 14, LADDER}, {20, 14, LADDER},
{20, 15, LADDER}, {20, 15, LADDER},
{20, 16, LADDER}, {20, 16, LADDER},
{20, 17, LADDER}, {20, 17, LADDER},
{20, 18, LADDER}, {14, 19, NUGGET}, // Some gold pieces.
{14, 20, NUGGET}, // Some gold pieces. {15, 19, NUGGET},
{15, 20, NUGGET}, {16, 19, NUGGET},
{16, 20, NUGGET}, {17, 19, NUGGET},
{17, 20, NUGGET}, {20, 19, HERO}, // Extra tiles for the editor.
{20, 20, HERO}, // Extra tiles for the editor. {21, 19, ENEMY},
{21, 20, ENEMY}, {22, 19, FBRICK},
{22, 20, FBRICK}, {23, 19, HLADDER},
{23, 20, HLADDER},
{0, 0, FREE} {0, 0, FREE}
}; };
GS::GS (QObject * parent) GS::GS (QObject * parent)
: :
QGraphicsScene (parent), QGraphicsScene (parent),
m_tilesWide (32), m_tilesWide (FIELDWIDTH + 2),
m_tilesHigh (24), m_tilesHigh (FIELDHEIGHT + 2),
m_tileSize (10) m_tileSize (10)
{ {
m_renderer = new KGrRenderer (this); m_renderer = new KGrRenderer (dynamic_cast<QGraphicsScene *>(this));
m_renderSet = m_renderer->getSetRenderer(); m_renderSet = m_renderer->getSetRenderer();
m_renderActors = m_renderer->getActorsRenderer(); m_renderActors = m_renderer->getActorsRenderer();
// IDW test. // IDW test. View is always >= m_grid, leaving >=2 tile widths of border.
m_grid = new QGraphicsRectItem(0, 0, m_tilesWide * m_tileSize, m_grid = new QGraphicsRectItem(0, 0, (m_tilesWide + 2) * m_tileSize,
m_tilesHigh * m_tileSize); (m_tilesHigh + 2) * m_tileSize);
m_grid->setPen (QPen (Qt::white));
addItem (m_grid); addItem (m_grid);
for (int lev = 10; lev <= 13; lev++) { for (int lev = 10; lev <= 13; lev++) { // Test getBackgroundKey().
qDebug() << "Background" << lev << m_renderer->getBackgroundKey(lev); qDebug() << "Background" << lev << m_renderer->getBackgroundKey(lev);
} }
} }
...@@ -105,31 +106,36 @@ GS::~GS() ...@@ -105,31 +106,36 @@ GS::~GS()
void GS::redrawScene (QSize size) void GS::redrawScene (QSize size)
{ {
// Centre the tile grid in the scene. // Centre the tile grid in the scene.
int tileSize = qMin (size.width()/m_tilesWide, size.height()/m_tilesHigh); int tileSize = qMin (size.width()/(m_tilesWide + 2),
qDebug() << "View size" << size << "tile size" << tileSize << size.width() << "/" << m_tilesWide << "=" << size.width()/m_tilesWide << "|" << size.height() << "/" << m_tilesHigh << "=" << size.height()/m_tilesHigh; size.height()/(m_tilesHigh + 2));
qDebug() << "View size" << size << "tile size" << tileSize
<< size.width() << "/" << m_tilesWide + 2
<< "=" << size.width()/(m_tilesWide + 2) << "|"
<< size.height() << "/" << m_tilesHigh + 2
<< "=" << size.height()/(m_tilesHigh + 2);
setSceneRect (0, 0, size.width(), size.height()); setSceneRect (0, 0, size.width(), size.height());
m_gridTopLeft = QPoint ((size.width() - m_tilesWide * tileSize)/2, m_gridTopLeft = QPoint ((size.width() - m_tilesWide * tileSize)/2,
(size.height() - m_tilesHigh * tileSize)/2); (size.height() - m_tilesHigh * tileSize)/2);
qDebug() << "Top left is" << m_gridTopLeft; qDebug() << "Top left is" << m_gridTopLeft;
m_grid->setRect ((size.width() - m_tilesWide * tileSize)/2, m_grid->setRect ((size.width() - (m_tilesWide + 2) * tileSize)/2,
(size.height() - m_tilesHigh * tileSize)/2, (size.height() - (m_tilesHigh + 2) * tileSize)/2,
m_tilesWide * tileSize, m_tilesHigh * tileSize); (m_tilesWide + 2) * tileSize, (m_tilesHigh + 2) * tileSize);
// NOTE: The background picture can be the same size as the level-layout, as // NOTE: The background picture can be the same size as the level-layout, as
// in this example (Egypt theme), OR the same size as the entire viewport. // in this example (Egypt theme), OR the same size as the entire viewport.
if (m_tiles.count() == 0) { if (m_tiles.count() == 0) {
QString pixmapKey = m_renderer->getPixmapKey (BACKDROP); QString pixmapKey = m_renderer->getBackgroundKey (1); // Test level 1.
m_background = new KGameRenderedItem (m_renderSet, pixmapKey); m_background = new KGameRenderedItem (m_renderSet, pixmapKey);
addItem (m_background); addItem (m_background);
qDebug() << "BACKGROUND pixmap key" << pixmapKey; qDebug() << "BACKGROUND pixmap key" << pixmapKey;
} }
if (tileSize != m_tileSize) { if (tileSize != m_tileSize) {
m_background->setRenderSize (QSize ((m_tilesWide - 4) * tileSize, m_background->setRenderSize (QSize ((m_tilesWide - 2) * tileSize,
(m_tilesHigh - 4) * tileSize)); (m_tilesHigh - 2) * tileSize));
} }
m_background->setPos (m_gridTopLeft.x() + 2 * tileSize, m_background->setPos (m_gridTopLeft.x() + tileSize,
m_gridTopLeft.y() + 2 * tileSize); m_gridTopLeft.y() + tileSize);
if (m_tiles.count() == 0) { if (m_tiles.count() == 0) {
m_tileSize = tileSize; m_tileSize = tileSize;
...@@ -235,8 +241,8 @@ void GS::paintCell (const int i, const int j, const char type) ...@@ -235,8 +241,8 @@ void GS::paintCell (const int i, const int j, const char type)
} }
addItem (m_tiles.at(offset)); addItem (m_tiles.at(offset));
m_tiles.at(offset)->setRenderSize (QSize (m_tileSize, m_tileSize)); m_tiles.at(offset)->setRenderSize (QSize (m_tileSize, m_tileSize));
m_tiles.at(offset)->setPos (m_gridTopLeft.x() + (i + 1) * m_tileSize, m_tiles.at(offset)->setPos (m_gridTopLeft.x() + i * m_tileSize,
m_gridTopLeft.y() + (j + 1) * m_tileSize); m_gridTopLeft.y() + j * m_tileSize);
qDebug() << "Tile" << type << "i,j" << i << j << "size" << m_tileSize << qDebug() << "Tile" << type << "i,j" << i << j << "size" << m_tileSize <<
"at" << m_tiles.at(offset)->pos(); "at" << m_tiles.at(offset)->pos();
} }
......
...@@ -18,19 +18,23 @@ ...@@ -18,19 +18,23 @@
// These are rough QGraphicsScene and QGraphicsView classes for testing the // These are rough QGraphicsScene and QGraphicsView classes for testing the
// KGrRenderer class, but they illustrate points about KGoldrunner graphics. // KGrRenderer class, but they illustrate points about KGoldrunner graphics.
// //
// 1. The scene has examples of every type of SVG element used in KGr. // 1. The scene has examples of every type of SVG element used in KGr.
// 2. There is a brick marking each corner of the level-layout. // 2. There is a brick marking each corner of the level-layout.
// 3. There is an empty border, at least two bricks wide, around the layout. // 3. There is an empty border, at least two bricks wide, around the layout.
// 4. The border usually holds the scores and titles and acts as a buffer zone // 4. The border usually holds the scores and titles and acts as a buffer zone
// for mouse moves. // for mouse moves.
// 5. The rectangle around the level-layout and border is there for testing // 5. The rectangle around the level-layout and border is there for testing
// purposes only and is not part of KGoldrunner. // purposes only and is not part of KGoldrunner.
// 6. Again, purely for testing purposes, the sprites at the top left change // 6. Again, purely for testing purposes, the sprites at the top left change
// their animation frames as the view is resized. // their animation frames as the view is resized.
// 7. The border and its contents have not been drawn. // 7. The border and its contents have not been drawn.
// 8. Some borders (e.g. Egypt) contain border tiles (not drawn here). // 8. Some borders (e.g. Egypt) contain border tiles (not drawn here).
// 9. Some (e.g. Default) contain display-tiles for scores (not drawn here). // 9. Some (e.g. Default) contain display-tiles for scores (not drawn here).
// // 10. The central grid has internal tile-coordinates running from (0, 0) to
// (29, 21). Row 0, row 29, column 0 and column 29 are usually empty, but
// can contain border-tiles (as in the Egyptian theme). The KGoldrunner
// level-layouts use tile-coordinates running from (1, 1) to (28, 20).
#ifndef G_H #ifndef G_H
#define G_H #define G_H
......
...@@ -123,7 +123,7 @@ KGoldrunner::KGoldrunner() ...@@ -123,7 +123,7 @@ KGoldrunner::KGoldrunner()
// Tell the KMainWindow that the KGrCanvas object is the main widget. // Tell the KMainWindow that the KGrCanvas object is the main widget.
setCentralWidget (view); setCentralWidget (view);
m_renderer = new KGrRenderer (view); // IDW test. // m_renderer = new KGrRenderer (view); // IDW test.
// Set up our actions (menu, toolbar and keystrokes) ... // Set up our actions (menu, toolbar and keystrokes) ...
setupActions(); setupActions();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <QDebug> #include <QDebug>
#include <QString> #include <QString>
#include <QGraphicsScene>
#include "kgrglobals.h" #include "kgrglobals.h"
#include "kgrthemetypes.h" #include "kgrthemetypes.h"
...@@ -32,9 +33,10 @@ ...@@ -32,9 +33,10 @@
#include <cmath> #include <cmath>
KGrRenderer::KGrRenderer (QObject * parent) KGrRenderer::KGrRenderer (QGraphicsScene * scene)
: :
QObject (parent) QObject (scene),
m_scene (scene)
{ {
qDebug() << "KGrRenderer called"; qDebug() << "KGrRenderer called";
...@@ -96,9 +98,25 @@ void KGrRenderer::currentThemeChanged (const KgTheme* currentSetTheme) ...@@ -96,9 +98,25 @@ void KGrRenderer::currentThemeChanged (const KgTheme* currentSetTheme)
m_actorsProvider->setCurrentTheme (actorsTheme); m_actorsProvider->setCurrentTheme (actorsTheme);
qDebug() << "actorsTheme" << actorsTheme->customData("Set") qDebug() << "actorsTheme" << actorsTheme->customData("Set")
<< actorsTheme->customData("Actors"); << actorsTheme->customData("Actors");
return; break;
} }
} }
// Save the KGoldrunner attributes of the current theme.
QString s = currentSetTheme->customData("DrawCanvasBorder", "0");
m_hasBorder = (s == QString ("1"));
qDebug() << "THEME HAS BORDER?" << s << m_hasBorder;
s = currentSetTheme->customData("BorderColor", "#000000");
m_borderColor = QColor (s);
qDebug() << "SET BORDER COLOR" << s << m_borderColor;
s = currentSetTheme->customData("TextColor", "#FFFFFF");
m_textColor = QColor (s);
qDebug() << "SET TEXT COLOR" << s << m_textColor;
// Fill the scene (and view) with the new background color. Do this even if
// the background has no border, to avoid ugly white rectangles appearing
// if rendering and painting is momentarily a bit slow.
m_scene->setBackgroundBrush (m_borderColor);
} }
void KGrRenderer::selectTheme() void KGrRenderer::selectTheme()
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <QString> #include <QString>
#include <KGameRenderer> #include <KGameRenderer>
class QGraphicsScene;
class KgThemeProvider; class KgThemeProvider;
class KgThemeSelector; class KgThemeSelector;
...@@ -57,7 +58,7 @@ class KGrRenderer : public QObject ...@@ -57,7 +58,7 @@ class KGrRenderer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
KGrRenderer (QObject * parent); KGrRenderer (QGraphicsScene * scene);
virtual ~KGrRenderer(); virtual ~KGrRenderer();
/* /*
...@@ -116,11 +117,18 @@ private: ...@@ -116,11 +117,18 @@ private:
// no suffix, >0 = number of variants. // no suffix, >0 = number of variants.
}; };
QGraphicsScene * m_scene; // The scene to be rendered.
KgThemeProvider * m_setProvider; // Provider for Set themes. KgThemeProvider * m_setProvider; // Provider for Set themes.
KgThemeProvider * m_actorsProvider; // Provider for Actors themes. KgThemeProvider * m_actorsProvider; // Provider for Actors themes.
KgThemeSelector * m_themeSelector; // Selector (dialog) for themes. KgThemeSelector * m_themeSelector; // Selector (dialog) for themes.
bool m_hasBorder; // Whether the theme has a border or the
// background pixmap fills the view.
QColor m_borderColor; // The color of the theme's border.
QColor m_textColor; // The color of the theme's text.
KGameRenderer * m_setRenderer; // Renderer for Set SVG files. KGameRenderer * m_setRenderer; // Renderer for Set SVG files.
KGameRenderer * m_actorsRenderer; // Renderer for Actors SVG files. KGameRenderer * m_actorsRenderer; // Renderer for Actors SVG files.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment