2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIRICHTEXT_H__
|
|
|
|
#define __UIRICHTEXT_H__
|
|
|
|
|
|
|
|
#include "ui/UIWidget.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2016-03-07 09:50:47 +08:00
|
|
|
#include "base/CCValue.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2016-01-22 13:44:45 +08:00
|
|
|
class Label;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2016-03-07 09:50:47 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich text element base class.
|
|
|
|
* It defines the basic common properties for all rich text element.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichElement : public Ref
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich element type.
|
|
|
|
*/
|
2014-05-12 10:39:30 +08:00
|
|
|
enum class Type
|
|
|
|
{
|
2016-03-07 09:50:47 +08:00
|
|
|
TEXT, /*!< RichElementText */
|
|
|
|
IMAGE, /*!< RichElementImage */
|
|
|
|
CUSTOM, /*!< RichElementCustomNode */
|
|
|
|
NEWLINE /*!< RichElementNewLine */
|
2014-05-12 10:39:30 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
RichElement(){};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual ~RichElement(){};
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize a rich element with different arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in @see `Color3B`.
|
|
|
|
* @param opacity A opacity value in `GLubyte`.
|
|
|
|
* @return True if initialize success, false otherwise.
|
|
|
|
*/
|
2019-06-05 17:58:33 +08:00
|
|
|
bool init(int tag, const Color3B& color, uint8_t opacity);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-03-07 09:50:47 +08:00
|
|
|
bool equalType(Type type);
|
|
|
|
void setColor(const Color3B& color);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
Type _type; /*!< Rich element type. */
|
|
|
|
int _tag; /*!< A integer tag value. */
|
|
|
|
Color3B _color; /*!< A color in `Color3B`. */
|
|
|
|
uint8_t _opacity; /*!< A opacity value in `GLubyte`. */
|
2014-03-11 17:13:54 +08:00
|
|
|
friend class RichText;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich element for displaying text.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichElementText : public RichElement
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
RichElementText() { _type = Type::TEXT; };
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ITALICS_FLAG = 1 << 0, /*!< italic text */
|
|
|
|
BOLD_FLAG = 1 << 1, /*!< bold text */
|
|
|
|
UNDERLINE_FLAG = 1 << 2, /*!< underline */
|
|
|
|
STRIKETHROUGH_FLAG = 1 << 3, /*!< strikethrough */
|
|
|
|
URL_FLAG = 1 << 4, /*!< url of anchor */
|
|
|
|
OUTLINE_FLAG = 1 << 5, /*!< outline effect */
|
|
|
|
SHADOW_FLAG = 1 << 6, /*!< shadow effect */
|
|
|
|
GLOW_FLAG = 1 << 7 /*!< glow effect */
|
2016-01-20 12:41:31 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual ~RichElementText(){};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Initialize a RichElementText with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param text Content string.
|
|
|
|
* @param fontName Content font name.
|
|
|
|
* @param fontSize Content font size.
|
2016-07-10 16:38:32 +08:00
|
|
|
* @param flags italics, bold, underline, strikethrough, url, outline, shadow or glow
|
2016-03-07 09:50:47 +08:00
|
|
|
* @param url uniform resource locator
|
|
|
|
* @param outlineColor the color of the outline
|
|
|
|
* @param outlineSize the outline effect size value
|
|
|
|
* @param shadowColor the shadow effect color value
|
|
|
|
* @param shadowOffset shadow effect offset value
|
|
|
|
* @param shadowBlurRadius the shadow effect blur radius
|
|
|
|
* @param glowColor glow color
|
2015-12-21 07:21:45 +08:00
|
|
|
* @return True if initialize success, false otherwise.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool init(int tag,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view text,
|
|
|
|
std::string_view fontName,
|
2021-12-25 10:04:45 +08:00
|
|
|
float fontSize,
|
|
|
|
uint32_t flags,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view url,
|
2021-12-25 10:04:45 +08:00
|
|
|
const Color3B& outlineColor = Color3B::WHITE,
|
|
|
|
int outlineSize = -1,
|
|
|
|
const Color3B& shadowColor = Color3B::BLACK,
|
|
|
|
const Vec2& shadowOffset = Vec2(2.0, -2.0),
|
|
|
|
int shadowBlurRadius = 0,
|
|
|
|
const Color3B& glowColor = Color3B::WHITE);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Create a RichElementText with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param text Content string.
|
|
|
|
* @param fontName Content font name.
|
|
|
|
* @param fontSize Content font size.
|
2016-07-10 16:38:32 +08:00
|
|
|
* @param flags italics, bold, underline, strikethrough, url, outline, shadow or glow
|
2016-03-07 09:50:47 +08:00
|
|
|
* @param url uniform resource locator
|
|
|
|
* @param outlineColor the color of the outline
|
|
|
|
* @param outlineSize the outline effect size value
|
|
|
|
* @param shadowColor the shadow effect color value
|
|
|
|
* @param shadowOffset shadow effect offset value
|
|
|
|
* @param shadowBlurRadius the shadow effect blur radius
|
|
|
|
* @param glowColor glow color
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return RichElementText instance.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static RichElementText* create(int tag,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view text,
|
|
|
|
std::string_view fontName,
|
2021-12-25 10:04:45 +08:00
|
|
|
float fontSize,
|
|
|
|
uint32_t flags = 0,
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string_view url = "",
|
2021-12-25 10:04:45 +08:00
|
|
|
const Color3B& outlineColor = Color3B::WHITE,
|
|
|
|
int outlineSize = -1,
|
|
|
|
const Color3B& shadowColor = Color3B::BLACK,
|
|
|
|
const Vec2& shadowOffset = Vec2(2.0, -2.0),
|
|
|
|
int shadowBlurRadius = 0,
|
|
|
|
const Color3B& glowColor = Color3B::WHITE);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
std::string _text;
|
|
|
|
std::string _fontName;
|
|
|
|
float _fontSize;
|
2016-01-20 12:41:31 +08:00
|
|
|
uint32_t _flags;
|
|
|
|
std::string _url;
|
2021-12-25 10:04:45 +08:00
|
|
|
Color3B _outlineColor; /*!< the color of the outline */
|
|
|
|
int _outlineSize; /*!< the outline effect size value */
|
|
|
|
Color3B _shadowColor; /*!< the shadow effect color value */
|
|
|
|
Vec2 _shadowOffset; /*!< shadow effect offset value */
|
|
|
|
int _shadowBlurRadius; /*!< the shadow effect blur radius */
|
|
|
|
Color3B _glowColor; /*!< attributes of glow tag */
|
2014-03-11 17:13:54 +08:00
|
|
|
friend class RichText;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich element for displaying images.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichElementImage : public RichElement
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
RichElementImage() { _type = Type::IMAGE; };
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual ~RichElementImage(){};
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize a RichElementImage with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param filePath A image file name.
|
2016-03-07 09:50:47 +08:00
|
|
|
* @param url uniform resource locator
|
2017-07-24 10:35:52 +08:00
|
|
|
* @param texType texture type, may be a valid file path, or a sprite frame name
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return True if initialize success, false otherwise.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool init(int tag,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view filePath,
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string_view url = "",
|
2021-12-25 10:04:45 +08:00
|
|
|
Widget::TextureResType texType = Widget::TextureResType::LOCAL);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a RichElementImage with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param filePath A image file name.
|
2016-03-07 09:50:47 +08:00
|
|
|
* @param url uniform resource locator
|
2017-07-24 10:35:52 +08:00
|
|
|
* @param texType texture type, may be a valid file path, or a sprite frame name
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return A RichElementImage instance.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static RichElementImage* create(int tag,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view filePath,
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string_view url = "",
|
2021-12-25 10:04:45 +08:00
|
|
|
Widget::TextureResType texType = Widget::TextureResType::LOCAL);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
void setWidth(int width);
|
|
|
|
void setHeight(int height);
|
2022-08-12 06:22:21 +08:00
|
|
|
inline void setScale(float scale) { _scaleX = _scaleY = scale; }
|
|
|
|
inline void setScaleX(float scaleX) { _scaleX = scaleX; }
|
|
|
|
inline void setScaleY(float scaleY) { _scaleY = scaleY; }
|
2021-12-26 23:26:34 +08:00
|
|
|
void setUrl(std::string_view url);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
std::string _filePath;
|
|
|
|
Rect _textureRect;
|
2017-07-24 10:35:52 +08:00
|
|
|
Widget::TextureResType _textureType;
|
2014-03-11 17:13:54 +08:00
|
|
|
friend class RichText;
|
2016-01-20 12:41:31 +08:00
|
|
|
int _width;
|
|
|
|
int _height;
|
2022-08-12 06:22:21 +08:00
|
|
|
float _scaleX;
|
|
|
|
float _scaleY;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string _url; /*!< attributes of anchor tag */
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich element for displaying custom node type.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichElementCustomNode : public RichElement
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
RichElementCustomNode() { _type = Type::CUSTOM; };
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
virtual ~RichElementCustomNode() { AX_SAFE_RELEASE(_customNode); };
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize a RichElementCustomNode with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param customNode A custom node pointer.
|
|
|
|
* @return True if initialize success, false otherwise.
|
|
|
|
*/
|
2019-06-05 17:58:33 +08:00
|
|
|
bool init(int tag, const Color3B& color, uint8_t opacity, Node* customNode);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Create a RichElementCustomNode with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @param customNode A custom node pointer.
|
|
|
|
* @return A RichElementCustomNode instance.
|
|
|
|
*/
|
2019-06-05 17:58:33 +08:00
|
|
|
static RichElementCustomNode* create(int tag, const Color3B& color, uint8_t opacity, Node* customNode);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
Node* _customNode;
|
|
|
|
friend class RichText;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-09-28 13:33:17 +08:00
|
|
|
/**
|
|
|
|
*@brief Rich element for new line.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichElementNewLine : public RichElement
|
2015-09-28 13:33:17 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
|
|
|
* @js ctor
|
|
|
|
* @lua new
|
|
|
|
*
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
RichElementNewLine() { _type = Type::NEWLINE; };
|
|
|
|
|
2015-09-28 13:33:17 +08:00
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~RichElementNewLine(){};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-09-28 13:33:17 +08:00
|
|
|
/**
|
|
|
|
* @brief Create a RichElementNewLine with various arguments.
|
|
|
|
*
|
|
|
|
* @param tag A integer tag value.
|
|
|
|
* @param color A color in Color3B.
|
|
|
|
* @param opacity A opacity in GLubyte.
|
|
|
|
* @return A RichElementNewLine instance.
|
|
|
|
*/
|
2019-06-05 17:58:33 +08:00
|
|
|
static RichElementNewLine* create(int tag, const Color3B& color, uint8_t opacity);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-09-28 13:33:17 +08:00
|
|
|
protected:
|
|
|
|
friend class RichText;
|
|
|
|
};
|
2016-03-07 09:50:47 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief A container for displaying various RichElements.
|
|
|
|
* We could use it to display texts with images easily.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL RichText : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
enum WrapMode
|
|
|
|
{
|
2016-01-22 13:44:45 +08:00
|
|
|
WRAP_PER_WORD,
|
|
|
|
WRAP_PER_CHAR
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
enum class HorizontalAlignment
|
|
|
|
{
|
2017-07-05 09:25:12 +08:00
|
|
|
LEFT,
|
|
|
|
CENTER,
|
|
|
|
RIGHT,
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-03-07 09:50:47 +08:00
|
|
|
/**
|
|
|
|
* @brief call to open a resource specified by a URL
|
|
|
|
* @param url a URL
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
typedef std::function<void(std::string_view url)> OpenUrlHandler;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-03-07 09:50:47 +08:00
|
|
|
/**
|
|
|
|
* @brief called on the specified tag
|
|
|
|
* @param tagAttrValueMap the attributes of a tag
|
|
|
|
* @result text attributes and RichElement
|
|
|
|
*/
|
|
|
|
typedef std::function<std::pair<ValueMap, RichElement*>(const ValueMap& tagAttrValueMap)> VisitEnterHandler;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
static const std::string KEY_VERTICAL_SPACE; /*!< key of vertical space */
|
|
|
|
static const std::string KEY_WRAP_MODE; /*!< key of per word, or per char */
|
|
|
|
static const std::string KEY_HORIZONTAL_ALIGNMENT; /*!< key of left, right, or center */
|
|
|
|
static const std::string KEY_FONT_COLOR_STRING; /*!< key of font color */
|
|
|
|
static const std::string KEY_FONT_SIZE; /*!< key of font size */
|
|
|
|
static const std::string KEY_FONT_SMALL; /*!< key of font size small */
|
|
|
|
static const std::string KEY_FONT_BIG; /*!< key of font size big */
|
|
|
|
static const std::string KEY_FONT_FACE; /*!< key of font name */
|
|
|
|
static const std::string KEY_TEXT_BOLD; /*!< key of text bold */
|
|
|
|
static const std::string KEY_TEXT_ITALIC; /*!< key of text italic */
|
|
|
|
static const std::string KEY_TEXT_LINE; /*!< key of line style */
|
|
|
|
static const std::string VALUE_TEXT_LINE_NONE; /*!< value of none */
|
|
|
|
static const std::string VALUE_TEXT_LINE_DEL; /*!< value of strikethrough line */
|
|
|
|
static const std::string VALUE_TEXT_LINE_UNDER; /*!< value of underline */
|
|
|
|
static const std::string KEY_TEXT_STYLE; /*!< key of effect style */
|
|
|
|
static const std::string VALUE_TEXT_STYLE_NONE; /*!< value of none */
|
|
|
|
static const std::string VALUE_TEXT_STYLE_OUTLINE; /*!< value of outline */
|
|
|
|
static const std::string VALUE_TEXT_STYLE_SHADOW; /*!< value of shadow */
|
|
|
|
static const std::string VALUE_TEXT_STYLE_GLOW; /*!< value of glow */
|
|
|
|
static const std::string KEY_TEXT_OUTLINE_COLOR; /*!< key of outline color */
|
|
|
|
static const std::string KEY_TEXT_OUTLINE_SIZE; /*!< key of outline size */
|
|
|
|
static const std::string KEY_TEXT_SHADOW_COLOR; /*!< key of shadow color */
|
|
|
|
static const std::string KEY_TEXT_SHADOW_OFFSET_WIDTH; /*!< key of shadow offset (width) */
|
|
|
|
static const std::string KEY_TEXT_SHADOW_OFFSET_HEIGHT; /*!< key of shadow offset (height) */
|
|
|
|
static const std::string KEY_TEXT_SHADOW_BLUR_RADIUS; /*!< key of shadow blur radius */
|
|
|
|
static const std::string KEY_TEXT_GLOW_COLOR; /*!< key of glow color */
|
|
|
|
static const std::string KEY_URL; /*!< key of url */
|
|
|
|
static const std::string KEY_ANCHOR_FONT_COLOR_STRING; /*!< key of font color of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_BOLD; /*!< key of text bold of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_ITALIC; /*!< key of text italic of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_LINE; /*!< key of line style of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_STYLE; /*!< key of effect style of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_OUTLINE_COLOR; /*!< key of outline color of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_OUTLINE_SIZE; /*!< key of outline size of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_SHADOW_COLOR; /*!< key of shadow color of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH; /*!< key of shadow offset (width) of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT; /*!< key of shadow offset (height) of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS; /*!< key of shadow blur radius of anchor tag */
|
|
|
|
static const std::string KEY_ANCHOR_TEXT_GLOW_COLOR; /*!< key of glow color of anchor tag */
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
RichText();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual ~RichText();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Create a empty RichText.
|
|
|
|
*
|
|
|
|
* @return RichText instance.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
static RichText* create();
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a RichText from an XML
|
|
|
|
*
|
|
|
|
* @return RichText instance.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static RichText* createWithXML(std::string_view xml,
|
2021-12-25 10:04:45 +08:00
|
|
|
const ValueMap& defaults = ValueMap(),
|
|
|
|
const OpenUrlHandler& handleOpenUrl = nullptr);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Insert a RichElement at a given index.
|
|
|
|
*
|
|
|
|
* @param element A RichElement type.
|
|
|
|
* @param index A given index.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void insertElement(RichElement* element, int index);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Add a RichElement at the end of RichText.
|
|
|
|
*
|
|
|
|
* @param element A RichElement instance.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void pushBackElement(RichElement* element);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Remove a RichElement at a given index.
|
|
|
|
*
|
|
|
|
* @param index A integer index value.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void removeElement(int index);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Remove specific RichElement.
|
|
|
|
*
|
|
|
|
* @param element A RichElement type.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void removeElement(RichElement* element);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Set vertical space between each RichElement.
|
|
|
|
*
|
|
|
|
* @param space Point in float.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setVerticalSpace(float space);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Rearrange all RichElement in the RichText.
|
2022-05-25 09:42:12 +08:00
|
|
|
* @param force Force the formatting of the contents
|
2015-03-25 18:17:58 +08:00
|
|
|
* It's usually called internally.
|
|
|
|
*/
|
2022-05-25 09:42:12 +08:00
|
|
|
void formatText(bool force = false);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// override functions.
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore) override;
|
2014-03-24 15:25:44 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2016-01-22 13:44:45 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void setWrapMode(WrapMode wrapMode); /*!< sets the wrapping mode: WRAP_PER_CHAR or WRAP_PER_WORD */
|
|
|
|
WrapMode getWrapMode() const; /*!< returns the current wrapping mode */
|
|
|
|
void setHorizontalAlignment(
|
|
|
|
HorizontalAlignment a); /*!< sets the horizontal alignment mode: LEFT, CENTER, or RIGHT */
|
2017-07-05 09:25:12 +08:00
|
|
|
HorizontalAlignment getHorizontalAlignment() const; /*!< returns the current horizontal alignment mode */
|
2021-12-25 10:04:45 +08:00
|
|
|
void setFontColor(
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string_view color); /*!< Set the font color. @param color the #RRGGBB hexadecimal notation. */
|
|
|
|
std::string getFontColor(); /*!< return the current font color */
|
|
|
|
Color3B getFontColor3B(); /*!< return the current font color */
|
|
|
|
void setFontSize(float size); /*!< Set the font size. @param size the font size. */
|
|
|
|
float getFontSize(); /*!< return the current font size */
|
|
|
|
void setFontFace(std::string_view face); /*!< Set the font face. @param face the font face. */
|
|
|
|
std::string getFontFace(); /*!< return the current font face */
|
2021-12-26 23:26:34 +08:00
|
|
|
void setAnchorFontColor(std::string_view color); /*!< Set the font color of a-tag. @param face the font color. */
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string getAnchorFontColor(); /*!< return the current font color of a-tag */
|
2022-08-12 06:22:21 +08:00
|
|
|
ax::Color3B getAnchorFontColor3B(); /*!< return the current font color of a-tag */
|
2021-12-28 11:00:34 +08:00
|
|
|
void setAnchorTextBold(bool enable); /*!< enable bold text of a-tag */
|
|
|
|
bool isAnchorTextBoldEnabled(); /*!< valid style is bold text of a-tag? */
|
|
|
|
void setAnchorTextItalic(bool enable); /*!< enable italic text of a-tag */
|
|
|
|
bool isAnchorTextItalicEnabled(); /*!< valid style is italic text of a-tag? */
|
|
|
|
void setAnchorTextDel(bool enable); /*!< enable the strikethrough of a-tag */
|
|
|
|
bool isAnchorTextDelEnabled(); /*!< valid strikethrough of a-tag? */
|
|
|
|
void setAnchorTextUnderline(bool enable); /*!< enable the underline of a-tag */
|
|
|
|
bool isAnchorTextUnderlineEnabled(); /*!< valid underline of a-tag? */
|
2016-07-16 03:18:40 +08:00
|
|
|
/** @brief enable the outline of a-tag */
|
2016-03-07 09:50:47 +08:00
|
|
|
void setAnchorTextOutline(bool enable, const Color3B& outlineColor = Color3B::WHITE, int outlineSize = -1);
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isAnchorTextOutlineEnabled(); /*!< valid outline of a-tag? */
|
|
|
|
Color3B getAnchorTextOutlineColor3B(); /*!< return the current text outline color of a-tag */
|
|
|
|
int getAnchorTextOutlineSize(); /*!< return the current text outline size of a-tag */
|
2016-07-16 03:18:40 +08:00
|
|
|
/** @brief enable the shadow of a-tag */
|
2021-12-25 10:04:45 +08:00
|
|
|
void setAnchorTextShadow(bool enable,
|
|
|
|
const Color3B& shadowColor = Color3B::BLACK,
|
|
|
|
const Vec2& offset = Vec2(2.0, -2.0),
|
|
|
|
int blurRadius = 0);
|
|
|
|
bool isAnchorTextShadowEnabled(); /*!< valid shadow of a-tag? */
|
|
|
|
Color3B getAnchorTextShadowColor3B(); /*!< return the current text shadow color of a-tag */
|
|
|
|
Vec2 getAnchorTextShadowOffset(); /*!< return the current text shadow offset of a-tag */
|
|
|
|
int getAnchorTextShadowBlurRadius(); /*!< return the current text shadow blur radius of a-tag */
|
2016-03-07 09:50:47 +08:00
|
|
|
void setAnchorTextGlow(bool enable, const Color3B& glowColor = Color3B::WHITE); /*!< enable the glow of a-tag */
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isAnchorTextGlowEnabled(); /*!< valid glow of a-tag? */
|
|
|
|
Color3B getAnchorTextGlowColor3B(); /*!< return the current text glow color of a-tag */
|
|
|
|
void setDefaults(const ValueMap& defaults); /*!< set the default values */
|
|
|
|
ValueMap getDefaults() const; /*!< returns the default values */
|
2016-03-07 09:50:47 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Color3B color3BWithString(std::string_view color); /*!< convert a color string into a Color3B. */
|
|
|
|
std::string stringWithColor3B(const ax::Color3B& color3b); /*!< convert a Color3B into a color string. */
|
|
|
|
std::string stringWithColor4B(const ax::Color4B& color4b); /*!< convert a Color4B into a color string. */
|
2016-03-07 09:50:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief add a callback to own tag.
|
|
|
|
* @param tag tag's name
|
|
|
|
* @param isFontElement use attributes of text tag
|
|
|
|
* @param handleVisitEnter callback
|
2016-01-22 13:44:45 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static void setTagDescription(std::string_view tag, bool isFontElement, VisitEnterHandler handleVisitEnter);
|
2016-01-22 13:44:45 +08:00
|
|
|
|
2016-03-07 09:50:47 +08:00
|
|
|
/**
|
|
|
|
* @brief remove a callback to own tag.
|
|
|
|
* @param tag tag's name
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static void removeTagDescription(std::string_view tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void openUrl(std::string_view url);
|
2016-03-07 09:50:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Asks the callback to open a resource specified by a URL.
|
|
|
|
* @discussion If you set up your own URL in the anchor tag, it is used to intercept the URL open.
|
|
|
|
* @param handleOpenUrl the callback
|
|
|
|
*/
|
|
|
|
void setOpenUrlHandler(const OpenUrlHandler& handleOpenUrl);
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
virtual bool init() override;
|
2016-01-20 12:41:31 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithXML(std::string_view xml,
|
2021-12-25 10:04:45 +08:00
|
|
|
const ValueMap& defaults = ValueMap(),
|
|
|
|
const OpenUrlHandler& handleOpenUrl = nullptr);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2014-07-24 11:51:47 +08:00
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void initRenderer() override;
|
2014-03-11 17:13:54 +08:00
|
|
|
void pushToContainer(Node* renderer);
|
2021-12-26 23:26:34 +08:00
|
|
|
void handleTextRenderer(std::string_view text,
|
|
|
|
std::string_view fontName,
|
2021-12-25 10:04:45 +08:00
|
|
|
float fontSize,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
|
|
|
uint32_t flags,
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string_view url = "",
|
2021-12-25 10:04:45 +08:00
|
|
|
const Color3B& outlineColor = Color3B::WHITE,
|
|
|
|
int outlineSize = -1,
|
|
|
|
const Color3B& shadowColor = Color3B::BLACK,
|
|
|
|
const Vec2& shadowOffset = Vec2(2.0, -2.0),
|
|
|
|
int shadowBlurRadius = 0,
|
|
|
|
const Color3B& glowColor = Color3B::WHITE);
|
2021-12-26 23:26:34 +08:00
|
|
|
void handleImageRenderer(std::string_view filePath,
|
2021-12-25 10:04:45 +08:00
|
|
|
Widget::TextureResType textureType,
|
|
|
|
const Color3B& color,
|
|
|
|
uint8_t opacity,
|
|
|
|
int width,
|
|
|
|
int height,
|
2022-08-12 06:22:21 +08:00
|
|
|
std::string_view url,
|
|
|
|
float scaleX = 1.f,
|
|
|
|
float scaleY = 1.f);
|
2014-03-11 17:13:54 +08:00
|
|
|
void handleCustomRenderer(Node* renderer);
|
2017-11-06 10:28:11 +08:00
|
|
|
void formatRenderers();
|
2014-03-11 17:13:54 +08:00
|
|
|
void addNewLine();
|
2021-12-25 10:04:45 +08:00
|
|
|
void doHorizontalAlignment(const Vector<Node*>& row, float rowWidth);
|
|
|
|
float stripTrailingWhitespace(const Vector<Node*>& row);
|
2016-01-22 13:44:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
bool _formatTextDirty;
|
|
|
|
Vector<RichElement*> _richElements;
|
2017-07-04 14:31:29 +08:00
|
|
|
std::vector<Vector<Node*>> _elementRenders;
|
2017-11-08 13:59:57 +08:00
|
|
|
std::vector<float> _lineHeights;
|
2014-03-11 17:13:54 +08:00
|
|
|
float _leftSpaceWidth;
|
2016-01-22 13:44:45 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap _defaults; /*!< default values */
|
|
|
|
OpenUrlHandler _handleOpenUrl; /*!< the callback for open URL */
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
} // namespace ui
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__UIRichText__) */
|