forked from len0rd/rockbox
Theme Editor: Implemented caching for rendered text, added profiling info to debug build, added a 500msec delay when rendering after code changes to prevent editor from hanging on large themes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27332 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6f06793f58
commit
6d609e009f
11 changed files with 158 additions and 18 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "rbfont.h"
|
||||
#include "rbfontcache.h"
|
||||
#include "rbtextcache.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QBrush>
|
||||
|
@ -166,6 +167,13 @@ RBFont::~RBFont()
|
|||
RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
||||
QGraphicsItem *parent)
|
||||
{
|
||||
|
||||
/* Checking for a cache hit first */
|
||||
QImage* image = RBTextCache::lookup(header.value("filename").toString()
|
||||
+ text);
|
||||
if(image)
|
||||
return new RBText(image, viewWidth, parent);
|
||||
|
||||
int firstChar = header.value("firstchar").toInt();
|
||||
int height = header.value("height").toInt();
|
||||
int maxWidth = header.value("maxwidth").toInt();
|
||||
|
@ -184,10 +192,10 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
|||
for(int i = 0; i < widths.count(); i++)
|
||||
totalWidth += widths[i];
|
||||
|
||||
QImage image(totalWidth, height, QImage::Format_Indexed8);
|
||||
image = new QImage(totalWidth, height, QImage::Format_Indexed8);
|
||||
|
||||
image.setColor(0, qRgba(0,0,0,0));
|
||||
image.setColor(1, color.rgb());
|
||||
image->setColor(0, qRgba(0,0,0,0));
|
||||
image->setColor(1, color.rgb());
|
||||
|
||||
/* Drawing the text */
|
||||
int startX = 0;
|
||||
|
@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
|||
for(int bit = 0; bit < 8; bit++)
|
||||
{
|
||||
if(mask & data)
|
||||
image.setPixel(x, y, 1);
|
||||
image->setPixel(x, y, 1);
|
||||
else
|
||||
image.setPixel(x, y, 0);
|
||||
image->setPixel(x, y, 0);
|
||||
|
||||
y++;
|
||||
mask <<= 1;
|
||||
|
@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
|||
startX += widths[i];
|
||||
}
|
||||
|
||||
RBTextCache::insert(header.value("filename").toString() + text, image);
|
||||
return new RBText(image, viewWidth, parent);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue