summaryrefslogtreecommitdiffstats
path: root/tdepacman/bitfont.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdepacman/bitfont.cpp')
-rw-r--r--tdepacman/bitfont.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tdepacman/bitfont.cpp b/tdepacman/bitfont.cpp
new file mode 100644
index 0000000..f1535fb
--- /dev/null
+++ b/tdepacman/bitfont.cpp
@@ -0,0 +1,71 @@
+#include "bitfont.h"
+
+Bitfont::Bitfont(TQString fontname, uchar firstChar, uchar lastChar)
+{
+ if (!fontname.isEmpty())
+ font.load(fontname);
+ if (font.width() == font.height()) {
+ fontWidth = fontHeight = font.width() / 16;
+ fontFirstChar = 1;
+ fontLastChar = 255;
+ } else {
+ fontWidth = font.width()/(lastChar-firstChar+1);
+ fontHeight = font.height();
+ fontFirstChar = firstChar;
+ fontLastChar = lastChar;
+ }
+}
+
+TQRect Bitfont::rect(TQString str)
+{
+ return TQRect(0, 0, str.length()*fontWidth, fontHeight);
+}
+
+TQPixmap Bitfont::text(TQString str, TQColor fg, TQColor bg)
+{
+ TQPixmap FG(str.length()*fontWidth, fontHeight);
+ TQBitmap MASK(str.length()*fontWidth, fontHeight, TRUE);
+
+ const uchar *s = reinterpret_cast<const unsigned char *>(str.latin1());
+ for (uint i = 0; i < str.length(); i++) {
+ if (font.width() == font.height())
+ bitBlt(&MASK, i*fontWidth, 0, &font,
+ (*s%16)*fontWidth, (*s/16)*fontWidth, fontWidth, fontHeight);
+ else
+ if (*s >= fontFirstChar && *s <= fontLastChar)
+ bitBlt(&MASK, i*fontWidth, 0, &font,
+ (*s-fontFirstChar)*fontWidth, 0, fontWidth, fontHeight);
+ s++;
+ }
+
+ FG.fill(fg);
+ FG.setMask(MASK);
+
+ if (bg.isValid()) {
+ TQPixmap BG(str.length()*fontWidth, fontHeight);
+ BG.fill(bg);
+ bitBlt(&BG, 0, 0, &FG);
+ return BG;
+ } else
+ return FG;
+}
+
+uchar Bitfont::firstChar()
+{
+ return fontFirstChar;
+}
+
+uchar Bitfont::lastChar()
+{
+ return fontLastChar;
+}
+
+int Bitfont::width()
+{
+ return fontWidth;
+}
+
+int Bitfont::height()
+{
+ return fontHeight;
+}