aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorMax Horn2005-01-06 19:09:34 +0000
committerMax Horn2005-01-06 19:09:34 +0000
commit4fae197c67b8cecf5a674c710530c44f5cef814e (patch)
treed9b403db62fe8864c8aab2a026466eb16d64d391 /graphics
parent5d88c3954968b8eccb86363055bda55300ac2586 (diff)
downloadscummvm-rg350-4fae197c67b8cecf5a674c710530c44f5cef814e.tar.gz
scummvm-rg350-4fae197c67b8cecf5a674c710530c44f5cef814e.tar.bz2
scummvm-rg350-4fae197c67b8cecf5a674c710530c44f5cef814e.zip
Patch #1092994 (Selfscaling GUI)
svn-id: r16455
Diffstat (limited to 'graphics')
-rw-r--r--graphics/font.cpp42
-rw-r--r--graphics/font.h12
-rw-r--r--graphics/scummfont.cpp23
3 files changed, 54 insertions, 23 deletions
diff --git a/graphics/font.cpp b/graphics/font.cpp
index ac92d1a04e..387fb8f3bf 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -20,6 +20,7 @@
#include "common/stdafx.h"
#include "graphics/font.h"
+#include "gui/newgui.h"
namespace Graphics {
@@ -36,8 +37,11 @@ int NewFont::getCharWidth(byte chr) const {
return desc.width[chr - desc.firstchar];
}
-void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color) const {
+void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
assert(dst != 0);
+ const int scaleFactor = scale ? g_gui.getScaleFactor() : 1;
+ tx *= scaleFactor; ty *= scaleFactor;
+
byte *ptr = (byte *)dst->getBasePtr(tx, ty);
assert(desc.bits != 0 && desc.maxwidth <= 16);
@@ -54,16 +58,30 @@ void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 colo
chr -= desc.firstchar;
const bitmap_t *tmp = desc.bits + (desc.offset ? desc.offset[chr] : (chr * desc.height));
- for (int y = 0; y < desc.height; y++, ptr += dst->pitch) {
- const bitmap_t buffer = *tmp++;
+ for (int y = 0; y < desc.height * scaleFactor; y++, ptr += dst->pitch) {
+ const bitmap_t *buffer = 0;
+ if(scaleFactor != 1) {
+ if(!(y % 2))
+ buffer = tmp++;
+ else
+ buffer = tmp;
+ } else
+ buffer = tmp++;
bitmap_t mask = 0x8000;
if (ty + y < 0 || ty + y >= dst->h)
continue;
-
- for (int x = 0; x < w; x++, mask >>= 1) {
+
+ for (int x = 0; x < w * scaleFactor; x++) {
+ if(scaleFactor != 1) {
+ if(!(x % 2) && x != 0)
+ mask >>= 1;
+ } else if(x != 0) {
+ mask >>= 1;
+ }
+
if (tx + x < 0 || tx + x >= dst->w)
continue;
- if ((buffer & mask) != 0) {
+ if ((*buffer & mask) != 0) {
if (dst->bytesPerPixel == 1)
ptr[x] = color;
else if (dst->bytesPerPixel == 2)
@@ -85,13 +103,13 @@ int Font::getStringWidth(const Common::String &str) const {
return space;
}
-void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis) const {
+void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis, bool scale) const {
assert(dst != 0);
const int leftX = x, rightX = x + w;
uint i;
int width = getStringWidth(s);
Common::String str;
-
+
if (useEllipsis && width > w) {
// String is too wide. So we shorten it "intellegently", by replacing
// parts of it by an ellipsis ("..."). There are three possibilities
@@ -100,12 +118,12 @@ void Font::drawString(const Surface *dst, const Common::String &s, int x, int y,
// make this configurable, replacing the middle probably is a good
// compromise.
const int ellipsisWidth = getStringWidth("...");
-
+
// SLOW algorithm to remove enough of the middle. But it is good enough
// for now.
const int halfWidth = (w - ellipsisWidth) / 2;
int w2 = 0;
-
+
for (i = 0; i < s.size(); ++i) {
int charWidth = getCharWidth(s[i]);
if (w2 + charWidth > halfWidth)
@@ -116,7 +134,7 @@ void Font::drawString(const Surface *dst, const Common::String &s, int x, int y,
// At this point we know that the first 'i' chars are together 'w2'
// pixels wide. We took the first i-1, and add "..." to them.
str += "...";
-
+
// The original string is width wide. Of those we already skipped past
// w2 pixels, which means (width - w2) remain.
// The new str is (w2+ellipsisWidth) wide, so we can accomodate about
@@ -150,7 +168,7 @@ void Font::drawString(const Surface *dst, const Common::String &s, int x, int y,
if (x+w > rightX)
break;
if (x >= leftX)
- drawChar(dst, str[i], x, y, color);
+ drawChar(dst, str[i], x, y, color, scale);
x += w;
}
}
diff --git a/graphics/font.h b/graphics/font.h
index 3a4c0df6c5..73f3fd0420 100644
--- a/graphics/font.h
+++ b/graphics/font.h
@@ -35,7 +35,7 @@ enum TextAlignment {
/**
* Instances of this class represent a distinct font, with a built-in renderer.
- * @todo Maybe move the high-level methods (drawString etc.) to a separate
+ * @todo Maybe move the high-level methods (drawString etc.) to a separate
* FontRenderer class? That way, we could have different variants... ?
* @todo Add more parameters to drawString, or additional similar methods,
* featuring abilities like
@@ -52,9 +52,9 @@ public:
virtual int getMaxCharWidth() const = 0;
virtual int getCharWidth(byte chr) const = 0;
- virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const = 0;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale = false) const = 0;
- void drawString(const Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlignment align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
+ void drawString(const Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlignment align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true, bool scale = false) const;
int getStringWidth(const Common::String &str) const;
};
@@ -65,7 +65,7 @@ public:
virtual int getMaxCharWidth() const { return 8; };
virtual int getCharWidth(byte chr) const;
- virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale) const;
};
extern const ScummFont g_scummfont;
@@ -96,12 +96,12 @@ protected:
public:
NewFont(const FontDesc &d) : desc(d) {}
-
+
virtual int getFontHeight() const { return desc.height; }
virtual int getMaxCharWidth() const { return desc.maxwidth; };
virtual int getCharWidth(byte chr) const;
- virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale) const;
};
extern const NewFont g_sysfont;
diff --git a/graphics/scummfont.cpp b/graphics/scummfont.cpp
index bf48e95c62..6c66137e9f 100644
--- a/graphics/scummfont.cpp
+++ b/graphics/scummfont.cpp
@@ -20,6 +20,7 @@
#include "stdafx.h"
#include "graphics/font.h"
+#include "gui/newgui.h"
namespace Graphics {
@@ -62,24 +63,36 @@ int ScummFont::getCharWidth(byte chr) const {
}
//void ScummFont::drawChar(byte chr, int xx, int yy, OverlayColor color) {
-void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color) const {
+void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
assert(dst != 0);
+ const int scaleFactor = scale ? g_gui.getScaleFactor() : 1;
+ tx *= scaleFactor; ty *= scaleFactor;
+
byte *ptr = (byte *)dst->getBasePtr(tx, ty);
const byte *tmp = guifont + 6 + guifont[4] + chr * 8;
uint buffer = 0;
uint mask = 0;
- for (int y = 0; y < 8; y++) {
+ for (int y = 0; y < 8 * scaleFactor; y++) {
if (ty + y < 0 || ty + y >= dst->h)
continue;
- for (int x = 0; x < 8; x++) {
+ for (int x = 0; x < 8 * scaleFactor; x++) {
+ if(scaleFactor != 1 && !(x % 2))
+ mask >>= 1;
+ else if(scaleFactor == 1)
+ mask >>= 1;
+
if (tx + x < 0 || tx + x >= dst->w)
continue;
unsigned char c;
- mask >>= 1;
+
if (mask == 0) {
- buffer = *tmp++;
+ if(scaleFactor != 1 && !(y % 2))
+ buffer = *tmp++;
+ else if(scaleFactor == 1)
+ buffer = *tmp++;
+
mask = 0x80;
}
c = ((buffer & mask) != 0);