summaryrefslogtreecommitdiffstats
path: root/gui/textbox.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2015-07-22 19:33:59 +0200
committerEthan Yonker <dees_troy@teamw.in>2015-10-26 17:54:16 +0100
commit44925ad19051d4ffe239b3ba99ea27e7275409dc (patch)
tree5ffc3a491429c71c360553452ea4369aa268e017 /gui/textbox.cpp
parentAdd nulls during reading of settings and info files (diff)
downloadandroid_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar.gz
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar.bz2
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar.lz
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar.xz
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.tar.zst
android_bootable_recovery-44925ad19051d4ffe239b3ba99ea27e7275409dc.zip
Diffstat (limited to 'gui/textbox.cpp')
-rw-r--r--gui/textbox.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/gui/textbox.cpp b/gui/textbox.cpp
new file mode 100644
index 000000000..277297fec
--- /dev/null
+++ b/gui/textbox.cpp
@@ -0,0 +1,120 @@
+/*
+ Copyright 2015 bigbiff/Dees_Troy/_that TeamWin
+ This file is part of TWRP/TeamWin Recovery Project.
+
+ TWRP is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ TWRP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TWRP. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// textbox.cpp - GUITextBox object
+
+#include <string>
+
+extern "C" {
+#include "../twcommon.h"
+#include "../minuitwrp/minui.h"
+}
+
+#include "rapidxml.hpp"
+#include "objects.hpp"
+
+GUITextBox::GUITextBox(xml_node<>* node) : GUIScrollList(node)
+{
+ xml_node<>* child;
+
+ mLastCount = 0;
+ mIsStatic = true;
+
+ allowSelection = false; // textbox doesn't support list item selections
+
+ child = FindNode(node, "color");
+ if (child)
+ {
+ mFontColor = LoadAttrColor(child, "foreground", mFontColor);
+ mBackgroundColor = LoadAttrColor(child, "background", mBackgroundColor);
+ //mScrollColor = LoadAttrColor(child, "scroll", mScrollColor);
+ }
+ child = FindNode(node, "text");
+ while (child) {
+ string txt = child->value();
+ mText.push_back(txt);
+ string lookup = gui_parse_text(txt);
+ if (lookup != txt)
+ mIsStatic = false;
+ mLastValue.push_back(lookup);
+ child = child->next_sibling("text");
+ }
+}
+
+int GUITextBox::Update(void)
+{
+ if (AddLines(&mLastValue, NULL, &mLastCount, &rText, NULL)) {
+ // someone added new text
+ // at least the scrollbar must be updated, even if the new lines are currently not visible
+ mUpdate = 1;
+ }
+
+ GUIScrollList::Update();
+
+ if (mUpdate) {
+ mUpdate = 0;
+ if (Render() == 0)
+ return 2;
+ }
+ return 0;
+}
+
+size_t GUITextBox::GetItemCount()
+{
+ return rText.size();
+}
+
+void GUITextBox::RenderItem(size_t itemindex, int yPos, bool selected __unused)
+{
+ // Set the color for the font
+ gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha);
+
+ // render text
+ const char* text = rText[itemindex].c_str();
+ gr_textEx(mRenderX, yPos, text, mFont->GetResource());
+}
+
+void GUITextBox::NotifySelect(size_t item_selected __unused)
+{
+ // do nothing - textbox ignores selections
+}
+
+int GUITextBox::NotifyVarChange(const std::string& varName, const std::string& value)
+{
+ GUIScrollList::NotifyVarChange(varName, value);
+
+ if(!isConditionTrue() || mIsStatic)
+ return 0;
+
+ // Check to see if the variable exists in mText
+ for (size_t i = 0; i < mText.size(); i++) {
+ string lookup = gui_parse_text(mText.at(i));
+ if (lookup != mText.at(i)) {
+ mLastValue.at(i) = lookup;
+ mUpdate = 1;
+ // There are ways to improve efficiency here, but I am not
+ // sure if we will even use this feature in the stock theme
+ // at all except for language translation. If we start using
+ // variables in textboxes in the stock theme, we can circle
+ // back and make improvements here.
+ mLastCount = 0;
+ rText.clear();
+ }
+ }
+ return 0;
+}