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-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-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-29 21:45:58 +00:00
|
|
|
renderer = sceneryCreateStandardRenderer();
|
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)
|
|
|
|
{
|
2012-01-29 21:45:58 +00:00
|
|
|
rendererInterrupt(&renderer);
|
2012-01-25 17:31:36 +00:00
|
|
|
render_thread->wait();
|
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
rendererSetPreviewCallbacks(&renderer, NULL, NULL, NULL);
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-01-25 17:31:36 +00:00
|
|
|
delete render_thread;
|
|
|
|
}
|
2012-01-29 21:45:58 +00:00
|
|
|
rendererDelete(&renderer);
|
2012-01-25 17:31:36 +00:00
|
|
|
delete pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogRender::startRender(int quality, int width, int height)
|
|
|
|
{
|
2012-01-29 21:45:58 +00:00
|
|
|
delete pixbuf;
|
|
|
|
pixbuf = new QImage(width, height, QImage::Format_ARGB32);
|
|
|
|
area->setMinimumSize(width, height);
|
|
|
|
area->setMaximumSize(width, height);
|
|
|
|
area->resize(width, height);
|
|
|
|
scroll->setMinimumSize(width > 800 ? 850 : width + 50, height > 600 ? 650 : height + 50);
|
|
|
|
|
|
|
|
rendererSetPreviewCallbacks(&renderer, _renderStart, _renderDraw, _renderUpdate);
|
|
|
|
|
|
|
|
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-01-18 16:20:14 +00:00
|
|
|
progress->hide();
|
2012-01-29 21:45:58 +00:00
|
|
|
//renderSetPreviewCallbacks(_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
|
|
|
}
|