paysages : Added layer naming.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@381 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-07-05 17:55:25 +00:00 committed by ThunderK
parent 3eedaf1366
commit 31f6e36b97
12 changed files with 96 additions and 34 deletions

View file

@ -29,7 +29,7 @@ GUI :
* Added grid and axis labels to curve editor. * Added grid and axis labels to curve editor.
* Added camera location to previews. * Added camera location to previews.
* Added toggles and choices to configure some previews. * Added toggles and choices to configure some previews.
* Added layer sorting. * Added layer sorting and naming.
Misc : Misc :
* Version handling in saved files. * Version handling in saved files.

1
TODO
View file

@ -6,7 +6,6 @@ Technology Preview 2 :
- Keep skydome lights in cache for a render. - Keep skydome lights in cache for a render.
- Add buttons to restore "auto" default values in tabs and dialogs. - Add buttons to restore "auto" default values in tabs and dialogs.
- Add "hardness to light" and shadow control ("minimum lighting") to material. - Add "hardness to light" and shadow control ("minimum lighting") to material.
- Add layer naming.
- Add logarithmic sliders for some float values. - Add logarithmic sliders for some float values.
- Improve previews. - Improve previews.
=> Add user markers on OSD => Add user markers on OSD

View file

@ -13,7 +13,8 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <qt4/QtCore/qvariant.h> #include <QVariant>
#include <QInputDialog>
BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent) 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); layers->layout()->addWidget(_layer_del);
QObject::connect(_layer_del, SIGNAL(clicked()), this, SLOT(layerDelClicked())); 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 = new QPushButton(QIcon("images/layer_up.png"), "", layers);
_layer_up->setToolTip(tr("Move layer upward")); _layer_up->setToolTip(tr("Move layer upward"));
_layer_up->setMaximumSize(30, 30); _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() void BaseForm::layerListChanged()
{ {
bool changed = _button_apply->isEnabled(); bool changed = _button_apply->isEnabled();
@ -441,6 +464,11 @@ void BaseForm::layerMovedEvent(int, int)
rebuildLayerList(); rebuildLayerList();
} }
void BaseForm::layerRenamedEvent(int, QString)
{
rebuildLayerList();
}
void BaseForm::layerSelectedEvent(int layer) void BaseForm::layerSelectedEvent(int layer)
{ {
QList<BaseInput*> inputs = _form->findChildren<BaseInput*>("_form_input_"); QList<BaseInput*> inputs = _form->findChildren<BaseInput*>("_form_input_");

View file

@ -39,6 +39,7 @@ private slots:
void layerDelClicked(); void layerDelClicked();
void layerUpClicked(); void layerUpClicked();
void layerDownClicked(); void layerDownClicked();
void layerRenameClicked();
void layerListChanged(); void layerListChanged();
protected: protected:
@ -64,19 +65,12 @@ protected:
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position); virtual void layerMovedEvent(int layer, int new_position);
virtual void layerRenamedEvent(int layer, QString new_name);
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
private: private:
bool _auto_update_previews; bool _auto_update_previews;
bool _auto_apply; 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* _previews;
QWidget* _form; QWidget* _form;
QWidget* _form_labels; QWidget* _form_labels;
@ -85,6 +79,16 @@ private:
QWidget* _buttons; QWidget* _buttons;
QPushButton* _button_apply; QPushButton* _button_apply;
QPushButton* _button_revert; 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 #endif

View file

@ -201,7 +201,7 @@ QStringList FormClouds::getLayers()
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
layer = cloudsGetLayer(&_definition, i); layer = cloudsGetLayer(&_definition, i);
result << QString(layer->name); result << QString::fromUtf8(layer->name);
} }
return result; return result;
@ -229,6 +229,16 @@ void FormClouds::layerDeletedEvent(int layer)
BaseForm::layerDeletedEvent(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) void FormClouds::layerSelectedEvent(int layer)
{ {
cloudsLayerCopyDefinition(cloudsGetLayer(&_definition, layer), &_layer); cloudsLayerCopyDefinition(cloudsGetLayer(&_definition, layer), &_layer);

View file

@ -24,6 +24,7 @@ protected:
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position); virtual void layerMovedEvent(int layer, int new_position);
virtual void layerRenamedEvent(int layer, QString new_name);
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
private: private:

View file

@ -190,7 +190,7 @@ QStringList FormTextures::getLayers()
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
layer = texturesGetLayer(&_definition, i); layer = texturesGetLayer(&_definition, i);
result << QString(layer->name); result << QString::fromUtf8(layer->name);
} }
return result; return result;
@ -218,6 +218,16 @@ void FormTextures::layerMovedEvent(int layer, int new_position)
BaseForm::layerMovedEvent(layer, 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) void FormTextures::layerSelectedEvent(int layer)
{ {
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer); texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);

