From c03743ed0c43812834951422eb122eff4d3ce2eb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 18 Jul 2013 18:16:46 +1000 Subject: [PATCH] Fixed wrong characters being drawn --- common/button.cpp | 2 +- common/raster_font.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/button.cpp b/common/button.cpp index 9dcf578..38c0cb6 100644 --- a/common/button.cpp +++ b/common/button.cpp @@ -56,7 +56,7 @@ void Button::DrawTo(SDL_Surface* const dest) { void Button::SetSurfaces(SDL_Surface* bg, SDL_Surface* fg) { //graphical stuff image.SetSurface(bg); - image.SetClipH(image.GetClipH() / 3); //3 phases, horizontal storage + image.SetClipH(image.GetClipH() / 3); //3 phases, vertical storage font.SetSurface(fg); //reset textX & textY diff --git a/common/raster_font.cpp b/common/raster_font.cpp index 61da639..45b36a0 100644 --- a/common/raster_font.cpp +++ b/common/raster_font.cpp @@ -23,6 +23,11 @@ #include +/* Note: This class can only take a raster font with 16*16 characters, and the + * indevidual characters must have the same dimensions. Overall this class is too + * restrictive; I suggest using a 3rd party library. +*/ + void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) { if (!image.GetSurface()) { throw(std::runtime_error("RasterFont not loaded")); @@ -30,8 +35,8 @@ void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, const Uint16 w = image.GetClipW(); const Uint16 h = image.GetClipH(); for (int i = 0; i < s.size(); i++) { - image.SetClipX(s[i] % w * w); - image.SetClipY(s[i] / h * h); + image.SetClipX(s[i] % 16 * w); + image.SetClipY(s[i] / 16 * h); image.DrawTo(dest, x + i * w, y); } }