add: LineGeometry & RoundedRectGeometry
This commit is contained in:
parent
b6308ababd
commit
92711b411a
|
|
@ -112,6 +112,60 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------
|
||||||
|
// LineGeometry
|
||||||
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
LineGeometry::LineGeometry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LineGeometry::LineGeometry(Point const & begin, Point const & end)
|
||||||
|
{
|
||||||
|
SetLine(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
LineGeometry::~LineGeometry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineGeometry::SetLine(Point const & begin, Point const & end)
|
||||||
|
{
|
||||||
|
cpPathGeometry path_geo;
|
||||||
|
cpGeometrySink path_sink;
|
||||||
|
|
||||||
|
HRESULT hr = devices::Graphics::Instance()->CreatePathGeometry(path_geo);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
hr = path_geo->Open(&path_sink);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
path_sink->BeginFigure(begin, D2D1_FIGURE_BEGIN_FILLED);
|
||||||
|
path_sink->AddLine(end);
|
||||||
|
path_sink->EndFigure(D2D1_FIGURE_END_OPEN);
|
||||||
|
hr = path_sink->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
geo_ = path_geo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineGeometry::SetBegin(Point const & begin)
|
||||||
|
{
|
||||||
|
SetLine(begin, end_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineGeometry::SetEnd(Point const & end)
|
||||||
|
{
|
||||||
|
SetLine(begin_, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// RectangleGeometry
|
// RectangleGeometry
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
@ -150,6 +204,7 @@ namespace easy2d
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
CircleGeometry::CircleGeometry()
|
CircleGeometry::CircleGeometry()
|
||||||
|
: radius_(0.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,6 +244,8 @@ namespace easy2d
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
EllipseGeometry::EllipseGeometry()
|
EllipseGeometry::EllipseGeometry()
|
||||||
|
: radius_x_(0.f)
|
||||||
|
, radius_y_(0.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,4 +371,46 @@ namespace easy2d
|
||||||
current_geometry_ = nullptr;
|
current_geometry_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------
|
||||||
|
// RoundedRectGeometry
|
||||||
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
RoundedRectGeometry::RoundedRectGeometry()
|
||||||
|
: radius_x_(0.f)
|
||||||
|
, radius_y_(0.f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RoundedRectGeometry::RoundedRectGeometry(Rect const & rect, float radius_x, float radius_y)
|
||||||
|
{
|
||||||
|
SetRoundedRect(rect, radius_x, radius_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
RoundedRectGeometry::~RoundedRectGeometry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoundedRectGeometry::SetRadius(float radius_x, float radius_y)
|
||||||
|
{
|
||||||
|
SetRoundedRect(rect_, radius_x, radius_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoundedRectGeometry::SetRect(Rect const & rect)
|
||||||
|
{
|
||||||
|
SetRoundedRect(rect, radius_x_, radius_y_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoundedRectGeometry::SetRoundedRect(Rect const & rect, float radius_x, float radius_y)
|
||||||
|
{
|
||||||
|
cpRoundedRectangleGeometry geo;
|
||||||
|
if (SUCCEEDED(devices::Graphics::Instance()->CreateRoundedRectangleGeometry(geo, rect, radius_x, radius_y)))
|
||||||
|
{
|
||||||
|
geo_ = geo;
|
||||||
|
rect_ = rect;
|
||||||
|
radius_x_ = radius_x;
|
||||||
|
radius_y_ = radius_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -39,6 +39,8 @@ namespace easy2d
|
||||||
class Geometry
|
class Geometry
|
||||||
: public Unit
|
: public Unit
|
||||||
{
|
{
|
||||||
|
friend class GeometryNode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Geometry();
|
Geometry();
|
||||||
|
|
||||||
|
|
@ -64,13 +66,48 @@ namespace easy2d
|
||||||
Point* tangent
|
Point* tangent
|
||||||
);
|
);
|
||||||
|
|
||||||
cpGeometry const& GetD2DGeometry() const { return geo_; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cpGeometry geo_;
|
cpGeometry geo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Ö±Ïß
|
||||||
|
class LineGeometry
|
||||||
|
: public Geometry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LineGeometry();
|
||||||
|
|
||||||
|
LineGeometry(
|
||||||
|
Point const& begin,
|
||||||
|
Point const& end
|
||||||
|
);
|
||||||
|
|
||||||
|
virtual ~LineGeometry();
|
||||||
|
|
||||||
|
Point const& GetBegin() const { return begin_; }
|
||||||
|
|
||||||
|
Point const& GetEnd() const { return end_; }
|
||||||
|
|
||||||
|
void SetLine(
|
||||||
|
Point const& begin,
|
||||||
|
Point const& end
|
||||||
|
);
|
||||||
|
|
||||||
|
void SetBegin(
|
||||||
|
Point const& begin
|
||||||
|
);
|
||||||
|
|
||||||
|
void SetEnd(
|
||||||
|
Point const& end
|
||||||
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Point begin_;
|
||||||
|
Point end_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 섯부앤近
|
// 섯부앤近
|
||||||
class RectangleGeometry
|
class RectangleGeometry
|
||||||
: public Geometry
|
: public Geometry
|
||||||
|
|
@ -221,4 +258,47 @@ namespace easy2d
|
||||||
cpPathGeometry current_geometry_;
|
cpPathGeometry current_geometry_;
|
||||||
cpGeometrySink current_sink_;
|
cpGeometrySink current_sink_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ¼¸ºÎÔ²½Ç¾ØÐÎ
|
||||||
|
class RoundedRectGeometry
|
||||||
|
: public Geometry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RoundedRectGeometry();
|
||||||
|
|
||||||
|
RoundedRectGeometry(
|
||||||
|
Rect const& rect,
|
||||||
|
float radius_x,
|
||||||
|
float radius_y
|
||||||
|
);
|
||||||
|
|
||||||
|
virtual ~RoundedRectGeometry();
|
||||||
|
|
||||||
|
float GetRadiusX() const { return radius_x_; }
|
||||||
|
|
||||||
|
float GetRadiusY() const { return radius_y_; }
|
||||||
|
|
||||||
|
void SetRadius(
|
||||||
|
float radius_x,
|
||||||
|
float radius_y
|
||||||
|
);
|
||||||
|
|
||||||
|
Rect const& GetRect() const { return rect_; }
|
||||||
|
|
||||||
|
void SetRect(
|
||||||
|
Rect const& rect
|
||||||
|
);
|
||||||
|
|
||||||
|
void SetRoundedRect(
|
||||||
|
Rect const& rect,
|
||||||
|
float radius_x,
|
||||||
|
float radius_y
|
||||||
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Rect rect_;
|
||||||
|
float radius_x_;
|
||||||
|
float radius_y_;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,18 +68,18 @@ namespace easy2d
|
||||||
|
|
||||||
void GeometryNode::OnDraw()
|
void GeometryNode::OnDraw()
|
||||||
{
|
{
|
||||||
if (geometry_)
|
if (geometry_ && geometry_->geo_)
|
||||||
{
|
{
|
||||||
auto graphics = devices::Graphics::Instance();
|
auto graphics = devices::Graphics::Instance();
|
||||||
graphics->SetTransform(geometry_->GetTransformMatrix() * GetTransformMatrix());
|
graphics->SetTransform(geometry_->GetTransformMatrix() * GetTransformMatrix());
|
||||||
|
|
||||||
graphics->FillGeometry(
|
graphics->FillGeometry(
|
||||||
geometry_->GetD2DGeometry(),
|
geometry_->geo_,
|
||||||
fill_color_
|
fill_color_
|
||||||
);
|
);
|
||||||
|
|
||||||
graphics->DrawGeometry(
|
graphics->DrawGeometry(
|
||||||
geometry_->GetD2DGeometry(),
|
geometry_->geo_,
|
||||||
stroke_color_,
|
stroke_color_,
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
outline_join_
|
outline_join_
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,9 @@ namespace easy2d
|
||||||
E2D_DECLARE_SMART_PTR(Task);
|
E2D_DECLARE_SMART_PTR(Task);
|
||||||
|
|
||||||
E2D_DECLARE_SMART_PTR(Geometry);
|
E2D_DECLARE_SMART_PTR(Geometry);
|
||||||
|
E2D_DECLARE_SMART_PTR(LineGeometry);
|
||||||
E2D_DECLARE_SMART_PTR(RectangleGeometry);
|
E2D_DECLARE_SMART_PTR(RectangleGeometry);
|
||||||
|
E2D_DECLARE_SMART_PTR(RoundedRectGeometry);
|
||||||
E2D_DECLARE_SMART_PTR(CircleGeometry);
|
E2D_DECLARE_SMART_PTR(CircleGeometry);
|
||||||
E2D_DECLARE_SMART_PTR(EllipseGeometry);
|
E2D_DECLARE_SMART_PTR(EllipseGeometry);
|
||||||
E2D_DECLARE_SMART_PTR(PathGeometry);
|
E2D_DECLARE_SMART_PTR(PathGeometry);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ namespace easy2d
|
||||||
|
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, cpGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, cpGeometry);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, cpRectangleGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, cpRectangleGeometry);
|
||||||
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, cpRoundedRectangleGeometry);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, cpEllipseGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, cpEllipseGeometry);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, cpGeometryGroup);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, cpGeometryGroup);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, cpPathGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, cpPathGeometry);
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,26 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT GraphicsDevice::CreateRoundedRectangleGeometry(cpRoundedRectangleGeometry & geo, Rect const & rect, float radius_x, float radius_y) const
|
||||||
|
{
|
||||||
|
if (!d2d.factory)
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
|
cpRoundedRectangleGeometry rounded_rect;
|
||||||
|
HRESULT hr = d2d.factory->CreateRoundedRectangleGeometry(
|
||||||
|
D2D1::RoundedRect(
|
||||||
|
rect,
|
||||||
|
radius_x,
|
||||||
|
radius_y
|
||||||
|
),
|
||||||
|
&rounded_rect
|
||||||
|
);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
geo = rounded_rect;
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateEllipseGeometry(cpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const
|
HRESULT GraphicsDevice::CreateEllipseGeometry(cpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const
|
||||||
{
|
{
|
||||||
if (!d2d.factory)
|
if (!d2d.factory)
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,13 @@ namespace easy2d
|
||||||
Rect const& rect
|
Rect const& rect
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
HRESULT CreateRoundedRectangleGeometry(
|
||||||
|
cpRoundedRectangleGeometry& geo,
|
||||||
|
Rect const& rect,
|
||||||
|
float radius_x,
|
||||||
|
float radius_y
|
||||||
|
) const;
|
||||||
|
|
||||||
HRESULT CreateEllipseGeometry(
|
HRESULT CreateEllipseGeometry(
|
||||||
cpEllipseGeometry& geo,
|
cpEllipseGeometry& geo,
|
||||||
Point const& center,
|
Point const& center,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue