46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
#pragma once
|
|
#include <QOpenGLFunctions>
|
|
#include <QOpenGLWidget>
|
|
#include <QPainter>
|
|
#include "Renderer/Preview/ElementRenderer.h"
|
|
#include "Editor/ThirdPartyLib/qquick/qquicksvgparser_p.h"
|
|
#include "Editor/util/PainterPathUtil.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(219/255., 78/255., 32/255., 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
QPainterPath path;
|
|
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);
|
|
QTransform transform;
|
|
transform.scale(10, 10);
|
|
path = transform.map(path);
|
|
float pixelRatio = devicePixelRatioF();
|
|
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()/pixelRatio), img);
|
|
};
|
|
void resizeGL(int w, int h) override {};
|
|
};
|
|
} |