This commit is contained in:
Nomango 2019-08-20 21:15:15 +08:00
parent ff8a05c3ac
commit d9e67fd737
17 changed files with 112 additions and 91 deletions

View File

@ -352,9 +352,7 @@ namespace kiwano
void RemoveFromParent();
// 判断点是否在角色内
bool ContainsPoint(
const Point& point
) const;
virtual bool ContainsPoint(const Point& point) const;
// 暂停角色更新
inline void PauseUpdating() { update_pausing_ = true; }

View File

@ -90,7 +90,7 @@ namespace kiwano
void GifSprite::OnRender(RenderTarget* rt)
{
if (frame_.IsValid() && rt->CheckVisibility(size_, transform_matrix_))
if (frame_.IsValid() && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
{
PrepareRender(rt);

View File

@ -44,10 +44,7 @@ namespace kiwano
Rect ShapeActor::GetBounds() const
{
if (!geo_)
return Rect{};
return geo_.GetBoundingBox(Matrix3x2());
return bounds_;
}
Rect ShapeActor::GetBoundingBox() const
@ -58,6 +55,11 @@ namespace kiwano
return geo_.GetBoundingBox(GetTransformMatrix());
}
bool ShapeActor::ContainsPoint(const Point& point) const
{
return geo_.ContainsPoint(point, GetTransformMatrix());
}
void ShapeActor::SetFillColor(const Color & color)
{
fill_color_ = color;
@ -78,9 +80,24 @@ namespace kiwano
stroke_style_ = stroke_style;
}
void ShapeActor::SetGeometry(Geometry geometry)
{
geo_ = geometry;
if (geo_)
{
bounds_ = geo_.GetBoundingBox(Matrix3x2());
SetSize(bounds_.GetSize());
}
else
{
bounds_ = Rect{};
SetSize(0.f, 0.f);
}
}
void ShapeActor::OnRender(RenderTarget* rt)
{
if (geo_ && rt->CheckVisibility(size_, transform_matrix_))
if (geo_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
{
PrepareRender(rt);
@ -117,12 +134,12 @@ namespace kiwano
void LineActor::SetPoint(Point const& point)
{
geo_ = Geometry::CreateLine(Point{}, point);
Geometry geo = Geometry::CreateLine(Point{}, point);
if (geo_)
if (geo)
{
point_ = point;
SetSize(point_);
SetGeometry(geo);
}
}
@ -146,12 +163,12 @@ namespace kiwano
void RectActor::SetRectSize(Size const& size)
{
geo_ = Geometry::CreateRect(Rect{ Point{}, size });
Geometry geo = Geometry::CreateRect(Rect{ Point{}, size });
if (geo_)
if (geo)
{
rect_size_ = size;
SetSize(size);
SetGeometry(geo);
}
}
@ -185,12 +202,12 @@ namespace kiwano
void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius)
{
geo_ = Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius);
Geometry geo = Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius);
if (geo_)
if (geo)
{
rect_size_ = size;
SetSize(size);
SetGeometry(geo);
}
}
@ -215,11 +232,11 @@ namespace kiwano
void CircleActor::SetRadius(Float32 radius)
{
geo_ = Geometry::CreateCircle(Point{}, radius);
Geometry geo = Geometry::CreateCircle(Point{}, radius);
if (geo_)
if (geo)
{
SetSize(Size{ radius * 2, radius * 2 });
SetGeometry(geo);
}
}
@ -243,11 +260,11 @@ namespace kiwano
void EllipseActor::SetRadius(Vec2 const& radius)
{
geo_ = Geometry::CreateEllipse(Point{}, radius);
Geometry geo = Geometry::CreateEllipse(Point{}, radius);
if (geo_)
if (geo)
{
SetSize(radius * 2);
SetGeometry(geo);
}
}
@ -272,12 +289,11 @@ namespace kiwano
void PathActor::EndPath(bool closed)
{
sink_.EndPath(closed);
geo_ = sink_.GetGeometry();
Geometry geo = sink_.GetGeometry();
if (geo_)
if (geo)
{
Rect bounds = geo_.GetBoundingBox();
SetSize(bounds.GetSize());
SetGeometry(geo);
}
}

View File

@ -38,16 +38,19 @@ namespace kiwano
virtual ~ShapeActor();
// 삿혤輕념奈<EB8590>
Color GetFillColor() const { return fill_color_; }
inline Color GetFillColor() const { return fill_color_; }
// 삿혤窟係奈<E4BF82>
Color GetStrokeColor() const { return stroke_color_; }
inline Color GetStrokeColor() const { return stroke_color_; }
// 삿혤窟係욱똑
Float32 GetStrokeWidth() const { return stroke_width_; }
inline Float32 GetStrokeWidth() const { return stroke_width_; }
// 삿혤窟係湳駕
StrokeStyle SetStrokeStyle() const { return stroke_style_; }
inline StrokeStyle SetStrokeStyle() const { return stroke_style_; }
// 获取形状
inline Geometry GetGeometry() const { return geo_; }
// 삿혤긋썹
Rect GetBounds() const override;
@ -55,31 +58,23 @@ namespace kiwano
// 삿혤棍학관鍋분
Rect GetBoundingBox() const override;
// 判断点是否在形状内
bool ContainsPoint(const Point& point) const override;
// <20>零輕념奈<EB8590>
void SetFillColor(
const Color& color
);
void SetFillColor(const Color& color);
// <20>零窟係奈<E4BF82>
void SetStrokeColor(
const Color& color
);
void SetStrokeColor(const Color& color);
// <20>零窟係욱똑
void SetStrokeWidth(
Float32 width
);
void SetStrokeWidth(Float32 width);
// <20>零窟係湳駕
void SetStrokeStyle(
StrokeStyle stroke_style
);
void SetStrokeStyle(StrokeStyle stroke_style);
// <20>零近榴
inline void SetGeometry(Geometry geometry) { geo_ = geometry; }
// ťńČĄĐÎ×´
inline Geometry GetGeometry() const { return geo_; }
void SetGeometry(Geometry geometry);
void OnRender(RenderTarget* rt) override;
@ -88,6 +83,7 @@ namespace kiwano
Color stroke_color_;
Float32 stroke_width_;
StrokeStyle stroke_style_;
Rect bounds_;
Geometry geo_;
};

View File

@ -104,7 +104,7 @@ namespace kiwano
void Sprite::OnRender(RenderTarget* rt)
{
if (frame_ && rt->CheckVisibility(size_, transform_matrix_))
if (frame_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
{
PrepareRender(rt);

View File

@ -204,7 +204,7 @@ namespace kiwano
{
UpdateLayout();
if (text_layout_ && rt->CheckVisibility(size_, transform_matrix_))
if (text_layout_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
{
PrepareRender(rt);
rt->DrawTextLayout(text_layout_);

View File

@ -40,7 +40,7 @@ namespace kiwano
}
}
EventListenerPtr EventDispatcher::AddListener(EventListenerPtr listener)
EventListener* EventDispatcher::AddListener(EventListenerPtr listener)
{
KGE_ASSERT(listener && "AddListener failed, NULL pointer exception");
@ -48,16 +48,13 @@ namespace kiwano
{
listeners_.push_back(listener);
}
return listener;
return listener.get();
}
void EventDispatcher::AddListener(UInt32 type, EventCallback callback, String const& name)
EventListener* EventDispatcher::AddListener(UInt32 type, EventCallback callback, String const& name)
{
EventListenerPtr listener = new EventListener(type, callback, name);
if (listener)
{
listeners_.push_back(listener);
}
return AddListener(listener);
}
void EventDispatcher::StartListeners(String const & listener_name)

View File

@ -29,12 +29,12 @@ namespace kiwano
public:
// 添加监听器
EventListenerPtr AddListener(
EventListener* AddListener(
EventListenerPtr listener
);
// 添加监听器
void AddListener(
EventListener* AddListener(
UInt32 type,
EventCallback callback,
String const& name = L""

View File

@ -46,7 +46,7 @@ namespace kiwano
inline bool IsName(String const& name) const { return name_ ? (*name_ == name) : name.empty(); }
inline UInt32 GetObjectID() const { return id_; }
inline UInt32 GetObjectID() const { return id_; }
String DumpObject();

View File

@ -22,11 +22,6 @@
namespace kiwano
{
Timer::Timer(Callback const& func, String const& name)
: Timer(func, Duration{}, -1, name)
{
}
Timer::Timer(Callback const& func, Duration delay, Int32 times, String const& name)
: running_(true)
, run_times_(0)
@ -91,4 +86,4 @@ namespace kiwano
return running_;
}
}
}

View File

@ -40,12 +40,7 @@ namespace kiwano
using Callback = Function<void()>;
public:
explicit Timer(
Callback const& func, /* 执行函数 */
String const& name = L"" /* 任务名称 */
);
explicit Timer(
Timer(
Callback const& func, /* 执行函数 */
Duration delay, /* 时间间隔(秒) */
Int32 times = -1, /* 执行次数(设 -1 为永久执行) */

View File

@ -41,7 +41,13 @@ namespace kiwano
}
}
void TimerManager::AddTimer(TimerPtr timer)
Timer* TimerManager::AddTimer(Timer::Callback const& func, Duration delay, Int32 times, String const& name)
{
TimerPtr timer = new Timer(func, delay, times, name);
return AddTimer(timer);
}
Timer* TimerManager::AddTimer(TimerPtr timer)
{
KGE_ASSERT(timer && "AddTimer failed, NULL pointer exception");
@ -50,6 +56,8 @@ namespace kiwano
timer->Reset();
timers_.push_back(timer);
}
return timer.get();
}
void TimerManager::StopTimers(String const& name)

View File

@ -28,8 +28,16 @@ namespace kiwano
using Timers = intrusive_list<TimerPtr>;
public:
// Ìí¼ÓÈÎÎñ
void AddTimer(
// 添加定时器
Timer* AddTimer(
Timer::Callback const& func, /* 执行函数 */
Duration delay, /* 时间间隔(秒) */
Int32 times = -1, /* 执行次数(设 -1 为永久执行) */
String const& name = L"" /* 任务名称 */
);
// 添加定时器
Timer* AddTimer(
TimerPtr timer
);

View File

@ -38,6 +38,11 @@ namespace kiwano
{
}
bool Geometry::IsValid() const
{
return geo_ != nullptr;
}
Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const
{
if (!geo_)
@ -49,7 +54,7 @@ namespace kiwano
return rect;
}
Float32 Geometry::GetLength()
Float32 Geometry::GetLength() const
{
Float32 length = 0.f;
if (geo_)
@ -60,7 +65,7 @@ namespace kiwano
return length;
}
bool Geometry::ComputePointAtLength(Float32 length, Point& point, Vec2& tangent)
bool Geometry::ComputePointAtLength(Float32 length, Point& point, Vec2& tangent) const
{
if (geo_)
{
@ -76,7 +81,7 @@ namespace kiwano
return false;
}
Geometry Geometry::CombineWith(Geometry input, CombineMode mode, Matrix3x2 const& input_matrix)
Geometry Geometry::CombineWith(Geometry input, CombineMode mode, Matrix3x2 const& input_matrix) const
{
if (geo_ && input.geo_)
{
@ -129,7 +134,7 @@ namespace kiwano
return Geometry();
}
Float32 Geometry::ComputeArea()
Float32 Geometry::ComputeArea() const
{
if (!geo_)
return 0.f;
@ -140,7 +145,7 @@ namespace kiwano
return area;
}
bool Geometry::ContainsPoint(Point const& point)
bool Geometry::ContainsPoint(Point const& point, Matrix3x2 const& transform) const
{
if (!geo_)
return false;
@ -149,7 +154,7 @@ namespace kiwano
// no matter it failed or not
geo_->FillContainsPoint(
DX::ConvertToPoint2F(point),
D2D1::Matrix3x2F::Identity(),
DX::ConvertToMatrix3x2F(transform),
&ret
);
return !!ret;

View File

@ -42,6 +42,8 @@ namespace kiwano
Geometry(ComPtr<ID2D1Geometry> geo);
bool IsValid() const;
// 获取外切包围盒
Rect GetBoundingBox(
Matrix3x2 const& transform = Matrix3x2()
@ -49,28 +51,29 @@ namespace kiwano
// 判断图形是否包含点
bool ContainsPoint(
Point const& point
);
Point const& point,
Matrix3x2 const& transform = Matrix3x2()
) const;
// 获取图形展开成一条直线的长度
Float32 GetLength();
Float32 GetLength() const;
// 计算面积
Float32 ComputeArea();
Float32 ComputeArea() const;
// 计算图形路径上点的位置和切线向量
bool ComputePointAtLength(
Float32 length,
Point& point,
Vec2& tangent
);
) const;
// 组合几何体
Geometry CombineWith(
Geometry input,
CombineMode mode,
Matrix3x2 const& input_matrix = Matrix3x2()
);
) const;
// 组合多个几何体
// 参数 modes 和 matrixs 的数量应为 1 或 geos 的数量减一
@ -114,7 +117,7 @@ namespace kiwano
inline void SetGeometry(ComPtr<ID2D1Geometry> geometry) { geo_ = geometry; }
inline operator bool() const { return static_cast<bool>(geo_); }
inline operator bool() const { return IsValid(); }
protected:
ComPtr<ID2D1Geometry> geo_;

View File

@ -625,10 +625,10 @@ namespace kiwano
ThrowIfFailed(hr);
}
bool RenderTarget::CheckVisibility(Size const& content_size, Matrix3x2 const& transform)
bool RenderTarget::CheckVisibility(Rect const& bounds, Matrix3x2 const& transform)
{
return Rect{ Point{}, reinterpret_cast<const Size&>(render_target_->GetSize()) }.Intersects(
transform.Transform(Rect{ Point{}, content_size })
transform.Transform(bounds)
);
}

View File

@ -159,7 +159,7 @@ namespace kiwano
);
bool CheckVisibility(
Size const& content_size,
Rect const& bounds,
Matrix3x2 const& transform
);