forked from len0rd/rockbox
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;
|
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 firstChar = header.value("firstchar").toInt();
|
||||||
int height = header.value("height").toInt();
|
int height = header.value("height").toInt();
|
||||||
|
@ -221,6 +222,6 @@ RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent)
|
||||||
startX += widths[i];
|
startX += widths[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RBText(image, parent);
|
return new RBText(image, viewWidth, parent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
RBFont(QString file);
|
RBFont(QString file);
|
||||||
virtual ~RBFont();
|
virtual ~RBFont();
|
||||||
|
|
||||||
RBText* renderText(QString text, QColor color,
|
RBText* renderText(QString text, QColor color, int maxWidth,
|
||||||
QGraphicsItem* parent = 0);
|
QGraphicsItem* parent = 0);
|
||||||
int lineHeight(){ return header.value("height", 0).toInt(); }
|
int lineHeight(){ return header.value("height", 0).toInt(); }
|
||||||
|
|
||||||
|
|
|
@ -23,18 +23,24 @@
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
RBText::RBText(const QImage &image, QGraphicsItem *parent)
|
RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent)
|
||||||
:QGraphicsItem(parent), image(image)
|
:QGraphicsItem(parent), image(image), maxWidth(maxWidth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBText::boundingRect() const
|
QRectF RBText::boundingRect() const
|
||||||
{
|
{
|
||||||
|
if(image.width() < maxWidth)
|
||||||
return QRectF(0, 0, image.width(), image.height());
|
return QRectF(0, 0, image.width(), image.height());
|
||||||
|
else
|
||||||
|
return QRectF(0, 0, maxWidth, image.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
|
if(image.width() < maxWidth)
|
||||||
painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
|
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
|
class RBText : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBText(const QImage& image, QGraphicsItem* parent);
|
RBText(const QImage& image, int maxWidth, QGraphicsItem* parent);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage image;
|
QImage image;
|
||||||
|
int maxWidth;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
: QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
|
: QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
|
||||||
background(info.screen()->background()), textOffset(0,0),
|
background(info.screen()->background()), textOffset(0,0),
|
||||||
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
||||||
statusBarTexture(":/render/statusbar.png")
|
statusBarTexture(":/render/statusbar.png"),
|
||||||
|
leftGraphic(0), centerGraphic(0), rightGraphic(0)
|
||||||
{
|
{
|
||||||
if(!node->tag)
|
if(!node->tag)
|
||||||
{
|
{
|
||||||
|
@ -173,26 +174,31 @@ void RBViewport::newLine()
|
||||||
textOffset.setY(textOffset.y() + lineHeight);
|
textOffset.setY(textOffset.y() + lineHeight);
|
||||||
textOffset.setX(0);
|
textOffset.setX(0);
|
||||||
textAlign = Left;
|
textAlign = Left;
|
||||||
|
|
||||||
leftText.clear();
|
leftText.clear();
|
||||||
rightText.clear();
|
rightText.clear();
|
||||||
centerText.clear();
|
centerText.clear();
|
||||||
|
|
||||||
|
leftGraphic = 0;
|
||||||
|
centerGraphic = 0;
|
||||||
|
rightGraphic = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBViewport::write(QString text)
|
void RBViewport::write(QString text)
|
||||||
{
|
{
|
||||||
if(textAlign == Left)
|
if(textAlign == Left)
|
||||||
{
|
{
|
||||||
leftText.append(font->renderText(text, foreground, this));
|
leftText.append(text);
|
||||||
alignLeft();
|
alignLeft();
|
||||||
}
|
}
|
||||||
else if(textAlign == Center)
|
else if(textAlign == Center)
|
||||||
{
|
{
|
||||||
centerText.append(font->renderText(text, foreground, this));
|
centerText.append(text);
|
||||||
alignCenter();
|
alignCenter();
|
||||||
}
|
}
|
||||||
else if(textAlign == Right)
|
else if(textAlign == Right)
|
||||||
{
|
{
|
||||||
rightText.append(font->renderText(text, foreground, this));
|
rightText.append(text);
|
||||||
alignRight();
|
alignRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,50 +275,53 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
|
||||||
void RBViewport::alignLeft()
|
void RBViewport::alignLeft()
|
||||||
{
|
{
|
||||||
int y = textOffset.y();
|
int y = textOffset.y();
|
||||||
int x = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < leftText.count(); i++)
|
if(leftGraphic)
|
||||||
{
|
delete leftGraphic;
|
||||||
leftText[i]->setPos(x, y);
|
|
||||||
x += leftText[i]->boundingRect().width();
|
leftGraphic = font->renderText(leftText, foreground, size.width(), this);
|
||||||
}
|
leftGraphic->setPos(0, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBViewport::alignCenter()
|
void RBViewport::alignCenter()
|
||||||
{
|
{
|
||||||
int y = textOffset.y();
|
int y = textOffset.y();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int width = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < centerText.count(); i++)
|
if(centerGraphic)
|
||||||
width += centerText[i]->boundingRect().width();
|
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 = size.width() - centerGraphic->boundingRect().width();
|
||||||
x += centerText[i]->boundingRect().width();
|
x /= 2;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
centerGraphic->setPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBViewport::alignRight()
|
void RBViewport::alignRight()
|
||||||
{
|
{
|
||||||
|
|
||||||
int y = textOffset.y();
|
int y = textOffset.y();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int width = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < rightText.count(); i++)
|
if(rightGraphic)
|
||||||
width += rightText[i]->boundingRect().width();
|
delete rightGraphic;
|
||||||
|
|
||||||
x = size.width() - width;
|
rightGraphic = font->renderText(rightText, foreground, size.width(), this);
|
||||||
|
|
||||||
for(int i = 0; i < rightText.count(); i++)
|
if(rightGraphic->boundingRect().width() < size.width())
|
||||||
{
|
x = size.width() - rightGraphic->boundingRect().width();
|
||||||
rightText[i]->setPos(x, y);
|
else
|
||||||
x += rightText[i]->boundingRect().width();
|
x = 0;
|
||||||
}
|
|
||||||
|
|
||||||
|
rightGraphic->setPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,17 @@ private:
|
||||||
|
|
||||||
RBScreen* screen;
|
RBScreen* screen;
|
||||||
|
|
||||||
QList<QGraphicsItem*> leftText;
|
QString leftText;
|
||||||
QList<QGraphicsItem*> centerText;
|
QString centerText;
|
||||||
QList<QGraphicsItem*> rightText;
|
QString rightText;
|
||||||
Alignment textAlign;
|
Alignment textAlign;
|
||||||
|
|
||||||
bool showStatusBar;
|
bool showStatusBar;
|
||||||
QPixmap statusBarTexture;
|
QPixmap statusBarTexture;
|
||||||
|
|
||||||
|
RBText* leftGraphic;
|
||||||
|
RBText* centerGraphic;
|
||||||
|
RBText* rightGraphic;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RBVIEWPORT_H
|
#endif // RBVIEWPORT_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue