summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-07 06:50:30 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-07 06:50:30 +0000
commit3214e3710ad0d73c1b775b8af002763cbb42382c (patch)
tree67355953e4e3079d0a3ab4ff688dfa6d413d6f36 /utils
parentce5ee193d41061a6b8c9a2b87dc8a43303f82ab9 (diff)
downloadrockbox-3214e3710ad0d73c1b775b8af002763cbb42382c.tar.gz
rockbox-3214e3710ad0d73c1b775b8af002763cbb42382c.tar.bz2
rockbox-3214e3710ad0d73c1b775b8af002763cbb42382c.zip
Theme Editor: Made all lines of text render as a single graphic, viewport size limits now enforced on text width
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27327 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp5
-rw-r--r--utils/themeeditor/graphics/rbfont.h2
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp14
-rw-r--r--utils/themeeditor/graphics/rbtext.h3
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp63
-rw-r--r--utils/themeeditor/graphics/rbviewport.h10
6 files changed, 59 insertions, 38 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index 1c2739d118..e8bff40e13 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -155,7 +155,8 @@ RBFont::~RBFont()
delete[] widthData;
}
-RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent)
+RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
+ QGraphicsItem *parent)
{
int firstChar = header.value("firstchar").toInt();
int height = header.value("height").toInt();
@@ -221,6 +222,6 @@ RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent)
startX += widths[i];
}
- return new RBText(image, parent);
+ return new RBText(image, viewWidth, parent);
}
diff --git a/utils/themeeditor/graphics/rbfont.h b/utils/themeeditor/graphics/rbfont.h
index bc695a0709..6169d92940 100644
--- a/utils/themeeditor/graphics/rbfont.h
+++ b/utils/themeeditor/graphics/rbfont.h
@@ -35,7 +35,7 @@ public:
RBFont(QString file);
virtual ~RBFont();
- RBText* renderText(QString text, QColor color,
+ RBText* renderText(QString text, QColor color, int maxWidth,
QGraphicsItem* parent = 0);
int lineHeight(){ return header.value("height", 0).toInt(); }
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
index 76b817793e..d7fe542ab1 100644
--- a/utils/themeeditor/graphics/rbtext.cpp
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -23,18 +23,24 @@
#include <QPainter>
-RBText::RBText(const QImage &image, QGraphicsItem *parent)
- :QGraphicsItem(parent), image(image)
+RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent)
+ :QGraphicsItem(parent), image(image), maxWidth(maxWidth)
{
}
QRectF RBText::boundingRect() const
{
- return QRectF(0, 0, image.width(), image.height());
+ if(image.width() < maxWidth)
+ return QRectF(0, 0, image.width(), image.height());
+ else
+ return QRectF(0, 0, maxWidth, image.height());
}
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
- painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
+ if(image.width() < maxWidth)
+ painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
+ else
+ painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height());
}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
index 37b1747705..d03505491e 100644
--- a/utils/themeeditor/graphics/rbtext.h
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -28,7 +28,7 @@
class RBText : public QGraphicsItem
{
public:
- RBText(const QImage& image, QGraphicsItem* parent);
+ RBText(const QImage& image, int maxWidth, QGraphicsItem* parent);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@@ -36,6 +36,7 @@ public:
private:
QImage image;
+ int maxWidth;
};
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index 3b8a02dd87..77fe346090 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -33,7 +33,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
: QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
background(info.screen()->background()), textOffset(0,0),
screen(info.screen()), textAlign(Left), showStatusBar(false),
- statusBarTexture(":/render/statusbar.png")
+ statusBarTexture(":/render/statusbar.png"),
+ leftGraphic(0), centerGraphic(0), rightGraphic(0)
{
if(!node->tag)
{
@@ -173,26 +174,31 @@ void RBViewport::newLine()
textOffset.setY(textOffset.y() + lineHeight);
textOffset.setX(0);
textAlign = Left;
+
leftText.clear();
rightText.clear();
centerText.clear();
+
+ leftGraphic = 0;
+ centerGraphic = 0;
+ rightGraphic = 0;
}
void RBViewport::write(QString text)
{
if(textAlign == Left)
{
- leftText.append(font->renderText(text, foreground, this));
+ leftText.append(text);
alignLeft();
}
else if(textAlign == Center)
{
- centerText.append(font->renderText(text, foreground, this));
+ centerText.append(text);
alignCenter();
}
else if(textAlign == Right)
{
- rightText.append(font->renderText(text, foreground, this));
+ rightText.append(text);
alignRight();
}
}
@@ -269,50 +275,53 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
void RBViewport::alignLeft()
{
int y = textOffset.y();
- int x = 0;
- for(int i = 0; i < leftText.count(); i++)
- {
- leftText[i]->setPos(x, y);
- x += leftText[i]->boundingRect().width();
- }
+ if(leftGraphic)
+ delete leftGraphic;
+
+ leftGraphic = font->renderText(leftText, foreground, size.width(), this);
+ leftGraphic->setPos(0, y);
}
void RBViewport::alignCenter()
{
int y = textOffset.y();
int x = 0;
- int width = 0;
- for(int i = 0; i < centerText.count(); i++)
- width += centerText[i]->boundingRect().width();
+ if(centerGraphic)
+ delete centerGraphic;
- x = (size.width() - width) / 2;
+ centerGraphic = font->renderText(centerText, foreground, size.width(),
+ this);
- for(int i = 0; i < centerText.count(); i++)
+ if(centerGraphic->boundingRect().width() < size.width())
+ {
+ x = size.width() - centerGraphic->boundingRect().width();
+ x /= 2;
+ }
+ else
{
- centerText[i]->setPos(x, y);
- x += centerText[i]->boundingRect().width();
+ x = 0;
}
+
+ centerGraphic->setPos(x, y);
}
void RBViewport::alignRight()
{
-
int y = textOffset.y();
int x = 0;
- int width = 0;
- for(int i = 0; i < rightText.count(); i++)
- width += rightText[i]->boundingRect().width();
+ if(rightGraphic)
+ delete rightGraphic;
- x = size.width() - width;
+ rightGraphic = font->renderText(rightText, foreground, size.width(), this);
- for(int i = 0; i < rightText.count(); i++)
- {
- rightText[i]->setPos(x, y);
- x += rightText[i]->boundingRect().width();
- }
+ if(rightGraphic->boundingRect().width() < size.width())
+ x = size.width() - rightGraphic->boundingRect().width();
+ else
+ x = 0;
+ rightGraphic->setPos(x, y);
}
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index 624a9686da..81841d5cfa 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -84,13 +84,17 @@ private:
RBScreen* screen;
- QList<QGraphicsItem*> leftText;
- QList<QGraphicsItem*> centerText;
- QList<QGraphicsItem*> rightText;
+ QString leftText;
+ QString centerText;
+ QString rightText;
Alignment textAlign;
bool showStatusBar;
QPixmap statusBarTexture;
+
+ RBText* leftGraphic;
+ RBText* centerGraphic;
+ RBText* rightGraphic;
};
#endif // RBVIEWPORT_H