int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); }
GUIInput::GUIInput(xml_node<>* node) : GUIObject(node) { xml_attribute<>* attr; xml_node<>* child; mInputText = NULL; mAction = NULL; mBackground = NULL; mCursor = NULL; mFont = NULL; mRendered = false; HasMask = false; DrawCursor = false; isLocalChange = true; HasAllowed = false; HasDisabled = false; skipChars = scrollingX = mFontHeight = mFontY = lastX = 0; mBackgroundX = mBackgroundY = mBackgroundW = mBackgroundH = MinLen = MaxLen = 0; mCursorLocation = -1; // -1 is always the end of the string CursorWidth = 3; ConvertStrToColor("black", &mBackgroundColor); ConvertStrToColor("white", &mCursorColor); if (!node) return; // Load text directly from the node mInputText = new GUIText(node); // Load action directly from the node mAction = new GUIAction(node); if (mInputText->Render() < 0) { delete mInputText; mInputText = NULL; } // Load the background child = node->first_node("background"); if (child) { attr = child->first_attribute("resource"); if (attr) mBackground = PageManager::FindResource(attr->value()); attr = child->first_attribute("color"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mBackgroundColor); } } if (mBackground && mBackground->GetResource()) { mBackgroundW = gr_get_width(mBackground->GetResource()); mBackgroundH = gr_get_height(mBackground->GetResource()); } // Load the cursor color child = node->first_node("cursor"); if (child) { attr = child->first_attribute("resource"); if (attr) mCursor = PageManager::FindResource(attr->value()); attr = child->first_attribute("color"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mCursorColor); } 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 = atoi(cwidth.c_str()); } } DrawCursor = HasInputFocus; // Load the font, and possibly override the color child = node->first_node("font"); if (child) { attr = child->first_attribute("resource"); if (attr) { mFont = PageManager::FindResource(attr->value()); mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL); } } child = node->first_node("text"); if (child) mText = child->value(); mLastValue = gui_parse_text(mText); child = node->first_node("data"); if (child) { attr = child->first_attribute("name"); if (attr) mVariable = attr->value(); attr = child->first_attribute("default"); if (attr) DataManager::SetValue(mVariable, attr->value()); attr = child->first_attribute("mask"); if (attr) { mMask = attr->value(); HasMask = true; } attr = child->first_attribute("maskvariable"); if (attr) mMaskVariable = attr->value(); else mMaskVariable = mVariable; } // Load input restrictions child = node->first_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(); } } // Load the placement LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); if (mInputText && mFontHeight && mFontHeight < (unsigned)mRenderH) { mFontY = ((mRenderH - mFontHeight) / 2) + mRenderY; mInputText->SetRenderPos(mRenderX, mFontY); } else mFontY = mRenderY; if (mInputText) mInputText->SetMaxWidth(mRenderW); isLocalChange = false; HandleTextLocation(-3); }
GUIListBox::GUIListBox(xml_node<>* node) : GUIObject(node) { xml_attribute<>* attr; xml_node<>* child; int header_separator_color_specified = 0, header_separator_height_specified = 0, header_text_color_specified = 0, header_background_color_specified = 0; mStart = mLineSpacing = startY = mFontHeight = mSeparatorH = scrollingY = scrollingSpeed = 0; mIconWidth = mIconHeight = mSelectedIconHeight = mSelectedIconWidth = mUnselectedIconHeight = mUnselectedIconWidth = mHeaderIconHeight = mHeaderIconWidth = 0; mHeaderSeparatorH = mLineHeight = mHeaderIsStatic = mHeaderH = actualLineHeight = 0; mIconSelected = mIconUnselected = mBackground = mFont = mHeaderIcon = NULL; mBackgroundX = mBackgroundY = mBackgroundW = mBackgroundH = 0; mFastScrollW = mFastScrollLineW = mFastScrollRectW = mFastScrollRectH = 0; mFastScrollRectX = mFastScrollRectY = -1; mUpdate = 0; touchDebounce = 6; ConvertStrToColor("black", &mBackgroundColor); ConvertStrToColor("black", &mHeaderBackgroundColor); ConvertStrToColor("black", &mSeparatorColor); ConvertStrToColor("black", &mHeaderSeparatorColor); ConvertStrToColor("white", &mFontColor); ConvertStrToColor("white", &mHeaderFontColor); ConvertStrToColor("white", &mFastScrollLineColor); ConvertStrToColor("white", &mFastScrollRectColor); hasHighlightColor = false; hasFontHighlightColor = false; isHighlighted = false; startSelection = -1; // Load header text child = node->first_node("header"); if (child) { attr = child->first_attribute("icon"); if (attr) mHeaderIcon = PageManager::FindResource(attr->value()); attr = child->first_attribute("background"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mHeaderBackgroundColor); header_background_color_specified = -1; } attr = child->first_attribute("textcolor"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mHeaderFontColor); header_text_color_specified = -1; } attr = child->first_attribute("separatorcolor"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mHeaderSeparatorColor); header_separator_color_specified = -1; } attr = child->first_attribute("separatorheight"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mHeaderSeparatorH = atoi(parsevalue.c_str()); header_separator_height_specified = -1; } } child = node->first_node("text"); if (child) mHeaderText = child->value(); 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); } } // Simple way to check for static state mLastValue = gui_parse_text(mHeaderText); if (mLastValue != mHeaderText) mHeaderIsStatic = 0; else mHeaderIsStatic = -1; child = node->first_node("icon"); if (child) { attr = child->first_attribute("selected"); if (attr) mIconSelected = PageManager::FindResource(attr->value()); attr = child->first_attribute("unselected"); if (attr) mIconUnselected = PageManager::FindResource(attr->value()); } child = node->first_node("background"); if (child) { attr = child->first_attribute("resource"); if (attr) mBackground = PageManager::FindResource(attr->value()); attr = child->first_attribute("color"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mBackgroundColor); if (!header_background_color_specified) ConvertStrToColor(color, &mHeaderBackgroundColor); } } // Load the placement LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); // Load the font, and possibly override the color child = node->first_node("font"); if (child) { attr = child->first_attribute("resource"); if (attr) mFont = PageManager::FindResource(attr->value()); attr = child->first_attribute("color"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mFontColor); if (!header_text_color_specified) ConvertStrToColor(color, &mHeaderFontColor); } attr = child->first_attribute("spacing"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mLineSpacing = atoi(parsevalue.c_str()); } attr = child->first_attribute("highlightcolor"); memset(&mFontHighlightColor, 0, sizeof(COLOR)); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mFontHighlightColor); hasFontHighlightColor = true; } } // Load the separator if it exists child = node->first_node("separator"); if (child) { attr = child->first_attribute("color"); if (attr) { std::string color = attr->value(); ConvertStrToColor(color, &mSeparatorColor); if (!header_separator_color_specified) ConvertStrToColor(color, &mHeaderSeparatorColor); } attr = child->first_attribute("height"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mSeparatorH = atoi(parsevalue.c_str()); if (!header_separator_height_specified) mHeaderSeparatorH = mSeparatorH; } } // Handle the result variable child = node->first_node("data"); if (child) { attr = child->first_attribute("name"); if (attr) mVariable = attr->value(); attr = child->first_attribute("default"); if (attr) DataManager::SetValue(mVariable, attr->value()); } // Fast scroll colors child = node->first_node("fastscroll"); if (child) { attr = child->first_attribute("linecolor"); if(attr) ConvertStrToColor(attr->value(), &mFastScrollLineColor); attr = child->first_attribute("rectcolor"); if(attr) ConvertStrToColor(attr->value(), &mFastScrollRectColor); attr = child->first_attribute("w"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mFastScrollW = atoi(parsevalue.c_str()); } attr = child->first_attribute("linew"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mFastScrollLineW = atoi(parsevalue.c_str()); } attr = child->first_attribute("rectw"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mFastScrollRectW = atoi(parsevalue.c_str()); } attr = child->first_attribute("recth"); if (attr) { string parsevalue = gui_parse_text(attr->value()); mFastScrollRectH = atoi(parsevalue.c_str()); } } // Retrieve the line height mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL); mLineHeight = mFontHeight; mHeaderH = mFontHeight; if (mIconSelected && mIconSelected->GetResource()) { mSelectedIconWidth = gr_get_width(mIconSelected->GetResource()); mSelectedIconHeight = gr_get_height(mIconSelected->GetResource()); if (mSelectedIconHeight > (int)mLineHeight) mLineHeight = mSelectedIconHeight; mIconWidth = mSelectedIconWidth; } if (mIconUnselected && mIconUnselected->GetResource()) { mUnselectedIconWidth = gr_get_width(mIconUnselected->GetResource()); mUnselectedIconHeight = gr_get_height(mIconUnselected->GetResource()); if (mUnselectedIconHeight > (int)mLineHeight) mLineHeight = mUnselectedIconHeight; if (mUnselectedIconWidth > mIconWidth) mIconWidth = mUnselectedIconWidth; } if (mHeaderIcon && mHeaderIcon->GetResource()) { mHeaderIconWidth = gr_get_width(mHeaderIcon->GetResource()); mHeaderIconHeight = gr_get_height(mHeaderIcon->GetResource()); if (mHeaderIconHeight > mHeaderH) mHeaderH = mHeaderIconHeight; if (mHeaderIconWidth > mIconWidth) mIconWidth = mHeaderIconWidth; } mHeaderH += mLineSpacing + mHeaderSeparatorH; actualLineHeight = mLineHeight + mLineSpacing + mSeparatorH; if (mHeaderH < actualLineHeight) mHeaderH = actualLineHeight; if (actualLineHeight / 3 > 6) touchDebounce = actualLineHeight / 3; if (mBackground && mBackground->GetResource()) { mBackgroundW = gr_get_width(mBackground->GetResource()); mBackgroundH = gr_get_height(mBackground->GetResource()); } // Get the currently selected value for the list DataManager::GetValue(mVariable, currentValue); // Get the data for the list child = node->first_node("listitem"); if (!child) return; while (child) { ListData data; attr = child->first_attribute("name"); if (!attr) return; data.displayName = attr->value(); data.variableValue = child->value(); if (child->value() == currentValue) { data.selected = 1; } else { data.selected = 0; } mList.push_back(data); child = child->next_sibling("listitem"); } }