diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-31 01:00:11 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-31 01:00:11 +0200 |
commit | 210e29362095a6069e0e3534f6426e39e95026e7 (patch) | |
tree | 11b8d84f67a967df6d49c2d62ae7f0e4c30e6c24 | |
parent | 8b7ea2983245e2c2e046054a0acd0995e86e285e (diff) | |
download | graphlcd-base-210e29362095a6069e0e3534f6426e39e95026e7.tar.gz graphlcd-base-210e29362095a6069e0e3534f6426e39e95026e7.tar.bz2 |
added text effects (shadow, outline)
-rw-r--r-- | glcdskin/object.c | 76 | ||||
-rw-r--r-- | glcdskin/object.h | 11 | ||||
-rw-r--r-- | glcdskin/parser.c | 2 |
3 files changed, 84 insertions, 5 deletions
diff --git a/glcdskin/object.c b/glcdskin/object.c index ead6197..806a738 100644 --- a/glcdskin/object.c +++ b/glcdskin/object.c @@ -49,6 +49,8 @@ cSkinObject::cSkinObject(cSkinDisplay * Parent) mFont(this, false), mText(this, false), mCondition(NULL), + mEffect(tfxNone), + mEffectColor(this, cColor(cColor::White)), mLastChange(0), mChangeDelay(-1), // delay between two images frames: -1: not animated / don't care mStoredImagePath(""), @@ -89,6 +91,8 @@ cSkinObject::cSkinObject(const cSkinObject & Src) mFont(Src.mFont), mText(Src.mText), mCondition(Src.mCondition), + mEffect(Src.mEffect), + mEffectColor(Src.mEffectColor), mLastChange(0), mChangeDelay(-1), mStoredImagePath(Src.mStoredImagePath), @@ -188,6 +192,19 @@ bool cSkinObject::ParseVerticalAlignment(const std::string & Text) return true; } +bool cSkinObject::ParseEffect(const std::string & Text) +{ + if (Text == "none") + mEffect = tfxNone; + else if (Text == "shadow") + mEffect = tfxShadow; + else if (Text == "outline") + mEffect = tfxOutline; + else + return false; + return true; +} + bool cSkinObject::ParseIntParam(const std::string &Text, int & Param) { if (isalpha(Text[0]) || Text[0] == '#') @@ -488,6 +505,29 @@ void cSkinObject::Render(GLCD::cBitmap * screen) currScrollTime = (int)(t); } + // amount of loops for effects (no effect: 1 loop) + int loop; + int loops = 1; + int varx[5] = {0, 0, 0, 0, 0}; + int vary[5] = {0, 0, 0, 0, 0}; + + switch (mEffect) { + case tfxShadow: + loops = 2; + varx[0] = 1; vary[0] = 1; + break; + case tfxOutline: + loops = 5; + varx[0] = -1; vary[0] = 0; + varx[1] = 1; vary[1] = 0; + varx[2] = 0; vary[2] = -1; + varx[3] = 0; vary[3] = 1; + break; + case tfxNone: // no-one gets forgotten here, so make g++ happy + default: + loops = 1; + } + if (skinFont) { const cFont * font = skinFont->Font(); @@ -548,7 +588,13 @@ void cSkinObject::Render(GLCD::cBitmap * screen) x += (Size().w - w) / 2; } } - screen->DrawText(x, yoff + Pos().y + i * font->LineHeight(), x + Size().w - 1, lines[i], font, mColor, mBackgroundColor); + for (loop = 0; loop < loops; loop++) { + screen->DrawText( + varx[loop] + x, vary[loop] + yoff + Pos().y + i * font->LineHeight(), + x + Size().w - 1, lines[i], font, + ((loop+1 == loops) ? mColor : mEffectColor), mBackgroundColor + ); + } } } else @@ -586,7 +632,12 @@ void cSkinObject::Render(GLCD::cBitmap * screen) { str = text.substr(pos1, pos2 - pos1); tabWidth = mSkin->Config().GetTabPosition(tab, Size().w, *font); - screen->DrawText(x, yoff + Pos().y, x + tabWidth - 1, str, font, mColor, mBackgroundColor); + for (loop = 0; loop < loops; loop++) { + screen->DrawText( + varx[loop] + x, vary[loop] + yoff + Pos().y, x + tabWidth - 1, str, font, + ((loop+1 == loops) ? mColor : mEffectColor), mBackgroundColor + ); + } pos1 = pos2 + 1; pos2 = text.find('\t', pos1); tabWidth += font->Width(' '); @@ -595,7 +646,12 @@ void cSkinObject::Render(GLCD::cBitmap * screen) tab++; } str = text.substr(pos1); - screen->DrawText(x, yoff + Pos().y, x + w - 1, str, font, mColor, mBackgroundColor); + for (loop = 0; loop < loops; loop++) { + screen->DrawText( + varx[loop] + x, vary[loop] + yoff + Pos().y, x + w - 1, str, font, + ((loop+1 == loops) ? mColor : mEffectColor), mBackgroundColor + ); + } } else { @@ -648,9 +704,19 @@ void cSkinObject::Render(GLCD::cBitmap * screen) } w += font->Width(" "); std::string textdoubled = text + " " + text; - screen->DrawText(x, yoff + Pos().y, x + Size().w - 1, textdoubled, font, mColor, mBackgroundColor, true, corr_scrolloffset); + for (loop = 0; loop < loops; loop++) { + screen->DrawText( + varx[loop] + x, vary[loop] + yoff + Pos().y, x + Size().w - 1, textdoubled, font, + ((loop+1 == loops) ? mColor : mEffectColor), mBackgroundColor, true, corr_scrolloffset + ); + } } else { - screen->DrawText(x, yoff + Pos().y, x + Size().w - 1, text, font, mColor, mBackgroundColor, true, mScrollOffset); + for (loop = 0; loop < loops; loop++) { + screen->DrawText( + varx[loop] + x, vary[loop] + yoff + Pos().y, x + Size().w - 1, text, font, + ((loop+1 == loops) ? mColor : mEffectColor), mBackgroundColor, true, mScrollOffset + ); + } } if (updateScroll) { diff --git a/glcdskin/object.h b/glcdskin/object.h index cb5f35a..5131cd4 100644 --- a/glcdskin/object.h +++ b/glcdskin/object.h @@ -60,6 +60,14 @@ enum eTextVerticalAlignment tvaBottom }; +enum eEffect +{ + tfxNone, + tfxShadow, + tfxOutline +}; + + class cSkinColor { @@ -130,6 +138,8 @@ private: cSkinString mFont; cSkinString mText; cSkinFunction * mCondition; + eEffect mEffect; // effect: none, shadow, or outline + cSkinColor mEffectColor; // effect colour (= shadow colour or colour of outline) uint64_t mLastChange; // timestamp: last change in dynamic object (scroll, frame change, ...) int mChangeDelay; // delay between two changes (frame change, scrolling, ...) @@ -162,6 +172,7 @@ public: bool ParseCondition(const std::string &Text); bool ParseAlignment(const std::string &Text); bool ParseVerticalAlignment(const std::string &Text); + bool ParseEffect(const std::string &Text); bool ParseFontFace(const std::string &Text); bool ParseIntParam(const std::string &Text, int & Param); bool ParseWidth(const std::string &Text); diff --git a/glcdskin/parser.c b/glcdskin/parser.c index b52427b..0fc9689 100644 --- a/glcdskin/parser.c +++ b/glcdskin/parser.c @@ -296,6 +296,8 @@ bool StartElem(const std::string & name, std::map<std::string,std::string> & att ATTRIB_OPT_FUNC("scrolltime", object->ParseScrollTime); ATTRIB_OPT_STRING("alttext", object->mAltText); ATTRIB_OPT_FUNC("altcondition", object->ParseAltCondition); + ATTRIB_OPT_FUNC_PARAM("effectcolor", object->ParseColor, object->mEffectColor); + ATTRIB_OPT_FUNC("effect", object->ParseEffect); } else if (name == "button") { |