Theme Editor: Working on image rendering

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27083 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-23 07:18:22 +00:00
parent a937b8ba05
commit d3027053f9
5 changed files with 113 additions and 15 deletions

View file

@ -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));
}

View file

@ -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;
};

View file

@ -54,6 +54,7 @@ public:
void loadImage(QString name, RBImage* image)
{
images.insert(name, image);
image->hide();
}
RBImage* getImage(QString name){ return images.value(name, 0); }

View file

@ -37,6 +37,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
/* 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 @@ QRectF RBViewport::boundingRect() const
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 */

View file

@ -25,6 +25,8 @@
#include "parsetreenode.h"
#include "parsetreemodel.h"
#include "rbimage.h"
#include <iostream>
int ParseTreeNode::openConditionals = 0;
@ -504,6 +506,8 @@ void ParseTreeNode::render(const RBRenderInfo& info)
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 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
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;