1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

clang-format files in rwviewer

This commit is contained in:
Daniel Evans 2016-09-09 21:13:21 +01:00
parent 8a19f9b5d0
commit d1c33af268
15 changed files with 692 additions and 760 deletions

View File

@ -1,7 +1,6 @@
#include "AnimationListModel.hpp"
QVariant AnimationListModel::data(const QModelIndex& index, int role) const
{
QVariant AnimationListModel::data(const QModelIndex& index, int role) const {
if (role == Qt::DisplayRole) {
if (index.row() >= 0 && (unsigned)index.row() < animations.size()) {
auto& f = animations.at(index.row());
@ -13,8 +12,9 @@ QVariant AnimationListModel::data(const QModelIndex& index, int role) const
return QVariant::Invalid;
}
QVariant AnimationListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant AnimationListModel::headerData(int section,
Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if (section == 0) {
return "Name";
@ -23,13 +23,10 @@ QVariant AnimationListModel::headerData(int section, Qt::Orientation orientation
return QVariant::Invalid;
}
int AnimationListModel::rowCount(const QModelIndex& parent) const
{
int AnimationListModel::rowCount(const QModelIndex& parent) const {
return animations.size();
}
int AnimationListModel::columnCount(const QModelIndex& parent) const
{
int AnimationListModel::columnCount(const QModelIndex& parent) const {
return 1;
}

View File

@ -6,27 +6,29 @@
typedef std::vector<std::pair<std::string, Animation*>> AnimationList;
class AnimationListModel : public QAbstractListModel
{
class AnimationListModel : public QAbstractListModel {
Q_OBJECT
AnimationList animations;
public:
AnimationListModel(const AnimationList& anims, QObject* parent = 0)
: QAbstractListModel(parent), animations(anims)
{}
: QAbstractListModel(parent), animations(anims) {
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
const AnimationList& getAnimations() const { return animations; }
const AnimationList& getAnimations() const {
return animations;
}
};
#endif

View File

@ -2,8 +2,7 @@
#include <QVBoxLayout>
AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
{
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
setWindowTitle("Animations");
QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget();
@ -19,12 +18,13 @@ AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
filter = new QSortFilterProxyModel;
table->setModel(filter);
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
}
void AnimationListWidget::setAnimations(const AnimationList& archive)
{
void AnimationListWidget::setAnimations(const AnimationList& archive) {
auto m = new AnimationListModel(archive);
filter->setSourceModel(m);
if (model) {
@ -33,8 +33,7 @@ void AnimationListWidget::setAnimations(const AnimationList& archive)
model = m;
}
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current)
{
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) {
auto mts = filter->mapToSource(current);
if (mts.row() >= 0 && (unsigned)mts.row() < model->getAnimations().size()) {
auto& f = model->getAnimations().at(mts.row());
@ -42,7 +41,6 @@ void AnimationListWidget::selectedIndexChanged(const QModelIndex& current)
}
}
void AnimationListWidget::setFilter(const QString &f)
{
void AnimationListWidget::setFilter(const QString& f) {
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
}

View File

@ -2,13 +2,12 @@
#ifndef _ANIMATIONLISTWIDGET_HPP_
#define _ANIMATIONLISTWIDGET_HPP_
#include <QDockWidget>
#include <QListView>
#include <QLineEdit>
#include <QListView>
#include <QSortFilterProxyModel>
#include "AnimationListModel.hpp"
class AnimationListWidget : public QDockWidget
{
class AnimationListWidget : public QDockWidget {
Q_OBJECT
QSortFilterProxyModel* filter;
@ -17,7 +16,6 @@ class AnimationListWidget : public QDockWidget
QLineEdit* searchbox;
public:
AnimationListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
void setAnimations(const AnimationList& anims);

View File

@ -1,9 +1,9 @@
#include "IMGArchiveModel.hpp"
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const
{
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const {
if (role == Qt::DisplayRole) {
if(index.row() >= 0 && (unsigned) index.row() < archive.getAssetCount()) {
if (index.row() >= 0 &&
(unsigned)index.row() < archive.getAssetCount()) {
auto& f = archive.getAssetInfoByIndex(index.row());
if (index.column() == 0) {
return QString(f.name);
@ -16,8 +16,8 @@ QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const
return QVariant::Invalid;
}
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if (section == 0) {
return "Name";
@ -29,13 +29,10 @@ QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation, i
return QVariant::Invalid;
}
int IMGArchiveModel::rowCount(const QModelIndex& parent) const
{
int IMGArchiveModel::rowCount(const QModelIndex& parent) const {
return archive.getAssetCount();
}
int IMGArchiveModel::columnCount(const QModelIndex& parent) const
{
int IMGArchiveModel::columnCount(const QModelIndex& parent) const {
return 2;
}

View File

@ -4,27 +4,29 @@
#include <QAbstractItemModel>
#include <loaders/LoaderIMG.hpp>
class IMGArchiveModel : public QAbstractListModel
{
class IMGArchiveModel : public QAbstractListModel {
Q_OBJECT
LoaderIMG archive;
public:
IMGArchiveModel(const LoaderIMG& archive, QObject* parent = 0)
: QAbstractListModel(parent), archive(archive)
{}
: QAbstractListModel(parent), archive(archive) {
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
const LoaderIMG& getArchive() const { return archive; }
const LoaderIMG& getArchive() const {
return archive;
}
};
#endif

View File

@ -1,48 +1,41 @@
#include "ItemListModel.hpp"
#include <engine/GameData.hpp>
qint16 ItemListModel::getIDOf(unsigned int row) const
{
if( row < world()->data->objectTypes.size() )
{
qint16 ItemListModel::getIDOf(unsigned int row) const {
if (row < world()->data->objectTypes.size()) {
return row;
}
return -1;
}
ItemListModel::ItemListModel(GameWorld *world, QObject *parent) :
QAbstractTableModel(parent), _world( world )
{
ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
: QAbstractTableModel(parent), _world(world) {
}
int ItemListModel::rowCount(const QModelIndex &parent) const
{
int ItemListModel::rowCount(const QModelIndex &parent) const {
return _world->data->objectTypes.size();
}
int ItemListModel::columnCount(const QModelIndex &parent) const
{
int ItemListModel::columnCount(const QModelIndex &parent) const {
return 2;
}
QVariant ItemListModel::data(const QModelIndex &index, int role) const
{
QVariant ItemListModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
qint16 id = getIDOf(index.row());
if (id == -1) return QVariant::Invalid;
if (index.column() == 0) {
return id;
}
else if ( index.column() == 1 ) {
} else if (index.column() == 1) {
return QString::fromStdString("TODO");
}
}
return QVariant::Invalid;
}
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if (section == 0) {
return "ID";
@ -54,7 +47,9 @@ QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int
return QVariant::Invalid;
}
QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const
{
return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex();
QModelIndex ItemListModel::index(int row, int column,
const QModelIndex &parent) const {
return hasIndex(row, column, parent)
? createIndex(row, column, getIDOf(row))
: QModelIndex();
}

View File

@ -5,8 +5,7 @@
#include <engine/GameWorld.hpp>
class ItemListModel : public QAbstractTableModel
{
class ItemListModel : public QAbstractTableModel {
Q_OBJECT
GameWorld* _world;
@ -14,7 +13,9 @@ class ItemListModel : public QAbstractTableModel
public:
explicit ItemListModel(GameWorld* _world, QObject* parent = 0);
GameWorld* world() const { return _world; }
GameWorld* world() const {
return _world;
}
qint16 getIDOf(unsigned int row) const;
@ -22,9 +23,11 @@ public:
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex& parent) const;
};

View File

@ -1,10 +1,9 @@
#include "ItemListWidget.hpp"
#include <QVBoxLayout>
#include <QHeaderView>
#include <QVBoxLayout>
ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
{
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
setWindowTitle("Items");
QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget();
@ -22,26 +21,25 @@ ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
filter = new QSortFilterProxyModel;
table->setModel(filter);
filter->setFilterKeyColumn(-1); // Search all columns
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
}
void ItemListWidget::worldLoaded(GameWorld *world)
{
void ItemListWidget::worldLoaded(GameWorld* world) {
if (model) delete model;
model = new ItemListModel(world, this);
filter->setSourceModel(model);
}
void ItemListWidget::selectedIndexChanged(const QModelIndex& current)
{
void ItemListWidget::selectedIndexChanged(const QModelIndex& current) {
auto mts = filter->mapToSource(current);
if (mts.isValid()) {
emit selectedItemChanged(model->getIDOf(mts.row()));
}
}
void ItemListWidget::setFilter(const QString &f)
{
void ItemListWidget::setFilter(const QString& f) {
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
}

View File

@ -2,13 +2,12 @@
#ifndef _ITEMLISTWIDGET_HPP_
#define _ITEMLISTWIDGET_HPP_
#include <QDockWidget>
#include <QTableView>
#include <QLineEdit>
#include <QSortFilterProxyModel>
#include <QTableView>
#include "ItemListModel.hpp"
class ItemListWidget : public QDockWidget
{
class ItemListWidget : public QDockWidget {
Q_OBJECT
QSortFilterProxyModel* filter;

View File

@ -1,21 +1,21 @@
#include "ViewerWidget.hpp"
#include <QFileDialog>
#include <QMouseEvent>
#include <algorithm>
#include <data/Model.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <objects/GameObject.hpp>
#include <render/GameRenderer.hpp>
#include <render/OpenGLRenderer.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <QMouseEvent>
#include <objects/GameObject.hpp>
#include <engine/Animator.hpp>
#include <data/Skeleton.hpp>
#include <QFileDialog>
#include <algorithm>
#include <objects/InstanceObject.hpp>
#include <objects/CharacterObject.hpp>
#include <objects/InstanceObject.hpp>
#include <objects/VehicleObject.hpp>
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent,
const QGLWidget* shareWidget, Qt::WindowFlags f)
: QGLWidget(g, parent, shareWidget, f)
, gworld(nullptr)
, activeModel(nullptr)
@ -28,31 +28,22 @@ ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareW
, dragging(false)
, moveFast(false)
, _frameWidgetDraw(nullptr)
, _frameWidgetGeom(nullptr)
{
, _frameWidgetGeom(nullptr) {
setFocusPolicy(Qt::StrongFocus);
}
struct WidgetVertex {
float x, y, z;
static const AttributeList vertex_attributes() {
return {
{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}
};
return {{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}};
}
};
std::vector<WidgetVertex> widgetVerts = {
{-.5f, 0.f, 0.f},
{ .5f, 0.f, 0.f},
{ 0.f,-.5f, 0.f},
{ 0.f, .5f, 0.f},
{ 0.f, 0.f,-.5f},
{ 0.f, 0.f, .5f}
};
std::vector<WidgetVertex> widgetVerts = {{-.5f, 0.f, 0.f}, {.5f, 0.f, 0.f},
{0.f, -.5f, 0.f}, {0.f, .5f, 0.f},
{0.f, 0.f, -.5f}, {0.f, 0.f, .5f}};
void ViewerWidget::initializeGL()
{
void ViewerWidget::initializeGL() {
QGLWidget::initializeGL();
timer.setInterval(25);
connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
@ -67,19 +58,18 @@ void ViewerWidget::initializeGL()
glGenTextures(1, &whiteTex);
glBindTexture(GL_TEXTURE_2D, whiteTex);
GLuint tex = 0xFFFFFFFF;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE,
&tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
void ViewerWidget::resizeGL(int w, int h)
{
void ViewerWidget::resizeGL(int w, int h) {
QGLWidget::resizeGL(w, h);
glViewport(0, 0, w, h);
}
void ViewerWidget::paintGL()
{
void ViewerWidget::paintGL() {
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -121,14 +111,18 @@ void ViewerWidget::paintGL()
emit modelChanged(_lastModel);
}
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y), cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y),
cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
if( model )
{
if (model) {
glm::mat4 proj = vc.frustum.projection();
glm::mat4 view = glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f));
glm::mat4 view =
glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f),
glm::vec3(0.f, 0.f, 1.f));
r.getRenderer()->setSceneParameters({ proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f), glm::vec4(0.f), 90.f, vc.frustum.far });
r.getRenderer()->setSceneParameters(
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
glm::vec4(0.f), 90.f, vc.frustum.far});
r.getRenderer()->invalidate();
@ -138,36 +132,30 @@ void ViewerWidget::paintGL()
drawFrameWidget(model->frames[model->rootFrameIdx]);
r.renderPostProcess();
}
else if (world()->allObjects.size() > 0)
{
} else if (world()->allObjects.size() > 0) {
vc.frustum.fov = glm::radians(90.f);
vc.frustum.far = 1000.f;
vc.position = viewPosition;
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x, glm::vec3(0.f, 0.f, 1.f))
* glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f));
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x,
glm::vec3(0.f, 0.f, 1.f)) *
glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f));
r.renderWorld(world(), vc, 0.f);
}
}
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m)
{
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
auto thisM = m * f->getTransform();
if(f->getGeometries().size() == 0)
{
if (f->getGeometries().size() == 0) {
Renderer::DrawParameters dp;
dp.count = _frameWidgetGeom->getCount();
dp.start = 0;
dp.ambient = 1.f;
dp.diffuse = 1.f;
if( f == selectedFrame )
{
if (f == selectedFrame) {
dp.colour = {255, 255, 0, 255};
// Sorry!
glLineWidth(10.f);
}
else
{
} else {
dp.colour = {255, 255, 255, 255};
glLineWidth(1.f);
}
@ -180,31 +168,23 @@ void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m)
}
}
GameWorld* ViewerWidget::world()
{
GameWorld* ViewerWidget::world() {
return gworld;
}
void ViewerWidget::showObject(qint16 item)
{
void ViewerWidget::showObject(qint16 item) {
currentObjectID = item;
if (dummyObject) gworld->destroyObject(dummyObject);
auto def = world()->data->objectTypes[item];
if( def )
{
if(def->class_type == ObjectData::class_id)
{
if (def) {
if (def->class_type == ObjectData::class_id) {
dummyObject = gworld->createInstance(item, {});
}
else if(def->class_type == CharacterData::class_id)
{
} else if (def->class_type == CharacterData::class_id) {
dummyObject = gworld->createPedestrian(item, {});
}
else if(def->class_type == VehicleData::class_id)
{
} else if (def->class_type == VehicleData::class_id) {
dummyObject = gworld->createVehicle(item, {});
}
RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
@ -214,24 +194,19 @@ void ViewerWidget::showObject(qint16 item)
}
}
void ViewerWidget::showModel(Model* model)
{
void ViewerWidget::showModel(Model* model) {
if (dummyObject) gworld->destroyObject(dummyObject);
dummyObject = nullptr;
activeModel = model;
}
void ViewerWidget::selectFrame(ModelFrame* frame)
{
void ViewerWidget::selectFrame(ModelFrame* frame) {
selectedFrame = frame;
}
void ViewerWidget::exportModel()
{
QString toSv = QFileDialog::getSaveFileName(this,
"Export Model",
QDir::homePath(),
"Model (*.DFF)");
void ViewerWidget::exportModel() {
QString toSv = QFileDialog::getSaveFileName(
this, "Export Model", QDir::homePath(), "Model (*.DFF)");
if (toSv.size() == 0) return;
@ -252,77 +227,60 @@ void ViewerWidget::exportModel()
#endif
}
void ViewerWidget::dataLoaded(GameWorld *world)
{
void ViewerWidget::dataLoaded(GameWorld* world) {
gworld = world;
}
void ViewerWidget::setRenderer(GameRenderer *render)
{
void ViewerWidget::setRenderer(GameRenderer* render) {
renderer = render;
}
void ViewerWidget::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Shift)
moveFast = true;
void ViewerWidget::keyPressEvent(QKeyEvent* e) {
if (e->key() == Qt::Key_Shift) moveFast = true;
glm::vec3 movement;
if (e->key() == Qt::Key_W)
movement.y += moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_S)
movement.y -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_A)
movement.x -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_D)
movement.x += moveFast? 10.f : 1.f;
if (e->key() == Qt::Key_W) movement.y += moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_S) movement.y -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_A) movement.x -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_D) movement.x += moveFast ? 10.f : 1.f;
if (movement.length() > 0.f)
{
movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f))
* glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) * movement;
if (movement.length() > 0.f) {
movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) *
glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) *
movement;
viewPosition += movement;
}
}
void ViewerWidget::keyReleaseEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Shift)
moveFast = false;
void ViewerWidget::keyReleaseEvent(QKeyEvent* e) {
if (e->key() == Qt::Key_Shift) moveFast = false;
}
Model* ViewerWidget::currentModel() const
{
Model* ViewerWidget::currentModel() const {
return activeModel;
}
GameObject* ViewerWidget::currentObject() const
{
GameObject* ViewerWidget::currentObject() const {
return dummyObject;
}
void ViewerWidget::mousePressEvent(QMouseEvent* e)
{
void ViewerWidget::mousePressEvent(QMouseEvent* e) {
dragging = true;
dstart = e->localPos();
dastart = viewAngles;
}
void ViewerWidget::mouseReleaseEvent(QMouseEvent*)
{
void ViewerWidget::mouseReleaseEvent(QMouseEvent*) {
dragging = false;
}
void ViewerWidget::mouseMoveEvent(QMouseEvent* e)
{
void ViewerWidget::mouseMoveEvent(QMouseEvent* e) {
if (dragging) {
auto d = e->localPos() - dstart;
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
}
}
void ViewerWidget::wheelEvent(QWheelEvent* e)
{
void ViewerWidget::wheelEvent(QWheelEvent* e) {
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
}

View File

@ -1,14 +1,14 @@
#pragma once
#ifndef _VIEWERWIDGET_HPP_
#define _VIEWERWIDGET_HPP_
#include <QTimer>
#include <data/Model.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <QTimer>
#include <loaders/LoaderIFP.hpp>
#include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp>
#include <data/Model.hpp>
#include <glm/glm.hpp>
#include <loaders/LoaderIFP.hpp>
// Prevent Qt from conflicting with glLoadGen
#define GL_ARB_debug_output
@ -17,8 +17,7 @@
class GameRenderer;
class Model;
class ViewerWidget : public QGLWidget
{
class ViewerWidget : public QGLWidget {
Q_OBJECT
GameRenderer* renderer;
@ -50,9 +49,10 @@ class ViewerWidget : public QGLWidget
GLuint whiteTex;
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
public:
ViewerWidget(QGLFormat g, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
public:
ViewerWidget(QGLFormat g, QWidget* parent = 0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual void initializeGL();
@ -84,7 +84,6 @@ signals:
void modelChanged(Model* model);
protected:
void keyPressEvent(QKeyEvent*) override;
void keyReleaseEvent(QKeyEvent*) override;
void mousePressEvent(QMouseEvent*) override;

View File

@ -1,22 +1,22 @@
#include "ViewerWindow.hpp"
#include "views/ObjectViewer.hpp"
#include "views/ModelViewer.hpp"
#include "views/WorldViewer.hpp"
#include <ViewerWidget.hpp>
#include "views/ModelViewer.hpp"
#include "views/ObjectViewer.hpp"
#include "views/WorldViewer.hpp"
#include <engine/GameState.hpp>
#include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp>
#include <QMenuBar>
#include <QFileDialog>
#include <QApplication>
#include <QSettings>
#include <QPushButton>
#include <QSignalMapper>
#include <QDebug>
#include <fstream>
#include <QFileDialog>
#include <QMenuBar>
#include <QOffscreenSurface>
#include <QPushButton>
#include <QSettings>
#include <QSignalMapper>
#include <fstream>
static int MaxRecentGames = 5;
@ -24,8 +24,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
, gameData(nullptr)
, gameWorld(nullptr)
, renderer(nullptr)
{
, renderer(nullptr) {
setMinimumSize(640, 480);
QMenuBar* mb = this->menuBar();
@ -43,7 +42,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
recentSep = file->addSeparator();
auto ex = file->addAction("E&xit");
ex->setShortcut(QKeySequence::Quit);
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));
connect(ex, SIGNAL(triggered()), QApplication::instance(),
SLOT(closeAllWindows()));
//----------------------- View Mode setup
@ -53,7 +53,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
viewerWidget = new ViewerWidget(glFormat);
viewerWidget->context()->makeCurrent();
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*)));
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget,
SLOT(dataLoaded(GameWorld*)));
//------------- Object Viewer
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
@ -74,7 +75,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
int i = 0;
for (auto viewer : m_views) {
viewSwitcher->addWidget(viewer);
connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*)));
connect(this, SIGNAL(loadedData(GameWorld*)), viewer,
SLOT(showData(GameWorld*)));
auto viewerButton = new QPushButton(m_viewNames[i].c_str());
signalMapper->setMapping(m_views[i], i);
@ -84,16 +86,21 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
i++;
}
// Map world viewer loading placements to switch to the world viewer
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map()));
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)),
signalMapper, SLOT(map()));
switchView(ViewMode::Object);
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString)));
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this,
SLOT(showObjectModel(uint16_t)));
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)),
m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model],
SLOT(loadAnimations(QString)));
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int)));
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher,
SLOT(setCurrentIndex(int)));
switchPanel->addStretch();
auto mainlayout = new QHBoxLayout();
@ -109,15 +116,15 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
anim->addAction("Load &Animations", this, SLOT(openAnimations()));
QMenu* map = mb->addMenu("&Map");
map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements()));
map->addAction("Load IPL", m_views[ViewMode::World],
SLOT(loadPlacements()));
this->setCentralWidget(mainwidget);
updateRecentGames();
}
void ViewerWindow::showEvent(QShowEvent*)
{
void ViewerWindow::showEvent(QShowEvent*) {
static bool first = true;
if (first) {
QSettings settings("OpenRW", "rwviewer");
@ -127,39 +134,35 @@ void ViewerWindow::showEvent(QShowEvent*)
}
}
void ViewerWindow::closeEvent(QCloseEvent* event)
{
void ViewerWindow::closeEvent(QCloseEvent* event) {
QSettings settings("OpenRW", "rwviewer");
settings.setValue("window/geometry", saveGeometry());
settings.setValue("window/windowState", saveState());
QMainWindow::closeEvent(event);
}
void ViewerWindow::openAnimations()
{
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)");
void ViewerWindow::openAnimations() {
QFileDialog dialog(this, "Open Animations", QDir::homePath(),
"IFP Animations (*.ifp)");
if (dialog.exec()) {
loadAnimations(dialog.selectedFiles()[0]);
}
}
void ViewerWindow::loadGame()
{
void ViewerWindow::loadGame() {
QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"),
QDir::homePath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
this, tr("Open Directory"), QDir::homePath(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.size() > 0) loadGame(dir);
}
void ViewerWindow::loadGame(const QString &path)
{
void ViewerWindow::loadGame(const QString& path) {
QDir gameDir(path);
if (gameDir.exists() && path.size() > 0) {
gameData = new GameData( &engineLog, &work, gameDir.absolutePath().toStdString() );
gameData = new GameData(&engineLog, &work,
gameDir.absolutePath().toStdString());
gameWorld = new GameWorld(&engineLog, &work, gameData);
renderer = new GameRenderer(&engineLog, gameData);
gameWorld->state = new GameState;
@ -180,35 +183,29 @@ void ViewerWindow::loadGame(const QString &path)
updateRecentGames();
}
void ViewerWindow::openRecent()
{
void ViewerWindow::openRecent() {
QAction* r = qobject_cast<QAction*>(sender());
if (r) {
loadGame(r->data().toString());
}
}
void ViewerWindow::switchView(int mode)
{
if( mode < int(m_views.size()) )
{
void ViewerWindow::switchView(int mode) {
if (mode < int(m_views.size())) {
m_views[mode]->setViewerWidget(viewerWidget);
}
else
{
} else {
RW_ERROR("Unhandled view mode" << mode);
}
}
void ViewerWindow::showObjectModel(uint16_t)
{
void ViewerWindow::showObjectModel(uint16_t) {
// Switch to the model viewer
switchView(ViewMode::Model);
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) );
viewSwitcher->setCurrentIndex(
viewSwitcher->indexOf(m_views[ViewMode::Model]));
}
void ViewerWindow::updateRecentGames()
{
void ViewerWindow::updateRecentGames() {
QSettings settings("OpenRW", "rwviewer");
QStringList recent = settings.value("recentGames").toStringList();
@ -218,13 +215,10 @@ void ViewerWindow::updateRecentGames()
recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
recentGames[i]->setData(recent[i]);
recentGames[i]->setVisible(true);
}
else {
} else {
recentGames[i]->setVisible(false);
}
}
recentSep->setVisible(recent.size() > 0);
}

View File

@ -1,9 +1,9 @@
#pragma once
#ifndef _VIEWERWINDOW_HPP_
#define _VIEWERWINDOW_HPP_
#include <core/Logger.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <core/Logger.hpp>
#include <QMainWindow>
#include <QStackedWidget>
@ -16,16 +16,10 @@ class ViewerInterface;
class GameRenderer;
class QGLContext;
class ViewerWindow : public QMainWindow
{
class ViewerWindow : public QMainWindow {
Q_OBJECT
enum ViewMode {
Object = 0,
Model = 1,
World = 2,
_Count
};
enum ViewMode { Object = 0, Model = 1, World = 2, _Count };
Logger engineLog;
WorkContext work;
@ -44,8 +38,8 @@ class ViewerWindow : public QMainWindow
QStackedWidget* viewSwitcher;
QGLContext* context;
public:
public:
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
/**
@ -80,7 +74,6 @@ private slots:
void showObjectModel(uint16_t object);
private:
QList<QAction*> recentGames;
QAction* recentSep;
void updateRecentGames();

View File

@ -2,8 +2,7 @@
#include <QStyleFactory>
#include "ViewerWindow.hpp"
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
ViewerWindow viewer;