2023-01-11 10:21:18 +00:00
|
|
|
#include "TestFramework.h"
|
|
|
|
#include "TestUtils.h"
|
2023-01-12 10:58:43 +00:00
|
|
|
#include "TestRenderUtils.h"
|
2023-01-11 10:21:18 +00:00
|
|
|
|
|
|
|
#include "RectangleNode.h"
|
2023-01-24 08:57:16 +00:00
|
|
|
#include "CircleNode.h"
|
|
|
|
#include "LineNode.h"
|
|
|
|
#include "PathNode.h"
|
2023-01-24 17:15:25 +00:00
|
|
|
#include "PolygonNode.h"
|
2023-01-12 10:58:43 +00:00
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addRect(const Point2& loc, Vector<Ptr<MaterialNode> >& nodes, double radius = 0.0)
|
2023-01-24 08:57:16 +00:00
|
|
|
{
|
2023-01-30 14:53:49 +00:00
|
|
|
auto node = std::make_unique<RectangleNode>(Transform(loc), 150.0, 100.0);
|
2023-01-24 08:57:16 +00:00
|
|
|
node->setRadius(radius);
|
|
|
|
nodes.push_back(std::move(node));
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addCircle(const Point2& loc, Vector<Ptr<MaterialNode> >& nodes, double minorRadius = 0.0)
|
2023-01-24 08:57:16 +00:00
|
|
|
{
|
|
|
|
const auto radius = 50.0;
|
|
|
|
auto centre_loc = loc;
|
2023-01-30 14:53:49 +00:00
|
|
|
centre_loc.moveBy(0.0, radius);
|
2023-01-24 08:57:16 +00:00
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
auto node = std::make_unique<CircleNode>(Transform(centre_loc), radius);
|
2023-01-24 08:57:16 +00:00
|
|
|
|
|
|
|
if (minorRadius != 0.0)
|
|
|
|
{
|
|
|
|
node->setMinorRadius(minorRadius);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes.push_back(std::move(node));
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addLine(const Point2& loc, Vector<Ptr<MaterialNode> >& nodes)
|
2023-01-24 08:57:16 +00:00
|
|
|
{
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<Point2> points = { Point2(150.0, 100.0) };
|
2023-01-30 14:53:49 +00:00
|
|
|
auto node = std::make_unique<LineNode>(Transform(loc), points);
|
2023-01-24 08:57:16 +00:00
|
|
|
nodes.push_back(std::move(node));
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addPath(const Point2& loc, const String& path, Vector<Ptr<MaterialNode> >& nodes)
|
2023-01-24 08:57:16 +00:00
|
|
|
{
|
2023-01-30 14:53:49 +00:00
|
|
|
auto node = std::make_unique<PathNode>(Transform(loc), path);
|
2023-01-24 08:57:16 +00:00
|
|
|
nodes.push_back(std::move(node));
|
|
|
|
}
|
2023-01-11 10:21:18 +00:00
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addPolygon(const Point2& loc, Vector<Ptr<MaterialNode> >& nodes)
|
2023-01-24 17:15:25 +00:00
|
|
|
{
|
2023-01-30 14:53:49 +00:00
|
|
|
auto p0 = Point2{ 0.0, 0.0 };
|
|
|
|
auto p1 = Point2{ 150.0, 0.0 };
|
|
|
|
auto p2 = Point2{ 75.0, 75.0 };
|
2023-01-24 17:15:25 +00:00
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
auto node = std::make_unique<PolygonNode>(Transform(loc));
|
2023-01-24 17:15:25 +00:00
|
|
|
node->setPoints({ p0, p1, p2 });
|
|
|
|
nodes.push_back(std::move(node));
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
void addShapes(const Point2& start_loc, Vector<Ptr<MaterialNode> >& nodes, bool use_fill = false)
|
2023-01-11 10:21:18 +00:00
|
|
|
{
|
2023-01-24 11:04:47 +00:00
|
|
|
auto loc = start_loc;
|
2023-01-11 10:21:18 +00:00
|
|
|
|
2023-01-24 11:04:47 +00:00
|
|
|
auto fill_color = Color(200, 0, 200);
|
2023-01-11 10:21:18 +00:00
|
|
|
|
2023-01-24 08:57:16 +00:00
|
|
|
addRect(loc, nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(250, 0);
|
2023-01-24 08:57:16 +00:00
|
|
|
addCircle(loc, nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(100, 0);
|
2023-01-24 08:57:16 +00:00
|
|
|
addLine(loc, nodes);
|
2023-01-11 10:21:18 +00:00
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(200, 0);
|
2023-01-24 17:15:25 +00:00
|
|
|
addPolygon(loc, nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc = Point2(10, 150);
|
2023-01-24 08:57:16 +00:00
|
|
|
addRect(loc, nodes, 10.0);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(250, 0);
|
2023-01-24 08:57:16 +00:00
|
|
|
addCircle(loc, nodes, 75.0);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(100, 0);
|
2023-01-24 08:57:16 +00:00
|
|
|
addPath(loc, "M0 0 h150 v100 h-150Z", nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc = Point2(10, 300);
|
2023-01-24 11:04:47 +00:00
|
|
|
addPath(loc, "M0 0 h150 q50 50 0 100 h-150Z", nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(250, 0);
|
2023-01-24 11:04:47 +00:00
|
|
|
addPath(loc, "M0 0 h150 c25 25 25 75 0 100 h-150Z", nodes);
|
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
loc.moveBy(250, 0);
|
2023-01-24 11:04:47 +00:00
|
|
|
addPath(loc, "M0 0 h150 a50 50 0 0 1 0 100 h-150Z", nodes);
|
|
|
|
|
|
|
|
if (use_fill)
|
|
|
|
{
|
|
|
|
for (auto& node : nodes)
|
|
|
|
{
|
|
|
|
node->setFillColor(fill_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(TestD2dOffScreenRendering_Outlines, "graphics")
|
|
|
|
{
|
|
|
|
TestRenderer renderer(800, 800);
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<Ptr<MaterialNode> > nodes;
|
2023-01-24 11:04:47 +00:00
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
auto loc = Point2(10, 10);
|
2023-01-24 11:04:47 +00:00
|
|
|
|
|
|
|
addShapes(loc, nodes, false);
|
|
|
|
|
|
|
|
auto scene = renderer.getScene();
|
|
|
|
for (const auto& node : nodes)
|
|
|
|
{
|
|
|
|
scene->addNode(node.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "outlines.svg");
|
|
|
|
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "outlines.png");
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE(TestD2dOffScreenRendering_Fill, "graphics")
|
|
|
|
{
|
|
|
|
TestRenderer renderer(800, 800);
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<Ptr<MaterialNode> > nodes;
|
2023-01-24 11:04:47 +00:00
|
|
|
|
2023-01-30 14:53:49 +00:00
|
|
|
auto loc = Point2(10, 10);
|
2023-01-24 11:04:47 +00:00
|
|
|
|
|
|
|
addShapes(loc, nodes, true);
|
|
|
|
|
2023-01-24 08:57:16 +00:00
|
|
|
auto scene = renderer.getScene();
|
|
|
|
for (const auto& node : nodes)
|
|
|
|
{
|
|
|
|
scene->addNode(node.get());
|
|
|
|
}
|
2023-01-24 11:04:47 +00:00
|
|
|
|
|
|
|
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "fill.svg");
|
|
|
|
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "fill.png");
|
2023-01-11 10:21:18 +00:00
|
|
|
};
|