void ITools::addUnderline(void* vv) { Text* tt = (Text*)vv; Color4B color = tt->getTextColor(); DrawNode* drawLine = DrawNode::create(); drawLine->drawLine(Vec2(0,0), Vec2(tt->getContentSize().width,0), Color4F((float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255)); drawLine->setPosition(Vec2(0,2)); tt->addChild(drawLine); }
void TextReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *textOptions) { Text* label = static_cast<Text*>(node); auto options = (TextOptions*)textOptions; bool touchScaleEnabled = options->touchScaleEnable() != 0; label->setTouchScaleChangeEnabled(touchScaleEnabled); std::string text = options->text()->c_str(); label->setString(text); int fontSize = options->fontSize(); label->setFontSize(fontSize); std::string fontName = options->fontName()->c_str(); label->setFontName(fontName); Size areaSize = Size(options->areaWidth(), options->areaHeight()); if (!areaSize.equals(Size::ZERO)) { label->setTextAreaSize(areaSize); } TextHAlignment h_alignment = (TextHAlignment)options->hAlignment(); label->setTextHorizontalAlignment(h_alignment); TextVAlignment v_alignment = (TextVAlignment)options->vAlignment(); label->setTextVerticalAlignment((TextVAlignment)v_alignment); bool fileExist = false; std::string errorFilePath = ""; auto resourceData = options->fontResource(); std::string path = resourceData->path()->c_str(); if (path != "") { if (FileUtils::getInstance()->isFileExist(path)) { fileExist = true; } else { errorFilePath = path; fileExist = false; } if (fileExist) { label->setFontName(path); } else { auto alert = Label::create(); alert->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); label->addChild(alert); } } bool outlineEnabled = options->outlineEnabled(); if (outlineEnabled) { auto f_outlineColor = options->outlineColor(); if (f_outlineColor) { Color4B outlineColor(f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b(), f_outlineColor->a()); label->enableOutline(outlineColor, options->outlineSize()); } } bool shadowEnabled = options->shadowEnabled(); if (shadowEnabled) { auto f_shadowColor = options->shadowColor(); if (f_shadowColor) { Color4B shadowColor(f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b(), f_shadowColor->a()); label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius()); } } // Save node color before set widget properties auto oldColor = node->getColor(); auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); // restore node color and set color to text to fix shadow & outline color won't show correct bug node->setColor(oldColor); auto optionsWidget = (WidgetOptions*)options->widgetOptions(); auto f_color = optionsWidget->color(); Color4B color(f_color->r(), f_color->g(), f_color->b(), f_color->a()); ((Text *)node)->setTextColor(color); label->setUnifySizeEnabled(false); bool IsCustomSize = options->isCustomSize() != 0; label->ignoreContentAdaptWithSize(!IsCustomSize); auto widgetOptions = options->widgetOptions(); if (!label->isIgnoreContentAdaptWithSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); label->setContentSize(contentSize); } }