You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
4.8 KiB
176 lines
4.8 KiB
4 years ago
|
#include <tdeglobalsettings.h>
|
||
4 years ago
|
#include <kdebug.h>
|
||
|
|
||
4 years ago
|
#include <tqvaluevector.h>
|
||
|
#include <tqstringlist.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqfontmetrics.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqbitmap.h>
|
||
4 years ago
|
|
||
|
#include "frame.h"
|
||
|
|
||
|
void Frame::convertDataToPixmap(const Screen *screen)
|
||
|
{
|
||
|
if(!height() || !width()) {
|
||
|
// Assume we're not ready to go.
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int w = screen->cellWidth(), h = screen->cellHeight();
|
||
4 years ago
|
TQPixmap pix(width() * w, height() * h);
|
||
4 years ago
|
pix.fill();
|
||
|
|
||
4 years ago
|
TQBitmap mask(pix.size(), true);
|
||
4 years ago
|
|
||
4 years ago
|
TQPainter p, p2;
|
||
4 years ago
|
|
||
|
p.begin(&pix, true);
|
||
|
p2.begin(&mask, true);
|
||
|
|
||
4 years ago
|
p.setFont(TDEGlobalSettings::fixedFont());
|
||
4 years ago
|
TQFontMetrics fm(p.font());
|
||
4 years ago
|
int leadHeight = fm.leading() + fm.descent();
|
||
|
|
||
|
for(unsigned j = 0; j < m_data.count(); ++j) {
|
||
4 years ago
|
TQValueVector<Screen::Pixel> row = m_data[j];
|
||
4 years ago
|
if(row.isEmpty())
|
||
|
continue;
|
||
|
|
||
|
unsigned first, last;
|
||
|
for (first = 0; first < row.count() && row[first].letter == ' '; ++first)
|
||
|
;
|
||
|
|
||
|
last = row.count() - 1; // Assume the end is already stripped.
|
||
|
|
||
|
for(unsigned i = first; i <= last; ++i) {
|
||
|
if(row[i].letter == m_transparentChar)
|
||
|
continue;
|
||
|
|
||
4 years ago
|
p2.fillRect(i * w, j * h, w, h, TQt::color1);
|
||
4 years ago
|
|
||
|
p.setPen(row[i].color);
|
||
4 years ago
|
p.fillRect(i * w, j * h, w, h, TQt::black);
|
||
|
p.drawText(i * w, j * h + (h - 1 - leadHeight), TQChar(row[i].letter));
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
pix.setMask(mask);
|
||
|
|
||
4 years ago
|
TQPixmap erase(pix);
|
||
|
erase.fill(TQt::black);
|
||
4 years ago
|
erase.setMask(mask);
|
||
|
|
||
|
m_pixmap = pix;
|
||
|
m_erasePixmap = erase;
|
||
|
|
||
|
// Clear m_data to save a wee bit of memory.
|
||
|
m_data.clear();
|
||
|
}
|
||
|
|
||
4 years ago
|
Frame::Frame (TQString text, TQString mask, TQRgb defaultColor, TQChar transparent)
|
||
4 years ago
|
{
|
||
|
//First, process the pixels.
|
||
|
|
||
4 years ago
|
TQStringList rows = TQStringList::split('\n', text, true);
|
||
4 years ago
|
m_height = rows.size();
|
||
|
m_width = 0;
|
||
|
m_transparentChar = transparent;
|
||
|
|
||
4 years ago
|
for (TQStringList::iterator i = rows.begin(); i != rows.end(); ++i)
|
||
4 years ago
|
{
|
||
4 years ago
|
TQValueVector<Screen::Pixel> row;
|
||
4 years ago
|
for (int pos = 0; pos < (*i).length(); ++pos)
|
||
|
{
|
||
|
Screen::Pixel p;
|
||
|
p.letter = (*i).at(pos).unicode();
|
||
|
p.color = defaultColor;
|
||
|
row.append(p);
|
||
|
}
|
||
|
|
||
4 years ago
|
m_width = TQMAX(m_width, row.size());
|
||
4 years ago
|
m_data.append(row);
|
||
|
}
|
||
|
|
||
|
//Now, the colors.
|
||
4 years ago
|
TQStringList cols = TQStringList::split('\n', mask, true);
|
||
4 years ago
|
int y = 0;
|
||
4 years ago
|
for (TQStringList::iterator i = cols.begin(); i != cols.end(); ++i)
|
||
4 years ago
|
{
|
||
|
if (y >= m_data.size())
|
||
|
break;
|
||
|
|
||
|
for (int pos = 0; pos < (*i).length() && pos < m_data[y].size(); ++pos)
|
||
|
{
|
||
|
switch ((*i).at(pos).unicode())
|
||
|
{
|
||
|
//Colors stolen from konsole, TEWidget.cpp
|
||
|
case 'R':
|
||
|
m_data[y][pos].color = 0xFF5454;
|
||
|
break;
|
||
|
case 'r':
|
||
|
m_data[y][pos].color = 0xB21818;
|
||
|
break;
|
||
|
case 'C':
|
||
|
m_data[y][pos].color = 0x54FFFF;
|
||
|
break;
|
||
|
case 'c':
|
||
|
m_data[y][pos].color = 0x18B2B2;
|
||
|
break;
|
||
|
case 'Y':
|
||
|
m_data[y][pos].color = 0xFFFF54;
|
||
|
break;
|
||
|
case 'y':
|
||
|
m_data[y][pos].color = 0xB26818;
|
||
|
break;
|
||
|
case 'G':
|
||
|
m_data[y][pos].color = 0x54FF54;
|
||
|
break;
|
||
|
case 'g':
|
||
|
m_data[y][pos].color = 0x18B218;
|
||
|
break;
|
||
|
case 'B':
|
||
|
m_data[y][pos].color = 0x5454FF;
|
||
|
break;
|
||
|
case 'b':
|
||
|
m_data[y][pos].color = 0x1818B2;
|
||
|
break;
|
||
|
case 'M':
|
||
|
m_data[y][pos].color = 0xFF54FF;
|
||
|
break;
|
||
|
case 'm':
|
||
|
m_data[y][pos].color = 0xB218B2;
|
||
|
break;
|
||
|
case 'W':
|
||
|
m_data[y][pos].color = 0xFFFFFF;
|
||
|
break;
|
||
|
case 'w':
|
||
|
m_data[y][pos].color = 0xB2B2B2;
|
||
|
break;
|
||
|
case ' ':
|
||
|
break;
|
||
|
default:
|
||
4 years ago
|
tqDebug("dunno about color code:'%c'", (*i).at(pos).unicode());
|
||
4 years ago
|
m_data[y][pos].color = 0xFFFFFF;
|
||
|
}
|
||
|
}
|
||
|
++y;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Frame::paint(Screen* scr, int x, int y)
|
||
|
{
|
||
|
if(m_pixmap.isNull())
|
||
|
convertDataToPixmap(scr);
|
||
|
|
||
|
scr->updateSpan(x, y, m_pixmap);
|
||
|
}
|
||
|
|
||
|
void Frame::erase(Screen* scr, int x, int y)
|
||
|
{
|
||
|
if(m_erasePixmap.isNull())
|
||
|
convertDataToPixmap(scr);
|
||
|
|
||
|
scr->clearSpan(x, y, m_erasePixmap);
|
||
|
}
|