diff options
author | Vojtech Bocek <vbocek@gmail.com> | 2013-07-25 22:53:02 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit@198.50.184.117> | 2013-08-24 14:56:48 +0200 |
commit | fafb0c541bb4b24515c57251a44d87825eec90fb (patch) | |
tree | 9cddb55ceef8912c8fafe618c98147ff6df19ef6 /gui/button.cpp | |
parent | Clean-up in partitions.hpp (diff) | |
download | android_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 '')
-rw-r--r-- | gui/button.cpp | 255 |
1 files changed, 127 insertions, 128 deletions
diff --git a/gui/button.cpp b/gui/button.cpp index af7d07b8f..9fc85a052 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -42,42 +42,42 @@ extern "C" { #include "objects.hpp" GUIButton::GUIButton(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - mButtonImg = NULL; - mButtonIcon = NULL; - mButtonLabel = NULL; - mAction = NULL; - mRendered = false; + mButtonImg = NULL; + mButtonIcon = NULL; + mButtonLabel = NULL; + mAction = NULL; + mRendered = false; hasHighlightColor = false; renderHighlight = false; hasFill = false; - if (!node) return; + if (!node) return; - // Three of the four can be loaded directly from the node - mButtonImg = new GUIImage(node); - mButtonLabel = new GUIText(node); - mAction = new GUIAction(node); + // Three of the four can be loaded directly from the node + mButtonImg = new GUIImage(node); + mButtonLabel = new GUIText(node); + mAction = new GUIAction(node); - if (mButtonImg->Render() < 0) - { - delete mButtonImg; - mButtonImg = NULL; - } - if (mButtonLabel->Render() < 0) - { - delete mButtonLabel; - mButtonLabel = NULL; - } + if (mButtonImg->Render() < 0) + { + delete mButtonImg; + mButtonImg = NULL; + } + if (mButtonLabel->Render() < 0) + { + delete mButtonLabel; + mButtonLabel = NULL; + } // Load fill if it exists memset(&mFillColor, 0, sizeof(COLOR)); child = node->first_node("fill"); - if (child) - { + if (child) + { attr = child->first_attribute("color"); if (attr) { hasFill = true; @@ -89,14 +89,14 @@ GUIButton::GUIButton(xml_node<>* node) LOGERR("No image resource or fill specified for button.\n"); } - // The icon is a special case - child = node->first_node("icon"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) - mButtonIcon = PageManager::FindResource(attr->value()); - } + // The icon is a special case + child = node->first_node("icon"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) + mButtonIcon = PageManager::FindResource(attr->value()); + } memset(&mHighlightColor, 0, sizeof(COLOR)); child = node->first_node("highlight"); @@ -109,43 +109,43 @@ GUIButton::GUIButton(xml_node<>* node) } } - int x, y, w, h; - if (mButtonImg) { + int x, y, w, h; + if (mButtonImg) { mButtonImg->GetRenderPos(x, y, w, h); } else if (hasFill) { LoadPlacement(node->first_node("placement"), &x, &y, &w, &h); } SetRenderPos(x, y, w, h); - return; + return; } GUIButton::~GUIButton() { - if (mButtonImg) delete mButtonImg; - if (mButtonLabel) delete mButtonLabel; - if (mAction) delete mAction; - if (mButtonIcon) delete mButtonIcon; + if (mButtonImg) delete mButtonImg; + if (mButtonLabel) delete mButtonLabel; + if (mAction) delete mAction; + if (mButtonIcon) delete mButtonIcon; } int GUIButton::Render(void) { - if (!isConditionTrue()) - { - mRendered = false; - return 0; - } + if (!isConditionTrue()) + { + mRendered = false; + return 0; + } - int ret = 0; + int ret = 0; - if (mButtonImg) ret = mButtonImg->Render(); - if (ret < 0) return ret; + if (mButtonImg) ret = mButtonImg->Render(); + if (ret < 0) return ret; if (hasFill) { gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } - if (mButtonIcon && mButtonIcon->GetResource()) - gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); - if (mButtonLabel) { + if (mButtonIcon && mButtonIcon->GetResource()) + gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); + if (mButtonLabel) { int w, h; mButtonLabel->GetCurrentBounds(w, h); if (w != mTextW) { @@ -163,109 +163,109 @@ int GUIButton::Render(void) mButtonLabel->SetRenderPos(mTextX, mTextY); } ret = mButtonLabel->Render(); - if (ret < 0) return ret; + if (ret < 0) return ret; } if (renderHighlight && hasHighlightColor) { gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } - mRendered = true; - return ret; + mRendered = true; + return ret; } int GUIButton::Update(void) { - if (!isConditionTrue()) return (mRendered ? 2 : 0); - if (!mRendered) return 2; + if (!isConditionTrue()) return (mRendered ? 2 : 0); + if (!mRendered) return 2; - int ret = 0, ret2 = 0; + int ret = 0, ret2 = 0; - if (mButtonImg) ret = mButtonImg->Update(); - if (ret < 0) return ret; + if (mButtonImg) ret = mButtonImg->Update(); + if (ret < 0) return ret; - if (ret == 0) - { - if (mButtonLabel) { + if (ret == 0) + { + if (mButtonLabel) { ret2 = mButtonLabel->Update(); - if (ret2 < 0) return ret2; - if (ret2 > ret) ret = ret2; + if (ret2 < 0) return ret2; + if (ret2 > ret) ret = ret2; } - } - else if (ret == 1) - { - // The button re-rendered, so everyone else is a render - if (mButtonIcon && mButtonIcon->GetResource()) - gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); - if (mButtonLabel) ret = mButtonLabel->Render(); - if (ret < 0) return ret; - ret = 1; - } - else - { - // Aparently, the button needs a background update - ret = 2; - } - return ret; + } + else if (ret == 1) + { + // The button re-rendered, so everyone else is a render + if (mButtonIcon && mButtonIcon->GetResource()) + gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); + if (mButtonLabel) ret = mButtonLabel->Render(); + if (ret < 0) return ret; + ret = 1; + } + else + { + // Aparently, the button needs a background update + ret = 2; + } + return ret; } int GUIButton::SetRenderPos(int x, int y, int w, int h) { - mRenderX = x; - mRenderY = y; - if (w || h) - { - mRenderW = w; - mRenderH = h; - } + mRenderX = x; + mRenderY = y; + if (w || h) + { + mRenderW = w; + mRenderH = h; + } - mIconW = 0; mIconH = 0; - if (mButtonIcon && mButtonIcon->GetResource()) - { - mIconW = gr_get_width(mButtonIcon->GetResource()); - mIconH = gr_get_height(mButtonIcon->GetResource()); - } + mIconW = 0; mIconH = 0; + if (mButtonIcon && mButtonIcon->GetResource()) + { + mIconW = gr_get_width(mButtonIcon->GetResource()); + mIconH = gr_get_height(mButtonIcon->GetResource()); + } - mTextH = 0; - mTextW = 0; - mIconX = mRenderX + ((mRenderW - mIconW) / 2); - if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH); - if (mTextW) - { - // As a special case, we'll allow large text which automatically moves it to the right. - if (mTextW > mRenderW) - { - mTextX = mRenderW + mRenderX + 5; - mRenderW += mTextW + 5; - } - else - { - mTextX = mRenderX + ((mRenderW - mTextW) / 2); - } - } + mTextH = 0; + mTextW = 0; + mIconX = mRenderX + ((mRenderW - mIconW) / 2); + if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH); + if (mTextW) + { + // As a special case, we'll allow large text which automatically moves it to the right. + if (mTextW > mRenderW) + { + mTextX = mRenderW + mRenderX + 5; + mRenderW += mTextW + 5; + } + else + { + mTextX = mRenderX + ((mRenderW - mTextW) / 2); + } + } - if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH) - { - mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2); - mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2); - } - else - { - int divisor = mRenderH - (mIconH + mTextH); - mIconY = mRenderY + (divisor / 3); - mTextY = mRenderY + (divisor * 2 / 3) + mIconH; - } + if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH) + { + mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2); + mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2); + } + else + { + int divisor = mRenderH - (mIconH + mTextH); + mIconY = mRenderY + (divisor / 3); + mTextY = mRenderY + (divisor * 2 / 3) + mIconH; + } - if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY); - if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - return 0; + if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY); + if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + return 0; } int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y) { static int last_state = 0; - if (!isConditionTrue()) return -1; + if (!isConditionTrue()) return -1; if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) { if (last_state == 1) { last_state = 0; @@ -289,6 +289,5 @@ int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y) } if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH) return 0; - return (mAction ? mAction->NotifyTouch(state, x, y) : 1); + return (mAction ? mAction->NotifyTouch(state, x, y) : 1); } - |