ArchitectureColoredPainting/UnitTest/ElementRendererTest.h

44 lines
1.4 KiB
C++

#pragma once
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QPainter>
#include "Renderer/Preview/ElementRenderer.h"
#include "Editor/ThirdPartyLib/qquick/qquicksvgparser_p.h"
#include "Renderer/Painting/MaterialStyleStroke.h"
#include "Renderer/Painting/ElementStyle.h"
namespace UnitTest
{
class TestGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
private:
Renderer::ElementRenderer renderer;
Renderer::ElementStyle& style;
public:
TestGLWidget(Renderer::ElementStyle& style, QWidget* parent = nullptr)
: QOpenGLWidget(parent), renderer(this), style(style) {};
void initializeGL() override
{
initializeOpenGLFunctions();
renderer.initialize();
};
void paintGL() override
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
QPainterPath path;
QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", path);
/*QTransform transform;
transform.scale(10, 10);
transform.map(path);*/
float pixelRatio = 30;
auto [img, pos] = renderer.drawElement(path, style, pixelRatio, false);
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.drawImage(QRectF(QPointF(0, 0), img.size()/devicePixelRatioF()), img);
};
void resizeGL(int w, int h) override {};
};
}