forked from len0rd/rockbox
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:
parent
a937b8ba05
commit
d3027053f9
5 changed files with 113 additions and 15 deletions
|
@ -20,19 +20,55 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QBitmap>
|
||||||
|
|
||||||
#include "rbimage.h"
|
#include "rbimage.h"
|
||||||
|
|
||||||
RBImage::RBImage(QString file, int tiles)
|
RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent)
|
||||||
:image(file), tiles(tiles)
|
: 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)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBImage::draw(QPainter *painter, int x, int y, int tile)
|
size = QRectF(x, y, image->width(), image->height() / tiles);
|
||||||
{
|
|
||||||
if(tiles == 0)
|
}
|
||||||
painter->drawPixmap(x, y, image.width(), image.height(), image);
|
else
|
||||||
else
|
image = 0;
|
||||||
painter->drawPixmap(x, y, image, 0, tile * (image.height() / tiles),
|
}
|
||||||
image.width(), image.height() / tiles);
|
|
||||||
|
RBImage::~RBImage()
|
||||||
|
{
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,32 @@
|
||||||
#define RBIMAGE_H
|
#define RBIMAGE_H
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class RBImage
|
class RBImage: public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBImage(QString file, int tiles = 0);
|
RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0);
|
||||||
void draw(QPainter* painter, int x, int y, int tile = 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:
|
private:
|
||||||
QPixmap image;
|
QPixmap* image;
|
||||||
int tiles;
|
int tiles;
|
||||||
|
int currentTile;
|
||||||
|
|
||||||
|
QRectF size;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
void loadImage(QString name, RBImage* image)
|
void loadImage(QString name, RBImage* image)
|
||||||
{
|
{
|
||||||
images.insert(name, image);
|
images.insert(name, image);
|
||||||
|
image->hide();
|
||||||
}
|
}
|
||||||
RBImage* getImage(QString name){ return images.value(name, 0); }
|
RBImage* getImage(QString name){ return images.value(name, 0); }
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
/* Default viewport takes up the entire screen */
|
/* Default viewport takes up the entire screen */
|
||||||
size = QRectF(0, 0, info.screen()->getWidth(),
|
size = QRectF(0, 0, info.screen()->getWidth(),
|
||||||
info.screen()->getHeight());
|
info.screen()->getHeight());
|
||||||
|
customUI = false;
|
||||||
|
|
||||||
if(info.model()->rowCount(QModelIndex()) > 1)
|
if(info.model()->rowCount(QModelIndex()) > 1)
|
||||||
{
|
{
|
||||||
|
@ -122,8 +123,9 @@ QRectF RBViewport::boundingRect() const
|
||||||
void RBViewport::paint(QPainter *painter,
|
void RBViewport::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
QColor color = customUI ? Qt::blue : Qt::red;
|
painter->setBrush(Qt::NoBrush);
|
||||||
painter->fillRect(size, color);
|
painter->setPen(customUI ? Qt::blue : Qt::red);
|
||||||
|
painter->drawRect(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called at the end of a logical line */
|
/* Called at the end of a logical line */
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "parsetreenode.h"
|
#include "parsetreenode.h"
|
||||||
#include "parsetreemodel.h"
|
#include "parsetreemodel.h"
|
||||||
|
|
||||||
|
#include "rbimage.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int ParseTreeNode::openConditionals = 0;
|
int ParseTreeNode::openConditionals = 0;
|
||||||
|
@ -504,6 +506,8 @@ void ParseTreeNode::render(const RBRenderInfo& info)
|
||||||
|
|
||||||
for(int i = element->params_count; i < children.count(); i++)
|
for(int i = element->params_count; i < children.count(); i++)
|
||||||
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
|
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
|
||||||
|
|
||||||
|
std::cout << rendered->children().count() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This version is called for logical lines and such */
|
/* 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)
|
else if(element->type == TAG)
|
||||||
{
|
{
|
||||||
QString filename;
|
QString filename;
|
||||||
|
QString id;
|
||||||
|
int x, y, tiles;
|
||||||
|
RBImage* image;
|
||||||
|
|
||||||
/* Two switch statements to narrow down the tag name */
|
/* Two switch statements to narrow down the tag name */
|
||||||
switch(element->tag->name[0])
|
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':
|
case 'X':
|
||||||
|
|
||||||
switch(element->tag->name[1])
|
switch(element->tag->name[1])
|
||||||
{
|
{
|
||||||
case '\0':
|
case '\0':
|
||||||
/* %X tag */
|
/* %X */
|
||||||
filename = QString(element->params[0].data.text);
|
filename = QString(element->params[0].data.text);
|
||||||
info.screen()->setBackdrop(filename);
|
info.screen()->setBackdrop(filename);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue