#ifndef VOLUMERENDERWINDOW_H
#define VOLUMERENDERWINDOW_H

#include "glwindow.h"
#include "volumerenderer.h"

/*!
\file 
Defines the \ref VolumeRenderWindow class.
*/

/*!
	A GLWindow that uses the VolumeRenderer for drawing, and provides some interaction with it. 
	The VolumeRenderer also defines the requested \c QSurfaceFormat of the window, so you don't have to set it manually.
*/
class VolumeRenderWindow : public GLWindow
{
	Q_OBJECT

public:
	/*!
	Constructs a new VolumeRenderWindow.
	The supplied renderer defines the surface format used (using \ref VolumeRenderer::getDesiredFormat).
	\param renderer The VolumeRenderer to use. Must not be \c NULL. The window does take ownership of the renderer!
	\param parent See \c QWindow constructor.
	*/
	explicit VolumeRenderWindow(VolumeRenderer* renderer, QWindow* parent = nullptr);
	~VolumeRenderWindow();

	/*!
		Calls \ref VolumeRenderer::initialize and checks for errors.
	*/
	bool initialize() override;
	/*!
		Calls \ref VolumeRenderer::drawCurrent
	*/
	void render() override;    

	/*!
		Returns the VolumeRenderer used
	*/
	VolumeRenderer* getRenderer() const { return m_renderer; }

	/*!
		Notifies the renderer that the size has changed. Used for projection and \c glViewport.
	*/
	void resizeEvent(QResizeEvent* ev) override;

	/*!
		Changes the renderer rotation parameters.
	*/
	void mouseMoveEvent(QMouseEvent* ev) override;

	/*
		Changes renderer distance parameter.
	*/
	void wheelEvent(QWheelEvent* ev) override;

	/*!	
		Needed for mouse tracking.
	*/
	void mousePressEvent(QMouseEvent* ev) override;

private slots:
	/*!
	Slot for the renderer to notify the VolumeRenderWindow of changes.
	*/
	void rendererWantsDraw();

	/*!
	Slot for the renderer to notify the VolumeRenderWindow of changes.
	*/
	void rendererUpdated();

private:
	VolumeRenderer* m_renderer;
	QPoint m_lastMousePos;
};

#endif // VOLUMERENDERWINDOW_H
