diff --git a/ChangeLog b/ChangeLog index eb1c924..de7cb90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,7 +29,7 @@ GUI : * Added grid and axis labels to curve editor. * Added camera location to previews. * Added toggles and choices to configure some previews. - * Added layer sorting. + * Added layer sorting and naming. Misc : * Version handling in saved files. diff --git a/TODO b/TODO index 77682d0..1c84f7d 100644 --- a/TODO +++ b/TODO @@ -6,7 +6,6 @@ Technology Preview 2 : - Keep skydome lights in cache for a render. - Add buttons to restore "auto" default values in tabs and dialogs. - Add "hardness to light" and shadow control ("minimum lighting") to material. -- Add layer naming. - Add logarithmic sliders for some float values. - Improve previews. => Add user markers on OSD diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 59e51d4..aaea595 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -13,7 +13,8 @@ #include #include #include -#include +#include +#include BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent) { @@ -60,6 +61,12 @@ BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget layers->layout()->addWidget(_layer_del); QObject::connect(_layer_del, SIGNAL(clicked()), this, SLOT(layerDelClicked())); + _layer_rename = new QPushButton(QIcon("images/layer_rename.png"), "", layers); + _layer_rename->setToolTip(tr("Rename layer")); + _layer_rename->setMaximumSize(30, 30); + layers->layout()->addWidget(_layer_rename); + QObject::connect(_layer_rename, SIGNAL(clicked()), this, SLOT(layerRenameClicked())); + _layer_up = new QPushButton(QIcon("images/layer_up.png"), "", layers); _layer_up->setToolTip(tr("Move layer upward")); _layer_up->setMaximumSize(30, 30); @@ -292,6 +299,22 @@ void BaseForm::layerDownClicked() } } +void BaseForm::layerRenameClicked() +{ + int layer = _layer_list->currentIndex(); + if (layer >= 0) + { + QString new_name = QInputDialog::getText(this, tr("Rename layer"), tr("New name: "), QLineEdit::Normal, _layer_names[layer]); + if (not new_name.isEmpty()) + { + layerRenamedEvent(layer, new_name); + + _button_apply->setEnabled(true); + _button_revert->setEnabled(true); + } + } +} + void BaseForm::layerListChanged() { bool changed = _button_apply->isEnabled(); @@ -441,6 +464,11 @@ void BaseForm::layerMovedEvent(int, int) rebuildLayerList(); } +void BaseForm::layerRenamedEvent(int, QString) +{ + rebuildLayerList(); +} + void BaseForm::layerSelectedEvent(int layer) { QList inputs = _form->findChildren("_form_input_"); diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 82863a5..6dc394d 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -39,6 +39,7 @@ private slots: void layerDelClicked(); void layerUpClicked(); void layerDownClicked(); + void layerRenameClicked(); void layerListChanged(); protected: @@ -64,19 +65,12 @@ protected: 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); private: bool _auto_update_previews; bool _auto_apply; - bool _with_layers; - QComboBox* _layer_list; - int _layer_count; - QStringList _layer_names; - QPushButton* _layer_new; - QPushButton* _layer_del; - QPushButton* _layer_up; - QPushButton* _layer_down; QWidget* _previews; QWidget* _form; QWidget* _form_labels; @@ -85,6 +79,16 @@ private: QWidget* _buttons; QPushButton* _button_apply; QPushButton* _button_revert; + + bool _with_layers; + QComboBox* _layer_list; + int _layer_count; + QStringList _layer_names; + QPushButton* _layer_new; + QPushButton* _layer_del; + QPushButton* _layer_up; + QPushButton* _layer_down; + QPushButton* _layer_rename; }; #endif diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 35c180f..53c0dbb 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -201,7 +201,7 @@ QStringList FormClouds::getLayers() for (i = 0; i < n; i++) { layer = cloudsGetLayer(&_definition, i); - result << QString(layer->name); + result << QString::fromUtf8(layer->name); } return result; @@ -229,6 +229,16 @@ void FormClouds::layerDeletedEvent(int layer) BaseForm::layerDeletedEvent(layer); } +void FormClouds::layerRenamedEvent(int layer, QString new_name) +{ + CloudsLayerDefinition* layer_def; + + layer_def = cloudsGetLayer(&_definition, layer); + cloudsLayerSetName(layer_def, new_name.toUtf8().data()); + + BaseForm::layerRenamedEvent(layer, new_name); +} + void FormClouds::layerSelectedEvent(int layer) { cloudsLayerCopyDefinition(cloudsGetLayer(&_definition, layer), &_layer); diff --git a/gui_qt/formclouds.h b/gui_qt/formclouds.h index 2193cc1..7356295 100644 --- a/gui_qt/formclouds.h +++ b/gui_qt/formclouds.h @@ -24,6 +24,7 @@ protected: 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); private: diff --git a/gui_qt/formtextures.cpp b/gui_qt/formtextures.cpp index 2b6247c..a3e9dcb 100644 --- a/gui_qt/formtextures.cpp +++ b/gui_qt/formtextures.cpp @@ -190,7 +190,7 @@ QStringList FormTextures::getLayers() for (i = 0; i < n; i++) { layer = texturesGetLayer(&_definition, i); - result << QString(layer->name); + result << QString::fromUtf8(layer->name); } return result; @@ -218,6 +218,16 @@ void FormTextures::layerMovedEvent(int layer, int new_position) BaseForm::layerMovedEvent(layer, new_position); } +void FormTextures::layerRenamedEvent(int layer, QString new_name) +{ + TextureLayerDefinition* layer_def; + + layer_def = texturesGetLayer(&_definition, layer); + texturesLayerSetName(layer_def, new_name.toUtf8().data()); + + BaseForm::layerRenamedEvent(layer, new_name); +} + void FormTextures::layerSelectedEvent(int layer) { texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer); diff --git a/gui_qt/formtextures.h b/gui_qt/formtextures.h index 9b2b7f3..acc3f79 100644 --- a/gui_qt/formtextures.h +++ b/gui_qt/formtextures.h @@ -18,6 +18,7 @@ protected: 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); public slots: diff --git a/images/layer_rename.png b/images/layer_rename.png new file mode 100644 index 0000000..761044b Binary files /dev/null and b/images/layer_rename.png differ diff --git a/lib_paysages/clouds.c b/lib_paysages/clouds.c index 8e20681..1b51526 100644 --- a/lib_paysages/clouds.c +++ b/lib_paysages/clouds.c @@ -621,7 +621,6 @@ static int _cmpLayer(const void* layer1, const void* layer2) Color cloudsApply(CloudsDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end) { int i; - Color layer_color; CloudsLayerDefinition layers[CLOUDS_MAX_LAYERS]; if (definition->nblayers < 1) diff --git a/lib_paysages/pack.c b/lib_paysages/pack.c index 3329f0f..858ad96 100644 --- a/lib_paysages/pack.c +++ b/lib_paysages/pack.c @@ -111,10 +111,12 @@ void packCloseStream(PackStream* stream) void packWriteDouble(PackStream* stream, double* value) { + int written; uint64_t servalue; servalue = pack754_64(*value); - fwrite(&servalue, sizeof(uint64_t), 1, stream->fd); + written = fwrite(&servalue, sizeof(uint64_t), 1, stream->fd); + assert(written == 1); } void packReadDouble(PackStream* stream, double* value) @@ -130,7 +132,10 @@ void packReadDouble(PackStream* stream, double* value) void packWriteInt(PackStream* stream, int* value) { - fprintf(stream->fd, "%d;", *value); + int written; + + written = fprintf(stream->fd, "%d;", *value); + assert(written > 1); } void packReadInt(PackStream* stream, int* value) @@ -143,9 +148,11 @@ void packReadInt(PackStream* stream, int* value) void packWriteString(PackStream* stream, char* value, int max_length) { - int len = strnlen(value, max_length - 1); + int written; + int len = strnlen(value, max_length - 1) + 1; packWriteInt(stream, &len); - fwrite(value, len + 1, 1, stream->fd); + written = fwrite(value, 1, len, stream->fd); + assert(written == len); } void packReadString(PackStream* stream, char* value, int max_length) @@ -153,10 +160,10 @@ void packReadString(PackStream* stream, char* value, int max_length) int read; int len; packReadInt(stream, &len); - if (len > max_length - 1) + if (len > max_length) { - len = max_length - 1; + len = max_length; } - read = fread(value, len + 1, 1, stream->fd); - assert(read == len + 1); + read = fread(value, 1, len, stream->fd); + assert(read == len); } diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 88ab553..138d8f7 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -34,20 +34,23 @@ void texturesQuit() void texturesSave(PackStream* stream, TexturesDefinition* definition) { + TextureLayerDefinition* layer; int i; packWriteInt(stream, &definition->nblayers); for (i = 0; i < definition->nblayers; i++) { - packWriteString(stream, definition->layers[i].name, TEXTURES_MAX_NAME_LENGTH); - zoneSave(stream, definition->layers[i].zone); - noiseSaveGenerator(stream, definition->layers[i].bump_noise); - packWriteDouble(stream, &definition->layers[i].bump_height); - packWriteDouble(stream, &definition->layers[i].bump_scaling); - materialSave(stream, &definition->layers[i].material); - packWriteDouble(stream, &definition->layers[i].thickness); - packWriteDouble(stream, &definition->layers[i].slope_range); - packWriteDouble(stream, &definition->layers[i].thickness_transparency); + layer = definition->layers + i; + + packWriteString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH); + zoneSave(stream, layer->zone); + noiseSaveGenerator(stream, layer->bump_noise); + packWriteDouble(stream, &layer->bump_height); + packWriteDouble(stream, &layer->bump_scaling); + materialSave(stream, &layer->material); + packWriteDouble(stream, &layer->thickness); + packWriteDouble(stream, &layer->slope_range); + packWriteDouble(stream, &layer->thickness_transparency); } } @@ -72,9 +75,9 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition) packReadDouble(stream, &layer->bump_height); packReadDouble(stream, &layer->bump_scaling); materialLoad(stream, &layer->material); - packReadDouble(stream, &definition->layers[i].thickness); - packReadDouble(stream, &definition->layers[i].slope_range); - packReadDouble(stream, &definition->layers[i].thickness_transparency); + packReadDouble(stream, &layer->thickness); + packReadDouble(stream, &layer->slope_range); + packReadDouble(stream, &layer->thickness_transparency); } texturesValidateDefinition(definition);