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
52 TextActor(StringView text, const TextStyle& style);
53
54 virtual ~TextActor();
55
58 StringView GetText() const;
59
62 TextStyle GetStyle() const;
63
66 RefPtr<TextLayout> GetLayout() const;
67
70 Size GetSize() const override;
71
74 RefPtr<Brush> GetFillBrush() const;
75
78 RefPtr<Brush> GetOutlineBrush() const;
79
82 RefPtr<StrokeStyle> GetOutlineStrokeStyle() const;
83
86 RefPtr<Font> GetFont() const;
87
90 void SetText(StringView text);
91
94 void SetStyle(const TextStyle& style);
95
98 void SetFont(RefPtr<Font> font);
99
102 void SetFillBrush(RefPtr<Brush> brush);
103
106 void SetFillColor(const Color& color);
107
110 void SetWrapWidth(float wrap_width);
111
114 void SetLineSpacing(float line_spacing);
115
118 void SetAlignment(TextAlign align);
119
122 void SetOutlineBrush(RefPtr<Brush> brush);
123
126 void SetOutlineColor(const Color& outline_color);
127
130 void SetOutlineStrokeStyle(RefPtr<StrokeStyle> stroke);
131
134 void SetUnderline(bool enable);
135
138 void SetStrikethrough(bool enable);
139
142 void SetTextLayout(RefPtr<TextLayout> layout);
143
147 void UpdateDirtyLayout();
148
152 void ForceUpdateLayout();
153
154 void OnRender(RenderContext& ctx) override;
155
156protected:
157 void Update(Duration dt) override;
158
159 bool CheckVisibility(RenderContext& ctx) const override;
160
161 void UpdateCachedTexture();
162
165 void SetPreRenderEnabled(bool enable);
166
167private:
168 bool is_cache_dirty_;
169 String content_;
170 TextStyle style_;
171 RefPtr<TextLayout> layout_;
172 RefPtr<Brush> fill_brush_;
173 RefPtr<Brush> outline_brush_;
174 RefPtr<StrokeStyle> outline_stroke_;
175 RefPtr<Texture> texture_cached_;
176 RefPtr<RenderContext> render_ctx_;
177};
178
182{
183 return content_;
184}
185
187{
188 return style_.font;
189}
190
192{
193 return style_;
194}
195
197{
198 return layout_;
199}
200
202{
203 return fill_brush_;
204}
205
207{
208 return outline_brush_;
209}
210
212{
213 return outline_stroke_;
214}
215
216} // namespace kiwano
角色
Definition: Actor.h:63
Definition: Color.h:41
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
文本角色
Definition: TextActor.h:39
RefPtr< Font > GetFont() const
获取字体
Definition: TextActor.h:186
RefPtr< TextLayout > GetLayout() const
获取文本布局
Definition: TextActor.h:196
RefPtr< StrokeStyle > GetOutlineStrokeStyle() const
获取描边线条样式
Definition: TextActor.h:211
RefPtr< Brush > GetFillBrush() const
获取填充画刷
Definition: TextActor.h:201
RefPtr< Brush > GetOutlineBrush() const
获取描边画刷
Definition: TextActor.h:206
TextStyle GetStyle() const
获取文本样式
Definition: TextActor.h:191
StringView GetText() const
获取文本
Definition: TextActor.h:181
文本样式
Definition: TextStyle.h:51
RefPtr< Font > font
字体
Definition: TextStyle.h:53
TextAlign
文本对齐方式
Definition: TextStyle.h:39
时间段
Definition: Duration.h:48