From c2d7a375563b93ee7dac34b22ca78c09ca928f02 Mon Sep 17 00:00:00 2001 From: mrwastl Date: Sat, 29 Oct 2011 22:49:47 +0200 Subject: added additional parameter 'evaluate' for ; variables can now be evaluate: 'always': eval at every access, 'tick': eval. once per display update, 'switch': once per channel or menu update, 'once': eval. only once, interval: eval only after a certain amount of time. default = 'tick'; removed method ImageFile::SupportsScaling() (no longer required) --- glcdgraphics/imagefile.h | 2 +- glcdskin/parser.c | 1 + glcdskin/skin.c | 2 ++ glcdskin/skin.h | 7 +++++ glcdskin/variable.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++-- glcdskin/variable.h | 16 ++++++++++- 6 files changed, 93 insertions(+), 4 deletions(-) diff --git a/glcdgraphics/imagefile.h b/glcdgraphics/imagefile.h index 2cc1eba..959d31e 100644 --- a/glcdgraphics/imagefile.h +++ b/glcdgraphics/imagefile.h @@ -31,7 +31,7 @@ public: virtual bool Load(cImage & image, const std::string & fileName); virtual bool Save(cImage & image, const std::string & fileName); - virtual bool SupportsScaling(void) { return true; } + //virtual bool SupportsScaling(void) { return true; } virtual bool LoadScaled(cImage & image, const std::string & fileName, uint16_t & scalew, uint16_t & scaleh); }; diff --git a/glcdskin/parser.c b/glcdskin/parser.c index ca90829..a9cc3de 100644 --- a/glcdskin/parser.c +++ b/glcdskin/parser.c @@ -247,6 +247,7 @@ bool StartElem(const std::string & name, std::map & att { variable = new cSkinVariable(skin); ATTRIB_MAN_STRING("id", variable->mId); + ATTRIB_OPT_FUNC("evaluate", variable->ParseEvalMode); ATTRIB_MAN_FUNC("value", variable->ParseValue); if (context[context.size() - 1] == "condblock") { if (attrs.find("condition") != attrs.end()) { diff --git a/glcdskin/skin.c b/glcdskin/skin.c index c4e8e4b..122b162 100644 --- a/glcdskin/skin.c +++ b/glcdskin/skin.c @@ -21,6 +21,8 @@ cSkin::cSkin(cSkinConfig & Config, const std::string & Name) name(Name) { mImageCache = new cImageCache(this, 100); + tsEvalTick = 0; + tsEvalSwitch = 0; } cSkin::~cSkin(void) diff --git a/glcdskin/skin.h b/glcdskin/skin.h index a095ebb..048c193 100644 --- a/glcdskin/skin.h +++ b/glcdskin/skin.h @@ -43,6 +43,8 @@ private: cSkinDisplays displays; cSkinVariables mVariables; cImageCache * mImageCache; + uint64_t tsEvalTick; + uint64_t tsEvalSwitch; public: cSkin(cSkinConfig & Config, const std::string & Name); @@ -66,6 +68,11 @@ public: cColor GetBackgroundColor(void) { return config.GetDriver()->GetBackgroundColor(); } cColor GetForegroundColor(void) { return config.GetDriver()->GetForegroundColor(); } + + void SetTSEvalTick(uint64_t ts) { tsEvalTick = ts; } + void SetTSEvalSwitch(uint64_t ts) { tsEvalSwitch = ts; } + const uint64_t GetTSEvalTick(void) { return tsEvalTick; } + const uint64_t GetTSEvalSwitch(void) { return tsEvalSwitch; } }; } // end of namespace diff --git a/glcdskin/variable.c b/glcdskin/variable.c index 7fe0149..b300afc 100644 --- a/glcdskin/variable.c +++ b/glcdskin/variable.c @@ -13,18 +13,55 @@ cSkinVariable::cSkinVariable(cSkin * Parent) mCondition(NULL), mFunction(NULL), mDummyDisplay(mSkin), - mDummyObject(&mDummyDisplay) + mDummyObject(&mDummyDisplay), + mEvalMode(tevmTick), + mEvalInterval(0), + mTimestamp(0) { } +bool cSkinVariable::ParseEvalMode(const std::string & Text) +{ + + if (Text == "always") { + mEvalMode = tevmAlways; + } else if (Text == "tick") { + mEvalMode = tevmTick; + } else if (Text == "switch") { + mEvalMode = tevmSwitch; + } else if (Text == "once") { + mEvalMode = tevmOnce; + } else if (Text.length() > 9 && Text.substr(0,9) == "interval:") { + char * e; + const char * t = Text.substr(9).c_str(); + long l = strtol(t, &e, 10); + if ( ! (e == t || *e != '\0') && (l >= 100)) + { + mEvalInterval = (int) l; + mEvalMode = tevmInterval; + return true; + } + return false; + } else { + return false; + } + return true; +} + + bool cSkinVariable::ParseValue(const std::string & Text) { if (isalpha(Text[0]) || Text[0] == '#' || Text[0] == '{') { - delete mFunction; + //delete mFunction; mFunction = new cSkinFunction(&mDummyObject); if (mFunction->Parse(Text)) { + if (mEvalMode == tevmOnce) { + mValue = mFunction->Evaluate(); + delete mFunction; + mFunction = NULL; + } //mValue = func->Evaluate(); //delete func; return true; @@ -60,6 +97,34 @@ bool cSkinVariable::ParseCondition(const std::string & Text) return false; } + +const cType & cSkinVariable::Value(void) +{ + if ( mTimestamp > 0 && + ( ( mEvalMode == tevmTick && mTimestamp >= mSkin->GetTSEvalTick() ) || + ( mEvalMode == tevmSwitch && mTimestamp >= mSkin->GetTSEvalSwitch() ) || + ( mEvalMode == tevmInterval && (mTimestamp + (uint64_t)mEvalInterval) > mSkin->Config().Now()) + ) + ) + { + return mValue; + } + + if (mFunction != NULL) { + mValue = mFunction->Evaluate(); + // should've been solved in ParseValue already, just to be sure ... + if (mEvalMode == tevmOnce) { + delete mFunction; + mFunction = NULL; + } + } + if (mEvalMode == tevmTick || mEvalMode == tevmSwitch || mEvalMode == tevmInterval) { + mTimestamp = mSkin->Config().Now(); + } + return mValue; +} + + cSkinVariables::cSkinVariables(void) { } diff --git a/glcdskin/variable.h b/glcdskin/variable.h index fdeebbc..8c6ef6f 100644 --- a/glcdskin/variable.h +++ b/glcdskin/variable.h @@ -23,6 +23,16 @@ namespace GLCD { +enum eEvalMode +{ + tevmAlways, + tevmTick, + tevmSwitch, + tevmOnce, + tevmInterval +}; + + class cSkin; class cSkinVariable @@ -38,17 +48,21 @@ private: cSkinFunction * mFunction; cSkinDisplay mDummyDisplay; cSkinObject mDummyObject; + eEvalMode mEvalMode; + int mEvalInterval; + uint64_t mTimestamp; public: cSkinVariable(cSkin * Parent); + bool ParseEvalMode(const std::string & Text); bool ParseValue(const std::string & Text); bool ParseCondition(const std::string & Text); cSkin * Skin(void) const { return mSkin; } const std::string & Id(void) const { return mId; } // const cType & Value(void) const { return mValue; } - const cType & Value(void) { if (mFunction != NULL) { mValue = mFunction->Evaluate(); } return mValue; } ; + const cType & Value(void); cSkinFunction * Condition(void) const { return mCondition; } }; -- cgit v1.2.3