Start dx path support.

This commit is contained in:
jmsgrogan 2023-01-20 17:30:05 +00:00
parent f8a2ce3c59
commit a46477cdcf
5 changed files with 91 additions and 22 deletions

View file

@ -11,6 +11,11 @@
#include "Line.h"
#include "Path.h"
#include "Curve.h"
#include "Arc.h"
#include "QuadraticBezierCurve.h"
#include "CubicBezierCurve.h"
#include "FileLogger.h"
#include "SceneModel.h"
@ -152,18 +157,27 @@ void DirectX2dPainter::paintPath(SceneModel* model)
{
if (element->getType() == AbstractGeometricItem::Type::LINE)
{
for (const auto& point : dynamic_cast<Line*>(element.get())->getPoints().getPoints())
{
MLOG_INFO("Adding line entry at: " << point.getX() << " " << point.getY());
path_sink->AddLine(toD2dPoint(point));
}
MLOG_INFO("Finished line");
onLine(element.get(), path_sink.Get());
}
else if (element->getType() == AbstractGeometricItem::Type::LINE_SEGMENT)
{
const auto loc = element->getEndPoint();
MLOG_INFO("Adding segment entry at: " << loc.getX() << " " << loc.getY());
path_sink->AddLine(toD2dPoint(loc));
onLineSegment(element.get(), path_sink.Get());
}
else if (element->getType() == AbstractGeometricItem::Type::CURVE)
{
auto curve = dynamic_cast<Curve*>(element.get());
if (curve->getCurveType() == Curve::CurveType::ARC)
{
onArc(curve, path_sink.Get());
}
else if (curve->getCurveType() == Curve::CurveType::CUBIC_BEZIER)
{
onCubicBezier(curve, path_sink.Get());
}
else if (curve->getCurveType() == Curve::CurveType::QUADRATIC_BEZIER)
{
onQuadraticBezier(curve, path_sink.Get());
}
}
}
path_sink->EndFigure(D2D1_FIGURE_END_CLOSED);
@ -183,6 +197,37 @@ void DirectX2dPainter::paintPath(SceneModel* model)
}
}
void DirectX2dPainter::onArc(Curve* element, ID2D1GeometrySink* sink)
{
}
void DirectX2dPainter::onQuadraticBezier(Curve* element, ID2D1GeometrySink* sink)
{
}
void DirectX2dPainter::onCubicBezier(Curve* element, ID2D1GeometrySink* sink)
{
}
void DirectX2dPainter::onLine(PathElement* element, ID2D1GeometrySink* sink)
{
for (const auto& point : dynamic_cast<Line*>(element)->getPoints().getPoints())
{
MLOG_INFO("Adding line entry at: " << point.getX() << " " << point.getY());
sink->AddLine(toD2dPoint(point));
}
MLOG_INFO("Finished line");
}
void DirectX2dPainter::onLineSegment(PathElement* element, ID2D1GeometrySink* sink)
{
const auto loc = element->getEndPoint();
MLOG_INFO("Adding segment entry at: " << loc.getX() << " " << loc.getY());
sink->AddLine(toD2dPoint(loc));
}
void DirectX2dPainter::setD2dInterface(DirectX2dInterface* d2dIterface)
{

View file

@ -8,7 +8,11 @@ class SceneModel;
class Point;
class DirectX2dInterface;
class PathElement;
class Curve;
struct ID2D1SolidColorBrush;
struct ID2D1GeometrySink;
namespace D2D1
{
@ -30,9 +34,15 @@ public:
void setD2dInterface(DirectX2dInterface* d2dIterface);
private:
static D2D1::ColorF toD2dColor(const Color& color);
void onLine(PathElement* element, ID2D1GeometrySink* sink);
static D2D_POINT_2F toD2dPoint(const Point& point);
void onLineSegment(PathElement* element, ID2D1GeometrySink* sink);
void onArc(Curve* element, ID2D1GeometrySink* sink);
void onQuadraticBezier(Curve* element, ID2D1GeometrySink* sink);
void onCubicBezier(Curve* element, ID2D1GeometrySink* sink);
void paintRect(SceneModel* model);
@ -40,6 +50,10 @@ private:
void paintPath(SceneModel* model);
static D2D1::ColorF toD2dColor(const Color& color);
static D2D_POINT_2F toD2dPoint(const Point& point);
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mSolidBrush;
DirectX2dInterface* mD2dInterface{ nullptr };