Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cocos/ui/UIRichText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ void RichText::formatText()
case RichElement::Type::IMAGE:
{
RichElementImage* elmtImage = static_cast<RichElementImage*>(element);
handleImageRenderer(elmtImage->_filePath, elmtImage->_color, elmtImage->_opacity, elmtImage->_width, elmtImage->_height, elmtImage->_url);
handleImageRenderer(elmtImage->_filePath, elmtImage->_textureType, elmtImage->_color, elmtImage->_opacity, elmtImage->_width, elmtImage->_height, elmtImage->_url);
break;
}
case RichElement::Type::CUSTOM:
Expand Down Expand Up @@ -1740,9 +1740,14 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo
}
}

void RichText::handleImageRenderer(const std::string& filePath, const Color3B &/*color*/, GLubyte /*opacity*/, int width, int height, const std::string& url)
void RichText::handleImageRenderer(const std::string& filePath, Widget::TextureResType textureType, const Color3B &/*color*/, GLubyte /*opacity*/, int width, int height, const std::string& url)
{
Sprite* imageRenderer = Sprite::create(filePath);
Sprite* imageRenderer;
if (textureType == Widget::TextureResType::LOCAL)
imageRenderer = Sprite::create(filePath);
else
imageRenderer = Sprite::createWithSpriteFrameName(filePath);

if (imageRenderer)
{
auto currentSize = imageRenderer->getContentSize();
Expand Down
2 changes: 1 addition & 1 deletion cocos/ui/UIRichText.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class CC_GUI_DLL RichText : public Widget
const Color3B& outlineColor = Color3B::WHITE, int outlineSize = -1,
const Color3B& shadowColor = Color3B::BLACK, const Size& shadowOffset = Size(2.0, -2.0), int shadowBlurRadius = 0,
const Color3B& glowColor = Color3B::WHITE);
void handleImageRenderer(const std::string& filePath, const Color3B& color, GLubyte opacity, int width, int height, const std::string& url);
void handleImageRenderer(const std::string& filePath, Widget::TextureResType textureType, const Color3B& color, GLubyte opacity, int width, int height, const std::string& url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add a new API, rather than change the current one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, do you mean to provide a new api for using sprite frames?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatriceJiang
And the current one is a little weird, developer can't use sprite frames when they want to set the content size, they have to use a local sprite which is the same as the one in the plist. In a project, using the same sprite with different size at different places is very normal, do you think so? :)

Copy link
Contributor

@PatriceJiang PatriceJiang Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same sprite with different size

These sprites do share same Texture underlying, but I think they should not be "the same sprite".
A Sprite holds partial render info of a Texture instance. Since the position/size differs, they should be separated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background is: language is javescript, using createWithXML to create richtext.
The case is that:
There is a file, "res/star.png". I want to create two richtexts using the "star" loading from the file, one richtext's _ignoreSize is true, and the other has to be false, then I can't put "res/star.png" into plist, because when _ignoreSize is true, RichText can't load image from plist.
In my project, almost all of the pngs has been put into plist due to resource management and performance.

Am I clear?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a new issue and provide a description there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, the new issue is #19114

void handleCustomRenderer(Node* renderer);
void formatRenderers();
void addNewLine();
Expand Down