2019-04-11 14:40:54 +08:00
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
//
|
|
|
|
|
// 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-08-13 23:21:20 +08:00
|
|
|
#include "ShapeActor.h"
|
2019-08-14 21:52:49 +08:00
|
|
|
#include "../base/Logger.h"
|
|
|
|
|
#include "../renderer/Renderer.h"
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-13 23:21:20 +08:00
|
|
|
ShapeActor::ShapeActor()
|
2019-08-08 14:15:06 +08:00
|
|
|
: fill_color_(Color::White)
|
|
|
|
|
, stroke_color_(Color(Color::Black, 0))
|
|
|
|
|
, stroke_width_(1.f)
|
|
|
|
|
, outline_join_(StrokeStyle::Miter)
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
ShapeActor::ShapeActor(Geometry geometry)
|
2019-08-13 23:21:20 +08:00
|
|
|
: ShapeActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-08 14:15:06 +08:00
|
|
|
SetGeometry(geometry);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
ShapeActor::~ShapeActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 00:28:25 +08:00
|
|
|
Rect ShapeActor::GetBounds() const
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
if (!geo_)
|
|
|
|
|
return Rect{};
|
|
|
|
|
|
2019-08-14 23:36:29 +08:00
|
|
|
return geo_.GetBoundingBox(Matrix3x2());
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-14 00:28:25 +08:00
|
|
|
Rect ShapeActor::GetBoundingBox() const
|
|
|
|
|
{
|
|
|
|
|
if (!geo_)
|
|
|
|
|
return Rect{};
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
return geo_.GetBoundingBox(GetTransformMatrix());
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void ShapeActor::SetFillColor(const Color & color)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
fill_color_ = color;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void ShapeActor::SetStrokeColor(const Color & color)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
stroke_color_ = color;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void ShapeActor::SetStrokeWidth(float width)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
stroke_width_ = std::max(width, 0.f);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void ShapeActor::SetOutlineJoinStyle(StrokeStyle outline_join)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
outline_join_ = outline_join;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 00:28:25 +08:00
|
|
|
void ShapeActor::OnRender(Renderer* renderer)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
if (geo_)
|
|
|
|
|
{
|
2019-08-14 00:28:25 +08:00
|
|
|
PrepareRender(renderer);
|
|
|
|
|
|
|
|
|
|
renderer->FillGeometry(
|
2019-08-08 14:15:06 +08:00
|
|
|
geo_,
|
|
|
|
|
fill_color_
|
|
|
|
|
);
|
|
|
|
|
|
2019-08-14 00:28:25 +08:00
|
|
|
renderer->DrawGeometry(
|
2019-08-08 14:15:06 +08:00
|
|
|
geo_,
|
|
|
|
|
stroke_color_,
|
|
|
|
|
stroke_width_,
|
|
|
|
|
outline_join_
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// LineActor
|
2019-03-31 01:37:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
LineActor::LineActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
LineActor::LineActor(Point const& end)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetEndPoint(end);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
LineActor::~LineActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void LineActor::SetEndPoint(Point const& end)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
geo_ = Geometry::CreateLine(Point{}, end);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
if (geo_)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetSize(end);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// RectActor
|
2019-03-31 01:37:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
RectActor::RectActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
RectActor::RectActor(Size const& size)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRectSize(size);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
RectActor::~RectActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void RectActor::SetRectSize(Size const& size)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
geo_ = Geometry::CreateRect(Rect{ Point{}, size });
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
if (geo_)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetSize(size);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// RoundRectActor
|
2019-08-08 14:15:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
RoundRectActor::RoundRectActor()
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
RoundRectActor::RoundRectActor(Size const& size, Vec2 const& radius)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRoundedRect(size, radius);
|
2019-08-08 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
RoundRectActor::~RoundRectActor()
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void RoundRectActor::SetRadius(Vec2 const& radius)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRoundedRect(size_, radius);
|
2019-08-08 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void RoundRectActor::SetRectSize(Size const& size)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRoundedRect(size, radius_);
|
2019-08-08 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
geo_ = Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius);
|
2019-08-08 14:15:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
if (geo_)
|
2019-08-08 14:15:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetSize(size);
|
2019-08-08 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// CircleActor
|
2019-03-31 01:37:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
CircleActor::CircleActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
: radius_(0.f)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
CircleActor::CircleActor(float radius)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRadius(radius);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
CircleActor::~CircleActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void CircleActor::SetRadius(float radius)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
geo_ = Geometry::CreateCircle(Point{}, radius);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
if (geo_)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetSize(radius * 2, radius * 2);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// EllipseActor
|
2019-03-31 01:37:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
EllipseActor::EllipseActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
EllipseActor::EllipseActor(Vec2 const& radius)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetRadius(radius);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
EllipseActor::~EllipseActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
void EllipseActor::SetRadius(Vec2 const& radius)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
geo_ = Geometry::CreateEllipse(Point{}, radius);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
if (geo_)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
SetSize(radius * 2);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2019-08-13 23:21:20 +08:00
|
|
|
// PathActor
|
2019-03-31 01:37:06 +08:00
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
PathActor::PathActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
PathActor::~PathActor()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::BeginPath(Point const& begin_pos)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.BeginPath(begin_pos);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::EndPath(bool closed)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.EndPath(closed);
|
|
|
|
|
geo_ = sink_.GetGeometry();
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::AddLine(Point const& point)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.AddLine(point);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::AddLines(Vector<Point> const& points)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.AddLines(points);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::AddBezier(Point const& point1, Point const& point2, Point const& point3)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.AddBezier(point1, point2, point3);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small)
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
sink_.AddArc(point, radius, rotation, clockwise, is_small);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 23:21:20 +08:00
|
|
|
void PathActor::ClearPath()
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-08-14 21:38:37 +08:00
|
|
|
geo_.SetGeometry(nullptr);
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-08 14:15:06 +08:00
|
|
|
}
|