diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-10-29 22:49:47 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-10-29 22:49:47 +0200 |
commit | c2d7a375563b93ee7dac34b22ca78c09ca928f02 (patch) | |
tree | 020389e2693783b28a137015e28d3cf6577a55df /glcdskin/variable.c | |
parent | b560da0e0e08d791bbc404da19c394657af816ac (diff) | |
download | graphlcd-base-c2d7a375563b93ee7dac34b22ca78c09ca928f02.tar.gz graphlcd-base-c2d7a375563b93ee7dac34b22ca78c09ca928f02.tar.bz2 |
added additional parameter 'evaluate' for <variable/>; 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)
Diffstat (limited to 'glcdskin/variable.c')
-rw-r--r-- | glcdskin/variable.c | 69 |
1 files changed, 67 insertions, 2 deletions
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) { } |