forked from len0rd/rockbox
Theme Editor: Began in implementing tag rendering, %X tag now recognized
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27043 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
08d09e678f
commit
ac9287bdb5
11 changed files with 177 additions and 18 deletions
38
utils/themeeditor/graphics/rbimage.cpp
Normal file
38
utils/themeeditor/graphics/rbimage.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Robert Bieber
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include "rbimage.h"
|
||||||
|
|
||||||
|
RBImage::RBImage(QString file, int tiles)
|
||||||
|
:image(file), tiles(tiles)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RBImage::draw(QPainter *painter, int x, int y, int tile)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
39
utils/themeeditor/graphics/rbimage.h
Normal file
39
utils/themeeditor/graphics/rbimage.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Robert Bieber
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef RBIMAGE_H
|
||||||
|
#define RBIMAGE_H
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class RBImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RBImage(QString file, int tiles = 0);
|
||||||
|
void draw(QPainter* painter, int x, int y, int tile = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPixmap image;
|
||||||
|
int tiles;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RBIMAGE_H
|
|
@ -38,13 +38,16 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
|
||||||
QString fg = info.settings()->value("foreground color", "FFFFFF");
|
QString fg = info.settings()->value("foreground color", "FFFFFF");
|
||||||
fgColor = stringToColor(fg, Qt::black);
|
fgColor = stringToColor(fg, Qt::black);
|
||||||
|
|
||||||
/* Loading backdrop if available */
|
settings = info.settings();
|
||||||
QString base = info.settings()->value("themebase", "");
|
|
||||||
QString backdropFile = info.settings()->value("backdrop", "");
|
|
||||||
|
|
||||||
if(QFile::exists(base + "/backdrops/" + backdropFile))
|
/* Loading backdrop if available */
|
||||||
|
themeBase = info.settings()->value("themebase", "");
|
||||||
|
QString backdropFile = info.settings()->value("backdrop", "");
|
||||||
|
backdropFile.replace("/.rockbox/backdrops/", "");
|
||||||
|
|
||||||
|
if(QFile::exists(themeBase + "/backdrops/" + backdropFile))
|
||||||
{
|
{
|
||||||
backdrop = new QPixmap(base + "/backdrops/" + backdropFile);
|
backdrop = new QPixmap(themeBase + "/backdrops/" + backdropFile);
|
||||||
|
|
||||||
/* If a backdrop has been found, use its width and height */
|
/* If a backdrop has been found, use its width and height */
|
||||||
if(!backdrop->isNull())
|
if(!backdrop->isNull())
|
||||||
|
@ -100,6 +103,19 @@ void RBScreen::showViewport(QString name)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RBScreen::setBackdrop(QString filename)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(backdrop)
|
||||||
|
delete backdrop;
|
||||||
|
|
||||||
|
filename = settings->value("imagepath", "") + "/" + filename;
|
||||||
|
|
||||||
|
if(QFile::exists(filename))
|
||||||
|
backdrop = new QPixmap(filename);
|
||||||
|
else
|
||||||
|
backdrop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
QColor RBScreen::stringToColor(QString str, QColor fallback)
|
QColor RBScreen::stringToColor(QString str, QColor fallback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "projectmodel.h"
|
#include "projectmodel.h"
|
||||||
#include "rbrenderinfo.h"
|
#include "rbrenderinfo.h"
|
||||||
|
#include "rbimage.h"
|
||||||
|
|
||||||
class RBViewport;
|
class RBViewport;
|
||||||
|
|
||||||
|
@ -50,6 +51,14 @@ public:
|
||||||
}
|
}
|
||||||
void showViewport(QString name);
|
void showViewport(QString name);
|
||||||
|
|
||||||
|
void loadImage(QString name, RBImage* image)
|
||||||
|
{
|
||||||
|
images.insert(name, image);
|
||||||
|
}
|
||||||
|
RBImage* getImage(QString name){ return images.value(name, 0); }
|
||||||
|
|
||||||
|
void setBackdrop(QString filename);
|
||||||
|
|
||||||
static QColor stringToColor(QString str, QColor fallback);
|
static QColor stringToColor(QString str, QColor fallback);
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,10 +68,13 @@ private:
|
||||||
QColor bgColor;
|
QColor bgColor;
|
||||||
QColor fgColor;
|
QColor fgColor;
|
||||||
QPixmap* backdrop;
|
QPixmap* backdrop;
|
||||||
|
QString themeBase;
|
||||||
|
|
||||||
ProjectModel* project;
|
ProjectModel* project;
|
||||||
|
|
||||||
QMap<QString, RBViewport*> namedViewports;
|
QMap<QString, RBViewport*> namedViewports;
|
||||||
|
QMap<QString, RBImage*> images;
|
||||||
|
QMap<QString, QString>* settings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,11 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
if(info.model()->rowCount(QModelIndex()) > 1)
|
if(info.model()->rowCount(QModelIndex()) > 1)
|
||||||
{
|
{
|
||||||
/* If there is more than one viewport in the document */
|
/* If there is more than one viewport in the document */
|
||||||
displayed = false;
|
setVisible(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
displayed = true;
|
setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -58,7 +58,6 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
{
|
{
|
||||||
case '\0':
|
case '\0':
|
||||||
customUI = false;
|
customUI = false;
|
||||||
displayed = true;
|
|
||||||
param = 0;
|
param = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
/* A preloaded viewport definition */
|
/* A preloaded viewport definition */
|
||||||
ident = node->params[0].data.text;
|
ident = node->params[0].data.text;
|
||||||
customUI = false;
|
customUI = false;
|
||||||
displayed = false;
|
hide();
|
||||||
info.screen()->loadViewport(ident, this);
|
info.screen()->loadViewport(ident, this);
|
||||||
param = 1;
|
param = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -77,11 +76,11 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
param = 1;
|
param = 1;
|
||||||
if(node->params[0].type == skin_tag_parameter::DEFAULT)
|
if(node->params[0].type == skin_tag_parameter::DEFAULT)
|
||||||
{
|
{
|
||||||
displayed = true;
|
setVisible(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
displayed = false;
|
hide();
|
||||||
info.screen()->loadViewport(ident, this);
|
info.screen()->loadViewport(ident, this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -124,7 +123,11 @@ void RBViewport::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
QColor color = customUI ? Qt::blue : Qt::red;
|
QColor color = customUI ? Qt::blue : Qt::red;
|
||||||
if(displayed)
|
painter->fillRect(size, color);
|
||||||
painter->fillRect(size, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called at the end of a logical line */
|
||||||
|
void RBViewport::newline()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -40,14 +40,13 @@ public:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
void show(){ displayed = true; }
|
void newline();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF size;
|
QRectF size;
|
||||||
QColor background;
|
QColor background;
|
||||||
QColor foreground;
|
QColor foreground;
|
||||||
|
|
||||||
bool displayed;
|
|
||||||
bool customUI;
|
bool customUI;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -257,7 +257,7 @@ void SkinDocument::codeChanged()
|
||||||
else
|
else
|
||||||
emit titleChanged(titleText);
|
emit titleChanged(titleText);
|
||||||
|
|
||||||
model->render(project);
|
model->render(project, &fileName);
|
||||||
|
|
||||||
cursorChanged();
|
cursorChanged();
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
||||||
QAbstractItemModel(parent)
|
QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
|
@ -293,6 +295,16 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
|
||||||
settings.insert("themebase", base.canonicalPath());
|
settings.insert("themebase", base.canonicalPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(file)
|
||||||
|
{
|
||||||
|
QString skinFile = *file;
|
||||||
|
QStringList decomp = skinFile.split("/");
|
||||||
|
skinFile = decomp[decomp.count() - 1];
|
||||||
|
skinFile.chop(skinFile.length() - skinFile.lastIndexOf("."));
|
||||||
|
settings.insert("imagepath", settings.value("themebase","") + "/wps/" +
|
||||||
|
skinFile);
|
||||||
|
}
|
||||||
|
|
||||||
RBScreen* screen = 0;
|
RBScreen* screen = 0;
|
||||||
RBRenderInfo info(this, project, &settings, screen);
|
RBRenderInfo info(this, project, &settings, screen);
|
||||||
|
|
||||||
|
|
|
@ -475,6 +475,7 @@ ParseTreeNode* ParseTreeNode::getParent() const
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This version is called for the root node and for viewports */
|
||||||
void ParseTreeNode::render(const RBRenderInfo& info)
|
void ParseTreeNode::render(const RBRenderInfo& info)
|
||||||
{
|
{
|
||||||
/* Parameters don't get rendered */
|
/* Parameters don't get rendered */
|
||||||
|
@ -500,5 +501,41 @@ void ParseTreeNode::render(const RBRenderInfo& info)
|
||||||
}
|
}
|
||||||
|
|
||||||
rendered = new RBViewport(element, info);
|
rendered = new RBViewport(element, info);
|
||||||
|
|
||||||
|
for(int i = element->params_count; i < children.count(); i++)
|
||||||
|
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This version is called for logical lines and such */
|
||||||
|
void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
|
||||||
|
{
|
||||||
|
if(element->type == LINE)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < children.count(); i++)
|
||||||
|
children[i]->render(info, viewport);
|
||||||
|
viewport->newline();
|
||||||
|
}
|
||||||
|
else if(element->type == TAG)
|
||||||
|
{
|
||||||
|
QString filename;
|
||||||
|
|
||||||
|
/* Two switch statements to narrow down the tag name */
|
||||||
|
switch(element->tag->name[0])
|
||||||
|
{
|
||||||
|
|
||||||
|
case 'X':
|
||||||
|
|
||||||
|
switch(element->tag->name[1])
|
||||||
|
{
|
||||||
|
case '\0':
|
||||||
|
/* %X tag */
|
||||||
|
filename = QString(element->params[0].data.text);
|
||||||
|
info.screen()->setBackdrop(filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(const RBRenderInfo& info);
|
void render(const RBRenderInfo& info);
|
||||||
|
void render(const RBRenderInfo &info, RBViewport* viewport);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParseTreeNode* parent;
|
ParseTreeNode* parent;
|
||||||
|
|
|
@ -37,7 +37,8 @@ HEADERS += models/parsetreemodel.h \
|
||||||
gui/skinviewer.h \
|
gui/skinviewer.h \
|
||||||
graphics/rbscreen.h \
|
graphics/rbscreen.h \
|
||||||
graphics/rbviewport.h \
|
graphics/rbviewport.h \
|
||||||
graphics/rbrenderinfo.h
|
graphics/rbrenderinfo.h \
|
||||||
|
graphics/rbimage.h
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
models/parsetreemodel.cpp \
|
models/parsetreemodel.cpp \
|
||||||
models/parsetreenode.cpp \
|
models/parsetreenode.cpp \
|
||||||
|
@ -51,7 +52,8 @@ SOURCES += main.cpp \
|
||||||
gui/skinviewer.cpp \
|
gui/skinviewer.cpp \
|
||||||
graphics/rbscreen.cpp \
|
graphics/rbscreen.cpp \
|
||||||
graphics/rbviewport.cpp \
|
graphics/rbviewport.cpp \
|
||||||
graphics/rbrenderinfo.cpp
|
graphics/rbrenderinfo.cpp \
|
||||||
|
graphics/rbimage.cpp
|
||||||
OTHER_FILES += README \
|
OTHER_FILES += README \
|
||||||
resources/windowicon.png \
|
resources/windowicon.png \
|
||||||
resources/appicon.xcf \
|
resources/appicon.xcf \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue