summaryrefslogtreecommitdiffstats
path: root/gui/checkbox.cpp
diff options
context:
space:
mode:
authorVojtech Bocek <vbocek@gmail.com>2013-07-25 22:53:02 +0200
committerGerrit Code Review <gerrit@198.50.184.117>2013-08-24 14:56:48 +0200
commitfafb0c541bb4b24515c57251a44d87825eec90fb (patch)
tree9cddb55ceef8912c8fafe618c98147ff6df19ef6 /gui/checkbox.cpp
parentClean-up in partitions.hpp (diff)
downloadandroid_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.gz
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.bz2
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.lz
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.xz
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.zst
android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.zip
Diffstat (limited to 'gui/checkbox.cpp')
-rw-r--r--gui/checkbox.cpp224
1 files changed, 114 insertions, 110 deletions
diff --git a/gui/checkbox.cpp b/gui/checkbox.cpp
index 077d5e2dc..b6d5e6348 100644
--- a/gui/checkbox.cpp
+++ b/gui/checkbox.cpp
@@ -26,63 +26,64 @@ extern "C" {
#include "objects.hpp"
GUICheckbox::GUICheckbox(xml_node<>* node)
- : Conditional(node)
+ : Conditional(node)
{
- xml_attribute<>* attr;
- xml_node<>* child;
-
- mChecked = NULL;
- mUnchecked = NULL;
- mLabel = NULL;
- mRendered = false;
-
- mLastState = 0;
-
- if (!node) return;
-
- // The label can be loaded directly
- mLabel = new GUIText(node);
-
- // Read the check states
- child = node->first_node("image");
- if (child)
- {
- attr = child->first_attribute("checked");
- if (attr)
- mChecked = PageManager::FindResource(attr->value());
- attr = child->first_attribute("unchecked");
- if (attr)
- mUnchecked = PageManager::FindResource(attr->value());
- }
-
- // Get the variable data
- child = node->first_node("data");
- if (child)
- {
- attr = child->first_attribute("variable");
- if (attr)
- mVarName = attr->value();
- attr = child->first_attribute("default");
- if (attr)
- DataManager::SetValue(mVarName, attr->value());
- }
-
- mCheckW = 0; mCheckH = 0;
- if (mChecked && mChecked->GetResource())
- {
- mCheckW = gr_get_width(mChecked->GetResource());
- mCheckH = gr_get_height(mChecked->GetResource());
- }
- else if (mUnchecked && mUnchecked->GetResource())
- {
- mCheckW = gr_get_width(mUnchecked->GetResource());
- mCheckH = gr_get_height(mUnchecked->GetResource());
- }
-
- int x, y, w, h;
- mLabel->GetRenderPos(x, y, w, h);
- SetRenderPos(x, y, 0, 0);
- return;
+ xml_attribute<>* attr;
+ xml_node<>* child;
+
+ mChecked = NULL;
+ mUnchecked = NULL;
+ mLabel = NULL;
+ mRendered = false;
+
+ mLastState = 0;
+
+ if (!node)
+ return;
+
+ // The label can be loaded directly
+ mLabel = new GUIText(node);
+
+ // Read the check states
+ child = node->first_node("image");
+ if (child)
+ {
+ attr = child->first_attribute("checked");
+ if (attr)
+ mChecked = PageManager::FindResource(attr->value());
+ attr = child->first_attribute("unchecked");
+ if (attr)
+ mUnchecked = PageManager::FindResource(attr->value());
+ }
+
+ // Get the variable data
+ child = node->first_node("data");
+ if (child)
+ {
+ attr = child->first_attribute("variable");
+ if (attr)
+ mVarName = attr->value();
+ attr = child->first_attribute("default");
+ if (attr)
+ DataManager::SetValue(mVarName, attr->value());
+ }
+
+ mCheckW = 0; mCheckH = 0;
+ if (mChecked && mChecked->GetResource())
+ {
+ mCheckW = gr_get_width(mChecked->GetResource());
+ mCheckH = gr_get_height(mChecked->GetResource());
+ }
+ else if (mUnchecked && mUnchecked->GetResource())
+ {
+ mCheckW = gr_get_width(mUnchecked->GetResource());
+ mCheckH = gr_get_height(mUnchecked->GetResource());
+ }
+
+ int x, y, w, h;
+ mLabel->GetRenderPos(x, y, w, h);
+ SetRenderPos(x, y, 0, 0);
+ return;
}
GUICheckbox::~GUICheckbox()
@@ -91,78 +92,81 @@ GUICheckbox::~GUICheckbox()
int GUICheckbox::Render(void)
{
- if (!isConditionTrue())
- {
- mRendered = false;
- return 0;
- }
-
- int ret = 0;
- int lastState = 0;
- DataManager::GetValue(mVarName, lastState);
-
- if (lastState)
- {
- if (mChecked && mChecked->GetResource())
- gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
- }
- else
- {
- if (mUnchecked && mUnchecked->GetResource())
- gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
- }
- if (mLabel) ret = mLabel->Render();
- mLastState = lastState;
- mRendered = true;
- return ret;
+ if (!isConditionTrue())
+ {
+ mRendered = false;
+ return 0;
+ }
+
+ int ret = 0;
+ int lastState = 0;
+ DataManager::GetValue(mVarName, lastState);
+
+ if (lastState)
+ {
+ if (mChecked && mChecked->GetResource())
+ gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
+ }
+ else
+ {
+ if (mUnchecked && mUnchecked->GetResource())
+ gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
+ }
+ if (mLabel)
+ ret = mLabel->Render();
+ mLastState = lastState;
+ mRendered = true;
+ return ret;
}
int GUICheckbox::Update(void)
{
- if (!isConditionTrue()) return (mRendered ? 2 : 0);
- if (!mRendered) return 2;
+ if (!isConditionTrue()) return (mRendered ? 2 : 0);
+ if (!mRendered) return 2;
- int lastState = 0;
- DataManager::GetValue(mVarName, lastState);
+ int lastState = 0;
+ DataManager::GetValue(mVarName, lastState);
- if (lastState != mLastState)
- return 2;
- return 0;
+ if (lastState != mLastState)
+ return 2;
+ return 0;
}
int GUICheckbox::SetRenderPos(int x, int y, int w, int h)
{
- mRenderX = x;
- mRenderY = y;
+ mRenderX = x;
+ mRenderY = y;
- if (w || h) return -1;
+ if (w || h)
+ return -1;
- int textW, textH;
- mLabel->GetCurrentBounds(textW, textH);
+ int textW, textH;
+ mLabel->GetCurrentBounds(textW, textH);
- w = textW + mCheckW + 5;
- mRenderW = w;
- mRenderH = mCheckH;
+ w = textW + mCheckW + 5;
+ mRenderW = w;
+ mRenderH = mCheckH;
- mTextX = mRenderX + mCheckW + 5;
- mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
+ mTextX = mRenderX + mCheckW + 5;
+ mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
- mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
- SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
- return 0;
+ mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
+ SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
+ return 0;
}
int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x, int y)
{
- if (!isConditionTrue()) return -1;
-
- if (state == TOUCH_RELEASE)
- {
- int lastState;
- DataManager::GetValue(mVarName, lastState);
- lastState = (lastState == 0) ? 1 : 0;
- DataManager::SetValue(mVarName, lastState);
- }
- return 0;
+ if (!isConditionTrue())
+ return -1;
+
+ if (state == TOUCH_RELEASE)
+ {
+ int lastState;
+ DataManager::GetValue(mVarName, lastState);
+ lastState = (lastState == 0) ? 1 : 0;
+ DataManager::SetValue(mVarName, lastState);
+ }
+ return 0;
}