ArchitectureColoredPainting/UnitTest/ElementRendererTest.h

45 lines
1.8 KiB
C
Raw Permalink Normal View History

2023-02-08 16:34:16 +08:00
#pragma once
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QPainter>
#include "Renderer/Preview/ElementRenderer.h"
#include "Editor/ThirdPartyLib/qquick/qquicksvgparser_p.h"
2023-02-15 15:37:30 +08:00
#include "Editor/util/PainterPathUtil.h"
2023-02-08 16:34:16 +08:00
#include "Renderer/Painting/MaterialStyleStroke.h"
#include "Renderer/Painting/ElementStyle.h"
namespace UnitTest
{
2023-02-10 13:48:30 +08:00
class TestGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
private:
2023-03-09 16:21:55 +08:00
Renderer::ElementRenderer& renderer;
2023-02-10 13:48:30 +08:00
Renderer::ElementStyle& style;
public:
TestGLWidget(Renderer::ElementStyle& style, QWidget* parent = nullptr)
2023-03-09 16:21:55 +08:00
: QOpenGLWidget(parent), renderer(*Renderer::ElementRenderer::instance()), style(style) {};
2023-02-10 13:48:30 +08:00
void initializeGL() override
{
initializeOpenGLFunctions();
};
void paintGL() override
{
2023-02-15 15:37:30 +08:00
glClearColor(219/255., 78/255., 32/255., 1.0);
2023-02-10 13:48:30 +08:00
glClear(GL_COLOR_BUFFER_BIT);
QPainterPath path;
2023-02-15 15:37:30 +08:00
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
path = PainterPathUtil::monotonization(path);
2023-02-10 18:39:55 +08:00
QTransform transform;
2023-02-15 15:37:30 +08:00
transform.scale(10, 10);
2023-02-10 18:39:55 +08:00
path = transform.map(path);
float pixelRatio = devicePixelRatioF();
2023-03-09 15:37:50 +08:00
auto [img, pos] = renderer.drawElement(path, style, pixelRatio);
2023-02-10 13:48:30 +08:00
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
2023-02-10 18:39:55 +08:00
painter.drawImage(QRectF(QPointF(0, 0), img.size()/pixelRatio), img);
2023-02-10 13:48:30 +08:00
};
void resizeGL(int w, int h) override {};
};
2023-02-08 16:34:16 +08:00
}