diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-05 18:33:23 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-05 18:33:23 +0200 |
commit | 245d1001901b69ded9dff996f7b09ac61ec5bed1 (patch) | |
tree | aef595a3cb995da34c586dfa8124601b66837412 | |
parent | 26f096b5cbf5f5102ce8bd24dff50b9ce7ecc558 (diff) | |
download | graphlcd-base-245d1001901b69ded9dff996f7b09ac61ec5bed1.tar.gz graphlcd-base-245d1001901b69ded9dff996f7b09ac61ec5bed1.tar.bz2 |
bug fixes: offset fix when using #variables in <text/>, scrolling texts now stay correctly in the object area (no more drawing outside the right side of the object area)
-rw-r--r-- | glcdgraphics/bitmap.c | 11 | ||||
-rw-r--r-- | glcdskin/string.c | 13 |
2 files changed, 15 insertions, 9 deletions
diff --git a/glcdgraphics/bitmap.c b/glcdgraphics/bitmap.c index 470b208..464f189 100644 --- a/glcdgraphics/bitmap.c +++ b/glcdgraphics/bitmap.c @@ -676,11 +676,16 @@ int cBitmap::DrawCharacter(int x, int y, int xmax, uint32_t c, const cFont * fon charBitmap = font->GetCharacter(c); if (charBitmap) { + int drawWidth = charBitmap->Width() - skipPixels; + if ( x + drawWidth-1 > xmax) + drawWidth = xmax - x + 1; + drawBitmap = new cBitmap(charBitmap->Width()-skipPixels,charBitmap->Height()); drawBitmap->Clear(bgcolor); if (drawBitmap) { - for (xt=0;xt<charBitmap->Width();xt++) { - for (yt=0;yt<charBitmap->Height();yt++) { + + for (xt = 0; xt < drawWidth; xt++) { + for (yt = 0; yt < charBitmap->Height() ; yt++) { dot = charBitmap->GetPixel(xt+skipPixels,yt); if ((dot | 0xFF000000) == cColor::Black) { // todo: does not work with antialising? drawBitmap->DrawPixel(xt, yt, color); @@ -692,7 +697,7 @@ int cBitmap::DrawCharacter(int x, int y, int xmax, uint32_t c, const cFont * fon DrawBitmap(x, y, *drawBitmap); delete drawBitmap; } - return charBitmap->Width() - skipPixels; + return drawWidth; //charBitmap->Width() - skipPixels; } return 0; } diff --git a/glcdskin/string.c b/glcdskin/string.c index f2195c6..8eaca44 100644 --- a/glcdskin/string.c +++ b/glcdskin/string.c @@ -136,7 +136,7 @@ bool cSkinString::Parse(const std::string & Text, bool Translate) // add #VARNAME# mText.append(varNameStart, (ptr - varNameStart)); mText.append("#"); - offset ++; // # adds one character -> fix offset + offset +=2; // adds two '#' -> fix offset ptr--; // we'd be at the correct position now but the for-loop does a ++ptr -> fix it by stepping back one char last = ptr + 1; } @@ -236,20 +236,21 @@ bool cSkinString::Parse(const std::string & Text, bool Translate) cType cSkinString::Evaluate(void) const { - std::string result_raw = "", result_trans = ""; - int offset = 0; - if (mText.length() == 0 && mTokens.size() == 1) return mSkin->Config().GetToken(mTokens[0]); - for (uint32_t i = 0; i < mTokens.size(); ++i) { - result_raw.append(mText.c_str() + offset, mTokens[i].Offset - offset); + std::string result_raw = ""; + int offset = 0; + for (uint32_t i = 0; i < mTokens.size(); i++) { + result_raw.append(mText.substr(offset, mTokens[i].Offset - offset) ); + std::string bla = mSkin->Config().GetToken(mTokens[i]); result_raw.append(mSkin->Config().GetToken(mTokens[i])); offset = mTokens[i].Offset; } result_raw.append(mText.c_str() + offset); // replace variable placeholders (#VARNAME#) with corresponding values + std::string result_trans = ""; size_t idxstart = 0, idxend = 0; size_t pos = 0; while ( (idxstart=result_raw.find("#", idxstart)) != std::string::npos ) { |