2012-01-06 16:09:03 +00:00
|
|
|
#include "dialogrender.h"
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/render.h"
|
|
|
|
#include "../lib_paysages/scenery.h"
|
|
|
|
#include "../lib_paysages/auto.h"
|
2012-01-06 16:09:03 +00:00
|
|
|
|
|
|
|
class RenderThread:public QThread
|
|
|
|
{
|
|
|
|
public:
|
2012-01-24 13:16:20 +00:00
|
|
|
RenderThread(Renderer* renderer):QThread()
|
|
|
|
{
|
|
|
|
_renderer = renderer;
|
|
|
|
}
|
2012-01-06 16:09:03 +00:00
|
|
|
void run()
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
autoRenderSceneTwoPass(_renderer, 0);
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
private:
|
|
|
|
Renderer* _renderer;
|
2012-01-06 16:09:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static DialogRender* _current_dialog;
|
|
|
|
|
|
|
|
static void _renderResize(int width, int height)
|
|
|
|
{
|
|
|
|
delete _current_dialog->pixbuf;
|
|
|
|
_current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32);
|
|
|
|
_current_dialog->area->setMinimumSize(width, height);
|
|
|
|
_current_dialog->area->setMaximumSize(width, height);
|
|
|
|
_current_dialog->area->resize(width, height);
|
2012-01-18 16:20:14 +00:00
|
|
|
_current_dialog->scroll->setMinimumSize(width > 800 ? 850 : width + 50, height > 600 ? 650 : height + 50);
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _renderClear(Color col)
|
|
|
|
{
|
|
|
|
_current_dialog->pixbuf->fill(QColor(col.r * 255.0, col.g * 255.0, col.b * 255.0).rgb());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _renderDraw(int x, int y, Color col)
|
|
|
|
{
|
|
|
|
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, QColor(col.r * 255.0, col.g * 255.0, col.b * 255.0).rgb());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _renderUpdate(double progress)
|
|
|
|
{
|
|
|
|
_current_dialog->area->update();
|
|
|
|
_current_dialog->progress_value = progress * 1000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class RenderArea:public QWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RenderArea(QWidget* parent):
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
setMinimumSize(800, 600);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.drawImage(0, 0, *_current_dialog->pixbuf);
|
|
|
|
_current_dialog->progress->setValue(_current_dialog->progress_value);
|
|
|
|
_current_dialog->progress->update();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-18 16:20:14 +00:00
|
|
|
DialogRender::DialogRender(QWidget *parent):
|
2012-01-26 18:20:19 +00:00
|
|
|
QDialog(parent, Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)
|
2012-01-06 16:09:03 +00:00
|
|
|
{
|
|
|
|
pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
|
|
|
|
_current_dialog = this;
|
2012-01-18 16:20:14 +00:00
|
|
|
render_thread = NULL;
|
2012-01-06 16:09:03 +00:00
|
|
|
|
|
|
|
setModal(true);
|
2012-01-16 21:29:21 +00:00
|
|
|
setWindowTitle("Paysages 3D - Render");
|
2012-01-06 16:09:03 +00:00
|
|
|
setLayout(new QVBoxLayout());
|
|
|
|
|
|
|
|
scroll = new QScrollArea(this);
|
|
|
|
scroll->setAlignment(Qt::AlignCenter);
|
|
|
|
area = new RenderArea(scroll);
|
|
|
|
scroll->setWidget(area);
|
|
|
|
layout()->addWidget(scroll);
|
|
|
|
|
|
|
|
progress = new QProgressBar(this);
|
|
|
|
progress->setMinimum(0);
|
|
|
|
progress->setMaximum(1000);
|
2012-01-10 20:51:27 +00:00
|
|
|
progress->setValue(0);
|
2012-01-06 16:09:03 +00:00
|
|
|
layout()->addWidget(progress);
|
|
|
|
progress_value = 0;
|
2012-01-18 16:20:14 +00:00
|
|
|
}
|
2012-01-06 16:09:03 +00:00
|
|
|
|
2012-01-25 17:31:36 +00:00
|
|
|
DialogRender::~DialogRender()
|
2012-01-18 16:20:14 +00:00
|
|
|
{
|
2012-01-25 17:31:36 +00:00
|
|
|
if (render_thread)
|
|
|
|
{
|
|
|
|
renderInterrupt();
|
|
|
|
render_thread->wait();
|
|
|
|
|
|
|
|
renderSetPreviewCallbacks(NULL, NULL, NULL, NULL);
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-01-25 17:31:36 +00:00
|
|
|
delete render_thread;
|
|
|
|
}
|
|
|
|
delete pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogRender::startRender(int quality, int width, int height)
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
renderer = sceneryGetStandardRenderer(quality);
|
|
|
|
renderSetSize(width, height);
|
2012-01-06 16:09:03 +00:00
|
|
|
renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate);
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
render_thread = new RenderThread(&renderer);
|
2012-01-06 16:09:03 +00:00
|
|
|
render_thread->start();
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-18 16:20:14 +00:00
|
|
|
exec();
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-01-18 16:20:14 +00:00
|
|
|
void DialogRender::loadLastRender()
|
2012-01-10 20:51:27 +00:00
|
|
|
{
|
2012-01-18 16:20:14 +00:00
|
|
|
progress->hide();
|
|
|
|
renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate);
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-18 16:20:14 +00:00
|
|
|
exec();
|
2012-01-10 20:51:27 +00:00
|
|
|
}
|