View file

@ -18,6 +18,7 @@ protected:
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position); virtual void layerMovedEvent(int layer, int new_position);
virtual void layerRenamedEvent(int layer, QString new_name);
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
public slots: public slots:

BIN
images/layer_rename.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -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) Color cloudsApply(CloudsDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end)
{ {
int i; int i;
Color layer_color;
CloudsLayerDefinition layers[CLOUDS_MAX_LAYERS]; CloudsLayerDefinition layers[CLOUDS_MAX_LAYERS];
if (definition->nblayers < 1) if (definition->nblayers < 1)

View file

@ -111,10 +111,12 @@ void packCloseStream(PackStream* stream)
void packWriteDouble(PackStream* stream, double* value) void packWriteDouble(PackStream* stream, double* value)
{ {
int written;
uint64_t servalue; uint64_t servalue;
servalue = pack754_64(*value); 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) void packReadDouble(PackStream* stream, double* value)
@ -130,7 +132,10 @@ void packReadDouble(PackStream* stream, double* value)
void packWriteInt(PackStream* stream, int* 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) 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) 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); 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) 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 read;
int len; int len;
packReadInt(stream, &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); read = fread(value, 1, len, stream->fd);
assert(read == len + 1); assert(read == len);
} }

View file

@ -34,20 +34,23 @@ void texturesQuit()
void texturesSave(PackStream* stream, TexturesDefinition* definition) void texturesSave(PackStream* stream, TexturesDefinition* definition)
{ {
TextureLayerDefinition* layer;
int i; int i;
packWriteInt(stream, &definition->nblayers); packWriteInt(stream, &definition->nblayers);
for (i = 0; i < definition->nblayers; i++) for (i = 0; i < definition->nblayers; i++)
{ {
packWriteString(stream, definition->layers[i].name, TEXTURES_MAX_NAME_LENGTH); layer = definition->layers + i;
zoneSave(stream, definition->layers[i].zone);
noiseSaveGenerator(stream, definition->layers[i].bump_noise); packWriteString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH);
packWriteDouble(stream, &definition->layers[i].bump_height); zoneSave(stream, layer->zone);
packWriteDouble(stream, &definition->layers[i].bump_scaling); noiseSaveGenerator(stream, layer->bump_noise);
materialSave(stream, &definition->layers[i].material); packWriteDouble(stream, &layer->bump_height);
packWriteDouble(stream, &definition->layers[i].thickness); packWriteDouble(stream, &layer->bump_scaling);
packWriteDouble(stream, &definition->layers[i].slope_range); materialSave(stream, &layer->material);
packWriteDouble(stream, &definition->layers[i].thickness_transparency); 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_height);
packReadDouble(stream, &layer->bump_scaling); packReadDouble(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material); materialLoad(stream, &layer->material);
packReadDouble(stream, &definition->layers[i].thickness); packReadDouble(stream, &layer->thickness);
packReadDouble(stream, &definition->layers[i].slope_range); packReadDouble(stream, &layer->slope_range);
packReadDouble(stream, &definition->layers[i].thickness_transparency); packReadDouble(stream, &layer->thickness_transparency);
} }
texturesValidateDefinition(definition); texturesValidateDefinition(definition);