paysages: Restored "save last render" feature.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@283 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-04-02 19:38:59 +00:00 committed by ThunderK
parent df7041a82b
commit 87382b9934
7 changed files with 106 additions and 77 deletions

View file

@ -10,11 +10,11 @@
#include "../lib_paysages/auto.h"
static DialogRender* _current_dialog;
static Renderer _renderer;
static bool _renderer_inited = false;
static void _renderStart(int width, int height, Color background)
{
delete _current_dialog->pixbuf;
_current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32);
_current_dialog->pixbuf->fill(colorToQColor(background).rgb());
}
@ -68,12 +68,13 @@ public:
}
};
DialogRender::DialogRender(QWidget *parent):
DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
QDialog(parent, Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)
{
pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
_current_dialog = this;
render_thread = NULL;
_renderer = renderer;
setModal(true);
setWindowTitle(tr("Paysages 3D - Render"));
@ -97,7 +98,7 @@ DialogRender::~DialogRender()
{
if (render_thread)
{
rendererInterrupt(&_renderer);
rendererInterrupt(_renderer);
render_thread->wait();
delete render_thread;
@ -107,23 +108,10 @@ DialogRender::~DialogRender()
void DialogRender::startRender(int quality, int width, int height)
{
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);
applyRenderSize(width, height);
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
if (_renderer_inited)
{
rendererDelete(&_renderer);
}
_renderer = sceneryCreateStandardRenderer();
_renderer_inited = true;
rendererSetPreviewCallbacks(&_renderer, _renderStart, _renderDraw, _renderUpdate);
render_thread = new RenderThread(&_renderer, width, height, quality);
render_thread = new RenderThread(_renderer, width, height, quality);
render_thread->start();
exec();
@ -131,23 +119,17 @@ void DialogRender::startRender(int quality, int width, int height)
void DialogRender::loadLastRender()
{
int width, height;
applyRenderSize(_renderer->render_width, _renderer->render_height);
progress->hide();
if (_renderer_inited)
{
width = _renderer.render_width;
height = _renderer.render_height;
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);
}
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
exec();
}
void DialogRender::applyRenderSize(int width, int height)
{
area->setMinimumSize(width, height);
area->setMaximumSize(width, height);
area->resize(width, height);
scroll->setMinimumSize(width > 800 ? 850 : width + 50, height > 600 ? 650 : height + 50);
}

View file

@ -11,7 +11,7 @@ class DialogRender : public QDialog
{
Q_OBJECT
public:
explicit DialogRender(QWidget *parent);
explicit DialogRender(QWidget *parent, Renderer* renderer);
~DialogRender();
void startRender(int quality, int width, int height);
@ -19,12 +19,16 @@ public:
QImage* pixbuf;
QWidget* area;
QScrollArea* scroll;
QProgressBar* progress;
int progress_value;
public slots:
void applyRenderSize(int width, int height);
private:
QScrollArea* scroll;
QThread* render_thread;
Renderer* _renderer;
};
#endif // _PAYSAGES_QT_DIALOGRENDER_H_

View file

@ -17,6 +17,8 @@ FormRender::FormRender(QWidget *parent) :
_width = 800;
_height = 600;
_camera = cameraCreateDefinition();
_renderer_inited = false;
addInput(new InputCamera(this, tr("Camera"), &_camera));
addInputInt(tr("Quality"), &_quality, 1, 10, 1, 1);
@ -33,6 +35,14 @@ FormRender::FormRender(QWidget *parent) :
revertConfig();
}
FormRender::~FormRender()
{
if (_renderer_inited)
{
rendererDelete(&_renderer);
}
}
void FormRender::revertConfig()
{
sceneryGetCamera(&_camera);
@ -51,9 +61,31 @@ void FormRender::configChangeEvent()
BaseForm::configChangeEvent();
}
void FormRender::startQuickRender()
{
if (_renderer_inited)
{
rendererDelete(&_renderer);
}
_renderer = sceneryCreateStandardRenderer();
_renderer_inited = true;
DialogRender* dialog = new DialogRender(this, &_renderer);
dialog->startRender(3, 400, 300);
delete dialog;
}
void FormRender::startRender()
{
DialogRender* dialog = new DialogRender(this);
if (_renderer_inited)
{
rendererDelete(&_renderer);
}
_renderer = sceneryCreateStandardRenderer();
_renderer_inited = true;
DialogRender* dialog = new DialogRender(this, &_renderer);
dialog->startRender(_quality, _width, _height);
delete dialog;
@ -61,20 +93,26 @@ void FormRender::startRender()
void FormRender::showRender()
{
DialogRender* dialog = new DialogRender(this);
dialog->loadLastRender();
if (_renderer_inited)
{
DialogRender* dialog = new DialogRender(this, &_renderer);
dialog->loadLastRender();
delete dialog;
delete dialog;
}
}
void FormRender::saveRender()
{
QString filepath;
filepath = QFileDialog::getSaveFileName(this, tr("Choose a filename to save the last render"));
if (!filepath.isNull())
if (_renderer_inited)
{
//renderSaveToFile((char*)filepath.toStdString().c_str());
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(filepath));
QString filepath;
filepath = QFileDialog::getSaveFileName(this, tr("Choose a filename to save the last render"));
if (!filepath.isNull())
{
renderSaveToFile(_renderer.render_area, (char*)filepath.toStdString().c_str());
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(filepath));
}
}
}

View file

