openrw/rwviewer/ViewerWidget.cpp

76 lines
1.4 KiB
C++
Raw Normal View History

2014-02-10 12:41:05 +00:00
#include "ViewerWidget.hpp"
2014-02-11 05:46:29 +00:00
ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
: QGLWidget(parent, shareWidget, f), gworld(nullptr), fm(ViewerWidget::UNK)
{
}
2014-02-10 12:41:05 +00:00
void ViewerWidget::initializeGL()
{
2014-02-10 17:22:07 +00:00
QGLWidget::initializeGL();
timer.setInterval(16);
connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
timer.start();
2014-02-11 05:46:29 +00:00
glewExperimental = 1;
glewInit();
gworld = new GameWorld("");
2014-02-10 12:41:05 +00:00
}
void ViewerWidget::resizeGL(int w, int h)
{
2014-02-10 17:22:07 +00:00
QGLWidget::resizeGL(w, h);
2014-02-11 05:46:29 +00:00
glViewport(0, 0, w, h);
2014-02-10 12:41:05 +00:00
}
void ViewerWidget::paintGL()
{
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
2014-02-10 17:22:07 +00:00
2014-02-11 05:46:29 +00:00
if( !currentFile.isEmpty() ) {
QString dbg =
QString("Viewing %1, %2")
.arg(currentFile);
switch(fm) {
case DFF: dbg = dbg.arg("DFF");
break;
case TXD: dbg = dbg.arg("TXD");
break;
case UNK: dbg = dbg.arg("Unknown");
break;
}
2014-02-10 17:22:07 +00:00
renderText(5, height() - 5, dbg);
}
2014-02-10 12:41:05 +00:00
}
2014-02-10 17:22:07 +00:00
2014-02-11 05:46:29 +00:00
GameWorld* ViewerWidget::world()
{
return gworld;
}
void ViewerWidget::showFile(const QString& file)
2014-02-10 17:22:07 +00:00
{
currentFile = file;
2014-02-11 05:46:29 +00:00
QString low = file.toLower();
if(low.endsWith("dff")) {
showDFF(file);
}
else if(low.endsWith("txd")) {
showTXD(file);
}
emit fileOpened(file);
}
void ViewerWidget::showDFF(const QString& file)
{
gworld->gameData.loadDFF(file.toStdString());
fm = ViewerWidget::DFF;
}
void ViewerWidget::showTXD(const QString& file)
{
fm = ViewerWidget::TXD;
}