GUI: Support styles in xml to reduce xml file size
Also allow sliders to have their own text label instead of requiring a whole separate text object for the label in the xml. Change-Id: I6e314efb4bb454d496555ff7e003d743063a1308
This commit is contained in:
+4
-4
@@ -226,9 +226,9 @@ GUIAction::GUIAction(xml_node<>* node)
|
||||
}
|
||||
|
||||
// First, get the action
|
||||
actions = node->first_node("actions");
|
||||
if (actions) child = actions->first_node("action");
|
||||
else child = node->first_node("action");
|
||||
actions = FindNode(node, "actions");
|
||||
if (actions) child = FindNode(actions, "action");
|
||||
else child = FindNode(node, "action");
|
||||
|
||||
if (!child) return;
|
||||
|
||||
@@ -247,7 +247,7 @@ GUIAction::GUIAction(xml_node<>* node)
|
||||
}
|
||||
|
||||
// Now, let's get either the key or region
|
||||
child = node->first_node("touch");
|
||||
child = FindNode(node, "touch");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("key");
|
||||
|
||||
+8
-19
@@ -29,7 +29,6 @@ extern "C" {
|
||||
GUIAnimation::GUIAnimation(xml_node<>* node) : GUIObject(node)
|
||||
{
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
|
||||
mAnimation = NULL;
|
||||
mFrame = 1;
|
||||
@@ -40,36 +39,26 @@ GUIAnimation::GUIAnimation(xml_node<>* node) : GUIObject(node)
|
||||
|
||||
if (!node) return;
|
||||
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
mAnimation = LoadAttrAnimation(child, "name");
|
||||
}
|
||||
mAnimation = LoadAttrAnimation(FindNode(node, "resource"), "name");
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
|
||||
child = node->first_node("speed");
|
||||
child = FindNode(node, "speed");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("fps");
|
||||
if (attr)
|
||||
mFPS = atoi(attr->value());
|
||||
attr = child->first_attribute("render");
|
||||
if (attr)
|
||||
mRender = atoi(attr->value());
|
||||
mFPS = LoadAttrInt(child, "fps", mFPS);
|
||||
mRender = LoadAttrInt(child, "render", mRender);
|
||||
}
|
||||
if (mFPS > 30) mFPS = 30;
|
||||
|
||||
child = node->first_node("loop");
|
||||
child = FindNode(node, "loop");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("frame");
|
||||
xml_attribute<>* attr = child->first_attribute("frame");
|
||||
if (attr)
|
||||
mLoop = atoi(attr->value()) - 1;
|
||||
attr = child->first_attribute("start");
|
||||
if (attr)
|
||||
mFrame = atoi(attr->value());
|
||||
mFrame = LoadAttrInt(child, "start", mFrame);
|
||||
}
|
||||
|
||||
// Fetch the render sizes
|
||||
|
||||
+8
-35
@@ -63,15 +63,11 @@ GUIButton::GUIButton(xml_node<>* node)
|
||||
mButtonLabel = new GUIText(node);
|
||||
mAction = new GUIAction(node);
|
||||
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
mButtonImg = new GUIImage(node);
|
||||
if (mButtonImg->Render() < 0)
|
||||
{
|
||||
mButtonImg = new GUIImage(node);
|
||||
if (mButtonImg->Render() < 0)
|
||||
{
|
||||
delete mButtonImg;
|
||||
mButtonImg = NULL;
|
||||
}
|
||||
delete mButtonImg;
|
||||
mButtonImg = NULL;
|
||||
}
|
||||
if (mButtonLabel->Render() < 0)
|
||||
{
|
||||
@@ -79,45 +75,22 @@ GUIButton::GUIButton(xml_node<>* node)
|
||||
mButtonLabel = NULL;
|
||||
}
|
||||
// Load fill if it exists
|
||||
memset(&mFillColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("fill");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasFill = true;
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mFillColor);
|
||||
}
|
||||
}
|
||||
mFillColor = LoadAttrColor(FindNode(node, "fill"), "color", &hasFill);
|
||||
if (!hasFill && mButtonImg == NULL) {
|
||||
LOGERR("No image resource or fill specified for button.\n");
|
||||
}
|
||||
|
||||
// The icon is a special case
|
||||
child = node->first_node("icon");
|
||||
if (child)
|
||||
{
|
||||
mButtonIcon = LoadAttrImage(child, "resource");
|
||||
}
|
||||
mButtonIcon = LoadAttrImage(FindNode(node, "icon"), "resource");
|
||||
|
||||
memset(&mHighlightColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("highlight");
|
||||
if (child) {
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasHighlightColor = true;
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mHighlightColor);
|
||||
}
|
||||
}
|
||||
mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlightColor);
|
||||
|
||||
int x, y, w, h;
|
||||
TextPlacement = TOP_LEFT;
|
||||
if (mButtonImg) {
|
||||
mButtonImg->GetRenderPos(x, y, w, h);
|
||||
} else if (hasFill) {
|
||||
LoadPlacement(node->first_node("placement"), &x, &y, &w, &h, &TextPlacement);
|
||||
LoadPlacement(FindNode(node, "placement"), &x, &y, &w, &h, &TextPlacement);
|
||||
}
|
||||
SetRenderPos(x, y, w, h);
|
||||
}
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ GUICheckbox::GUICheckbox(xml_node<>* node)
|
||||
mLabel = new GUIText(node);
|
||||
|
||||
// Read the check states
|
||||
child = node->first_node("image");
|
||||
child = FindNode(node, "image");
|
||||
if (child)
|
||||
{
|
||||
mChecked = LoadAttrImage(child, "checked");
|
||||
@@ -53,7 +53,7 @@ GUICheckbox::GUICheckbox(xml_node<>* node)
|
||||
}
|
||||
|
||||
// Get the variable data
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("variable");
|
||||
|
||||
+4
-9
@@ -101,7 +101,6 @@ extern "C" void gui_set_FILE(FILE* f)
|
||||
|
||||
GUIConsole::GUIConsole(xml_node<>* node) : GUIObject(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mFont = NULL;
|
||||
@@ -126,13 +125,9 @@ GUIConsole::GUIConsole(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
else
|
||||
{
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
mFont = LoadAttrFont(child, "resource");
|
||||
}
|
||||
mFont = LoadAttrFont(FindNode(node, "font"), "resource");
|
||||
|
||||
child = node->first_node("color");
|
||||
child = FindNode(node, "color");
|
||||
if (child)
|
||||
{
|
||||
mForegroundColor = LoadAttrColor(child, "foreground", mForegroundColor);
|
||||
@@ -141,9 +136,9 @@ GUIConsole::GUIConsole(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
|
||||
LoadPlacement(FindNode(node, "placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
|
||||
|
||||
child = node->first_node("slideout");
|
||||
child = FindNode(node, "slideout");
|
||||
if (child)
|
||||
{
|
||||
mSlideout = 1;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+275
-890
File diff suppressed because it is too large
Load Diff
@@ -70,8 +70,10 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) : GUIScrollList(node)
|
||||
if (attr)
|
||||
mPathVar = attr->value();
|
||||
attr = child->first_attribute("default");
|
||||
if (attr)
|
||||
if (attr) {
|
||||
mPathDefault = attr->value();
|
||||
DataManager::SetValue(mPathVar, attr->value());
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the result variable
|
||||
@@ -168,6 +170,8 @@ int GUIFileSelector::NotifyVarChange(const std::string& varName, const std::stri
|
||||
} else {
|
||||
// Reset the list to the top
|
||||
SetVisibleListLocation(0);
|
||||
if (value.empty())
|
||||
DataManager::SetValue(mPathVar, mPathDefault);
|
||||
}
|
||||
updateFileList = true;
|
||||
mUpdate = 1;
|
||||
@@ -288,6 +292,10 @@ void GUIFileSelector::SetPageFocus(int inFocus)
|
||||
{
|
||||
GUIScrollList::SetPageFocus(inFocus);
|
||||
if (inFocus) {
|
||||
std::string value;
|
||||
DataManager::GetValue(mPathVar, value);
|
||||
if (value.empty())
|
||||
DataManager::SetValue(mPathVar, mPathDefault);
|
||||
updateFileList = true;
|
||||
mUpdate = 1;
|
||||
}
|
||||
|
||||
+4
-12
@@ -27,23 +27,15 @@ extern "C" {
|
||||
|
||||
GUIFill::GUIFill(xml_node<>* node) : GUIObject(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
attr = node->first_attribute("color");
|
||||
if (!attr) {
|
||||
bool has_color = false;
|
||||
mColor = LoadAttrColor(node, "color", &has_color);
|
||||
if (!has_color) {
|
||||
LOGERR("No color specified for fill\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-10
@@ -27,9 +27,6 @@ extern "C" {
|
||||
|
||||
GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mImage = NULL;
|
||||
mHighlightImage = NULL;
|
||||
isHighlighted = false;
|
||||
@@ -37,15 +34,11 @@ GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
{
|
||||
mImage = LoadAttrImage(child, "resource");
|
||||
mHighlightImage = LoadAttrImage(child, "highlightresource");
|
||||
}
|
||||
mImage = LoadAttrImage(FindNode(node, "image"), "resource");
|
||||
mHighlightImage = LoadAttrImage(FindNode(node, "image"), "highlightresource");
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
|
||||
if (mImage && mImage->GetResource())
|
||||
{
|
||||
|
||||
+18
-40
@@ -85,7 +85,7 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
}
|
||||
|
||||
// Load the background
|
||||
child = node->first_node("background");
|
||||
child = FindNode(node, "background");
|
||||
if (child)
|
||||
{
|
||||
mBackground = LoadAttrImage(child, "resource");
|
||||
@@ -98,7 +98,7 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
}
|
||||
|
||||
// Load the cursor color
|
||||
child = node->first_node("cursor");
|
||||
child = FindNode(node, "cursor");
|
||||
if (child)
|
||||
{
|
||||
mCursor = LoadAttrImage(child, "resource");
|
||||
@@ -106,31 +106,26 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
attr = child->first_attribute("hasfocus");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
SetInputFocus(atoi(color.c_str()));
|
||||
}
|
||||
attr = child->first_attribute("width");
|
||||
if (attr)
|
||||
{
|
||||
std::string cwidth = gui_parse_text(attr->value());
|
||||
CursorWidth = scale_theme_x(atoi(cwidth.c_str()));
|
||||
std::string focus = attr->value();
|
||||
SetInputFocus(atoi(focus.c_str()));
|
||||
}
|
||||
CursorWidth = LoadAttrIntScaleX(child, "width", CursorWidth);
|
||||
}
|
||||
DrawCursor = HasInputFocus;
|
||||
|
||||
// Load the font
|
||||
child = node->first_node("font");
|
||||
child = FindNode(node, "font");
|
||||
if (child)
|
||||
{
|
||||
mFont = LoadAttrFont(child, "resource");
|
||||
mFontHeight = mFont->GetHeight();
|
||||
}
|
||||
|
||||
child = node->first_node("text");
|
||||
child = FindNode(node, "text");
|
||||
if (child) mText = child->value();
|
||||
mLastValue = gui_parse_text(mText);
|
||||
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("name");
|
||||
@@ -139,11 +134,8 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
attr = child->first_attribute("default");
|
||||
if (attr)
|
||||
DataManager::SetValue(mVariable, attr->value());
|
||||
attr = child->first_attribute("mask");
|
||||
if (attr) {
|
||||
mMask = attr->value();
|
||||
HasMask = true;
|
||||
}
|
||||
mMask = LoadAttrString(child, "mask");
|
||||
HasMask = !mMask.empty();
|
||||
attr = child->first_attribute("maskvariable");
|
||||
if (attr)
|
||||
mMaskVariable = attr->value();
|
||||
@@ -152,33 +144,19 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
}
|
||||
|
||||
// Load input restrictions
|
||||
child = node->first_node("restrict");
|
||||
child = FindNode(node, "restrict");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("minlen");
|
||||
if (attr) {
|
||||
std::string attrib = attr->value();
|
||||
MinLen = atoi(attrib.c_str());
|
||||
}
|
||||
attr = child->first_attribute("maxlen");
|
||||
if (attr) {
|
||||
std::string attrib = attr->value();
|
||||
MaxLen = atoi(attrib.c_str());
|
||||
}
|
||||
attr = child->first_attribute("allow");
|
||||
if (attr) {
|
||||
HasAllowed = true;
|
||||
AllowedList = attr->value();
|
||||
}
|
||||
attr = child->first_attribute("disable");
|
||||
if (attr) {
|
||||
HasDisabled = true;
|
||||
DisabledList = attr->value();
|
||||
}
|
||||
MinLen = LoadAttrInt(child, "minlen", MinLen);
|
||||
MaxLen = LoadAttrInt(child, "maxlen", MaxLen);
|
||||
AllowedList = LoadAttrString(child, "allow");
|
||||
HasAllowed = !AllowedList.empty();
|
||||
DisabledList = LoadAttrString(child, "disable");
|
||||
HasDisabled = !DisabledList.empty();
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
|
||||
if (mInputText && mFontHeight && mFontHeight < (unsigned)mRenderH) {
|
||||
|
||||
+9
-27
@@ -48,7 +48,8 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
|
||||
{
|
||||
int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0;
|
||||
rowY = colX = -1;
|
||||
highlightRenderCount = hasHighlight = hasCapsHighlight = 0;
|
||||
highlightRenderCount = 0;
|
||||
hasHighlight = hasCapsHighlight = false;
|
||||
char resource[10], layout[8], row[5], key[6], longpress[7];
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
@@ -66,36 +67,17 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
|
||||
if (!node) return;
|
||||
|
||||
// Load the action
|
||||
child = node->first_node("action");
|
||||
child = FindNode(node, "action");
|
||||
if (child)
|
||||
{
|
||||
mAction = new GUIAction(node);
|
||||
}
|
||||
|
||||
memset(&mHighlightColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("highlight");
|
||||
if (child) {
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasHighlight = 1;
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mHighlightColor);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&mCapsHighlightColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("capshighlight");
|
||||
if (child) {
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasCapsHighlight = 1;
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mCapsHighlightColor);
|
||||
}
|
||||
}
|
||||
mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlight);
|
||||
mCapsHighlightColor = LoadAttrColor(FindNode(node, "capshighlight"), "color", &hasCapsHighlight);
|
||||
|
||||
// Load the images for the different layouts
|
||||
child = node->first_node("layout");
|
||||
child = FindNode(node, "layout");
|
||||
if (child)
|
||||
{
|
||||
layoutindex = 1;
|
||||
@@ -120,7 +102,7 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
|
||||
// Load all of the layout maps
|
||||
layoutindex = 1;
|
||||
strcpy(layout, "layout1");
|
||||
keylayout = node->first_node(layout);
|
||||
keylayout = FindNode(node, layout);
|
||||
while (keylayout)
|
||||
{
|
||||
if (layoutindex > MAX_KEYBOARD_LAYOUTS) {
|
||||
@@ -212,12 +194,12 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
|
||||
}
|
||||
layoutindex++;
|
||||
layout[6] = (char)(layoutindex + 48);
|
||||
keylayout = node->first_node(layout);
|
||||
keylayout = FindNode(node, layout);
|
||||
}
|
||||
|
||||
int x, y, w, h;
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
|
||||
LoadPlacement(FindNode(node, "placement"), &x, &y, &w, &h);
|
||||
SetActionPos(x, y, KeyboardWidth, KeyboardHeight);
|
||||
SetRenderPos(x, y, w, h);
|
||||
return;
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node)
|
||||
mUpdate = 0;
|
||||
|
||||
// Get the icons, if any
|
||||
child = node->first_node("icon");
|
||||
child = FindNode(node, "icon");
|
||||
if (child) {
|
||||
mIconSelected = LoadAttrImage(child, "selected");
|
||||
mIconUnselected = LoadAttrImage(child, "unselected");
|
||||
@@ -47,7 +47,7 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node)
|
||||
SetMaxIconSize(iconWidth, iconHeight);
|
||||
|
||||
// Handle the result variable
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child) {
|
||||
attr = child->first_attribute("name");
|
||||
if (attr)
|
||||
@@ -60,7 +60,7 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node)
|
||||
}
|
||||
|
||||
// Get the data for the list
|
||||
child = node->first_node("listitem");
|
||||
child = FindNode(node, "listitem");
|
||||
if (!child) return;
|
||||
while (child) {
|
||||
ListData data;
|
||||
|
||||
+3
-3
@@ -51,11 +51,11 @@ void MouseCursor::LoadData(xml_node<>* node)
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
child = node->first_node("placement");
|
||||
child = FindNode(node, "placement");
|
||||
if(child)
|
||||
LoadPlacement(child, &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
|
||||
child = node->first_node("background");
|
||||
child = FindNode(node, "background");
|
||||
if(child)
|
||||
{
|
||||
m_color = LoadAttrColor(child, "color", m_color);
|
||||
@@ -67,7 +67,7 @@ void MouseCursor::LoadData(xml_node<>* node)
|
||||
}
|
||||
}
|
||||
|
||||
child = node->first_node("speed");
|
||||
child = FindNode(node, "speed");
|
||||
if(child)
|
||||
{
|
||||
attr = child->first_attribute("multiplier");
|
||||
|
||||
+3
-3
@@ -35,9 +35,9 @@ GUIObject::GUIObject(xml_node<>* node)
|
||||
if (!node) return;
|
||||
|
||||
// First, get the action
|
||||
xml_node<>* condition = node->first_node("conditions");
|
||||
if (condition) condition = condition->first_node("condition");
|
||||
else condition = node->first_node("condition");
|
||||
xml_node<>* condition = FindNode(node, "conditions");
|
||||
if (condition) condition = FindNode(condition, "condition");
|
||||
else condition = FindNode(node, "condition");
|
||||
|
||||
if (!condition) return;
|
||||
|
||||
|
||||
+6
-1
@@ -649,6 +649,7 @@ protected:
|
||||
std::vector<FileData> mFolderList;
|
||||
std::vector<FileData> mFileList;
|
||||
std::string mPathVar; // current path displayed, saved in the data manager
|
||||
std::string mPathDefault; // default value for the path if none is set in mPathVar
|
||||
std::string mExtn; // used for filtering the file list, for example, *.zip
|
||||
std::string mVariable; // set when the user selects an item, pull path like /path/to/foo
|
||||
std::string mSortVariable; // data manager variable used to change the sorting of files
|
||||
@@ -812,6 +813,7 @@ public:
|
||||
|
||||
protected:
|
||||
GUIAction* sAction;
|
||||
GUIText* sSliderLabel;
|
||||
ImageResource* sSlider;
|
||||
ImageResource* sSliderUsed;
|
||||
ImageResource* sTouch;
|
||||
@@ -875,7 +877,8 @@ protected:
|
||||
int currentLayout;
|
||||
int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
|
||||
unsigned int KeyboardWidth, KeyboardHeight;
|
||||
int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
|
||||
int rowY, colX, highlightRenderCount;
|
||||
bool hasHighlight, hasCapsHighlight;
|
||||
GUIAction* mAction;
|
||||
COLOR mHighlightColor;
|
||||
COLOR mCapsHighlightColor;
|
||||
@@ -1064,10 +1067,12 @@ private:
|
||||
};
|
||||
|
||||
// Helper APIs
|
||||
xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth = 0);
|
||||
std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue = "");
|
||||
int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue = 0);
|
||||
int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue = 0);
|
||||
int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue = 0);
|
||||
COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue = COLOR(0,0,0,0));
|
||||
COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue = COLOR(0,0,0,0));
|
||||
FontResource* LoadAttrFont(xml_node<>* element, const char* attrname);
|
||||
ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname);
|
||||
|
||||
+87
-3
@@ -103,6 +103,56 @@ int ConvertStrToColor(std::string str, COLOR* color)
|
||||
}
|
||||
|
||||
// Helper APIs
|
||||
xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth /* = 0 */)
|
||||
{
|
||||
xml_node<>* child = parent->first_node(nodename);
|
||||
if (child)
|
||||
return child;
|
||||
|
||||
if (depth == 10) {
|
||||
LOGERR("Too many style loops detected.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xml_node<>* style = parent->first_node("style");
|
||||
if (style) {
|
||||
while (style) {
|
||||
if (!style->first_attribute("name")) {
|
||||
LOGERR("No name given for style.\n");
|
||||
continue;
|
||||
} else {
|
||||
std::string name = style->first_attribute("name")->value();
|
||||
xml_node<>* node = PageManager::FindStyle(name);
|
||||
|
||||
if (node) {
|
||||
// We found the style that was named
|
||||
xml_node<>* stylenode = FindNode(node, nodename, depth + 1);
|
||||
if (stylenode)
|
||||
return stylenode;
|
||||
}
|
||||
}
|
||||
style = style->next_sibling("style");
|
||||
}
|
||||
} else {
|
||||
// Search for stylename in the parent node <object type="foo" stylename="foo2">
|
||||
xml_attribute<>* attr = parent->first_attribute("style");
|
||||
// If no style is found anywhere else and the node wasn't found in the object itself
|
||||
// as a special case we will search for a style that uses the same style name as the
|
||||
// object type, so <object type="button"> would search for a style named "button"
|
||||
if (!attr)
|
||||
attr = parent->first_attribute("type");
|
||||
if (attr) {
|
||||
xml_node<>* node = PageManager::FindStyle(attr->value());
|
||||
if (node) {
|
||||
xml_node<>* stylenode = FindNode(node, nodename, depth + 1);
|
||||
if (stylenode)
|
||||
return stylenode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue)
|
||||
{
|
||||
if (!element)
|
||||
@@ -130,9 +180,10 @@ int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalu
|
||||
return scale_theme_y(LoadAttrInt(element, attrname, defaultvalue));
|
||||
}
|
||||
|
||||
COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue)
|
||||
COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue)
|
||||
{
|
||||
string value = LoadAttrString(element, attrname);
|
||||
*found_color = !value.empty();
|
||||
// resolve variables
|
||||
DataManager::GetValue(value, value);
|
||||
COLOR ret = defaultvalue;
|
||||
@@ -142,6 +193,12 @@ COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalu
|
||||
return defaultvalue;
|
||||
}
|
||||
|
||||
COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue)
|
||||
{
|
||||
bool found_color = false;
|
||||
return LoadAttrColor(element, attrname, &found_color, defaultvalue);
|
||||
}
|
||||
|
||||
FontResource* LoadAttrFont(xml_node<>* element, const char* attrname)
|
||||
{
|
||||
std::string name = LoadAttrString(element, attrname, "");
|
||||
@@ -621,8 +678,7 @@ int PageSet::Load(ZipArchive* package)
|
||||
xml_node<>* parent;
|
||||
xml_node<>* child;
|
||||
xml_node<>* xmltemplate;
|
||||
xml_node<>* blank_templates;
|
||||
int pages_loaded = -1, ret;
|
||||
xml_node<>* xmlstyle;
|
||||
|
||||
parent = mDoc.first_node("recovery");
|
||||
if (!parent)
|
||||
@@ -701,6 +757,11 @@ int PageSet::Load(ZipArchive* package)
|
||||
if (xmltemplate)
|
||||
templates.push_back(xmltemplate);
|
||||
|
||||
// Load styles if present
|
||||
xmlstyle = parent->first_node("styles");
|
||||
if (xmlstyle)
|
||||
styles.push_back(xmlstyle);
|
||||
|
||||
child = parent->first_node("pages");
|
||||
if (child) {
|
||||
if (LoadPages(child)) {
|
||||
@@ -720,6 +781,7 @@ int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc)
|
||||
xml_node<>* parent;
|
||||
xml_node<>* child;
|
||||
xml_node<>* xmltemplate;
|
||||
xml_node<>* xmlstyle;
|
||||
long len;
|
||||
char* xmlFile = NULL;
|
||||
string filename;
|
||||
@@ -817,6 +879,11 @@ int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc)
|
||||
if (xmltemplate)
|
||||
templates.push_back(xmltemplate);
|
||||
|
||||
// Load styles if present
|
||||
xmlstyle = parent->first_node("styles");
|
||||
if (xmlstyle)
|
||||
styles.push_back(xmlstyle);
|
||||
|
||||
child = parent->first_node("pages");
|
||||
if (child && LoadPages(child))
|
||||
{
|
||||
@@ -1288,6 +1355,23 @@ HardwareKeyboard *PageManager::GetHardwareKeyboard()
|
||||
return mHardwareKeyboard;
|
||||
}
|
||||
|
||||
xml_node<>* PageManager::FindStyle(std::string name)
|
||||
{
|
||||
for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) {
|
||||
xml_node<>* node = (*itr)->first_node("style");
|
||||
|
||||
while (node) {
|
||||
if (!node->first_attribute("name"))
|
||||
continue;
|
||||
|
||||
if (name == node->first_attribute("name")->value())
|
||||
return node;
|
||||
node = node->next_sibling("style");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MouseCursor *PageManager::GetMouseCursor()
|
||||
{
|
||||
if(!mMouseCursor)
|
||||
|
||||
@@ -102,6 +102,8 @@ public:
|
||||
int SetKeyBoardFocus(int inFocus);
|
||||
int NotifyVarChange(std::string varName, std::string value);
|
||||
|
||||
std::vector<xml_node<>*> styles;
|
||||
|
||||
protected:
|
||||
int LoadPages(xml_node<>* pages);
|
||||
int LoadVariables(xml_node<>* vars);
|
||||
@@ -153,6 +155,8 @@ public:
|
||||
|
||||
static HardwareKeyboard *GetHardwareKeyboard();
|
||||
|
||||
static xml_node<>* FindStyle(std::string name);
|
||||
|
||||
protected:
|
||||
static PageSet* FindPackage(std::string name);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
|
||||
mUpdate = 0;
|
||||
updateList = false;
|
||||
|
||||
child = node->first_node("icon");
|
||||
child = FindNode(node, "icon");
|
||||
if (child)
|
||||
{
|
||||
mIconSelected = LoadAttrImage(child, "selected");
|
||||
@@ -47,7 +47,7 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
|
||||
}
|
||||
|
||||
// Handle the result variable
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("name");
|
||||
@@ -62,7 +62,7 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
|
||||
int iconHeight = std::max(mIconSelected->GetHeight(), mIconUnselected->GetHeight());
|
||||
SetMaxIconSize(iconWidth, iconHeight);
|
||||
|
||||
child = node->first_node("listtype");
|
||||
child = FindNode(node, "listtype");
|
||||
if (child && (attr = child->first_attribute("name"))) {
|
||||
ListType = attr->value();
|
||||
updateList = true;
|
||||
|
||||
+3
-3
@@ -42,7 +42,7 @@ GUIProgressBar::GUIProgressBar(xml_node<>* node) : GUIObject(node)
|
||||
return;
|
||||
}
|
||||
|
||||
child = node->first_node("resource");
|
||||
child = FindNode(node, "resource");
|
||||
if (child)
|
||||
{
|
||||
mEmptyBar = LoadAttrImage(child, "empty");
|
||||
@@ -50,10 +50,10 @@ GUIProgressBar::GUIProgressBar(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY);
|
||||
|
||||
// Load the data
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child)
|
||||
{
|
||||
mMinValVar = LoadAttrString(child, "min");
|
||||
|
||||
+7
-16
@@ -65,18 +65,9 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
|
||||
mLastHeaderValue = gui_parse_text(mHeaderText);
|
||||
mHeaderIsStatic = (mLastHeaderValue == mHeaderText);
|
||||
|
||||
memset(&mHighlightColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("highlight");
|
||||
if (child) {
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasHighlightColor = true;
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mHighlightColor);
|
||||
}
|
||||
}
|
||||
mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlightColor);
|
||||
|
||||
child = node->first_node("background");
|
||||
child = FindNode(node, "background");
|
||||
if (child)
|
||||
{
|
||||
mBackground = LoadAttrImage(child, "resource");
|
||||
@@ -84,11 +75,11 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
|
||||
// Load the font, and possibly override the color
|
||||
child = node->first_node("font");
|
||||
child = FindNode(node, "font");
|
||||
if (child)
|
||||
{
|
||||
mFont = LoadAttrFont(child, "resource");
|
||||
@@ -98,7 +89,7 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Load the separator if it exists
|
||||
child = node->first_node("separator");
|
||||
child = FindNode(node, "separator");
|
||||
if (child)
|
||||
{
|
||||
mSeparatorColor = LoadAttrColor(child, "color");
|
||||
@@ -106,7 +97,7 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Fast scroll
|
||||
child = node->first_node("fastscroll");
|
||||
child = FindNode(node, "fastscroll");
|
||||
if (child)
|
||||
{
|
||||
mFastScrollLineColor = LoadAttrColor(child, "linecolor");
|
||||
@@ -123,7 +114,7 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
|
||||
actualItemHeight = mFontHeight + mItemSpacing + mSeparatorH;
|
||||
|
||||
// Load the header if it exists
|
||||
child = node->first_node("header");
|
||||
child = FindNode(node, "header");
|
||||
if (child)
|
||||
{
|
||||
mHeaderH = mFontHeight;
|
||||
|
||||
+26
-2
@@ -33,6 +33,7 @@ GUISlider::GUISlider(xml_node<>* node) : GUIObject(node)
|
||||
xml_node<>* child;
|
||||
|
||||
sAction = NULL;
|
||||
sSliderLabel = NULL;
|
||||
sSlider = NULL;
|
||||
sSliderUsed = NULL;
|
||||
sTouch = NULL;
|
||||
@@ -44,7 +45,8 @@ GUISlider::GUISlider(xml_node<>* node) : GUIObject(node)
|
||||
return;
|
||||
}
|
||||
|
||||
child = node->first_node("resource");
|
||||
// Load the resources
|
||||
child = FindNode(node, "resource");
|
||||
if (child)
|
||||
{
|
||||
sSlider = LoadAttrImage(child, "base");
|
||||
@@ -52,11 +54,27 @@ GUISlider::GUISlider(xml_node<>* node) : GUIObject(node)
|
||||
sTouch = LoadAttrImage(child, "touch");
|
||||
}
|
||||
|
||||
// Load the text label
|
||||
sSliderLabel = new GUIText(node);
|
||||
if (sSliderLabel->Render() < 0)
|
||||
{
|
||||
delete sSliderLabel;
|
||||
sSliderLabel = NULL;
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
|
||||
Placement TextPlacement = CENTER;
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &TextPlacement);
|
||||
|
||||
mRenderW = sSlider->GetWidth();
|
||||
mRenderH = sSlider->GetHeight();
|
||||
if (sSliderLabel) {
|
||||
int sTextX = mRenderX + (mRenderW / 2);
|
||||
int w, h;
|
||||
sSliderLabel->GetCurrentBounds(w, h);
|
||||
int sTextY = mRenderY + ((mRenderH - h) / 2);
|
||||
sSliderLabel->SetRenderPos(sTextX, sTextY);
|
||||
}
|
||||
if (sTouch && sTouch->GetResource())
|
||||
{
|
||||
sTouchW = sTouch->GetWidth(); // Width of the "touch image" that follows the touch (arrow)
|
||||
@@ -78,6 +96,7 @@ GUISlider::GUISlider(xml_node<>* node) : GUIObject(node)
|
||||
GUISlider::~GUISlider()
|
||||
{
|
||||
delete sAction;
|
||||
delete sSliderLabel;
|
||||
}
|
||||
|
||||
int GUISlider::Render(void)
|
||||
@@ -99,6 +118,11 @@ int GUISlider::Render(void)
|
||||
if (sTouch && sTouch->GetResource())
|
||||
gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2)));
|
||||
|
||||
if (sSliderLabel) {
|
||||
int ret = sSliderLabel->Render();
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
|
||||
sUpdate = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+12
-41
@@ -70,7 +70,7 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
|
||||
|
||||
mAction = new GUIAction(node);
|
||||
|
||||
child = node->first_node("font");
|
||||
child = FindNode(node, "font");
|
||||
if (child)
|
||||
{
|
||||
mFont = LoadAttrFont(child, "resource");
|
||||
@@ -78,21 +78,16 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW);
|
||||
|
||||
child = node->first_node("colors");
|
||||
child = FindNode(node, "colors");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("line");
|
||||
if (attr)
|
||||
ConvertStrToColor(attr->value(), &mLineColor);
|
||||
|
||||
attr = child->first_attribute("slider");
|
||||
if (attr)
|
||||
ConvertStrToColor(attr->value(), &mSliderColor);
|
||||
mLineColor = LoadAttrColor(child, "line");
|
||||
mSliderColor = LoadAttrColor(child, "slider");
|
||||
}
|
||||
|
||||
child = node->first_node("resource");
|
||||
child = FindNode(node, "resource");
|
||||
if (child)
|
||||
{
|
||||
mBackgroundImage = LoadAttrImage(child, "background");
|
||||
@@ -100,7 +95,7 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
|
||||
mHandleHoverImage = LoadAttrImage(child, "handlehover");
|
||||
}
|
||||
|
||||
child = node->first_node("data");
|
||||
child = FindNode(node, "data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("variable");
|
||||
@@ -150,37 +145,13 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
|
||||
mChangeOnDrag = atoi(attr->value());
|
||||
}
|
||||
|
||||
child = node->first_node("dimensions");
|
||||
child = FindNode(node, "dimensions");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("lineh");
|
||||
if (attr)
|
||||
{
|
||||
string parsevalue = gui_parse_text(attr->value());
|
||||
mLineH = scale_theme_y(atoi(parsevalue.c_str()));
|
||||
}
|
||||
|
||||
attr = child->first_attribute("linepadding");
|
||||
if (attr)
|
||||
{
|
||||
string parsevalue = gui_parse_text(attr->value());
|
||||
mPadding = scale_theme_x(atoi(parsevalue.c_str()));
|
||||
mLinePadding = mPadding;
|
||||
}
|
||||
|
||||
attr = child->first_attribute("sliderw");
|
||||
if (attr)
|
||||
{
|
||||
string parsevalue = gui_parse_text(attr->value());
|
||||
mSliderW = scale_theme_x(atoi(parsevalue.c_str()));
|
||||
}
|
||||
|
||||
attr = child->first_attribute("sliderh");
|
||||
if (attr)
|
||||
{
|
||||
string parsevalue = gui_parse_text(attr->value());
|
||||
mSliderH = scale_theme_y(atoi(parsevalue.c_str()));
|
||||
}
|
||||
mLineH = LoadAttrIntScaleY(child, "lineh", mLineH);
|
||||
mLinePadding = LoadAttrIntScaleX(child, "linepadding", mLinePadding);
|
||||
mSliderW = LoadAttrIntScaleX(child, "sliderw", mSliderW);
|
||||
mSliderH = LoadAttrIntScaleY(child, "sliderh", mSliderH);
|
||||
}
|
||||
|
||||
mFontHeight = mFont->GetHeight();
|
||||
|
||||
+5
-9
@@ -44,18 +44,14 @@ GUIText::GUIText(xml_node<>* node)
|
||||
mHighlightColor = LoadAttrColor(node, "highlightcolor", mColor);
|
||||
|
||||
// Load the font, and possibly override the color
|
||||
xml_node<>* child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
mFont = LoadAttrFont(child, "resource");
|
||||
mColor = LoadAttrColor(child, "color", mColor);
|
||||
mHighlightColor = LoadAttrColor(child, "highlightcolor", mColor);
|
||||
}
|
||||
mFont = LoadAttrFont(FindNode(node, "font"), "resource");
|
||||
mColor = LoadAttrColor(FindNode(node, "font"), "color", mColor);
|
||||
mHighlightColor = LoadAttrColor(FindNode(node, "font"), "highlightcolor", mColor);
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
|
||||
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
|
||||
|
||||
child = node->first_node("text");
|
||||
xml_node<>* child = FindNode(node, "text");
|
||||
if (child) mText = child->value();
|
||||
|
||||
// Simple way to check for static state
|
||||
|
||||
Reference in New Issue
Block a user