@ -3,6 +3,7 @@
#include "baseform.h"
#include "../lib_paysages/camera.h"
#include "../lib_paysages/renderer.h"
class FormRender : public BaseForm
{
@ -10,10 +11,12 @@ class FormRender : public BaseForm
public:
explicit FormRender(QWidget *parent = 0);
~FormRender();
public slots:
virtual void revertConfig();
virtual void applyConfig();
void startQuickRender();
protected slots:
virtual void configChangeEvent();
@ -28,6 +31,8 @@ private:
int _width;
int _height;
CameraDefinition _camera;
Renderer _renderer;
bool _renderer_inited;
};
#endif // _PAYSAGES_QT_FORMRENDER_H_

View file

@ -98,9 +98,8 @@ MainWindow::MainWindow(QWidget *parent) :
tabs->addTab(form, tr("Lighting"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));*/
form = new FormRender(tabs);
tabs->addTab(form, tr("Render"));
//QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_form_render = new FormRender(tabs);
tabs->addTab(_form_render, tr("Render"));
menu = menuBar()->addMenu(tr("&Scene"));
menu->addAction(tr("&New"), this, SLOT(fileNew()), QKeySequence(tr("Crtl+N")));
@ -157,10 +156,7 @@ void MainWindow::fileLoad()
void MainWindow::quickPreview()
{
DialogRender* dialog = new DialogRender(this);
dialog->startRender(3, 400, 300);
delete dialog;
_form_render->startQuickRender();
}
void MainWindow::explore3D()

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_QT_MAINWINDOW_H_
#include <QMainWindow>
#include "formrender.h"
class MainWindow : public QMainWindow
{
@ -19,6 +20,9 @@ public slots:
void quickPreview();
void explore3D();
private:
FormRender* _form_render;
};
#endif

View file

@ -156,7 +156,7 @@ Cliquez avec le bouton droit sur un point pour le supprimer.</translation>
<context>
<name>DialogRender</name>
<message>
<location filename="../gui_qt/dialogrender.cpp" line="79"/>
<location filename="../gui_qt/dialogrender.cpp" line="80"/>
<source>Paysages 3D - Render</source>
<translation>Paysages 3D - Rendu</translation>
</message>
@ -320,47 +320,47 @@ Cliquez avec le bouton droit sur un point pour le supprimer.</translation>
<context>
<name>FormRender</name>
<message>
<location filename="../gui_qt/formrender.cpp" line="21"/>
<location filename="../gui_qt/formrender.cpp" line="23"/>
<source>Camera</source>
<translation>Caméra</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="22"/>
<location filename="../gui_qt/formrender.cpp" line="24"/>
<source>Quality</source>
<translation>Qualité de rendu</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="23"/>
<location filename="../gui_qt/formrender.cpp" line="25"/>
<source>Image width</source>
<translation>Largeur de l&apos;image</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="24"/>
<location filename="../gui_qt/formrender.cpp" line="26"/>
<source>Image height</source>
<translation>Hauteur de l&apos;image</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="26"/>
<location filename="../gui_qt/formrender.cpp" line="28"/>
<source>Start new render</source>
<translation>Démarrer un rendu</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="28"/>
<location filename="../gui_qt/formrender.cpp" line="30"/>
<source>Show last render</source>
<translation>Voir le dernier rendu</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="30"/>
<location filename="../gui_qt/formrender.cpp" line="32"/>
<source>Save last render</source>
<translation>Sauvegarder le dernier rendu</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="74"/>
<location filename="../gui_qt/formrender.cpp" line="111"/>
<source>Choose a filename to save the last render</source>
<translation>Choisissez un nom de fichier pour le rendu</translation>
</message>
<message>
<location filename="../gui_qt/formrender.cpp" line="78"/>
<location filename="../gui_qt/formrender.cpp" line="115"/>
<source>The picture %1 has been saved.</source>
<translation>L&apos;image %1 a é sauvegardée.</translation>
</message>
@ -601,62 +601,62 @@ Cliquez avec le bouton droit sur un point pour le supprimer.</translation>
<translation>Rendu</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="105"/>
<location filename="../gui_qt/mainwindow.cpp" line="104"/>
<source>&amp;Scene</source>
<translation>&amp;Scène</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="106"/>
<location filename="../gui_qt/mainwindow.cpp" line="105"/>
<source>&amp;New</source>
<translation>&amp;Nouvelle</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="106"/>
<location filename="../gui_qt/mainwindow.cpp" line="105"/>
<source>Crtl+N</source>
<translation>Ctrl+N</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="108"/>
<location filename="../gui_qt/mainwindow.cpp" line="107"/>
<source>&amp;Save</source>
<translation>&amp;Sauvegarder</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="108"/>
<location filename="../gui_qt/mainwindow.cpp" line="107"/>
<source>Crtl+S</source>
<translation>Ctrl+S</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="109"/>
<location filename="../gui_qt/mainwindow.cpp" line="108"/>
<source>&amp;Open</source>
<translation>&amp;Ouvrir</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="109"/>
<location filename="../gui_qt/mainwindow.cpp" line="108"/>
<source>Crtl+O</source>
<translation>Ctrl+O</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="111"/>
<location filename="../gui_qt/mainwindow.cpp" line="110"/>
<source>&amp;Quit</source>
<translation>&amp;Quitter</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="111"/>
<location filename="../gui_qt/mainwindow.cpp" line="110"/>
<source>Crtl+Q</source>
<translation>Ctrl+Q</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="113"/>
<location filename="../gui_qt/mainwindow.cpp" line="112"/>
<source>&amp;Actions</source>
<translation>&amp;Actions</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="114"/>
<location filename="../gui_qt/mainwindow.cpp" line="113"/>
<source>&amp;Explore in 3D</source>
<translation>&amp;Explorer en 3D</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="115"/>
<location filename="../gui_qt/mainwindow.cpp" line="114"/>
<source>&amp;Quick render</source>
<translation>Rendu r&amp;apide</translation>
</message>