Kiwano Engine v1.3.x
TextActor.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/2d/Actor.h>
23#include <kiwano/render/Color.h>
24#include <kiwano/render/TextLayout.h>
25
26namespace kiwano
27{
28
38class KGE_API TextActor : public Actor
39{
40public:
41 TextActor();
42
47 TextActor(StringView text, const TextStyle& style = TextStyle());
48
49 virtual ~TextActor();
50
53 StringView GetText() const;
54
57 TextStyle GetStyle() const;
58
61 RefPtr<TextLayout> GetLayout() const;
62
65 Size GetSize() const override;
66
69 RefPtr<Brush> GetFillBrush() const;
70
73 RefPtr<Brush> GetOutlineBrush() const;
74
77 RefPtr<StrokeStyle> GetOutlineStrokeStyle() const;
78
81 const Font& GetFont() const;
82
85 void SetText(StringView text);
86
89 void SetStyle(const TextStyle& style);
90
93 void SetFont(const Font& font);
94
97 void SetFillBrush(RefPtr<Brush> brush);
98
101 void SetFillColor(const Color& color);
102
105 void SetWrapWidth(float wrap_width);
106
109 void SetLineSpacing(float line_spacing);
110
113 void SetAlignment(TextAlign align);
114
117 void SetOutlineBrush(RefPtr<Brush> brush);
118
121 void SetOutlineColor(const Color& outline_color);
122
125 void SetOutlineStrokeStyle(RefPtr<StrokeStyle> stroke);
126
129 void SetUnderline(bool enable);
130
133 void SetStrikethrough(bool enable);
134
137 void SetTextLayout(RefPtr<TextLayout> layout);
138
142 void UpdateDirtyLayout();
143
147 void ForceUpdateLayout();
148
149 void OnRender(RenderContext& ctx) override;
150
151protected:
152 void Update(Duration dt) override;
153
154 bool CheckVisibility(RenderContext& ctx) const override;
155
156 void UpdateCachedBitmap();
157
160 void SetPreRenderEnabled(bool enable);
161
162private:
163 bool is_cache_dirty_;
164 String content_;
165 TextStyle style_;
166 RefPtr<TextLayout> layout_;
167 RefPtr<Brush> fill_brush_;
168 RefPtr<Brush> outline_brush_;
169 RefPtr<StrokeStyle> outline_stroke_;
170 RefPtr<Bitmap> cached_bitmap_;
171 RefPtr<RenderContext> render_ctx_;
172};
173
177{
178 return content_;
179}
180
181inline const Font& TextActor::GetFont() const
182{
183 return style_.font;
184}
185
187{
188 return style_;
189}
190
192{
193 return layout_;
194}
195
197{
198 return fill_brush_;
199}
200
202{
203 return outline_brush_;
204}
205
207{
208 return outline_stroke_;
209}
210
211} // namespace kiwano
角色
Definition: Actor.h:63
Definition: Color.h:41
字体
Definition: Font.h:112
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
文本角色
Definition: TextActor.h:39
RefPtr< TextLayout > GetLayout() const
获取文本布局
Definition: TextActor.h:191
RefPtr< StrokeStyle > GetOutlineStrokeStyle() const
获取描边线条样式
Definition: TextActor.h:206
RefPtr< Brush > GetFillBrush() const
获取填充画刷
Definition: TextActor.h:196
RefPtr< Brush > GetOutlineBrush() const
获取描边画刷
Definition: TextActor.h:201
const Font & GetFont() const
获取字体
Definition: TextActor.h:181
TextStyle GetStyle() const
获取文本样式
Definition: TextActor.h:186
StringView GetText() const
获取文本
Definition: TextActor.h:176
文本样式
Definition: TextStyle.h:64
Font font
字体
Definition: TextStyle.h:72
TextAlign
文本对齐方式
Definition: TextStyle.h:39
时间段
Definition: Duration.h:48