qmlfrontend/game_view.h
author Wuzzy <Wuzzy2@mail.ru>
Thu, 25 Apr 2019 23:01:05 +0200
changeset 14839 e239378a9400
parent 14713 cc6ab1e3f7d5
child 14842 ef9630519491
permissions -rw-r--r--
Prevent entering “/”, “\” and “:” in team and scheme names. The name of teams and schems is saved in the file name itself, so these characters would cause trouble as they are used in path names in Linux and Windows.

#ifndef GAMEVIEW_H
#define GAMEVIEW_H

#include <QQuickItem>

#include <QPointer>
#include <QScopedPointer>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLShaderProgram>

#include "engine_instance.h"

class GameViewRenderer : public QObject, protected QOpenGLFunctions {
  Q_OBJECT
 public:
  explicit GameViewRenderer();
  ~GameViewRenderer() override;

  void tick(quint32 delta);
  void setEngineInstance(EngineInstance* engineInstance);

 public slots:
  void paint();
  void onViewportSizeChanged(QQuickWindow* window);

 private:
  quint32 m_delta;
  QPointer<EngineInstance> m_engineInstance;
};

class GameView : public QQuickItem {
  Q_OBJECT

  Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE
                 setEngineInstance NOTIFY engineInstanceChanged)

 public:
  explicit GameView();

  Q_INVOKABLE void tick(quint32 delta);

  EngineInstance* engineInstance() const;

 signals:
  void engineInstanceChanged(EngineInstance* engineInstance);

 public slots:
  void sync();
  void cleanup();
  void setEngineInstance(EngineInstance* engineInstance);

 private slots:
  void handleWindowChanged(QQuickWindow* win);

 private:
  quint32 m_delta;
  QScopedPointer<GameViewRenderer> m_renderer;
  bool m_windowChanged;
  QPointer<EngineInstance> m_engineInstance;
  QSize m_viewportSize;
  QPoint m_centerPoint;
};

#endif  // GAMEVIEW_H