Magic_Game/core/Node/Shape/Shape.cpp

110 lines
1.7 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\..\e2dshape.h"
e2d::Shape::Shape()
2018-05-24 20:37:34 +08:00
: _style(Style::Solid)
2018-05-24 20:10:11 +08:00
, _fillColor(0x6090A0U)
, _lineColor(0x78B7D0U)
, _strokeWidth(2)
, _strokeStyle(nullptr)
{
}
e2d::Shape::~Shape()
{
}
void e2d::Shape::onRender() const
{
auto pBrush = Renderer::getInstance()->getSolidColorBrush();
pBrush->SetOpacity(_displayOpacity);
switch (_style)
{
2018-05-24 20:37:34 +08:00
case Style::Fill:
{
2018-07-29 02:24:34 +08:00
pBrush->SetColor((D2D1_COLOR_F)_fillColor);
this->_renderFill();
2018-07-29 02:24:34 +08:00
pBrush->SetColor((D2D1_COLOR_F)_lineColor);
this->_renderLine();
break;
}
2018-05-24 20:37:34 +08:00
case Style::Round:
{
2018-07-29 02:24:34 +08:00
pBrush->SetColor((D2D1_COLOR_F)_lineColor);
this->_renderLine();
break;
}
2018-05-24 20:37:34 +08:00
case Style::Solid:
{
2018-07-29 02:24:34 +08:00
pBrush->SetColor((D2D1_COLOR_F)_fillColor);
this->_renderFill();
break;
}
default:
break;
}
}
e2d::Color e2d::Shape::getFillColor() const
{
return _fillColor;
}
e2d::Color e2d::Shape::getLineColor() const
{
return _lineColor;
}
2018-07-28 20:06:27 +08:00
float e2d::Shape::getStrokeWidth() const
{
return _strokeWidth;
}
e2d::Shape::Style e2d::Shape::getStyle() const
{
return _style;
}
void e2d::Shape::setFillColor(Color fillColor)
{
_fillColor = fillColor;
}
void e2d::Shape::setLineColor(Color lineColor)
{
_lineColor = lineColor;
}
2018-07-28 20:06:27 +08:00
void e2d::Shape::setStrokeWidth(float strokeWidth)
{
2018-07-28 20:06:27 +08:00
_strokeWidth = strokeWidth * 2;
}
void e2d::Shape::setStyle(Style style)
{
_style = style;
}
2018-05-24 20:10:11 +08:00
void e2d::Shape::setLineJoin(LineJoin lineJoin)
{
switch (lineJoin)
{
2018-05-24 20:37:34 +08:00
case LineJoin::Miter:
_strokeStyle = Renderer::getMiterStrokeStyle();
2018-05-24 20:10:11 +08:00
break;
2018-05-24 20:37:34 +08:00
case LineJoin::Bevel:
_strokeStyle = Renderer::getBevelStrokeStyle();
2018-05-24 20:10:11 +08:00
break;
2018-05-24 20:37:34 +08:00
case LineJoin::Round:
_strokeStyle = Renderer::getRoundStrokeStyle();
2018-05-24 20:10:11 +08:00
break;
default:
_strokeStyle = nullptr;
break;
}
}