diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2010-06-18 22:59:14 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2010-06-18 22:59:14 +0200 |
commit | f5f1d102c99ef7b3f1e0aec6463a8c17d3262bad (patch) | |
tree | 8467e6ee4a260ff1c2a033838f72a5a4a8ea088b /glcdskin | |
parent | 4a7aeebfab185320694c88d6d3ff5a1537f94660 (diff) | |
download | graphlcd-base-f5f1d102c99ef7b3f1e0aec6463a8c17d3262bad.tar.gz graphlcd-base-f5f1d102c99ef7b3f1e0aec6463a8c17d3262bad.tar.bz2 |
text-object: added support for alternative text / alternative condition; bug fixes: annoying update problems should now be fixed; bug fix in brightness update detection; overloadable method for getting a timestamp that is compliant to VDR timestamp (cSkinConfig::Now(), will be overloaded in vdr-plugin-graphlcd to return the value of cTimeMs::Now()); serdisp-driver: call rotate only if UpsideDown is set
Diffstat (limited to 'glcdskin')
-rw-r--r-- | glcdskin/config.c | 11 | ||||
-rw-r--r-- | glcdskin/config.h | 2 | ||||
-rw-r--r-- | glcdskin/object.c | 63 | ||||
-rw-r--r-- | glcdskin/object.h | 19 | ||||
-rw-r--r-- | glcdskin/parser.c | 2 |
5 files changed, 79 insertions, 18 deletions
diff --git a/glcdskin/config.c b/glcdskin/config.c index 518218e..c733427 100644 --- a/glcdskin/config.c +++ b/glcdskin/config.c @@ -1,6 +1,8 @@ #include "config.h" #include "type.h" +#include <sys/time.h> + namespace GLCD { @@ -39,4 +41,13 @@ int cSkinConfig::GetTabPosition(int Index, int MaxWidth, const cFont & Font) return 0; } +uint64_t cSkinConfig::Now(void) +{ + struct timeval tv; + + gettimeofday(&tv, 0); + return (uint64_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000); +} + + } // end of namespace diff --git a/glcdskin/config.h b/glcdskin/config.h index f6c8af9..ce68513 100644 --- a/glcdskin/config.h +++ b/glcdskin/config.h @@ -15,6 +15,7 @@ #include <string> +#include <stdint.h> namespace GLCD { @@ -35,6 +36,7 @@ public: virtual cType GetToken(const tSkinToken & Token); virtual int GetTokenId(const std::string & Name); virtual int GetTabPosition(int Index, int MaxWidth, const cFont & Font); + virtual uint64_t Now(void); }; } // end of namespace diff --git a/glcdskin/object.c b/glcdskin/object.c index faa4758..5e63361 100644 --- a/glcdskin/object.c +++ b/glcdskin/object.c @@ -3,7 +3,6 @@ #include "skin.h" #include "cache.h" #include "function.h" -#include <sys/time.h> namespace GLCD { @@ -53,7 +52,9 @@ cSkinObject::cSkinObject(cSkinDisplay * Parent) mScrollSpeed(0), // scroll speed: default (0) mScrollTime(0), // scroll time interval: default (0) mScrollOffset(0), // scroll offset (pixels) - mCurrText(""), + mCurrText(""), // current text (for checks if text has changed) + mAltText(""), // alternative text source for text-objects + mAltCondition(NULL), // condition when alternative sources are used mObjects(NULL) { } @@ -79,7 +80,7 @@ cSkinObject::cSkinObject(const cSkinObject & Src) mCondition(Src.mCondition), mLastChange(0), mChangeDelay(-1), - mStoredImagePath(""), + mStoredImagePath(Src.mStoredImagePath), mImageFrameId(0), mScrollLoopMode(Src.mScrollLoopMode), mScrollLoopReached(Src.mScrollLoopReached), @@ -87,6 +88,8 @@ cSkinObject::cSkinObject(const cSkinObject & Src) mScrollTime(Src.mScrollTime), mScrollOffset(Src.mScrollOffset), mCurrText(Src.mCurrText), + mAltText(Src.mAltText), + mAltCondition(Src.mAltCondition), mObjects(NULL) { if (Src.mObjects) @@ -246,6 +249,19 @@ bool cSkinObject::ParseScrollTime(const std::string & Text) } +bool cSkinObject::ParseAltCondition(const std::string & Text) +{ + cSkinFunction *result = new cSkinFunction(this); + if (result->Parse(Text)) + { + delete mAltCondition; + mAltCondition = result; + return true; + } + return false; +} + + void cSkinObject::SetListIndex(int MaxItems, int Index) { mText.SetListIndex(MaxItems, Index); @@ -276,14 +292,12 @@ tSize cSkinObject::Size(void) const void cSkinObject::Render(GLCD::cBitmap * screen) { - struct timeval tv; uint64_t timestamp; if (mCondition != NULL && !mCondition->Evaluate()) return; - gettimeofday(&tv, 0); - timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; + timestamp = mSkin->Config().Now(); switch (Type()) { @@ -436,7 +450,19 @@ void cSkinObject::Render(GLCD::cBitmap * screen) if (skinFont) { const cFont * font = skinFont->Font(); - std::string text = mText.Evaluate(); + std::string text = ""; + + // is an alternative text defined + alternative condition defined and true? + if (mAltCondition != NULL && mAltCondition->Evaluate() && (mAltText.size() != 0)) { + cSkinString *result = new cSkinString(this, false); + + if (result->Parse(mAltText)) { + text = (std::string) result->Evaluate(); + } + delete result; + } else { // nope: use the original text + text = (std::string) mText.Evaluate(); + } if (! (text == mCurrText) ) { mScrollOffset = 0; @@ -447,7 +473,6 @@ void cSkinObject::Render(GLCD::cBitmap * screen) if (mMultiline) { - // scrolling in multiline not supported at the moment mScrollLoopReached = true; // avoid check in NeedsUpdate() @@ -556,7 +581,7 @@ void cSkinObject::Render(GLCD::cBitmap * screen) if (updateScroll) { mScrollOffset += currScrollSpeed; - if ( x + Size().w + mScrollOffset > w+Size().w) { + if ( x + Size().w + mScrollOffset >= (w+Size().w - font->Width(" "))) { if (currScrollLoopMode == 1) // reset mScrollOffset in next step (else: string not redrawn when scroll done) mScrollLoopReached = true; @@ -650,6 +675,20 @@ bool cSkinObject::NeedsUpdate(uint64_t CurrentTime) int currScrollLoopMode = 1; // default values if no setup default values available int currScrollTime = 500; + std::string text = ""; + + // is an alternative text defined + alternative condition defined and true? + if (mAltCondition != NULL && mAltCondition->Evaluate() && (mAltText.size() != 0)) { + cSkinString *result = new cSkinString(this, false); + + if (result->Parse(mAltText)) { + text = (std::string) result->Evaluate(); + } + delete result; + } else { // nope: use the original text + text = (std::string) mText.Evaluate(); + } + // get default values from derived config-class if available tSkinToken token = tSkinToken(); token.Id = mSkin->Config().GetTokenId("ScrollMode"); @@ -669,8 +708,10 @@ bool cSkinObject::NeedsUpdate(uint64_t CurrentTime) if (mScrollTime > 0) currScrollTime = mScrollTime; - if (currScrollLoopMode > 0 && (!mScrollLoopReached || mScrollOffset) && - (int)(CurrentTime-mLastChange) >= currScrollTime + if ( (text != mCurrText) || + ( (currScrollLoopMode > 0) && (!mScrollLoopReached || mScrollOffset) && + ((int)(CurrentTime-mLastChange) >= currScrollTime) + ) ) { return true; diff --git a/glcdskin/object.h b/glcdskin/object.h index 188dd79..2e05a12 100644 --- a/glcdskin/object.h +++ b/glcdskin/object.h @@ -77,9 +77,9 @@ public: }; private: - cSkinDisplay * mDisplay; + cSkinDisplay * mDisplay; // parent display cSkin * mSkin; - eType mType; + eType mType; // type of object, one of enum eType tPoint mPos1; tPoint mPos2; eColor mColor; @@ -96,7 +96,7 @@ private: cSkinString mText; cSkinFunction * mCondition; - uint64_t mLastChange; // last change in dynamic object (scroll, frame change, ...) + uint64_t mLastChange; // timestamp: last change in dynamic object (scroll, frame change, ...) int mChangeDelay; // delay between two changes (frame change, scrolling, ...) // special values: -2: no further looping (mScrollLoopMode == 'once') // -1: not set (ie: not an animated image) @@ -111,7 +111,10 @@ private: int mScrollOffset; // scroll offset (pixels) std::string mCurrText; // current text (for checks if text has changed) - cSkinObjects * mObjects; // used for block objects such as <list> + std::string mAltText; // alternative text source for text-objects + cSkinFunction * mAltCondition; // condition when alternative sources are used + + cSkinObjects * mObjects; // used for block objects such as <list> public: cSkinObject(cSkinDisplay * parent); @@ -127,9 +130,11 @@ public: bool ParseWidth(const std::string &Text); bool ParseHeight(const std::string &Text); - bool ParseScrollLoopMode(const std::string & Text); - bool ParseScrollSpeed(const std::string & Text); - bool ParseScrollTime(const std::string & Text); + bool ParseScrollLoopMode(const std::string & Text); // parse scroll mode ([never|once|always]) + bool ParseScrollSpeed(const std::string & Text); // parse scroll speed + bool ParseScrollTime(const std::string & Text); // parse scroll time interval + + bool ParseAltCondition(const std::string &Text); // parse condition for alternative use (eg. alternative sources) void SetListIndex(int MaxItems, int Index); diff --git a/glcdskin/parser.c b/glcdskin/parser.c index cd76b24..ce6ed2a 100644 --- a/glcdskin/parser.c +++ b/glcdskin/parser.c @@ -217,6 +217,8 @@ bool StartElem(const std::string & name, std::map<std::string,std::string> & att ATTRIB_OPT_FUNC("scrollmode", object->ParseScrollLoopMode); ATTRIB_OPT_FUNC("scrollspeed", object->ParseScrollSpeed); ATTRIB_OPT_FUNC("scrolltime", object->ParseScrollTime); + ATTRIB_OPT_STRING("alttext", object->mAltText); + ATTRIB_OPT_FUNC("altcondition", object->ParseAltCondition); #if 0 if (name == "blink") { |