1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 11:22:45 +01:00
openrw/rwviewer/ViewerWidget.hpp

110 lines
2.5 KiB
C++
Raw Normal View History

#ifndef _RWVIEWER_VIEWERWIDGET_HPP_
#define _RWVIEWER_VIEWERWIDGET_HPP_
2016-09-09 22:13:21 +02:00
#include <QTimer>
2017-01-03 15:18:06 +01:00
#include <data/Clump.hpp>
2014-02-11 06:46:29 +01:00
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp>
2014-06-10 21:26:04 +02:00
#include <glm/glm.hpp>
2016-09-09 22:13:21 +02:00
#include <loaders/LoaderIFP.hpp>
2014-02-10 13:41:05 +01:00
2018-02-09 13:26:51 +01:00
// Prevent Qt from conflicting with glLoadGen on macOS
#include "OpenGLCompat.h"
#include <QOpenGLWindow>
2015-04-13 02:48:29 +02:00
class GameRenderer;
2017-01-03 15:18:06 +01:00
class Clump;
class ViewerWidget : public QWindow {
2016-09-09 22:13:21 +02:00
Q_OBJECT
2014-02-10 13:41:05 +01:00
public:
enum class Mode {
//! View an Object, \see showObject
Object,
//! View a DFF model, \see showModel
Model,
//! View loaded instances, \see showWorld();
World,
};
ViewerWidget(QOpenGLContext* context, QWindow* parent);
2016-09-09 22:13:21 +02:00
void initGL();
void paintGL();
2014-06-08 02:58:49 +02:00
void renderNow();
bool event(QEvent*) override;
2014-02-11 06:46:29 +01:00
void exposeEvent(QExposeEvent*) override;
2014-06-08 02:58:49 +02:00
ClumpPtr currentModel() const;
2016-09-09 22:13:21 +02:00
GameObject* currentObject() const;
2016-09-09 22:13:21 +02:00
GameWorld* world();
2014-02-10 18:22:07 +01:00
void setMode(Mode m) {
_viewMode = m;
}
Mode currentMode() const {
return _viewMode;
}
2014-02-10 18:22:07 +01:00
public slots:
void showObject(quint16 item);
void showModel(ClumpPtr model);
2016-09-09 22:13:21 +02:00
void selectFrame(ModelFrame* frame);
void exportModel();
2014-06-10 01:46:48 +02:00
void gameLoaded(GameWorld* world, GameRenderer* renderer);
2015-04-13 02:48:29 +02:00
signals:
2016-09-09 22:13:21 +02:00
void fileOpened(const QString& file);
2014-02-11 06:46:29 +01:00
void modelChanged(ClumpPtr model);
2014-06-10 17:47:44 +02:00
2014-02-11 16:45:45 +01:00
protected:
2016-09-09 22:13:21 +02:00
void keyPressEvent(QKeyEvent*) override;
void keyReleaseEvent(QKeyEvent*) override;
void mousePressEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
void wheelEvent(QWheelEvent*) override;
Mode _viewMode = Mode::World;
QOpenGLContext* context;
GameWorld* _world = nullptr;
GameRenderer* _renderer = nullptr;
ClumpPtr _model;
ModelFrame* selectedFrame = nullptr;
GameObject* _object = nullptr;
quint16 _objectID = 0;
float viewDistance;
glm::vec2 viewAngles{};
glm::vec3 viewPosition{};
bool dragging;
QPointF dstart;
glm::vec2 dastart{};
bool moveFast;
DrawBuffer* _frameWidgetDraw;
GeometryBuffer* _frameWidgetGeom;
GLuint whiteTex;
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
bool initialised = false;
void drawModel(GameRenderer& r, ClumpPtr& model);
void drawObject(GameRenderer& r, GameObject* object);
void drawWorld(GameRenderer& r);
2014-02-10 13:41:05 +01:00
};
2014-03-01 12:19:33 +01:00
#endif