qmlfrontend/game_view.h
branchui-scaling
changeset 15288 c4fd2813b127
parent 14847 ef9630519491
equal deleted inserted replaced
13395:0135e64c6c66 15288:c4fd2813b127
       
     1 #ifndef GAMEVIEW_H
       
     2 #define GAMEVIEW_H
       
     3 
       
     4 #include <QQuickItem>
       
     5 
       
     6 #include <QPointer>
       
     7 #include <QScopedPointer>
       
     8 #include <QtGui/QOpenGLFunctions>
       
     9 #include <QtGui/QOpenGLShaderProgram>
       
    10 
       
    11 #include "engine_instance.h"
       
    12 
       
    13 class GameViewRenderer : public QObject, protected QOpenGLFunctions {
       
    14   Q_OBJECT
       
    15  public:
       
    16   explicit GameViewRenderer();
       
    17   ~GameViewRenderer() override;
       
    18 
       
    19   void tick(quint32 delta);
       
    20   void setEngineInstance(EngineInstance* engineInstance);
       
    21 
       
    22  public slots:
       
    23   void paint();
       
    24   void onViewportSizeChanged(QQuickWindow* window);
       
    25 
       
    26  private:
       
    27   quint32 m_delta;
       
    28   QPointer<EngineInstance> m_engineInstance;
       
    29 };
       
    30 
       
    31 class GameView : public QQuickItem {
       
    32   Q_OBJECT
       
    33 
       
    34   Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE
       
    35                  setEngineInstance NOTIFY engineInstanceChanged)
       
    36 
       
    37  public:
       
    38   explicit GameView(QQuickItem* parent = nullptr);
       
    39 
       
    40   Q_INVOKABLE void tick(quint32 delta);
       
    41 
       
    42   EngineInstance* engineInstance() const;
       
    43 
       
    44  signals:
       
    45   void engineInstanceChanged(EngineInstance* engineInstance);
       
    46 
       
    47  public slots:
       
    48   void sync();
       
    49   void cleanup();
       
    50   void setEngineInstance(EngineInstance* engineInstance);
       
    51 
       
    52  private slots:
       
    53   void handleWindowChanged(QQuickWindow* win);
       
    54 
       
    55  private:
       
    56   quint32 m_delta;
       
    57   QScopedPointer<GameViewRenderer> m_renderer;
       
    58   bool m_windowChanged;
       
    59   QPointer<EngineInstance> m_engineInstance;
       
    60   QSize m_viewportSize;
       
    61   QPoint m_centerPoint;
       
    62 };
       
    63 
       
    64 #endif  // GAMEVIEW_H