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
This commit is contained in:
parent
ce5ee193d4
commit
3214e3710a
6 changed files with 59 additions and 38 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
centerText[i]->setPos(x, y);
|
||||
x += centerText[i]->boundingRect().width();
|
||||
x = size.width() - centerGraphic->boundingRect().width();
|
||||
x /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue