From aa62e467029980db575d95fb48ef701916daacc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 10 Jul 2012 20:00:44 +0000 Subject: [PATCH] paysages : Terrain canvas (WIP). git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@386 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseformlayer.cpp | 65 +++++++++++++++++++++++++++++++++++- gui_qt/baseformlayer.h | 18 +++++++++- gui_qt/dialoglayers.cpp | 2 +- gui_qt/dialoglayers.h | 2 +- gui_qt/formterrain.cpp | 4 +-- gui_qt/formterraincanvas.cpp | 4 +-- gui_qt/formterraincanvas.h | 2 +- lib_paysages/layers.c | 7 ++++ lib_paysages/layers.h | 1 + 9 files changed, 96 insertions(+), 9 deletions(-) diff --git a/gui_qt/baseformlayer.cpp b/gui_qt/baseformlayer.cpp index 629de47..b94aac0 100644 --- a/gui_qt/baseformlayer.cpp +++ b/gui_qt/baseformlayer.cpp @@ -1,5 +1,68 @@ #include "baseformlayer.h" -BaseFormLayer::BaseFormLayer(QWidget* parent) : BaseForm(parent, false, true) +BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true) { + _layers_original = layers; + _layers_modified = layersCreateCopy(_layers_original); +} + +BaseFormLayer::~BaseFormLayer() +{ + layersDelete(_layers_modified); +} + +void BaseFormLayer::configChangeEvent() +{ + /*texturesLayerCopyDefinition(&_layer, texturesGetLayer(&_definition, currentLayer())); + + layersValidate(_layers_modified);*/ + BaseForm::configChangeEvent(); +} + +QStringList BaseFormLayer::getLayers() +{ + QStringList result; + + for (int i = 0; i < layersCount(_layers_modified); i++) + { + result << QString::fromUtf8(layersGetName(_layers_modified, i)); + } + + return result; +} + +void BaseFormLayer::layerAddedEvent() +{ + if (layersAddLayer(_layers_modified, NULL) >= 0) + { + BaseForm::layerAddedEvent(); + } +} + +void BaseFormLayer::layerDeletedEvent(int layer) +{ + layersDeleteLayer(_layers_modified, layer); + + BaseForm::layerDeletedEvent(layer); +} + +void BaseFormLayer::layerMovedEvent(int layer, int new_position) +{ + layersMove(_layers_modified, layer, new_position); + + BaseForm::layerMovedEvent(layer, new_position); +} + +void BaseFormLayer::layerRenamedEvent(int layer, QString new_name) +{ + layersSetName(_layers_modified, layer, new_name.toUtf8().data()); + + BaseForm::layerRenamedEvent(layer, new_name); +} + +void BaseFormLayer::layerSelectedEvent(int layer) +{ + //texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer); + + BaseForm::layerSelectedEvent(layer); } diff --git a/gui_qt/baseformlayer.h b/gui_qt/baseformlayer.h index a4aef00..1b3ce35 100644 --- a/gui_qt/baseformlayer.h +++ b/gui_qt/baseformlayer.h @@ -4,14 +4,30 @@ /* Base form, with automatic layer control */ #include "baseform.h" +#include "../lib_paysages/layers.h" class BaseFormLayer:public BaseForm { Q_OBJECT public: - BaseFormLayer(QWidget* parent); + BaseFormLayer(QWidget* parent, Layers* layers); + ~BaseFormLayer(); +protected: + virtual QStringList getLayers(); + virtual void layerAddedEvent(); + virtual void layerDeletedEvent(int layer); + virtual void layerMovedEvent(int layer, int new_position); + virtual void layerRenamedEvent(int layer, QString new_name); + virtual void layerSelectedEvent(int layer); + +protected slots: + virtual void configChangeEvent(); + +private: + Layers* _layers_original; + Layers* _layers_modified; }; #endif diff --git a/gui_qt/dialoglayers.cpp b/gui_qt/dialoglayers.cpp index df7d29d..2954d58 100644 --- a/gui_qt/dialoglayers.cpp +++ b/gui_qt/dialoglayers.cpp @@ -16,7 +16,7 @@ DialogLayers::DialogLayers(QWidget *parent, Layers* layers, QString title, FormL setLayout(new QVBoxLayout()); - _form = form_builder(this); + _form = form_builder(this, _layers); _form->hideButtons(); layout()->addWidget(_form); diff --git a/gui_qt/dialoglayers.h b/gui_qt/dialoglayers.h index b2397a2..5953e46 100644 --- a/gui_qt/dialoglayers.h +++ b/gui_qt/dialoglayers.h @@ -11,7 +11,7 @@ class DialogLayers; class BaseFormLayer; -typedef BaseFormLayer* (*FormLayerBuilder)(DialogLayers* parent); +typedef BaseFormLayer* (*FormLayerBuilder)(DialogLayers* parent, Layers* layers); class DialogLayers : public DialogWithPreview { diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 72e1ebc..664acdb 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -141,9 +141,9 @@ private: }; /**************** Form ****************/ -static BaseFormLayer* _formBuilderCanvas(DialogLayers* parent) +static BaseFormLayer* _formBuilderCanvas(DialogLayers* parent, Layers* layers) { - return new FormTerrainCanvas(parent); + return new FormTerrainCanvas(parent, layers); } FormTerrain::FormTerrain(QWidget *parent): diff --git a/gui_qt/formterraincanvas.cpp b/gui_qt/formterraincanvas.cpp index c40497a..cc3d38b 100644 --- a/gui_qt/formterraincanvas.cpp +++ b/gui_qt/formterraincanvas.cpp @@ -1,8 +1,8 @@ #include "formterraincanvas.h" /**************** Form ****************/ -FormTerrainCanvas::FormTerrainCanvas(QWidget *parent): - BaseFormLayer(parent) +FormTerrainCanvas::FormTerrainCanvas(QWidget *parent, Layers* layers): + BaseFormLayer(parent, layers) { } diff --git a/gui_qt/formterraincanvas.h b/gui_qt/formterraincanvas.h index 3f3a2c0..4b8ccde 100644 --- a/gui_qt/formterraincanvas.h +++ b/gui_qt/formterraincanvas.h @@ -10,7 +10,7 @@ class FormTerrainCanvas : public BaseFormLayer Q_OBJECT public: - FormTerrainCanvas(QWidget* parent); + FormTerrainCanvas(QWidget* parent, Layers* layers); public slots: virtual void revertConfig(); diff --git a/lib_paysages/layers.c b/lib_paysages/layers.c index d71f441..2e4f802 100644 --- a/lib_paysages/layers.c +++ b/lib_paysages/layers.c @@ -33,6 +33,13 @@ Layers* layersCreate(LayerType type, int max_layer_count) return result; } +Layers* layersCreateCopy(Layers* original) +{ + Layers* result = layersCreate(original->type, original->max_count); + layersCopy(original, result); + return result; +} + void layersDelete(Layers* layers) { int i; diff --git a/lib_paysages/layers.h b/lib_paysages/layers.h index 13a2384..6df2c1c 100644 --- a/lib_paysages/layers.h +++ b/lib_paysages/layers.h @@ -28,6 +28,7 @@ typedef struct { typedef struct Layers Layers; Layers* layersCreate(LayerType type, int max_layer_count); +Layers* layersCreateCopy(Layers* original); void layersDelete(Layers* layers); void layersCopy(Layers* source, Layers* destination);