Cache results of GUIObject::isConditionTrue()
Signed-off-by: Vojtech Bocek <vbocek@gmail.com> Change-Id: Ia50f7c365b2dc0a65ee046bb42972e3594264878
This commit is contained in:
+4
-7
@@ -144,16 +144,13 @@ int GUIAction::NotifyKey(int key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIAction::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if (varName.empty() && !isConditionValid() && !mKey && !mActionW)
|
||||
doActions();
|
||||
|
||||
// This handles notifying the condition system of page start
|
||||
if (varName.empty() && isConditionValid())
|
||||
NotifyPageSet();
|
||||
|
||||
if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
|
||||
else if((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
|
||||
doActions();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -865,8 +865,10 @@ int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIFileSelector::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIFileSelector::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if(!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
|
||||
+3
-1
@@ -591,8 +591,10 @@ int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIInput::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIInput::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if (varName == mVariable && !isLocalChange) {
|
||||
HandleTextLocation(-1003);
|
||||
return 0;
|
||||
|
||||
+3
-1
@@ -760,8 +760,10 @@ int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIListBox::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIListBox::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if(!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
|
||||
+16
-10
@@ -29,6 +29,8 @@ extern "C" {
|
||||
|
||||
GUIObject::GUIObject(xml_node<>* node)
|
||||
{
|
||||
mConditionsResult = true;
|
||||
|
||||
// Break out early, it's too hard to check if valid every step
|
||||
if (!node) return;
|
||||
|
||||
@@ -78,13 +80,7 @@ bool GUIObject::IsConditionVariable(std::string var)
|
||||
|
||||
bool GUIObject::isConditionTrue()
|
||||
{
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (!isConditionTrue(&(*iter)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return mConditionsResult;
|
||||
}
|
||||
|
||||
bool GUIObject::isConditionTrue(Condition* condition)
|
||||
@@ -159,12 +155,15 @@ bool GUIObject::isConditionValid()
|
||||
return !mConditions.empty();
|
||||
}
|
||||
|
||||
void GUIObject::NotifyPageSet()
|
||||
int GUIObject::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
mConditionsResult = true;
|
||||
|
||||
const bool varNameEmpty = varName.empty();
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); ++iter)
|
||||
{
|
||||
if (iter->mCompareOp == "modified")
|
||||
if(varNameEmpty && iter->mCompareOp == "modified")
|
||||
{
|
||||
string val;
|
||||
|
||||
@@ -176,7 +175,14 @@ void GUIObject::NotifyPageSet()
|
||||
}
|
||||
iter->mLastVal = val;
|
||||
}
|
||||
|
||||
if(varNameEmpty || iter->mVar1 == varName || iter->mVar2 == varName)
|
||||
iter->mLastResult = isConditionTrue(&(*iter));
|
||||
|
||||
if(!iter->mLastResult)
|
||||
mConditionsResult = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GUIObject::isMounted(string vol)
|
||||
|
||||
+19
-13
@@ -114,10 +114,6 @@ public:
|
||||
// Return 0 if this object handles the request, 1 if not
|
||||
virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
// Returns 0 on success, <0 on error
|
||||
virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
|
||||
|
||||
protected:
|
||||
int mActionX, mActionY, mActionW, mActionH;
|
||||
};
|
||||
@@ -132,16 +128,24 @@ public:
|
||||
bool IsConditionVariable(std::string var);
|
||||
bool isConditionTrue();
|
||||
bool isConditionValid();
|
||||
void NotifyPageSet();
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
// Returns 0 on success, <0 on error
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
protected:
|
||||
class Condition
|
||||
{
|
||||
public:
|
||||
Condition() {
|
||||
mLastResult = true;
|
||||
}
|
||||
|
||||
std::string mVar1;
|
||||
std::string mVar2;
|
||||
std::string mCompareOp;
|
||||
std::string mLastVal;
|
||||
bool mLastResult;
|
||||
};
|
||||
|
||||
std::vector<Condition> mConditions;
|
||||
@@ -149,6 +153,8 @@ protected:
|
||||
protected:
|
||||
bool isMounted(std::string vol);
|
||||
bool isConditionTrue(Condition* condition);
|
||||
|
||||
bool mConditionsResult;
|
||||
};
|
||||
|
||||
class InputObject
|
||||
@@ -189,7 +195,7 @@ public:
|
||||
virtual int GetCurrentBounds(int& w, int& h);
|
||||
|
||||
// Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// Set maximum width in pixels
|
||||
virtual int SetMaxWidth(unsigned width);
|
||||
@@ -264,7 +270,7 @@ public:
|
||||
public:
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
virtual int NotifyKey(int key);
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
virtual int doActions();
|
||||
|
||||
protected:
|
||||
@@ -441,7 +447,7 @@ public:
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// SetPos - Update the position of the render object
|
||||
// Return 0 on success, <0 on error
|
||||
@@ -545,7 +551,7 @@ public:
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// SetPos - Update the position of the render object
|
||||
// Return 0 on success, <0 on error
|
||||
@@ -633,7 +639,7 @@ public:
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// SetPos - Update the position of the render object
|
||||
// Return 0 on success, <0 on error
|
||||
@@ -737,7 +743,7 @@ public:
|
||||
|
||||
// NotifyVarChange - Notify of a variable change
|
||||
// Returns 0 on success, <0 on error
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
protected:
|
||||
Resource* mEmptyBar;
|
||||
@@ -854,7 +860,7 @@ public:
|
||||
virtual int Update(void);
|
||||
|
||||
// Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// NotifyTouch - Notify of a touch event
|
||||
// Return 0 on success, >0 to ignore remainder of touch, and <0 on error
|
||||
@@ -937,7 +943,7 @@ public:
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
|
||||
// Notify of a variable change
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
|
||||
|
||||
// SetPageFocus - Notify when a page gains or loses focus
|
||||
virtual void SetPageFocus(int inFocus);
|
||||
|
||||
+5
-7
@@ -519,13 +519,8 @@ void Page::SetPageFocus(int inFocus)
|
||||
|
||||
int Page::NotifyVarChange(std::string varName, std::string value)
|
||||
{
|
||||
std::vector<ActionObject*>::iterator iter;
|
||||
|
||||
// Don't try to handle a lack of handlers
|
||||
if (mActions.size() == 0)
|
||||
return 1;
|
||||
|
||||
for (iter = mActions.begin(); iter != mActions.end(); ++iter)
|
||||
std::vector<GUIObject*>::iterator iter;
|
||||
for (iter = mObjects.begin(); iter != mObjects.end(); ++iter)
|
||||
{
|
||||
if ((*iter)->NotifyVarChange(varName, value))
|
||||
LOGERR("An action handler errored on NotifyVarChange.\n");
|
||||
@@ -865,7 +860,10 @@ PageSet* PageManager::SelectPackage(std::string name)
|
||||
|
||||
tmp = FindPackage(name);
|
||||
if (tmp)
|
||||
{
|
||||
mCurrentSet = tmp;
|
||||
mCurrentSet->NotifyVarChange("", "");
|
||||
}
|
||||
else
|
||||
LOGERR("Unable to find package.\n");
|
||||
|
||||
|
||||
@@ -827,8 +827,10 @@ int GUIPartitionList::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIPartitionList::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIPartitionList::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if(!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
|
||||
+3
-1
@@ -172,8 +172,10 @@ int GUIProgressBar::Update(void)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int GUIProgressBar::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIProgressBar::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if(!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
|
||||
+3
-1
@@ -396,8 +396,10 @@ int GUISliderValue::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUISliderValue::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUISliderValue::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
if (mLabel)
|
||||
mLabel->NotifyVarChange(varName, value);
|
||||
if (varName == mVariable) {
|
||||
|
||||
+3
-1
@@ -222,8 +222,10 @@ std::string GUIText::parseText(void)
|
||||
}
|
||||
}
|
||||
|
||||
int GUIText::NotifyVarChange(std::string varName, std::string value)
|
||||
int GUIText::NotifyVarChange(const std::string& varName, const std::string& value)
|
||||
{
|
||||
GUIObject::NotifyVarChange(varName, value);
|
||||
|
||||
mVarChanged = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user