1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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;
}
|