[Scummvm-cvs-logs] CVS: scummvm/graphics font.cpp,1.4,1.5 font.h,1.3,1.4 scummfont.cpp,1.4,1.5
Max Horn
fingolfin at users.sourceforge.net
Thu Jan 6 11:10:28 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/sound audiocd.h,1.7,1.8
- Next message: [Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.53,1.54 dialog.cpp,1.46,1.47 newgui.cpp,1.94,1.95 newgui.h,1.50,1.51
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/graphics
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15359/graphics
Modified Files:
font.cpp font.h scummfont.cpp
Log Message:
Patch #1092994 (Selfscaling GUI)
Index: font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/graphics/font.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- font.cpp 1 Jan 2005 16:08:51 -0000 1.4
+++ font.cpp 6 Jan 2005 19:09:33 -0000 1.5
@@ -20,6 +20,7 @@
#include "common/stdafx.h"
#include "graphics/font.h"
+#include "gui/newgui.h"
namespace Graphics {
@@ -36,8 +37,11 @@
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 @@
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 @@
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 @@
// 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 @@
// 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 @@
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;
}
}
Index: font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/graphics/font.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- font.h 1 Jan 2005 16:08:51 -0000 1.3
+++ font.h 6 Jan 2005 19:09:33 -0000 1.4
@@ -35,7 +35,7 @@
/**
* 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 @@
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 @@
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 @@
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;
Index: scummfont.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/graphics/scummfont.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- scummfont.cpp 1 Jan 2005 16:08:51 -0000 1.4
+++ scummfont.cpp 6 Jan 2005 19:09:33 -0000 1.5
@@ -20,6 +20,7 @@
#include "stdafx.h"
#include "graphics/font.h"
+#include "gui/newgui.h"
namespace Graphics {
@@ -62,24 +63,36 @@
}
//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);
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/sound audiocd.h,1.7,1.8
- Next message: [Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.53,1.54 dialog.cpp,1.46,1.47 newgui.cpp,1.94,1.95 newgui.h,1.50,1.51
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list