98 lines
2.9 KiB
C++
98 lines
2.9 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
*
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
*
|
|
* @license APACHE v2.0 (see license file)
|
|
*/
|
|
|
|
#include <esvg/debug.h>
|
|
#include <esvg/Circle.h>
|
|
|
|
#undef __class__
|
|
#define __class__ "Circle"
|
|
|
|
esvg::Circle::Circle(PaintState _parentPaintState) : esvg::Base(_parentPaintState) {
|
|
|
|
}
|
|
|
|
esvg::Circle::~Circle() {
|
|
|
|
}
|
|
|
|
bool esvg::Circle::parse(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax) {
|
|
m_radius = 0.0;
|
|
m_position.setValue(0,0);
|
|
if (_element == nullptr) {
|
|
return false;
|
|
}
|
|
parseTransform(_element);
|
|
parsePaintAttr(_element);
|
|
|
|
// add the property of the parrent modifications ...
|
|
m_transformMatrix *= _parentTrans;
|
|
|
|
std::string content = _element->getAttribute("cx");
|
|
if (content.size()!=0) {
|
|
m_position.setX(parseLength(content));
|
|
}
|
|
content = _element->getAttribute("cy");
|
|
if (content.size()!=0) {
|
|
m_position.setY(parseLength(content));
|
|
}
|
|
content = _element->getAttribute("r");
|
|
if (content.size()!=0) {
|
|
m_radius = parseLength(content);
|
|
} else {
|
|
SVG_ERROR("(l "<<_element->getPos()<<") Circle \"r\" is not present");
|
|
return false;
|
|
}
|
|
if (0 > m_radius) {
|
|
m_radius = 0;
|
|
SVG_ERROR("(l "<<_element->getPos()<<") Circle \"r\" is negative");
|
|
return false;
|
|
}
|
|
_sizeMax.setValue(m_position.x() + m_radius, m_position.y() + m_radius);
|
|
return true;
|
|
}
|
|
|
|
void esvg::Circle::display(int32_t _spacing) {
|
|
SVG_DEBUG(spacingDist(_spacing) << "Circle " << m_position << " radius=" << m_radius);
|
|
}
|
|
|
|
|
|
void esvg::Circle::aggDraw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
|
|
SVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Circle");
|
|
/*
|
|
_myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
|
|
// Creating an ellipse
|
|
agg::ellipse myCircle(m_position.x(), m_position.y(), m_radius, m_radius, 0);
|
|
|
|
// Calculate transformation matrix ...
|
|
mat2 mtx = m_transformMatrix;
|
|
mtx *= _basicTrans;
|
|
|
|
// set the filling mode :
|
|
_myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
|
|
|
|
if (m_paint.fill.a != 0x00) {
|
|
agg::conv_transform<agg::ellipse, mat2> trans(myCircle, mtx);
|
|
_myRenderer.m_rasterizer.add_path(trans);
|
|
agg::render_scanlines(_myRenderer.m_rasterizer, _myRenderer.m_scanLine, *_myRenderer.m_renderArea);
|
|
}
|
|
|
|
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
|
_myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
|
// drawing as an outline
|
|
agg::conv_stroke<agg::ellipse> myCircleStroke(myCircle);
|
|
myCircleStroke.width(m_paint.strokeWidth);
|
|
agg::conv_transform<agg::conv_stroke<agg::ellipse>, mat2> transStroke(myCircleStroke, mtx);
|
|
// set the filling mode :
|
|
_myRenderer.m_rasterizer.filling_rule(agg::fill_non_zero);
|
|
_myRenderer.m_rasterizer.add_path(transStroke);
|
|
agg::render_scanlines(_myRenderer.m_rasterizer, _myRenderer.m_scanLine, *_myRenderer.m_renderArea);
|
|
}
|
|
*/
|
|
}
|
|
|