diff options
Diffstat (limited to 'utils/themeeditor/graphics')
-rw-r--r-- | utils/themeeditor/graphics/rbfont.cpp | 126 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfont.h | 14 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.cpp | 40 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.h | 42 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.cpp | 8 |
5 files changed, 213 insertions, 17 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> | 31 | quint16 RBFont::maxFontSizeFor16BitOffsets = 0xFFDB; |
29 | 32 | ||
30 | RBFont::RBFont(QString file) | 33 | RBFont::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 | ||
97 | RBFont::~RBFont() | 135 | RBFont::~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 | ||
101 | QGraphicsSimpleTextItem* RBFont::renderText(QString text, QColor color, | 145 | RBText* 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 | |||
30 | class RBFont | 32 | class RBFont |
31 | { | 33 | { |
32 | public: | 34 | public: |
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 | ||
40 | private: | 44 | private: |
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 | |||
26 | RBText::RBText(const QImage &image, QGraphicsItem *parent) | ||
27 | :QGraphicsItem(parent), image(image) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | QRectF RBText::boundingRect() const | ||
32 | { | ||
33 | return QRectF(0, 0, image.width(), image.height()); | ||
34 | } | ||
35 | |||
36 | void 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 | |||
28 | class RBText : public QGraphicsItem | ||
29 | { | ||
30 | public: | ||
31 | RBText(const QImage& image, QGraphicsItem* parent); | ||
32 | |||
33 | QRectF boundingRect() const; | ||
34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | ||
35 | QWidget *widget); | ||
36 | |||
37 | private: | ||
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 | ||
32 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | 32 | RBViewport::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); |