192 lines
4.6 KiB
C
192 lines
4.6 KiB
C
|
|
// 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
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|||
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
explicit TextActor(const String& text);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|||
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// @param font <20><><EFBFBD><EFBFBD>
|
|||
|
|
TextActor(const String& text, const Font& font);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|||
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// @param style <20>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
|||
|
|
TextActor(const String& text, const TextStyle& style);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|||
|
|
/// @param text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// @param font <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// @param style <20>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
|||
|
|
TextActor(const String& text, const Font& font, const TextStyle& style);
|
|||
|
|
|
|||
|
|
virtual ~TextActor();
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD>
|
|||
|
|
String const& GetText() const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
Font GetFont() const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ
|
|||
|
|
TextStyle GetStyle() const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
TextLayout GetLayout() const;
|
|||
|
|
|
|||
|
|
/// \~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>
|
|||
|
|
void SetFont(const Font& font);
|
|||
|
|
|
|||
|
|
/// \~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>
|
|||
|
|
void SetFontSize(
|
|||
|
|
float size
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
/// \~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
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ĭ<EFBFBD><C4AC>ֵΪ Color::White<74><65>
|
|||
|
|
void SetColor(Color const& color);
|
|||
|
|
|
|||
|
|
/// \~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
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD><C2BB>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
|
|||
|
|
void SetUnderline(bool underline);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
|
|||
|
|
void SetStrikethrough(bool strikethrough);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
|
void SetOutline(bool outline);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
|
void SetOutlineColor(Color const& outline_color);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD>
|
|||
|
|
void SetOutlineWidth(float outline_width);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB>ʽ
|
|||
|
|
void SetOutlineStroke(StrokeStyle outline_stroke);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void UpdateLayout();
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
static void SetDefaultFont(Font const& font);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|||
|
|
static void SetDefaultStyle(TextStyle const& style);
|
|||
|
|
|
|||
|
|
void OnRender(RenderTarget* rt) override;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
bool format_dirty_;
|
|||
|
|
bool layout_dirty_;
|
|||
|
|
TextLayout text_layout_;
|
|||
|
|
String text_;
|
|||
|
|
Font font_;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/** @} */
|
|||
|
|
|
|||
|
|
inline String const& TextActor::GetText() const { return text_; }
|
|||
|
|
|
|||
|
|
inline Font TextActor::GetFont() const { return font_; }
|
|||
|
|
|
|||
|
|
inline TextStyle TextActor::GetStyle() const { return text_layout_.GetTextStyle(); }
|
|||
|
|
|
|||
|
|
inline TextLayout TextActor::GetLayout() const { return text_layout_; }
|
|||
|
|
|
|||
|
|
}
|