2019-08-14 21:38:37 +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.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/renderer/win32/D2DDeviceResources.h>
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
|
{
|
2019-08-14 23:36:29 +08:00
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
class KGE_API Geometry
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2019-08-14 23:36:29 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
enum class CombineMode
|
|
|
|
|
|
{
|
|
|
|
|
|
Union, /* <20><><EFBFBD><EFBFBD> (A + B) */
|
|
|
|
|
|
Intersect, /* <20><><EFBFBD><EFBFBD> (A + B) */
|
|
|
|
|
|
Xor, /* <20>ԳƲ ((A - B) + (B - A)) */
|
|
|
|
|
|
Exclude /* <20> (A - B) */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
Geometry();
|
|
|
|
|
|
|
|
|
|
|
|
Geometry(ComPtr<ID2D1Geometry> geo);
|
|
|
|
|
|
|
2019-08-20 21:15:15 +08:00
|
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
2019-08-27 15:29:32 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
|
|
|
|
|
|
Rect GetBoundingBox() const;
|
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
|
|
|
|
|
|
Rect GetBoundingBox(
|
2019-08-27 15:29:32 +08:00
|
|
|
|
Matrix3x2 const& transform
|
2019-08-14 21:38:37 +08:00
|
|
|
|
) const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ж<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool ContainsPoint(
|
2019-08-20 21:15:15 +08:00
|
|
|
|
Point const& point,
|
|
|
|
|
|
Matrix3x2 const& transform = Matrix3x2()
|
|
|
|
|
|
) const;
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><>ȡͼ<C8A1><CDBC>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>ߵij<DFB5><C4B3><EFBFBD>
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float GetLength() const;
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float ComputeArea() const;
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>·<EFBFBD><C2B7><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>λ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool ComputePointAtLength(
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float length,
|
2019-08-14 21:38:37 +08:00
|
|
|
|
Point& point,
|
|
|
|
|
|
Vec2& tangent
|
2019-08-20 21:15:15 +08:00
|
|
|
|
) const;
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
2019-08-14 23:36:29 +08:00
|
|
|
|
// <20><><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Geometry CombineWith(
|
|
|
|
|
|
Geometry input,
|
|
|
|
|
|
CombineMode mode,
|
|
|
|
|
|
Matrix3x2 const& input_matrix = Matrix3x2()
|
2019-08-20 21:15:15 +08:00
|
|
|
|
) const;
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
2019-08-14 23:36:29 +08:00
|
|
|
|
// <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> modes <20><> matrixs <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӦΪ 1 <20><> geos <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ
|
|
|
|
|
|
static Geometry Combine(
|
|
|
|
|
|
Vector<Geometry> const& geos,
|
|
|
|
|
|
Vector<CombineMode> const& modes,
|
|
|
|
|
|
Vector<Matrix3x2> const& matrixs = { Matrix3x2() }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>
|
|
|
|
|
|
static Geometry CreateLine(
|
|
|
|
|
|
Point const& begin,
|
|
|
|
|
|
Point const& end
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
static Geometry CreateRect(
|
|
|
|
|
|
Rect const& rect
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>
|
|
|
|
|
|
static Geometry CreateRoundedRect(
|
|
|
|
|
|
Rect const& rect,
|
|
|
|
|
|
Vec2 const& radius
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
static Geometry CreateCircle(
|
|
|
|
|
|
Point const& center,
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float radius
|
2019-08-14 23:36:29 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
static Geometry CreateEllipse(
|
|
|
|
|
|
Point const& center,
|
|
|
|
|
|
Vec2 const& radius
|
|
|
|
|
|
);
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
inline ComPtr<ID2D1Geometry> GetGeometry() const { return geo_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline void SetGeometry(ComPtr<ID2D1Geometry> geometry) { geo_ = geometry; }
|
|
|
|
|
|
|
2019-08-20 21:15:15 +08:00
|
|
|
|
inline operator bool() const { return IsValid(); }
|
2019-08-14 21:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
ComPtr<ID2D1Geometry> geo_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
class KGE_API GeometrySink
|
2019-11-13 14:33:15 +08:00
|
|
|
|
: protected common::noncopyable
|
2019-08-14 21:38:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
GeometrySink();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
GeometrySink& BeginPath(
|
|
|
|
|
|
Point const& begin_pos = Point{} /* <20><>ʼ<EFBFBD><CABC> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
GeometrySink& EndPath(
|
|
|
|
|
|
bool closed = false /* ·<><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7>պ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
GeometrySink& AddLine(
|
|
|
|
|
|
Point const& point /* <20>˵<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
GeometrySink& AddLines(
|
|
|
|
|
|
Vector<Point> const& points
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-26 10:22:58 +08:00
|
|
|
|
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
GeometrySink& AddLines(
|
|
|
|
|
|
const Point* points,
|
2019-10-12 11:26:41 +08:00
|
|
|
|
size_t count
|
2019-08-26 10:22:58 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
GeometrySink& AddBezier(
|
|
|
|
|
|
Point const& point1, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵĵ<DFB5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> */
|
|
|
|
|
|
Point const& point2, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵĵڶ<C4B5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> */
|
|
|
|
|
|
Point const& point3 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5>յ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
|
|
|
|
|
|
GeometrySink& AddArc(
|
|
|
|
|
|
Point const& point, /* <20>յ<EFBFBD> */
|
|
|
|
|
|
Size const& radius, /* <20><>Բ<EFBFBD>뾶 */
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float rotation, /* <20><>Բ<EFBFBD><D4B2>ת<EFBFBD>Ƕ<EFBFBD> */
|
2019-08-14 21:38:37 +08:00
|
|
|
|
bool clockwise = true, /* ˳ʱ<CBB3><CAB1> or <20><>ʱ<EFBFBD><CAB1> */
|
|
|
|
|
|
bool is_small = true /* <20>Ƿ<EFBFBD>ȡС<C8A1><D0A1> 180<38><30> <20>Ļ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Geometry GetGeometry();
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
inline ComPtr<ID2D1PathGeometry> GetPathGeometry() const { return path_geo_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline void SetPathGeometry(ComPtr<ID2D1PathGeometry> path) { path_geo_ = path; }
|
|
|
|
|
|
|
2019-08-14 23:36:29 +08:00
|
|
|
|
inline ComPtr<ID2D1GeometrySink> GetGeometrySink() const { return sink_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline void SetGeometrySink(ComPtr<ID2D1GeometrySink> sink) { sink_ = sink; }
|
|
|
|
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
|
|
|
|
void OpenSink();
|
|
|
|
|
|
|
|
|
|
|
|
void CloseSink();
|
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
ComPtr<ID2D1PathGeometry> path_geo_;
|
|
|
|
|
|
ComPtr<ID2D1GeometrySink> sink_;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|