From 87382b9934d09cd703ed3f3d1d7aad22018de83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 2 Apr 2012 19:38:59 +0000 Subject: [PATCH] paysages: Restored "save last render" feature. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@283 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/dialogrender.cpp | 54 +++++++++++++------------------------- gui_qt/dialogrender.h | 8 ++++-- gui_qt/formrender.cpp | 58 ++++++++++++++++++++++++++++++++++------- gui_qt/formrender.h | 5 ++++ gui_qt/mainwindow.cpp | 10 +++---- gui_qt/mainwindow.h | 4 +++ i18n/paysages_fr.ts | 44 +++++++++++++++---------------- 7 files changed, 106 insertions(+), 77 deletions(-) diff --git a/gui_qt/dialogrender.cpp b/gui_qt/dialogrender.cpp index dbf81af..4b7a035 100644 --- a/gui_qt/dialogrender.cpp +++ b/gui_qt/dialogrender.cpp @@ -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); +} diff --git a/gui_qt/dialogrender.h b/gui_qt/dialogrender.h index 9e48ab8..77e49fd 100644 --- a/gui_qt/dialogrender.h +++ b/gui_qt/dialogrender.h @@ -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_ diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 9ee215b..81b1c63 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -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)); + } } } diff --git a/gui_qt/formrender.h b/gui_qt/formrender.h index 5657b9a..416bbf3 100644 --- a/gui_qt/formrender.h +++ b/gui_qt/formrender.h @@ -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_ diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index e5d132d..29d4192 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -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() diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index d95e815..64e79b9 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -2,6 +2,7 @@ #define _PAYSAGES_QT_MAINWINDOW_H_ #include +#include "formrender.h" class MainWindow : public QMainWindow { @@ -19,6 +20,9 @@ public slots: void quickPreview(); void explore3D(); + +private: + FormRender* _form_render; }; #endif diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 4354a1d..079bb49 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -156,7 +156,7 @@ Cliquez avec le bouton droit sur un point pour le supprimer. DialogRender - + Paysages 3D - Render Paysages 3D - Rendu @@ -320,47 +320,47 @@ Cliquez avec le bouton droit sur un point pour le supprimer. FormRender - + Camera Caméra - + Quality Qualité de rendu - + Image width Largeur de l'image - + Image height Hauteur de l'image - + Start new render Démarrer un rendu - + Show last render Voir le dernier rendu - + Save last render Sauvegarder le dernier rendu - + Choose a filename to save the last render Choisissez un nom de fichier pour le rendu - + The picture %1 has been saved. L'image %1 a été sauvegardée. @@ -601,62 +601,62 @@ Cliquez avec le bouton droit sur un point pour le supprimer. Rendu - + &Scene &Scène - + &New &Nouvelle - + Crtl+N Ctrl+N - + &Save &Sauvegarder - + Crtl+S Ctrl+S - + &Open &Ouvrir - + Crtl+O Ctrl+O - + &Quit &Quitter - + Crtl+Q Ctrl+Q - + &Actions &Actions - + &Explore in 3D &Explorer en 3D - + &Quick render Rendu r&apide