src/ui/canvas.h

Tue, 14 Jun 2022 22:31:39 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 14 Jun 2022 22:31:39 +0300
changeset 221
e28f89b8ccdf
parent 215
34c6e7bc4ee1
permissions
-rw-r--r--

simplify settings further

#pragma once
#include <QPainter>
#include <QBrush>
#include <QPen>
#include "gl/partrenderer.h"
#include "gl/gridprogram.h"
#include "gl/axesprogram.h"
#include "gl/vertexprogram.h"

class EditTools;

class Canvas : public PartRenderer
{
	Q_OBJECT
public:
	using OverpaintCallback = std::function<void(Canvas*, QPainter*)>;
	Canvas(
		Model* model,
		EditTools* document,
		DocumentManager* documents,
		const ColorTable& colorTable,
		QWidget* parent = nullptr);
	void setOverpaintCallback(OverpaintCallback fn);
	void drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const;
	void drawWorldPolyline(QPainter* painter, const std::vector<glm::vec3>& points);
	void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points);
	Winding worldPolygonWinding(const std::vector<glm::vec3>& points) const;
	const std::optional<glm::vec3>& getWorldPosition() const;
	const QSet<ModelId> selectedObjects() const;
	const glm::mat4& getGridMatrix() const;
	void closeShape();
	glm::vec3 cameraVector() const;
	std::optional<glm::vec3> worldPosition;
	DrawState* drawState = nullptr;
public Q_SLOTS:
	void handleSelectionChange(const QSet<ModelId>& selectedIds, const QSet<ModelId>& deselectedIds);
	void rebuildVertices(VertexMap* vertexMap);
	void setGridMatrix(const glm::mat4 &newMatrix);
protected:
	void mouseMoveEvent(QMouseEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;
	void initializeGL() override;
	void paintGL() override;
Q_SIGNALS:
	void newStatusText(const QString& newStatusText);
	void mouseClick(QMouseEvent* event);
	void mouseMove(QMouseEvent* event);
private:
	bool isGridPerpendicularToScreen(float threshold) const;
	QVector<QPointF> convertWorldPointsToScreenPoints(const std::vector<glm::vec3>& worldPoints) const;
	Q_SLOT void updateCanvasRenderPreferences();
	void renderAxesLabels(QPainter& painter);
	std::optional<GridProgram> gridProgram;
	std::optional<AxesProgram> axesProgram;
	std::optional<VertexProgram> vertexProgram;
	glm::mat4 gridMatrix;
	Plane gridPlane;
	int totalMouseMove = 0;
	bool isDark = true;
	QSet<ModelId> selection;
	OverpaintCallback overpaintCallback = nullptr;
	EditTools* document;
};

void adjustGridToView(Canvas* canvas);

mercurial