src/ui/canvas.h

Mon, 09 Mar 2020 14:21:54 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 09 Mar 2020 14:21:54 +0200
changeset 73
97df974b5ed5
parent 70
f21b800b02a4
child 104
cd4df75924b7
permissions
-rw-r--r--

ldraw::Id is now templated for extra type safety

#pragma once
#include "gl/partrenderer.h"
#include "gl/gridprogram.h"
#include "gl/axesprogram.h"

class Canvas : public PartRenderer
{
	Q_OBJECT
public:
	Canvas(
		Model* model,
		DocumentManager* documents,
		const ldraw::ColorTable& colorTable,
		QWidget* parent = nullptr);
public 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;
signals:
	void newStatusText(const QString& newStatusText);
	void selectionChanged(const QSet<ldraw::id_t>& newSelection);
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;
};

mercurial