2019-12-23 18:05:08 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <kiwano/2d/Actor.h>
|
|
|
|
|
|
#include <kiwano/renderer/Color.h>
|
|
|
|
|
|
#include <kiwano/renderer/TextLayout.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_DECLARE_SMART_PTR(TextActor);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Actors
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* @brief <EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
*/
|
|
|
|
|
|
class KGE_API TextActor
|
|
|
|
|
|
: public Actor
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|
|
|
|
|
TextActor();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-26 19:25:43 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
explicit TextActor(const String& text);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-26 19:25:43 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param style <20>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
|
|
|
|
|
TextActor(const String& text, const TextStyle& style);
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~TextActor();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
const String& GetText() const;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
2019-12-26 19:25:43 +08:00
|
|
|
|
const TextStyle& GetStyle() const;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
const TextLayout& GetLayout() const;
|
|
|
|
|
|
|
2020-01-09 08:45:00 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ִ<EFBFBD>С
|
|
|
|
|
|
Size GetLayoutSize() const;
|
|
|
|
|
|
|
2019-12-29 18:58:22 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>仭ˢ
|
|
|
|
|
|
BrushPtr GetFillBrush() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ˢ
|
|
|
|
|
|
BrushPtr GetOutlineBrush() const;
|
|
|
|
|
|
|
2019-12-26 19:25:43 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
FontPtr GetFont() const;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|
|
|
|
|
void SetText(String const& text);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
|
|
|
|
|
void SetStyle(const TextStyle& style);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
void SetFont(FontPtr font);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetFontFamily(String const& family);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ֺţ<D6BA>Ĭ<EFBFBD><C4AC>ֵΪ 18<31><38>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
void SetFontSize(float size);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸֵ<CFB8><D6B5>Ĭ<EFBFBD><C4AC>ֵΪ FontWeight::Normal<61><6C>
|
|
|
|
|
|
void SetFontWeight(uint32_t weight);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-27 23:42:51 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仭ˢ
|
|
|
|
|
|
void SetFillBrush(BrushPtr brush);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ĭ<EFBFBD><C4AC>ֵΪ Color::White<74><65>
|
|
|
|
|
|
void SetFillColor(Color const& color);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>壨Ĭ<E5A3A8><C4AC>ֵΪ false<73><65>
|
|
|
|
|
|
void SetItalic(bool italic);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>еĿ<D0B5><C4BF>ȣ<EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ 0<><30>
|
|
|
|
|
|
void SetWrapWidth(float wrap_width);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>ࣨĬ<E0A3A8><C4AC>Ϊ 0<><30>
|
|
|
|
|
|
void SetLineSpacing(float line_spacing);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD><C3B6>뷽ʽ<EBB7BD><CABD>Ĭ<EFBFBD><C4AC>Ϊ TextAlign::Left<66><74>
|
|
|
|
|
|
void SetAlignment(TextAlign align);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-27 23:42:51 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
|
|
|
|
|
void SetOutlineBrush(BrushPtr brush);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-27 23:42:51 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
2019-12-23 18:05:08 +08:00
|
|
|
|
void SetOutlineColor(Color const& outline_color);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-27 23:42:51 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD>
|
2019-12-23 18:05:08 +08:00
|
|
|
|
void SetOutlineWidth(float outline_width);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-27 23:42:51 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB>ʽ
|
2020-01-10 11:43:07 +08:00
|
|
|
|
void SetOutlineStroke(const StrokeStyle& outline_stroke);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2019-12-26 19:25:43 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD>»<EFBFBD><C2BB>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
|
|
|
|
|
|
void SetUnderline(bool enable);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʾɾ<CABE><C9BE><EFBFBD>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
|
|
|
|
|
|
void SetStrikethrough(bool enable);
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
2019-12-29 18:58:22 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
|
|
|
|
|
/// @details <20><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µģ<C2B5><C4A3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8>½ڵ<C2BD>״̬
|
|
|
|
|
|
void UpdateLayout();
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
static void SetDefaultStyle(TextStyle const& style);
|
|
|
|
|
|
|
2019-12-29 18:58:22 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡĬ<C8A1><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
static const TextStyle& GetDefaultStyle();
|
|
|
|
|
|
|
2020-01-10 15:22:12 +08:00
|
|
|
|
void OnRender(RenderContext& ctx) override;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
2019-12-27 23:42:51 +08:00
|
|
|
|
void OnUpdate(Duration dt) override;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-01-16 18:33:42 +08:00
|
|
|
|
bool CheckVisibility(RenderContext& ctx) const override;
|
2019-12-27 23:42:51 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
private:
|
2019-12-29 18:58:22 +08:00
|
|
|
|
bool show_underline_;
|
|
|
|
|
|
bool show_strikethrough_;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
TextLayout text_layout_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
2019-12-26 19:25:43 +08:00
|
|
|
|
inline const String& TextActor::GetText() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetText();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline FontPtr TextActor::GetFont() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetStyle().font;
|
|
|
|
|
|
}
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
2019-12-26 19:25:43 +08:00
|
|
|
|
inline const TextStyle& TextActor::GetStyle() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetStyle();
|
|
|
|
|
|
}
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
2019-12-26 19:25:43 +08:00
|
|
|
|
inline const TextLayout& TextActor::GetLayout() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_;
|
|
|
|
|
|
}
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
2020-01-09 08:45:00 +08:00
|
|
|
|
inline Size TextActor::GetLayoutSize() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetLayoutSize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-29 18:58:22 +08:00
|
|
|
|
inline BrushPtr TextActor::GetFillBrush() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetFillBrush();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline BrushPtr TextActor::GetOutlineBrush() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return text_layout_.GetOutlineBrush();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-26 19:25:43 +08:00
|
|
|
|
inline void TextActor::SetText(String const& text)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetText(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetStyle(const TextStyle& style)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetStyle(style);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetFont(FontPtr font)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetFont(font);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetFontFamily(String const& family)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetFontFamily(family);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetFontSize(float size)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetFontSize(size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetFontWeight(uint32_t weight)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetFontWeight(weight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetItalic(bool italic)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetItalic(italic);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetWrapWidth(float wrap_width)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetWrapWidth(wrap_width);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetLineSpacing(float line_spacing)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetLineSpacing(line_spacing);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetAlignment(TextAlign align)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetAlignment(align);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetUnderline(bool enable)
|
|
|
|
|
|
{
|
2019-12-29 18:58:22 +08:00
|
|
|
|
show_underline_ = enable;
|
2019-12-26 19:25:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetStrikethrough(bool enable)
|
|
|
|
|
|
{
|
2019-12-29 18:58:22 +08:00
|
|
|
|
show_strikethrough_ = enable;
|
2019-12-26 19:25:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-27 23:42:51 +08:00
|
|
|
|
inline void TextActor::SetFillBrush(BrushPtr brush)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetFillBrush(brush);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetOutlineBrush(BrushPtr brush)
|
2019-12-26 19:25:43 +08:00
|
|
|
|
{
|
2019-12-27 23:42:51 +08:00
|
|
|
|
text_layout_.SetOutlineBrush(brush);
|
2019-12-26 19:25:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void TextActor::SetOutlineWidth(float outline_width)
|
|
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetOutlineWidth(outline_width);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-10 11:43:07 +08:00
|
|
|
|
inline void TextActor::SetOutlineStroke(const StrokeStyle& outline_stroke)
|
2019-12-26 19:25:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
text_layout_.SetOutlineStroke(outline_stroke);
|
|
|
|
|
|
}
|
2019-12-23 18:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|