29
32
* ============================================================ */
31
41
#include <qpainter.h>
32
42
#include <qimage.h>
37
48
#include "texture.h"
80
Theme::Gradient gradient;
40
83
Texture::Texture(int w, int h, const QColor& from, const QColor& to,
41
84
Theme::Bevel bevel, Theme::Gradient gradient,
42
85
bool border, const QColor& borderColor)
45
m_gradient = gradient;
50
m_borderColor = borderColor;
90
d->gradient = gradient;
92
d->borderColor = borderColor;
63
if (m_width <= 0 || m_height <= 0)
105
if (d->width <= 0 || d->height <= 0)
67
108
if (bevel & Theme::SUNKEN)
78
119
if (gradient == Theme::SOLID)
102
143
Texture::~Texture()
112
155
QPixmap Texture::renderPixmap() const
114
if (m_width <= 0 || m_height <= 0)
157
if (d->width <= 0 || d->height <= 0)
115
158
return QPixmap();
120
QPixmap pix(m_width+2, m_height+2);
121
bitBlt(&pix, 1, 1, &m_pixmap, 0, 0);
163
QPixmap pix(d->width+2, d->height+2);
164
bitBlt(&pix, 1, 1, &d->pixmap, 0, 0);
122
165
QPainter p(&pix);
123
p.setPen(m_borderColor);
124
p.drawRect(0, 0, m_width+2, m_height+2);
166
p.setPen(d->borderColor);
167
p.drawRect(0, 0, d->width+2, d->height+2);
130
173
void Texture::doSolid()
132
m_pixmap.resize(m_width, m_height);
133
QPainter p(&m_pixmap);
134
p.fillRect(0, 0, m_width, m_height, m_color0);
135
if (m_bevel == Theme::RAISED)
175
d->pixmap.resize(d->width, d->height);
176
QPainter p(&d->pixmap);
177
p.fillRect(0, 0, d->width, d->height, d->color0);
178
if (d->bevel == Theme::RAISED)
137
p.setPen(m_color0.light(120));
138
p.drawLine(0, 0, m_width-1, 0); // top
139
p.drawLine(0, 0, 0, m_height-1); // left
140
p.setPen(m_color0.dark(120));
141
p.drawLine(0, m_height-1, m_width-1, m_height-1); // bottom
142
p.drawLine(m_width-1, 0, m_width-1, m_height-1); // right
180
p.setPen(d->color0.light(120));
181
p.drawLine(0, 0, d->width-1, 0); // top
182
p.drawLine(0, 0, 0, d->height-1); // left
183
p.setPen(d->color0.dark(120));
184
p.drawLine(0, d->height-1, d->width-1, d->height-1); // bottom
185
p.drawLine(d->width-1, 0, d->width-1, d->height-1); // right
144
else if (m_bevel == Theme::SUNKEN)
187
else if (d->bevel == Theme::SUNKEN)
146
p.setPen(m_color0.dark(120));
147
p.drawLine(0, 0, m_width-1, 0); // top
148
p.drawLine(0, 0, 0, m_height-1); // left
149
p.setPen(m_color0.light(120));
150
p.drawLine(0, m_height-1, m_width-1, m_height-1); // bottom
151
p.drawLine(m_width-1, 0, m_width-1, m_height-1); // right
189
p.setPen(d->color0.dark(120));
190
p.drawLine(0, 0, d->width-1, 0); // top
191
p.drawLine(0, 0, 0, d->height-1); // left
192
p.setPen(d->color0.light(120));
193
p.drawLine(0, d->height-1, d->width-1, d->height-1); // bottom
194
p.drawLine(d->width-1, 0, d->width-1, d->height-1); // right
156
199
void Texture::doHgradient()
158
201
float drx, dgx, dbx,
159
xr = (float) m_color0.red(),
160
xg = (float) m_color0.green(),
161
xb = (float) m_color0.blue();
162
unsigned char *pr = m_red, *pg = m_green, *pb = m_blue;
202
xr = (float) d->color0.red(),
203
xg = (float) d->color0.green(),
204
xb = (float) d->color0.blue();
205
unsigned char *pr = d->red, *pg = d->green, *pb = d->blue;
164
207
register int x, y;
166
drx = (float) (m_color1.red() - m_color0.red());
167
dgx = (float) (m_color1.green() - m_color0.green());
168
dbx = (float) (m_color1.blue() - m_color0.blue());
174
for (x = 0; x < m_width; x++) {
209
drx = (float) (d->color1.red() - d->color0.red());
210
dgx = (float) (d->color1.green() - d->color0.green());
211
dbx = (float) (d->color1.blue() - d->color0.blue());
217
for (x = 0; x < d->width; x++)
175
219
*(pr++) = (unsigned char) (xr);
176
220
*(pg++) = (unsigned char) (xg);
177
221
*(pb++) = (unsigned char) (xb);
184
for (y = 1; y < m_height; y++, pr += m_width, pg += m_width, pb += m_width) {
185
memcpy(pr, m_red, m_width);
186
memcpy(pg, m_green, m_width);
187
memcpy(pb, m_blue, m_width);
228
for (y = 1; y < d->height; y++, pr += d->width, pg += d->width, pb += d->width)
230
memcpy(pr, d->red, d->width);
231
memcpy(pg, d->green, d->width);
232
memcpy(pb, d->blue, d->width);
191
236
void Texture::doVgradient()
193
238
float dry, dgy, dby,
194
yr = (float) m_color0.red(),
195
yg = (float) m_color0.green(),
196
yb = (float) m_color0.blue();
198
dry = (float) (m_color1.red() - m_color0.red());
199
dgy = (float) (m_color1.green() - m_color0.green());
200
dby = (float) (m_color1.blue() - m_color0.blue());
206
unsigned char *pr = m_red, *pg = m_green, *pb = m_blue;
239
yr = (float) d->color0.red(),
240
yg = (float) d->color0.green(),
241
yb = (float) d->color0.blue();
243
dry = (float) (d->color1.red() - d->color0.red());
244
dgy = (float) (d->color1.green() - d->color0.green());
245
dby = (float) (d->color1.blue() - d->color0.blue());
251
unsigned char *pr = d->red, *pg = d->green, *pb = d->blue;
209
for (y = 0; y < m_height; y++, pr += m_width, pg += m_width, pb += m_width) {
210
memset(pr, (unsigned char) yr, m_width);
211
memset(pg, (unsigned char) yg, m_width);
212
memset(pb, (unsigned char) yb, m_width);
254
for (y = 0; y < d->height; y++, pr += d->width, pg += d->width, pb += d->width) {
255
memset(pr, (unsigned char) yr, d->width);
256
memset(pg, (unsigned char) yg, d->width);
257
memset(pb, (unsigned char) yb, d->width);
221
265
void Texture::doDgradient()
223
unsigned int* xtable = new unsigned int[m_width*3];
224
unsigned int* ytable = new unsigned int[m_height*3];
267
unsigned int* xtable = new unsigned int[d->width*3];
268
unsigned int* ytable = new unsigned int[d->height*3];
226
270
float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0,
227
xr = (float) m_color0.red(),
228
xg = (float) m_color0.green(),
229
xb = (float) m_color0.blue();
230
unsigned char *pr = m_red, *pg = m_green, *pb = m_blue;
231
unsigned int w = m_width * 2, h = m_height * 2;
271
xr = (float) d->color0.red(),
272
xg = (float) d->color0.green(),
273
xb = (float) d->color0.blue();
274
unsigned char *pr = d->red, *pg = d->green, *pb = d->blue;
275
unsigned int w = d->width * 2, h = d->height * 2;
232
276
unsigned int *xt = xtable;
233
277
unsigned int *yt = ytable;
236
279
register int x, y;
238
dry = drx = (float) (m_color1.red() - m_color0.red());
239
dgy = dgx = (float) (m_color1.green() - m_color0.green());
240
dby = dbx = (float) (m_color1.blue() - m_color0.blue());
281
dry = drx = (float) (d->color1.red() - d->color0.red());
282
dgy = dgx = (float) (d->color1.green() - d->color0.green());
283
dby = dbx = (float) (d->color1.blue() - d->color0.blue());
242
285
// Create X table
247
for (x = 0; x < m_width; x++) {
290
for (x = 0; x < d->width; x++)
248
292
*(xt++) = (unsigned char) (xr);
249
293
*(xt++) = (unsigned char) (xg);
250
294
*(xt++) = (unsigned char) (xb);
272
317
// Combine tables to create gradient
274
for (yt = ytable, y = 0; y < m_height; y++, yt += 3)
319
for (yt = ytable, y = 0; y < d->height; y++, yt += 3)
276
for (xt = xtable, x = 0; x < m_width; x++)
321
for (xt = xtable, x = 0; x < d->width; x++)
278
323
*(pr++) = *(xt++) + *(yt);
279
324
*(pg++) = *(xt++) + *(yt + 1);
288
333
void Texture::doBevel()
290
unsigned char *pr = m_red, *pg = m_green, *pb = m_blue;
335
unsigned char *pr = d->red, *pg = d->green, *pb = d->blue;
292
337
register unsigned char r, g, b, rr ,gg ,bb;
293
register unsigned int w = m_width, h = m_height - 1, wh = w * h;
338
register unsigned int w = d->width, h = d->height - 1, wh = w * h;
297
343
rr = r + (r >> 1);
298
344
if (rr < r) rr = ~0;
424
471
void Texture::buildImage()
426
unsigned char *pr = m_red, *pg = m_green, *pb = m_blue;
473
unsigned char *pr = d->red, *pg = d->green, *pb = d->blue;
428
QImage image(m_width, m_height, 32);
475
QImage image(d->width, d->height, 32);
430
477
unsigned int* bits = (unsigned int*) image.bits();
433
for (p =0; p < m_width*m_height; p++)
480
for (p =0; p < d->width*d->height; p++)
435
482
*bits = 0xff << 24 | *pr << 16 | *pg << 8 | *pb;