src/editmodes/abstracteditmode.h

Fri, 04 Jul 2014 22:19:01 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 04 Jul 2014 22:19:01 +0300
changeset 823
1a2f593f0c02
child 824
6add2126e7ff
permissions
-rw-r--r--

- saving work done on edit mode revamp

#pragma once
#include "../main.h"
#include "../glRenderer.h"

class QPainter;
class GLRenderer;

enum class EditModeType
{
	Select,
	Draw,
	Circle,
	MagicWand,
};

class AbstractEditMode
{
	GLRenderer* _renderer;
	QBrush		_polybrush;

public:
	struct MouseEventData
	{
		QMouseEvent* ev;
		Qt::KeyboardModifiers keymods;
		bool mouseMoved;
		Qt::MouseButtons releasedButtons;
	};

	AbstractEditMode (GLRenderer* renderer);

	virtual bool			allowFreeCamera() const = 0;
	virtual void			render (QPainter& painter) const {};
	GLRenderer*				renderer() const;
	virtual EditModeType	type() const = 0;
	virtual void			mousePressed (MouseEventData const& data) {}
	virtual void			mouseReleased (MouseEventData const& data) {}

	static AbstractEditMode* createByType (GLRenderer* renderer, EditModeType type);
};

//
// Base class for draw-like edit modes
//
class AbstractDrawMode : public AbstractEditMode
{
	QList<Vertex>			m_drawedVerts;
	Vertex					m_rectverts[4];

public:
	AbstractDrawMode (GLRenderer* renderer);

	virtual bool allowFreeCamera() const override
	{
		return false;
	}

	virtual void mouseReleased (MouseEventData const& data) override;
	void addDrawnVertex (const Vertex& pos);

	virtual bool preAddVertex (Vertex const&)
	{
		return false;
	}
};

//
// Base class for select-like edit modes
//
class AbstractSelectMode : public AbstractEditMode
{
public:
	AbstractSelectMode (GLRenderer* renderer);

	virtual bool allowFreeCamera() const override
	{
		return true;
	}
};

mercurial