summaryrefslogtreecommitdiff
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-06 19:19:11 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-06 19:19:11 +0000
commit39e252019f55dab3e6119cba92caf451c29aa92b (patch)
tree5c75ca0b516dba0cb012e05c53388caa91f8ef3a /utils/themeeditor
parent5de6ddcaa170cce4c0a2cd4b43aa76a4ef7ae175 (diff)
downloadrockbox-39e252019f55dab3e6119cba92caf451c29aa92b.tar.gz
rockbox-39e252019f55dab3e6119cba92caf451c29aa92b.zip
Theme Editor: Rockbox FNT files now supported. Theme editor will currently load fonts from the current project directory, or use the built-in font if they're not present
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27318 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp126
-rw-r--r--utils/themeeditor/graphics/rbfont.h14
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp40
-rw-r--r--utils/themeeditor/graphics/rbtext.h42
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp8
-rw-r--r--utils/themeeditor/themeeditor.pro6
6 files changed, 217 insertions, 19 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index 3988fbc64f..e59c79a970 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -24,10 +24,14 @@
24#include <QFont> 24#include <QFont>
25#include <QBrush> 25#include <QBrush>
26#include <QFile> 26#include <QFile>
27#include <QPainter>
28#include <QBitmap>
29#include <QImage>
27 30
28#include <QDebug> 31quint16 RBFont::maxFontSizeFor16BitOffsets = 0xFFDB;
29 32
30RBFont::RBFont(QString file) 33RBFont::RBFont(QString file)
34 : valid(false), imageData(0), offsetData(0), widthData(0)
31{ 35{
32 36
33 /* Attempting to locate the correct file name */ 37 /* Attempting to locate the correct file name */
@@ -40,6 +44,7 @@ RBFont::RBFont(QString file)
40 fin.open(QFile::ReadOnly); 44 fin.open(QFile::ReadOnly);
41 45
42 /* Loading the header info */ 46 /* Loading the header info */
47 quint8 byte;
43 quint16 word; 48 quint16 word;
44 quint32 dword; 49 quint32 dword;
45 50
@@ -89,23 +94,120 @@ RBFont::RBFont(QString file)
89 data >> dword; 94 data >> dword;
90 header.insert("nwidth", dword); 95 header.insert("nwidth", dword);
91 96
92 fin.close(); 97 /* Loading the image data */
98 imageData = new quint8[header.value("nbits").toInt()];
99 for(int i = 0; i < header.value("nbits").toInt(); i++)
100 {
101 data >> byte;
102 imageData[i] = byte;
103 }
104
105 /* Aligning on 16-bit boundary */
106 if(header.value("nbits").toInt() % 2 == 1)
107 data >> byte;
108
109 /* Loading the offset table if necessary */
110 if(header.value("noffset").toInt() > 0)
111 {
112 offsetData = new quint16[header.value("noffset").toInt()];
113 for(int i = 0; i < header.value("noffset").toInt(); i++)
114 {
115 data >> word;
116 offsetData[i] = word;
117 }
118 }
119
120 /* Loading the width table if necessary */
121 if(header.value("nwidth").toInt() > 0)
122 {
123 widthData = new quint8[header.value("nwidth").toInt()];
124 for(int i = 0; i < header.value("nwidth").toInt(); i++)
125 {
126 data >> byte;
127 widthData[i] = byte;
128 }
129 }
130
131 fin.close();
93 132
94 qDebug() << header ;
95} 133}
96 134
97RBFont::~RBFont() 135RBFont::~RBFont()
98{ 136{
137 if(imageData)
138 delete[] imageData;
139 if(offsetData)
140 delete[] offsetData;
141 if(widthData)
142 delete[] widthData;
99} 143}
100 144
101QGraphicsSimpleTextItem* RBFont::renderText(QString text, QColor color, 145RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent)
102 QGraphicsItem *parent)
103{ 146{
104 QGraphicsSimpleTextItem* retval = new QGraphicsSimpleTextItem(text, parent); 147 int firstChar = header.value("firstchar").toInt();
105 QFont font; 148 int height = header.value("height").toInt();
106 font.setFixedPitch(true); 149 int maxWidth = header.value("maxwidth").toInt();
107 font.setPixelSize(8); 150
108 retval->setFont(font); 151 /* First we determine the width of the combined text */
109 retval->setBrush(QBrush(color)); 152 QList<int> widths;
110 return retval; 153 for(int i = 0; i < text.length(); i++)
154 {
155 if(widthData)
156 widths.append(widthData[text[i].unicode() - firstChar]);
157 else
158 widths.append(maxWidth);
159 }
160
161 int totalWidth = 0;
162 for(int i = 0; i < widths.count(); i++)
163 totalWidth += widths[i];
164
165 QImage image(totalWidth, height, QImage::Format_Indexed8);
166
167 image.setColor(0, qRgba(0,0,0,0));
168 image.setColor(1, color.rgb());
169
170 /* Drawing the text */
171 int startX = 0;
172 for(int i = 0; i < text.length(); i++)
173 {
174 unsigned int offset;
175 if(offsetData)
176 offset = offsetData[text[i].unicode() - firstChar];
177 else
178 offset = (text[i].unicode() - firstChar) * maxWidth;
179
180 int bytesHigh = height / 8;
181 if(height % 8 > 0)
182 bytesHigh++;
183
184 int bytes = bytesHigh * widths[i];
185
186 for(int byte = 0; byte < bytes; byte++)
187 {
188 int x = startX + byte % widths[i];
189 int y = byte / widths[i] * 8;
190 quint8 data = imageData[offset];
191 quint8 mask = 0x1;
192 for(int bit = 0; bit < 8; bit++)
193 {
194 if(mask & data)
195 image.setPixel(x, y, 1);
196 else
197 image.setPixel(x, y, 0);
198
199 y++;
200 mask <<= 1;
201 if(y >= height)
202 break;
203 }
204
205 offset++;
206 }
207
208 startX += widths[i];
209 }
210
211 return new RBText(image, parent);
212
111} 213}
diff --git a/utils/themeeditor/graphics/rbfont.h b/utils/themeeditor/graphics/rbfont.h
index 2c1f8a9dce..bc695a0709 100644
--- a/utils/themeeditor/graphics/rbfont.h
+++ b/utils/themeeditor/graphics/rbfont.h
@@ -24,21 +24,29 @@
24 24
25#include <QString> 25#include <QString>
26#include <QFile> 26#include <QFile>
27#include <QGraphicsSimpleTextItem> 27#include <QGraphicsPixmapItem>
28#include <QHash> 28#include <QHash>
29 29
30#include "rbtext.h"
31
30class RBFont 32class RBFont
31{ 33{
32public: 34public:
33 RBFont(QString file); 35 RBFont(QString file);
34 virtual ~RBFont(); 36 virtual ~RBFont();
35 37
36 QGraphicsSimpleTextItem* renderText(QString text, QColor color, 38 RBText* renderText(QString text, QColor color,
37 QGraphicsItem* parent = 0); 39 QGraphicsItem* parent = 0);
38 int lineHeight(){ return 8; } 40 int lineHeight(){ return header.value("height", 0).toInt(); }
41
42 static quint16 maxFontSizeFor16BitOffsets;
39 43
40private: 44private:
41 QHash<QString, QVariant> header; 45 QHash<QString, QVariant> header;
46 bool valid;
47 quint8* imageData;
48 quint16* offsetData;
49 quint8* widthData;
42}; 50};
43 51
44#endif // RBFONT_H 52#endif // RBFONT_H
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
new file mode 100644
index 0000000000..76b817793e
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: rbfont.cpp 27301 2010-07-05 22:15:17Z bieber $
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "rbtext.h"
23
24#include <QPainter>
25
26RBText::RBText(const QImage &image, QGraphicsItem *parent)
27 :QGraphicsItem(parent), image(image)
28{
29}
30
31QRectF RBText::boundingRect() const
32{
33 return QRectF(0, 0, image.width(), image.height());
34}
35
36void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
37 QWidget *widget)
38{
39 painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
40}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
new file mode 100644
index 0000000000..37b1747705
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: rbfont.cpp 27301 2010-07-05 22:15:17Z bieber $
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef RBTEXT_H
23#define RBTEXT_H
24
25#include <QGraphicsItem>
26#include <QImage>
27
28class RBText : public QGraphicsItem
29{
30public:
31 RBText(const QImage& image, QGraphicsItem* parent);
32
33 QRectF boundingRect() const;
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
35 QWidget *widget);
36
37private:
38 QImage image;
39
40};
41
42#endif // RBTEXT_H
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index a92825362d..3b8a02dd87 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -30,8 +30,7 @@
30#include "skin_parser.h" 30#include "skin_parser.h"
31 31
32RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) 32RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
33 : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)), 33 : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
34 foreground(info.screen()->foreground()),
35 background(info.screen()->background()), textOffset(0,0), 34 background(info.screen()->background()), textOffset(0,0),
36 screen(info.screen()), textAlign(Left), showStatusBar(false), 35 screen(info.screen()), textAlign(Left), showStatusBar(false),
37 statusBarTexture(":/render/statusbar.png") 36 statusBarTexture(":/render/statusbar.png")
@@ -42,6 +41,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
42 size = QRectF(0, 0, info.screen()->getWidth(), 41 size = QRectF(0, 0, info.screen()->getWidth(),
43 info.screen()->getHeight()); 42 info.screen()->getHeight());
44 customUI = false; 43 customUI = false;
44 font = screen->getFont(1);
45 45
46 if(info.model()->rowCount(QModelIndex()) > 1) 46 if(info.model()->rowCount(QModelIndex()) > 1)
47 { 47 {
@@ -120,6 +120,10 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
120 y -= screen->parentItem()->pos().y(); 120 y -= screen->parentItem()->pos().y();
121 } 121 }
122 122
123 if(node->params[++param].type == skin_tag_parameter::DEFAULT)
124 font = screen->getFont(1);
125 else
126 font = screen->getFont(node->params[param].data.numeric);
123 127
124 setPos(x, y); 128 setPos(x, y);
125 size = QRectF(0, 0, w, h); 129 size = QRectF(0, 0, w, h);
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 4241598566..8a16fa926a 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -43,7 +43,8 @@ HEADERS += models/parsetreemodel.h \
43 gui/devicestate.h \ 43 gui/devicestate.h \
44 graphics/rbalbumart.h \ 44 graphics/rbalbumart.h \
45 graphics/rbprogressbar.h \ 45 graphics/rbprogressbar.h \
46 gui/findreplacedialog.h 46 gui/findreplacedialog.h \
47 graphics/rbtext.h
47SOURCES += main.cpp \ 48SOURCES += main.cpp \
48 models/parsetreemodel.cpp \ 49 models/parsetreemodel.cpp \
49 models/parsetreenode.cpp \ 50 models/parsetreenode.cpp \
@@ -63,7 +64,8 @@ SOURCES += main.cpp \
63 gui/devicestate.cpp \ 64 gui/devicestate.cpp \
64 graphics/rbalbumart.cpp \ 65 graphics/rbalbumart.cpp \
65 graphics/rbprogressbar.cpp \ 66 graphics/rbprogressbar.cpp \
66 gui/findreplacedialog.cpp 67 gui/findreplacedialog.cpp \
68 graphics/rbtext.cpp
67OTHER_FILES += README \ 69OTHER_FILES += README \
68 resources/windowicon.png \ 70 resources/windowicon.png \
69 resources/appicon.xcf \ 71 resources/appicon.xcf \