stuff-from-scratch/test/test_utils/TestRenderUtils.h

59 lines
1.1 KiB
C
Raw Normal View History

2023-01-12 10:58:43 +00:00
#pragma once
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "AbstractPainter.h"
2023-01-12 17:45:06 +00:00
#include "Scene.h"
#include "SvgConverter.h"
#include "SvgWriter.h"
#include "SvgDocument.h"
2023-01-12 10:58:43 +00:00
#include "Image.h"
#include "PngWriter.h"
2023-01-12 17:45:06 +00:00
#include "File.h"
2023-01-12 10:58:43 +00:00
class TestRenderer
{
public:
TestRenderer(unsigned width = 1000, unsigned height = 1000)
{
mSurface = std::make_unique<DrawingSurface>();
mSurface->setSize(width, height);
mDrawingContext = std::make_unique<DrawingContext>(mSurface.get());
}
Scene* getScene() const
{
return mSurface->getScene();
}
void write(const Path& path)
{
mDrawingContext->paint();
auto image = mSurface->getImage();
PngWriter writer;
writer.setPath(path);
writer.write(image);
}
2023-01-12 17:45:06 +00:00
void writeSvg(const Path& path)
{
SvgConverter converter;
auto svg_document = converter.convert(mSurface->getScene());
SvgWriter writer;
auto svg_content = writer.toString(svg_document.get());
File svg_file(path);
svg_file.writeText(svg_content);
}
2023-01-12 10:58:43 +00:00
private:
std::unique_ptr<DrawingSurface> mSurface;
std::unique_ptr<DrawingContext> mDrawingContext;
};