ArchitectureColoredPainting/UnitTest/ElementRendererTest.h

41 lines
1.3 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;
QPainterPath& path;
2023-02-10 13:48:30 +08:00
public:
TestGLWidget(Renderer::ElementStyle& style, QPainterPath& path, QWidget* parent = nullptr)
: QOpenGLWidget(parent), renderer(*Renderer::ElementRenderer::instance()), style(style), path(path) {};
2023-02-10 13:48:30 +08:00
void initializeGL() override
{
initializeOpenGLFunctions();
};
void paintGL() override
{
glClearColor(219 / 255., 78 / 255., 32 / 255., 1.0);
2023-02-10 13:48:30 +08:00
glClear(GL_COLOR_BUFFER_BIT);
2023-02-10 18:39:55 +08:00
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);
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
}