bool Font::_readBasicParameter(chstr line) { if (line.starts_with("Name=")) { this->name = line.replace("Name=", ""); return true; } if (line.starts_with("Height=")) { this->height = (float)line.replace("Height=", ""); return true; } if (line.starts_with("Scale=")) { this->baseScale = (float)line.replace("Scale=", ""); return true; } if (line.starts_with("LineHeight=")) { this->lineHeight = (float)line.replace("LineHeight=", ""); return true; } if (line.starts_with("Descender=")) { this->descender = (float)line.replace("Descender=", ""); this->customDescender = true; return true; } return false; }
void messageBox_platform(chstr title, chstr text, MessageBoxButton buttonMask, MessageBoxStyle style, hmap<MessageBoxButton, hstr> customButtonTitles, void(*callback)(MessageBoxButton)) { hstr ok; hstr yes; hstr no; hstr cancel; _makeButtonLabels(&ok, &yes, &no, &cancel, buttonMask, customButtonTitles); const char* buttons[4] = {"", NULL, NULL, NULL}; MessageBoxButton resultButtons[4] = {(MessageBoxButton)NULL, (MessageBoxButton)NULL, (MessageBoxButton)NULL, (MessageBoxButton)NULL}; int indexCancel = -1; if ((buttonMask & MESSAGE_BUTTON_OK) && (buttonMask & MESSAGE_BUTTON_CANCEL)) { // order is reversed because libKD prefers the colored button to be at place [1], at least on iOS // if this is going to be changed for a new platform, ifdef the button order for iOS buttons[1] = ok.cStr(); buttons[0] = cancel.cStr(); resultButtons[1] = MESSAGE_BUTTON_OK; resultButtons[0] = MESSAGE_BUTTON_CANCEL; indexCancel = 0; } else if ((buttonMask & MESSAGE_BUTTON_YES) && (buttonMask & MESSAGE_BUTTON_NO) && (buttonMask & MESSAGE_BUTTON_CANCEL)) { buttons[1] = yes.cStr(); buttons[0] = no.cStr(); buttons[2] = cancel.cStr(); resultButtons[1] = MESSAGE_BUTTON_YES; resultButtons[0] = MESSAGE_BUTTON_NO; resultButtons[2] = MESSAGE_BUTTON_CANCEL; indexCancel = 2; } else if (buttonMask & MESSAGE_BUTTON_OK) { buttons[0] = ok.cStr(); resultButtons[0] = MESSAGE_BUTTON_OK; indexCancel = 0; } else if ((buttonMask & MESSAGE_BUTTON_YES) && (buttonMask & MESSAGE_BUTTON_NO)) { buttons[1] = yes.cStr(); buttons[0] = no.cStr(); resultButtons[1] = MESSAGE_BUTTON_YES; resultButtons[0] = MESSAGE_BUTTON_NO; indexCancel = 1; } int index = kdShowMessage(title.cStr(), text.cStr(), buttons); if (index == -1) { index = indexCancel; } if (callback != NULL && index >= 0) { (*callback)(resultButtons[index]); } }
float Font::getTextWidth(chstr text) { // using static definitions to avoid memory allocation for optimization static float textX = 0.0f; static float textW = 0.0f; static float ax = 0.0f; static float aw = 0.0f; static float scale = 1.0f; static CharacterDefinition* character = NULL; static std::basic_string<unsigned int> chars; textX = 0.0f; textW = 0.0f; ax = 0.0f; aw = 0.0f; scale = this->getScale(); chars = text.u_str(); for_itert (unsigned int, i, 0, chars.size()) { character = &this->characters[chars[i]]; if (textX < -character->bx * scale) { ax = (character->aw - character->bx) * scale; aw = character->w * scale; } else { ax = character->aw * scale; aw = (character->w + character->bx) * scale; } textW = textX + hmax(ax, aw); textX += ax; } return textW; }
void Version::set(chstr versions) { if (Version::isVersionString(versions)) { this->set(versions.split('.', -1, true).cast<unsigned int>()); } }
grect hstr_to_grect(chstr string) { harray<hstr> data = string.split(aprilui::SeparatorParameter); if (data.size() != 4) { throw hl_exception("Cannot convert string '" + string + "' to gtypes::Rectangle."); } return grect(data[0].trim(), data[1].trim(), data[2].trim(), data[3].trim()); }
gvec2 hstr_to_gvec2(chstr string) { harray<hstr> data = string.split(aprilui::SeparatorParameter); if (data.size() != 2) { throw hl_exception("Cannot convert string '" + string + "' to gtypes::Vector2."); } return gvec2(data[0].trim(), data[1].trim()); }
Url::Url(chstr url) : valid(false), port(0), queryDelimiter('&') { if (url == "") { hlog::warn(logTag, "URL cannot be empty!"); return; } hstr newUrl = url; if (url.startsWith(HTTP_SCHEME)) { newUrl = newUrl(strlen(HTTP_SCHEME), -1); } this->host = newUrl; int index = 0; hstr query; hstr* current = &this->host; hstr* next = NULL; harray<hstr*> parts; parts += &this->path; parts += &query; parts += &this->fragment; harray<char> chars; chars += '/'; chars += '?'; chars += '#'; while (parts.size() > 0) { index = newUrl.indexOf(chars.removeFirst()); next = parts.removeFirst(); if (index >= 0) { *current = newUrl(0, index); *next = newUrl = newUrl(index, -1); current = next; } } this->_checkValues(query); }
bool LabelBase::setProperty(chstr name, chstr value) { if (name == "font") this->setFont(value); else if (name == "text_key") this->setTextKey(value); else if (name == "text") this->setText(value); else if (name == "horz_formatting") { if (value == "left") this->setHorzFormatting(atres::LEFT); else if (value == "right") this->setHorzFormatting(atres::RIGHT); else if (value == "center") this->setHorzFormatting(atres::CENTER); else if (value == "left_wrapped") this->setHorzFormatting(atres::LEFT_WRAPPED); else if (value == "right_wrapped") this->setHorzFormatting(atres::RIGHT_WRAPPED); else if (value == "center_wrapped") this->setHorzFormatting(atres::CENTER_WRAPPED); else if (value == "justified") this->setHorzFormatting(atres::JUSTIFIED); else { hlog::warn(aprilui::logTag, "'horz_formatting=' does not support value '" + value + "'."); return false; } } else if (name == "vert_formatting") { if (value == "top") this->setVertFormatting(atres::TOP); else if (value == "center") this->setVertFormatting(atres::CENTER); else if (value == "bottom") this->setVertFormatting(atres::BOTTOM); else { hlog::warn(aprilui::logTag, "'vert_formatting=' does not support value '" + value + "'."); return false; } } else if (name == "text_color") this->setTextColor(value); else if (name == "color") { throw hl_exception("LabelBase instance using 'color=' which is conflicted with TextImageButton's color and cannot be used! Maybe you meant 'text_color='?"); } else if (name == "effect") { this->setFontEffect(atres::NONE); this->setUseFontEffectColor(false); harray<hstr> values = value.split(":", -1, true); if (values.size() > 0) { if (values[0] == "none") this->setFontEffect(atres::NONE); else if (values[0] == "shadow") this->setFontEffect(atres::SHADOW); else if (values[0] == "border") this->setFontEffect(atres::BORDER); else { hlog::warn(aprilui::logTag, "'effect=' does not support value '" + values[0] + "'."); return false; } if (values.size() > 1) { if (values[1].is_hex() && (values[1].size() == 6 || values[1].size() == 8)) { this->setUseFontEffectColor(true); this->setFontEffectColor(values[1]); } else { hlog::warn(aprilui::logTag, "'effect=' is using invalid color modifier '" + values[1] + "'."); return false; } } } } else if (name == "text_offset_x") this->textOffset.x = (float)value; else if (name == "text_offset_y") this->textOffset.y = (float)value; else if (name == "background_color") this->setBackgroundColor(value); else return false; return true; }
void Emitter::setAngle(chstr value) { harray<hstr> data = value.split(aprilparticle::SeparatorRange); this->setAngleRange(data.first(), data.last()); }
void Emitter::setSize(chstr value) { harray<hstr> data = value.split(aprilparticle::SeparatorRange); this->setSizeRange(hstr_to_gvec2(data.first()), hstr_to_gvec2(data.last())); }
void TinyXml_Node::setProperty(chstr name, chstr value) { this->node->ToElement()->SetAttribute(name.c_str(), value.c_str()); }