完善Canvas
This commit is contained in:
parent
e53a7df27a
commit
8323a245ee
|
|
@ -42,6 +42,14 @@ e2d::Color::Color(UINT rgb, float alpha)
|
|||
_init(rgb, alpha);
|
||||
}
|
||||
|
||||
e2d::Color::Color(const D2D1_COLOR_F& color)
|
||||
: r(color.r)
|
||||
, g(color.g)
|
||||
, b(color.b)
|
||||
, a(color.a)
|
||||
{
|
||||
}
|
||||
|
||||
e2d::Color::operator D2D1_COLOR_F() const
|
||||
{
|
||||
return std::move(D2D1::ColorF(r, g, b, a));
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::Canvas::Canvas()
|
||||
e2d::Canvas::Canvas(float width, float height)
|
||||
: _renderer(nullptr)
|
||||
, _renderTarget(nullptr)
|
||||
, _fillBrush(nullptr)
|
||||
, _lineBrush(nullptr)
|
||||
, _strokeStyle(nullptr)
|
||||
, _strokeWidth(1.0f)
|
||||
, _stroke(Stroke::Miter)
|
||||
{
|
||||
_renderer = Game::getInstance()->getRenderer();
|
||||
_renderTarget = _renderer->getRenderTarget();
|
||||
|
|
@ -25,10 +26,11 @@ e2d::Canvas::Canvas()
|
|||
&_lineBrush
|
||||
)
|
||||
);
|
||||
|
||||
_strokeStyle = _renderer->getMiterStrokeStyle();
|
||||
|
||||
|
||||
this->setClipEnabled(true);
|
||||
this->setWidth(width);
|
||||
this->setHeight(height);
|
||||
this->setStrokeStyle(_stroke);
|
||||
}
|
||||
|
||||
e2d::Canvas::~Canvas()
|
||||
|
|
@ -69,6 +71,26 @@ void e2d::Canvas::setStrokeStyle(Stroke strokeStyle)
|
|||
}
|
||||
}
|
||||
|
||||
const e2d::Color & e2d::Canvas::getLineColor() const
|
||||
{
|
||||
return Color(_lineBrush->GetColor());
|
||||
}
|
||||
|
||||
const e2d::Color & e2d::Canvas::getFillColor() const
|
||||
{
|
||||
return Color(_fillBrush->GetColor());
|
||||
}
|
||||
|
||||
float e2d::Canvas::getStrokeWidth() const
|
||||
{
|
||||
return _strokeWidth;
|
||||
}
|
||||
|
||||
e2d::Stroke e2d::Canvas::getStrokeStyle() const
|
||||
{
|
||||
return _stroke;
|
||||
}
|
||||
|
||||
void e2d::Canvas::drawLine(const Point & begin, const Point & end)
|
||||
{
|
||||
_renderTarget->DrawLine(
|
||||
|
|
@ -80,6 +102,40 @@ void e2d::Canvas::drawLine(const Point & begin, const Point & end)
|
|||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::drawCircle(const Point & center, float radius)
|
||||
{
|
||||
_renderTarget->DrawEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
center.x,
|
||||
center.y
|
||||
),
|
||||
radius,
|
||||
radius
|
||||
),
|
||||
_lineBrush,
|
||||
_strokeWidth,
|
||||
_strokeStyle
|
||||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY)
|
||||
{
|
||||
_renderTarget->DrawEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
center.x,
|
||||
center.y
|
||||
),
|
||||
radiusX,
|
||||
radiusY
|
||||
),
|
||||
_lineBrush,
|
||||
_strokeWidth,
|
||||
_strokeStyle
|
||||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::drawRect(const Rect & rect)
|
||||
{
|
||||
_renderTarget->DrawRectangle(
|
||||
|
|
@ -114,6 +170,36 @@ void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radius
|
|||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::fillCircle(const Point & center, float radius)
|
||||
{
|
||||
_renderTarget->FillEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
center.x,
|
||||
center.y
|
||||
),
|
||||
radius,
|
||||
radius
|
||||
),
|
||||
_fillBrush
|
||||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY)
|
||||
{
|
||||
_renderTarget->FillEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
center.x,
|
||||
center.y
|
||||
),
|
||||
radiusX,
|
||||
radiusY
|
||||
),
|
||||
_fillBrush
|
||||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::fillRect(const Rect & rect)
|
||||
{
|
||||
_renderTarget->FillRectangle(
|
||||
|
|
@ -143,7 +229,3 @@ void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radius
|
|||
_fillBrush
|
||||
);
|
||||
}
|
||||
|
||||
void e2d::Canvas::visit(Game * game)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,6 +310,10 @@ public:
|
|||
float alpha
|
||||
);
|
||||
|
||||
Color(
|
||||
const D2D1_COLOR_F& color
|
||||
);
|
||||
|
||||
E2D_OP_EXPLICIT operator D2D1_COLOR_F() const;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1098,10 +1098,14 @@ protected:
|
|||
|
||||
// »²¼
|
||||
class Canvas :
|
||||
public Node
|
||||
public Node,
|
||||
public Drawable
|
||||
{
|
||||
public:
|
||||
Canvas();
|
||||
Canvas(
|
||||
float width,
|
||||
float height
|
||||
);
|
||||
|
||||
virtual ~Canvas();
|
||||
|
||||
|
|
@ -1125,12 +1129,37 @@ public:
|
|||
Stroke strokeStyle
|
||||
);
|
||||
|
||||
// »ñÈ¡ÏßÌõÑÕÉ«
|
||||
const Color& getLineColor() const;
|
||||
|
||||
// »ñÈ¡Ìî³äÑÕÉ«
|
||||
const Color& getFillColor() const;
|
||||
|
||||
// »ñÈ¡ÏßÌõ¿í¶È
|
||||
float getStrokeWidth() const;
|
||||
|
||||
// »ñÈ¡ÏßÌõÏཻÑùʽ
|
||||
Stroke getStrokeStyle() const;
|
||||
|
||||
// »Ö±Ïß
|
||||
void drawLine(
|
||||
const Point& begin,
|
||||
const Point& end
|
||||
);
|
||||
|
||||
// »Ô²Ðα߿ò
|
||||
void drawCircle(
|
||||
const Point& center,
|
||||
float radius
|
||||
);
|
||||
|
||||
// »ÍÖÔ²Ðα߿ò
|
||||
void drawEllipse(
|
||||
const Point& center,
|
||||
float radiusX,
|
||||
float radiusY
|
||||
);
|
||||
|
||||
// »¾ØÐα߿ò
|
||||
void drawRect(
|
||||
const Rect& rect
|
||||
|
|
@ -1143,6 +1172,19 @@ public:
|
|||
float radiusY
|
||||
);
|
||||
|
||||
// Ìî³äÔ²ÐÎ
|
||||
void fillCircle(
|
||||
const Point& center,
|
||||
float radius
|
||||
);
|
||||
|
||||
// Ìî³äÍÖÔ²ÐÎ
|
||||
void fillEllipse(
|
||||
const Point& center,
|
||||
float radiusX,
|
||||
float radiusY
|
||||
);
|
||||
|
||||
// Ìî³ä¾ØÐÎ
|
||||
void fillRect(
|
||||
const Rect& rect
|
||||
|
|
@ -1155,27 +1197,12 @@ public:
|
|||
float radiusY
|
||||
);
|
||||
|
||||
// 开启路径
|
||||
void beginPath();
|
||||
|
||||
// 添加点
|
||||
void addPoint(
|
||||
const Point& p
|
||||
);
|
||||
|
||||
// 结束路径
|
||||
void endPath();
|
||||
|
||||
// 遍历节点
|
||||
virtual void visit(
|
||||
Game * game
|
||||
) override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Canvas);
|
||||
|
||||
protected:
|
||||
float _strokeWidth;
|
||||
Stroke _stroke;
|
||||
Renderer * _renderer;
|
||||
ID2D1RenderTarget * _renderTarget;
|
||||
ID2D1SolidColorBrush * _fillBrush;
|
||||
|
|
|
|||
Loading…
Reference in New Issue