src/ui/canvas.h

Tue, 27 Jul 2021 12:44:54 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 27 Jul 2021 12:44:54 +0300
changeset 116
aad3e897bc32
parent 112
5760cbb32bc0
child 118
8e1c9f18ae15
permissions
-rw-r--r--

refactor

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

class Canvas : public PartRenderer
{
	Q_OBJECT
public:
	using OverpaintCallback = std::function<void(Canvas*, QPainter*)>;
	Canvas(
		Model* model,
		DocumentManager* documents,
		const ldraw::ColorTable& colorTable,
		QWidget* parent = nullptr);
	void clearSelection();
	void addToSelection(ldraw::id_t id);
	void setOverpaintCallback(OverpaintCallback fn);
	void drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const;
	void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points);
	const std::optional<glm::vec3>& getWorldPosition() const;
public Q_SLOTS:
	void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds);
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 selectionChanged(const QSet<ldraw::id_t>& newSelection);
	void mouseClick(Canvas* canvas);
	void mouseMove(Canvas* canvas);
private:
	void updateGridMatrix();
	glm::vec3 cameraVector() const;
	bool isGridPerpendicularToScreen(float threshold) const;
	std::optional<GridProgram> gridProgram;
	std::optional<AxesProgram> axesProgram;
	std::optional<glm::vec3> worldPosition;
	glm::mat4 gridMatrix;
	geom::Plane gridPlane;
	int totalMouseMove = 0;
	QSet<ldraw::id_t> selection;
	OverpaintCallback overpaintCallback = nullptr;
};

mercurial