#ifndef MAGNUM_ITEM_H
#define MAGNUM_ITEM_H

#include <Magnum/GL/Framebuffer.h>
#include <Magnum/Platform/GLContext.h>
#include "glclampf.h"
#include <QOpenGLFunctions>
#include <QtQuick/QQuickFramebufferObject>

// Forward declaring the renderer to avoid CMake's AUTOMOC
// to process Magnum's headers (where it fails)

class MagnumRenderer;

class MagnumItem : public QQuickFramebufferObject {
  Q_OBJECT
  Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
  Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
  Q_PROPERTY(qint8 count READ count WRITE setCount NOTIFY countChanged)
  Q_PROPERTY(qreal lagging READ lagging WRITE setLagging NOTIFY laggingChanged)
public:
  MagnumItem();
  Renderer *createRenderer() const override;

  inline qreal t() const { return m_t; }
  void setT(qreal t);

  inline qreal hue() const { return m_hue; }
  void setHue(qreal hue);

  inline qint8 count() const { return m_count; }
  void setCount(qint8 count);

  inline qreal lagging() const { return m_lagging; }
  void setLagging(qreal lagging);

signals:
  void tChanged();
  void hueChanged();
  void countChanged();
  void laggingChanged();

protected:
  void mousePressEvent(QMouseEvent *evt) override;
  void mouseMoveEvent(QMouseEvent *evt) override;
  void wheelEvent(QWheelEvent *evt) override;

private:
  void releaseResources() override;

  qreal m_t;
  qreal m_hue;
  qint8 m_count;
  qreal m_lagging;

  MagnumRenderer *m_renderer;
};

#endif // MAGNUM_ITEM_H
