Theme Editor: Working on image rendering
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27083 a1c6a512-1295-4272-9138-f99709370657
diff --git a/utils/themeeditor/graphics/rbimage.cpp b/utils/themeeditor/graphics/rbimage.cpp
index 5105c95..16e6bcb 100644
--- a/utils/themeeditor/graphics/rbimage.cpp
+++ b/utils/themeeditor/graphics/rbimage.cpp
@@ -20,19 +20,55 @@
****************************************************************************/
#include <QPainter>
+#include <QFile>
+#include <QBitmap>
#include "rbimage.h"
-RBImage::RBImage(QString file, int tiles)
- :image(file), tiles(tiles)
+RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent)
+ : QGraphicsItem(parent), tiles(tiles), currentTile(0)
{
+ if(QFile::exists(file))
+ {
+ image = new QPixmap(file);
+
+ if(image->isNull())
+ {
+ delete image;
+ image = 0;
+ return;
+ }
+ else
+ {
+ image->setMask(image->createMaskFromColor(QColor(255,0,255)));
+
+ }
+
+ size = QRectF(x, y, image->width(), image->height() / tiles);
+
+ }
+ else
+ image = 0;
}
-void RBImage::draw(QPainter *painter, int x, int y, int tile)
+RBImage::~RBImage()
{
- if(tiles == 0)
- painter->drawPixmap(x, y, image.width(), image.height(), image);
- else
- painter->drawPixmap(x, y, image, 0, tile * (image.height() / tiles),
- image.width(), image.height() / tiles);
+ if(image)
+ delete image;
+}
+
+QRectF RBImage::boundingRect() const
+{
+ return size;
+}
+
+void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ if(!image)
+ return;
+
+ painter->drawPixmap(size, *image, QRect(0, currentTile * image->height()
+ / tiles, image->width(),
+ image->height() / tiles));
}
diff --git a/utils/themeeditor/graphics/rbimage.h b/utils/themeeditor/graphics/rbimage.h
index 2eaf9b6..cc949d1 100644
--- a/utils/themeeditor/graphics/rbimage.h
+++ b/utils/themeeditor/graphics/rbimage.h
@@ -23,16 +23,32 @@
#define RBIMAGE_H
#include <QPixmap>
+#include <QGraphicsItem>
-class RBImage
+class RBImage: public QGraphicsItem
{
public:
- RBImage(QString file, int tiles = 0);
- void draw(QPainter* painter, int x, int y, int tile = 0);
+ RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0);
+ virtual ~RBImage();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+ void setTile(int tile)
+ {
+ currentTile = tile;
+ if(currentTile > tiles - 1)
+ currentTile = tiles -1;
+ }
+
private:
- QPixmap image;
+ QPixmap* image;
int tiles;
+ int currentTile;
+
+ QRectF size;
};
diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h
index b60705b..bc44071 100644
--- a/utils/themeeditor/graphics/rbscreen.h
+++ b/utils/themeeditor/graphics/rbscreen.h
@@ -54,6 +54,7 @@
void loadImage(QString name, RBImage* image)
{
images.insert(name, image);
+ image->hide();
}
RBImage* getImage(QString name){ return images.value(name, 0); }
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index 9d94967..3a20175 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -37,6 +37,7 @@
/* Default viewport takes up the entire screen */
size = QRectF(0, 0, info.screen()->getWidth(),
info.screen()->getHeight());
+ customUI = false;
if(info.model()->rowCount(QModelIndex()) > 1)
{
@@ -122,8 +123,9 @@
void RBViewport::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
- QColor color = customUI ? Qt::blue : Qt::red;
- painter->fillRect(size, color);
+ painter->setBrush(Qt::NoBrush);
+ painter->setPen(customUI ? Qt::blue : Qt::red);
+ painter->drawRect(size);
}
/* Called at the end of a logical line */
diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp
index ed518a4..41bee5c 100644
--- a/utils/themeeditor/models/parsetreenode.cpp
+++ b/utils/themeeditor/models/parsetreenode.cpp
@@ -25,6 +25,8 @@
#include "parsetreenode.h"
#include "parsetreemodel.h"
+#include "rbimage.h"
+
#include <iostream>
int ParseTreeNode::openConditionals = 0;
@@ -504,6 +506,8 @@
for(int i = element->params_count; i < children.count(); i++)
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
+
+ std::cout << rendered->children().count() << std::endl;
}
/* This version is called for logical lines and such */
@@ -518,17 +522,56 @@
else if(element->type == TAG)
{
QString filename;
+ QString id;
+ int x, y, tiles;
+ RBImage* image;
/* Two switch statements to narrow down the tag name */
switch(element->tag->name[0])
{
+ case 'x':
+ switch(element->tag->name[1])
+ {
+ case 'l':
+ /* %xl */
+ id = element->params[0].data.text;
+ filename = info.settings()->value("imagepath", "") + "/" +
+ element->params[1].data.text;
+ x = element->params[2].data.numeric;
+ y = element->params[3].data.numeric;
+ if(element->params_count > 4)
+ tiles = element->params[4].data.numeric;
+ else
+ tiles = 1;
+
+ info.screen()->loadImage(id, new RBImage(filename, tiles, x, y,
+ viewport));
+ break;
+
+ case '\0':
+ /* %x */
+ id = element->params[0].data.text;
+ filename = info.settings()->value("imagepath", "") + "/" +
+ element->params[1].data.text;
+ x = element->params[2].data.numeric;
+ y = element->params[3].data.numeric;
+ image = new RBImage(filename, 1, x, y, viewport);
+ info.screen()->loadImage(id, new RBImage(filename, 1, x, y,
+ viewport));
+ info.screen()->getImage(id)->show();
+ break;
+
+ }
+
+ break;
+
case 'X':
switch(element->tag->name[1])
{
case '\0':
- /* %X tag */
+ /* %X */
filename = QString(element->params[0].data.text);
info.screen()->setBackdrop(filename);
break;