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

View file

@ -17,6 +17,8 @@ FormRender::FormRender(QWidget *parent) :
_width = 800; _width = 800;
_height = 600; _height = 600;
_camera = cameraCreateDefinition(); _camera = cameraCreateDefinition();
_renderer_inited = false;
addInput(new InputCamera(this, tr("Camera"), &_camera)); addInput(new InputCamera(this, tr("Camera"), &_camera));
addInputInt(tr("Quality"), &_quality, 1, 10, 1, 1); addInputInt(tr("Quality"), &_quality, 1, 10, 1, 1);
@ -33,6 +35,14 @@ FormRender::FormRender(QWidget *parent) :
revertConfig(); revertConfig();
} }
FormRender::~FormRender()
{
if (_renderer_inited)
{
rendererDelete(&_renderer);
}
}
void FormRender::revertConfig() void FormRender::revertConfig()
{ {
sceneryGetCamera(&_camera); sceneryGetCamera(&_camera);
@ -51,9 +61,31 @@ void FormRender::configChangeEvent()
BaseForm::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() 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); dialog->startRender(_quality, _width, _height);
delete dialog; delete dialog;
@ -61,20 +93,26 @@ void FormRender::startRender()
void FormRender::showRender() void FormRender::showRender()
{ {
DialogRender* dialog = new DialogRender(this); if (_renderer_inited)
dialog->loadLastRender(); {
DialogRender* dialog = new DialogRender(this, &_renderer);
dialog->loadLastRender();
delete dialog; delete dialog;
}
} }
void FormRender::saveRender() void FormRender::saveRender()
{ {
QString filepath; if (_renderer_inited)
filepath = QFileDialog::getSaveFileName(this, tr("Choose a filename to save the last render"));
if (!filepath.isNull())
{ {
//renderSaveToFile((char*)filepath.toStdString().c_str()); QString filepath;
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(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 "baseform.h"
#include "../lib_paysages/camera.h" #include "../lib_paysages/camera.h"
#include "../lib_paysages/renderer.h"
class FormRender : public BaseForm class FormRender : public BaseForm
{ {
@ -10,10 +11,12 @@ class FormRender : public BaseForm
public: public:
explicit FormRender(QWidget *parent = 0); explicit FormRender(QWidget *parent = 0);
~FormRender();
public slots: public slots:
virtual void revertConfig(); virtual void revertConfig();
virtual void applyConfig(); virtual void applyConfig();
void startQuickRender();
protected slots: protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
@ -28,6 +31,8 @@ private:
int _width; int _width;
int _height; int _height;
CameraDefinition _camera; CameraDefinition _camera;
Renderer _renderer;
bool _renderer_inited;
}; };
#endif // _PAYSAGES_QT_FORMRENDER_H_ #endif // _PAYSAGES_QT_FORMRENDER_H_

View file

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

View file

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

View file

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