Fixed wrong characters being drawn
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ void Button::DrawTo(SDL_Surface* const dest) {
|
|||||||
void Button::SetSurfaces(SDL_Surface* bg, SDL_Surface* fg) {
|
void Button::SetSurfaces(SDL_Surface* bg, SDL_Surface* fg) {
|
||||||
//graphical stuff
|
//graphical stuff
|
||||||
image.SetSurface(bg);
|
image.SetSurface(bg);
|
||||||
image.SetClipH(image.GetClipH() / 3); //3 phases, horizontal storage
|
image.SetClipH(image.GetClipH() / 3); //3 phases, vertical storage
|
||||||
font.SetSurface(fg);
|
font.SetSurface(fg);
|
||||||
|
|
||||||
//reset textX & textY
|
//reset textX & textY
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
/* 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) {
|
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
||||||
if (!image.GetSurface()) {
|
if (!image.GetSurface()) {
|
||||||
throw(std::runtime_error("RasterFont not loaded"));
|
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 w = image.GetClipW();
|
||||||
const Uint16 h = image.GetClipH();
|
const Uint16 h = image.GetClipH();
|
||||||
for (int i = 0; i < s.size(); i++) {
|
for (int i = 0; i < s.size(); i++) {
|
||||||
image.SetClipX(s[i] % w * w);
|
image.SetClipX(s[i] % 16 * w);
|
||||||
image.SetClipY(s[i] / h * h);
|
image.SetClipY(s[i] / 16 * h);
|
||||||
image.DrawTo(dest, x + i * w, y);
|
image.DrawTo(dest, x + i * w, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user