Magic_Game/src/kiwano/2d/TextActor.cpp

77 lines
2.0 KiB
C++
Raw Normal View History

2019-04-11 14:40:54 +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.
2019-12-23 18:05:08 +08:00
#include <kiwano/2d/TextActor.h>
2019-11-13 14:33:15 +08:00
#include <kiwano/core/Logger.h>
2019-10-11 21:55:29 +08:00
#include <kiwano/renderer/Renderer.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
namespace
{
TextStyle text_default_style;
}
2019-12-26 19:25:43 +08:00
void TextActor::SetDefaultStyle(TextStyle const & style)
{
text_default_style = style;
}
2019-12-23 18:05:08 +08:00
TextActor::TextActor()
2019-12-26 19:25:43 +08:00
: TextActor(String())
{
}
2019-12-23 18:05:08 +08:00
TextActor::TextActor(String const& text)
2019-12-26 19:25:43 +08:00
: TextActor(text, text_default_style)
{
}
2019-12-23 18:05:08 +08:00
TextActor::TextActor(String const& text, const TextStyle & style)
{
2019-12-26 19:25:43 +08:00
SetText(text);
SetStyle(style);
}
2019-12-23 18:05:08 +08:00
TextActor::~TextActor()
{
}
2019-12-23 18:05:08 +08:00
void TextActor::OnRender(RenderTarget* rt)
{
UpdateLayout();
2019-12-26 19:25:43 +08:00
if (text_layout_.IsValid() && CheckVisibilty(rt))
{
2019-08-20 19:32:36 +08:00
PrepareRender(rt);
rt->DrawTextLayout(text_layout_);
}
}
2019-12-23 18:05:08 +08:00
void TextActor::UpdateLayout()
{
2019-12-26 19:25:43 +08:00
if (text_layout_.IsDirty())
2019-08-15 11:22:51 +08:00
{
2019-12-26 19:25:43 +08:00
text_layout_.Update();
2019-08-15 11:22:51 +08:00
SetSize(text_layout_.GetLayoutSize());
}
}
}