From 834f96d3a6b0b76898ae2d504f354c1c091a74ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 27 Jun 2012 10:30:00 +0000 Subject: [PATCH] paysages : Added GUI state saving/loading. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@364 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- ChangeLog | 1 + TODO | 1 - gui_qt/baseform.cpp | 22 ++++++++++ gui_qt/baseform.h | 3 ++ gui_qt/basepreview.cpp | 15 +++++++ gui_qt/basepreview.h | 4 ++ gui_qt/formrender.cpp | 22 ++++++++++ gui_qt/formrender.h | 3 ++ gui_qt/mainwindow.cpp | 37 +++++++++++++++++ gui_qt/mainwindow.h | 7 ++++ i18n/paysages_fr.ts | 92 +++++++++++++++++++++--------------------- lib_paysages/scenery.c | 42 ++++++++++++++----- lib_paysages/scenery.h | 4 ++ 13 files changed, 197 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index a208575..6fbf3e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ GUI : * Improved curve rendering. * New material editor. * Added render timer. + * Previews locations and render params are now saved. * Added camera location to previews. Misc : diff --git a/TODO b/TODO index 8052cfa..68c89c4 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,6 @@ Technology Preview 2 : - Render tab previews should not rerender when changing render options. - Add layer sorting/naming. - Add logarithmic sliders for some float values. -- Save GUI config (views, render params). - Improve previews. => Add a right click menu for toggles and modes => Add user markers on OSD diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 608c1cc..b203b13 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -104,6 +104,28 @@ void BaseForm::hideButtons() button_revert->hide(); } +void BaseForm::savePack(PackStream* stream) +{ + // Save previews status + // TODO Ensure same order in save and load + QList list_previews = previews->findChildren("_form_preview_"); + for (int i = 0; i < list_previews.size(); i++) + { + list_previews[i]->savePack(stream); + } +} + +void BaseForm::loadPack(PackStream* stream) +{ + // Load previews status + // TODO Ensure same order in save and load + QList list_previews = previews->findChildren("_form_preview_"); + for (int i = 0; i < list_previews.size(); i++) + { + list_previews[i]->loadPack(stream); + } +} + void BaseForm::configChangeEvent() { if (auto_apply) diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 9f94074..0f7f84c 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -10,6 +10,7 @@ #include "../lib_paysages/noise.h" #include "../lib_paysages/curve.h" #include "../lib_paysages/color.h" +#include "../lib_paysages/pack.h" class BaseForm:public QWidget { @@ -18,6 +19,8 @@ class BaseForm:public QWidget public: BaseForm(QWidget* parent, bool auto_apply=false, bool with_layers=false); void hideButtons(); + virtual void savePack(PackStream* stream); + virtual void loadPack(PackStream* stream); signals: void configApplied(); diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index 4a09383..da70358 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -309,6 +309,21 @@ void BasePreview::addOsd(QString name) setMouseTracking(true); } +void BasePreview::savePack(PackStream* stream) +{ + packWriteDouble(stream, &this->xoffset); + packWriteDouble(stream, &this->yoffset); + packWriteDouble(stream, &this->scaling); +} + +void BasePreview::loadPack(PackStream* stream) +{ + packReadDouble(stream, &this->xoffset); + packReadDouble(stream, &this->yoffset); + packReadDouble(stream, &this->scaling); + emit contentChange(); +} + void BasePreview::initDrawers() { _drawing_manager = new PreviewDrawingManager(); diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index 169b529..52eba54 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -9,6 +9,7 @@ #include #include #include "previewosd.h" +#include "../lib_paysages/pack.h" class BasePreview : public QWidget { Q_OBJECT @@ -19,6 +20,9 @@ public: void addOsd(QString name); + virtual void savePack(PackStream* stream); + virtual void loadPack(PackStream* stream); + static void initDrawers(); static void stopDrawers(); static void reviveAll(); diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index ccfbfcc..1cb415b 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -143,6 +143,28 @@ FormRender::~FormRender() } } +void FormRender::savePack(PackStream* stream) +{ + BaseForm::savePack(stream); + + packWriteInt(stream, &_params.width); + packWriteInt(stream, &_params.height); + packWriteInt(stream, &_params.antialias); + packWriteInt(stream, &_params.quality); +} + +void FormRender::loadPack(PackStream* stream) +{ + BaseForm::loadPack(stream); + + packReadInt(stream, &_params.width); + packReadInt(stream, &_params.height); + packReadInt(stream, &_params.antialias); + packReadInt(stream, &_params.quality); + + revertConfig(); +} + void FormRender::revertConfig() { sceneryGetCamera(&_camera); diff --git a/gui_qt/formrender.h b/gui_qt/formrender.h index eed7bd3..c5d7123 100644 --- a/gui_qt/formrender.h +++ b/gui_qt/formrender.h @@ -14,6 +14,9 @@ public: explicit FormRender(QWidget *parent = 0); ~FormRender(); + virtual void savePack(PackStream* stream); + virtual void loadPack(PackStream* stream); + public slots: virtual void revertConfig(); virtual void applyConfig(); diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 9b3d91f..c0920b8 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -27,6 +27,7 @@ #include "../lib_paysages/main.h" #include "../lib_paysages/auto.h" #include "../lib_paysages/scenery.h" +#include "tools.h" int main(int argc, char** argv) { @@ -130,6 +131,8 @@ QMainWindow(parent) setWindowTitle("Paysages 3D"); setWindowIcon(QIcon("images/logo_32.png")); + scenerySetCustomDataCallback(MainWindow::guiSaveCallback, MainWindow::guiLoadCallback, this); + refreshAll(); } @@ -145,6 +148,8 @@ bool MainWindow::event(QEvent* event) void MainWindow::refreshAll() { + logDebug("[MainWindow] Refreshing whole UI"); + // Refresh all tabs QList list_forms = this->findChildren("_base_form_"); for (int i = 0; i < list_forms.size(); i++) @@ -254,3 +259,35 @@ void MainWindow::explore3D() refreshAll(); } } + +void MainWindow::guiSaveCallback(PackStream* stream, void* data) +{ + ((MainWindow*)data)->guiSave(stream); +} + +void MainWindow::guiLoadCallback(PackStream* stream, void* data) +{ + ((MainWindow*)data)->guiLoad(stream); +} + +void MainWindow::guiSave(PackStream* stream) +{ + // Save all tabs status + // TODO Ensure same order in save and load + QList list_forms = this->findChildren("_base_form_"); + for (int i = 0; i < list_forms.size(); i++) + { + list_forms[i]->savePack(stream); + } +} + +void MainWindow::guiLoad(PackStream* stream) +{ + // Load all tabs status + // TODO Ensure same order in save and load + QList list_forms = this->findChildren("_base_form_"); + for (int i = 0; i < list_forms.size(); i++) + { + list_forms[i]->loadPack(stream); + } +} diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index 418e97a..3fa7c2f 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -3,6 +3,7 @@ #include #include "formrender.h" +#include "../lib_paysages/pack.h" class MainWindow : public QMainWindow { @@ -11,6 +12,9 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); virtual bool event(QEvent* event); + + static void guiSaveCallback(PackStream* stream, void* data); + static void guiLoadCallback(PackStream* stream, void* data); public slots: void refreshAll(); @@ -25,6 +29,9 @@ public slots: void explore3D(); private: + void guiSave(PackStream* stream); + void guiLoad(PackStream* stream); + FormRender* _form_render; }; diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 22c831f..b7430e8 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -29,7 +29,7 @@ Annuler les modifications - + Layer %1 Niveau %1 @@ -565,17 +565,17 @@ Maintenir Ctrl : Plus rapide Sauvegarder le dernier rendu - + Paysages 3D - Choose a filename to save the last render Paysages 3D - Choisissez un nom de fichier pour le rendu - + Images (*.png *.jpg) Images (*.png *.jpg) - + Can't write to file : %1 @@ -588,7 +588,7 @@ Maintenir Ctrl : Plus rapide Choisissez un nom de fichier pour le rendu - + The picture %1 has been saved. L'image %1 a été sauvegardée. @@ -955,144 +955,144 @@ Maintenir Ctrl : Plus rapide MainWindow - + Terrain Terrain - + Textures Textures - + Water Eau - + Atmosphere Atmosphère - + &Load &Ouvrir - + Crtl+L Ctrl+O - + &Explore (F2) &Explorer (F2) - + F2 F2 - + &Quick render (F5) &Rendu rapide (F5) - + F5 F5 - + Camera Caméra - + Do you want to start a new scenery ? Any unsaved changes will be lost. Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues. - + Paysages 3D - New scenery Paysages 3D - Nouvelle scène - + Paysages 3D - Choose a file to save the scenery Paysages 3D - Choisissez un fichier pour enregistrer la scène - - + + Paysages 3D Scenery (*.p3d) Scène Paysages 3D (*.p3d) - - + + Paysages 3D - File saving error - + Can't write specified file : %1 - + Unexpected error while saving file : %1 - + Do you want to load a scenery from file ? Any unsaved changes will be lost. Voulez-vous charger une scène ? Les modifications non sauvegardées seront perdues. - + Paysages 3D - Load scenery Paysages 3D - Charger une scène - + Paysages 3D - Choose a scenery file to load Paysages 3D - Choisissez un fichier de scène à charger - - - - + + + + Paysages 3D - File loading error - + Can't read specified file : %1 - + This file doesn't look like a Paysages 3D file : %1 - + This file was created with an incompatible Paysages 3D version : %1 - + Unexpected error while loading file : %1 - + A 3D landscape editing and rendering software. Authors : @@ -1106,12 +1106,12 @@ GLib - http://www.gtk.org/ - + Sky Ciel - + Clouds Nuages @@ -1120,7 +1120,7 @@ GLib - http://www.gtk.org/ Eclairage - + Render Rendu @@ -1129,22 +1129,22 @@ GLib - http://www.gtk.org/ &Scène - + &New &Nouveau - + Crtl+N Ctrl+N - + &Save &Sauvegarder - + Crtl+S Ctrl+S @@ -1181,7 +1181,7 @@ GLib - http://www.gtk.org/ Ai&de - + &About &A propos @@ -1202,7 +1202,7 @@ GLib - http://www.gtk.org/ Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues. - + Paysages 3D Paysages 3D diff --git a/lib_paysages/scenery.c b/lib_paysages/scenery.c index e31681e..8ab70ad 100644 --- a/lib_paysages/scenery.c +++ b/lib_paysages/scenery.c @@ -7,15 +7,19 @@ #include "system.h" #include "vegetation.h" -AtmosphereDefinition _atmosphere; -CameraDefinition _camera; -CloudsDefinition _clouds; -LightingDefinition _lighting; -SkyDefinition _sky; -TerrainDefinition _terrain; -TexturesDefinition _textures; -VegetationDefinition* _vegetation; -WaterDefinition _water; +static AtmosphereDefinition _atmosphere; +static CameraDefinition _camera; +static CloudsDefinition _clouds; +static LightingDefinition _lighting; +static SkyDefinition _sky; +static TerrainDefinition _terrain; +static TexturesDefinition _textures; +static VegetationDefinition* _vegetation; +static WaterDefinition _water; + +static SceneryCustomDataCallback _custom_save = NULL; +static SceneryCustomDataCallback _custom_load = NULL; +static void* _custom_data = NULL; void sceneryInit() { @@ -39,6 +43,9 @@ void sceneryInit() _textures = texturesCreateDefinition(); _vegetation = vegetationCreateDefinition(); _water = waterCreateDefinition(); + + _custom_save = NULL; + _custom_load = NULL; } void sceneryQuit() @@ -65,6 +72,13 @@ void sceneryQuit() noiseQuit(); } +void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data) +{ + _custom_save = callback_save; + _custom_load = callback_load; + _custom_data = data; +} + void scenerySave(PackStream* stream) { noiseSave(stream); @@ -77,6 +91,11 @@ void scenerySave(PackStream* stream) texturesSave(stream, &_textures); vegetationSave(stream, _vegetation); waterSave(stream, &_water); + + if (_custom_save) + { + _custom_save(stream, _custom_data); + } } void sceneryLoad(PackStream* stream) @@ -103,6 +122,11 @@ void sceneryLoad(PackStream* stream) texturesValidateDefinition(&_textures); vegetationValidateDefinition(_vegetation); waterValidateDefinition(&_water); + + if (_custom_load) + { + _custom_load(stream, _custom_data); + } } void scenerySetAtmosphere(AtmosphereDefinition* atmosphere) diff --git a/lib_paysages/scenery.h b/lib_paysages/scenery.h index 61e89da..f8cc370 100644 --- a/lib_paysages/scenery.h +++ b/lib_paysages/scenery.h @@ -24,9 +24,13 @@ extern "C" { #endif +typedef void (*SceneryCustomDataCallback)(PackStream* stream, void* data); + void sceneryInit(); void sceneryQuit(); +void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data); + void scenerySave(PackStream* stream); void sceneryLoad(PackStream* stream);