2012-01-06 16:09:03 +00:00
|
|
|
#include "dialogrender.h"
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QPainter>
|
2012-01-29 21:45:58 +00:00
|
|
|
#include "tools.h"
|
2012-01-06 16:09:03 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
|
|
|
#include "../lib_paysages/auto.h"
|
2012-01-06 16:09:03 +00:00
|
|
|
|
|
|
|
static DialogRender* _current_dialog;
|
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
static void _renderStart(int width, int height, Color background)
|
2012-01-06 16:09:03 +00:00
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
delete _current_dialog->pixbuf;
|
|
|
|
_current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32);
|
2012-01-29 21:45:58 +00:00
|
|
|
_current_dialog->pixbuf->fill(colorToQColor(background).rgb());
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _renderDraw(int x, int y, Color col)
|
|
|
|
{
|
2012-01-29 21:45:58 +00:00
|
|
|
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, colorToQColor(col).rgb());
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _renderUpdate(double progress)
|
|
|
|
{
|
|
|
|
_current_dialog->area->update();
|
|
|
|
_current_dialog->progress_value = progress * 1000.0;
|
|
|
|
}
|
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
class RenderThread:public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RenderThread(Renderer* renderer, int width, int height, int quality):QThread()
|
|
|
|
{
|
|
|
|
_renderer = renderer;
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
_quality = quality;
|
|
|
|
}
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
rendererStart(_renderer, _width, _height, _quality);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Renderer* _renderer;
|
|
|
|
int _width;
|
|
|
|
int _height;
|
|
|
|
int _quality;
|
|
|
|
};
|
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
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-04-02 19:38:59 +00:00
|
|
|
DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
|
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-04-02 19:38:59 +00:00
|
|
|
_renderer = renderer;
|
2012-01-06 16:09:03 +00:00
|
|
|
|
|
|
|
setModal(true);
|
2012-02-28 13:45:11 +00:00
|
|
|
setWindowTitle(tr("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-04-11 19:59:50 +00:00
|
|
|
|
|
|
|
// TEMP
|
|
|
|
progress->hide();
|
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)
|
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
rendererInterrupt(_renderer);
|
2012-01-25 17:31:36 +00:00
|
|
|
render_thread->wait();
|
|
|
|
|
|
|
|
delete render_thread;
|
|
|
|
}
|
|
|
|
delete pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogRender::startRender(int quality, int width, int height)
|
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
applyRenderSize(width, height);
|
|
|
|
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
|
2012-04-02 19:10:34 +00:00
|
|
|
|
2012-04-02 19:38:59 +00:00
|
|
|
render_thread = new RenderThread(_renderer, width, height, quality);
|
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-04-02 19:38:59 +00:00
|
|
|
applyRenderSize(_renderer->render_width, _renderer->render_height);
|
2012-01-18 16:20:14 +00:00
|
|
|
progress->hide();
|
2012-04-02 19:38:59 +00:00
|
|
|
rendererSetPreviewCallbacks(_renderer, _renderStart, _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
|
|
|
}
|
2012-04-02 19:38:59 +00:00
|
|
|
|
|
|
|
void DialogRender::applyRenderSize(int width, int height)
|
|
|
|
{
|
|
|
|
area->setMinimumSize(width, height);
|
|
|
|
area->setMaximumSize(width, height);
|
|
|
|
area->resize(width, height);
|
2012-04-11 19:59:50 +00:00
|
|
|
scroll->setMinimumSize(width > 800 ? 820 : width + 20, height > 600 ? 620 : height + 20);
|
2012-04-02 19:38:59 +00:00
|
|
|
}
|