From 1539c75d6d3acb6fa9073c453cff810a5a946a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 27 Jun 2012 12:49:51 +0000 Subject: [PATCH] paysages : Added grid and axis labels to curve editor. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@365 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- ChangeLog | 1 + TODO | 2 +- gui_qt/baseform.cpp | 4 ++-- gui_qt/baseform.h | 2 +- gui_qt/dialogcurve.cpp | 7 ++++--- gui_qt/dialogcurve.h | 4 ++-- gui_qt/formclouds.cpp | 2 +- gui_qt/formsky.cpp | 2 +- gui_qt/inputcurve.cpp | 6 ++++-- gui_qt/inputcurve.h | 4 +++- gui_qt/widgetcurveeditor.cpp | 39 ++++++++++++++++++++++++++++++++++-- gui_qt/widgetcurveeditor.h | 4 ++++ i18n/paysages_fr.ts | 30 ++++++++++++++++++++++----- 13 files changed, 86 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fbf3e0..49fc2bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ GUI : * New material editor. * Added render timer. * Previews locations and render params are now saved. + * Added grid and axis labels to curve editor. * Added camera location to previews. Misc : diff --git a/TODO b/TODO index 68c89c4..520e9c0 100644 --- a/TODO +++ b/TODO @@ -23,8 +23,8 @@ Technology Preview 2 : - Fix the distorted sun appearance. - Improve curve editor. => Add curve modes - => Add axis labels and grid => Add logarithmic mode + => Add zoom and scrolling - Fix "RGB parameters out of range" (and segfault) on preview while moving render params fast in render tab. => May need to change the updateData system. => Previews need to be paused while updating data. diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index b203b13..aa0d67c 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -285,9 +285,9 @@ BaseInput* BaseForm::addInputNoise(QString label, NoiseGenerator* value) return addInput(new InputNoise(form, label, value)); } -BaseInput* BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax) +BaseInput* BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel) { - return addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax)); + return addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax, xlabel, ylabel)); } BaseInput* BaseForm::addInputMaterial(QString label, SurfaceMaterial* material) diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 0f7f84c..1c61d84 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -47,7 +47,7 @@ protected: BaseInput* addInputColor(QString label, Color* value); BaseInput* addInputColorGradation(QString label, ColorGradation* value); BaseInput* addInputNoise(QString label, NoiseGenerator* value); - BaseInput* addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax); + BaseInput* addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); BaseInput* addInputMaterial(QString label, SurfaceMaterial* material); BaseInput* addInputEnum(QString label, int* value, const QStringList& values); diff --git a/gui_qt/dialogcurve.cpp b/gui_qt/dialogcurve.cpp index ad02e4b..93dcfd3 100644 --- a/gui_qt/dialogcurve.cpp +++ b/gui_qt/dialogcurve.cpp @@ -15,7 +15,7 @@ #include "widgetcurveeditor.h" /**************** Dialog ****************/ -DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) : QDialog(parent) +DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel) : QDialog(parent) { QWidget* buttons; QWidget* form; @@ -40,6 +40,7 @@ DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax label->setWordWrap(true); form_layout->addWidget(label, 0, 1); _curve_editor = new WidgetCurveEditor(form, xmin, xmax, ymin, ymax); + _curve_editor->setAxisLabels(xlabel, ylabel); _curve_editor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); form_layout->addWidget(_curve_editor, 0, 0); @@ -70,11 +71,11 @@ DialogCurve::~DialogCurve() curveDelete(_current); } -bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) +bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel) { int result; - DialogCurve* dialog = new DialogCurve(parent, curve, xmin, xmax, ymin, ymax); + DialogCurve* dialog = new DialogCurve(parent, curve, xmin, xmax, ymin, ymax, xlabel, ylabel); result = dialog->exec(); delete dialog; diff --git a/gui_qt/dialogcurve.h b/gui_qt/dialogcurve.h index 20d66b1..c93fd87 100644 --- a/gui_qt/dialogcurve.h +++ b/gui_qt/dialogcurve.h @@ -11,10 +11,10 @@ class DialogCurve : public QDialog { Q_OBJECT public: - explicit DialogCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax); + explicit DialogCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); ~DialogCurve(); - static bool getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax); + static bool getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); public slots: virtual void accept(); diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 9301f29..39e0618 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -157,7 +157,7 @@ FormClouds::FormClouds(QWidget *parent): addInputDouble(tr("Lower altitude"), &_layer.ymin, -10.0, 50.0, 0.5, 5.0); addInputDouble(tr("Upper altitude"), &_layer.ymax, -10.0, 50.0, 0.5, 5.0); addInputDouble(tr("Max coverage"), &_layer.base_coverage, 0.0, 1.0, 0.01, 0.1); - addInputCurve(tr("Coverage by altitude"), _layer.coverage_by_altitude, 0.0, 1.0, 0.0, 1.0); + addInputCurve(tr("Coverage by altitude"), _layer.coverage_by_altitude, 0.0, 1.0, 0.0, 1.0, tr("Altitude in cloud layer"), tr("Coverage value")); addInputNoise(tr("Shape noise"), _layer.shape_noise); addInputDouble(tr("Shape scaling"), &_layer.shape_scaling, 1.0, 10.0, 0.1, 1.0); addInputNoise(tr("Edge noise"), _layer.edge_noise); diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index 27dcc24..a82d5e0 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -111,7 +111,7 @@ FormSky::FormSky(QWidget *parent): addInputColor(tr("Sun color"), &_definition.sun_color); addInputDouble(tr("Sun radius"), &_definition.sun_radius, 0.0, 0.4, 0.004, 0.04); addInputDouble(tr("Sun halo radius"), &_definition.sun_halo_size, 0.0, 0.4, 0.004, 0.04); - addInputCurve(tr("Sun halo profile"), _definition.sun_halo_profile, 0.0, 1.0, 0.0, 1.0); + addInputCurve(tr("Sun halo profile"), _definition.sun_halo_profile, 0.0, 1.0, 0.0, 1.0, tr("Distance to center of the sun"), tr("Light influence (halo opacity)")); addInputDouble(tr("Influence of skydome on lighting"), &_definition.dome_lighting, 0.0, 2.0, 0.01, 0.1); input = addInputBoolean(tr("Auto colors from daytime"), &_definition.model_custom.auto_from_daytime); input->setVisibilityCondition((int*)&_definition.model, SKY_MODEL_CUSTOM); diff --git a/gui_qt/inputcurve.cpp b/gui_qt/inputcurve.cpp index 32f6150..8c48ef0 100644 --- a/gui_qt/inputcurve.cpp +++ b/gui_qt/inputcurve.cpp @@ -49,13 +49,15 @@ public: double _ymax; }; -InputCurve::InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax) : BaseInput(form, label) +InputCurve::InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel) : BaseInput(form, label) { _value = value; _xmin = xmin; _xmax = xmax; _ymin = ymin; _ymax = ymax; + _xlabel = xlabel; + _ylabel = ylabel; _preview = new CurveSmallPreview(form, value, xmin, xmax, ymin, ymax); _preview->setMinimumSize(100, 40); @@ -84,7 +86,7 @@ void InputCurve::revert() void InputCurve::editCurve() { - if (DialogCurve::getCurve(_control, _value, _xmin, _xmax, _ymin, _ymax)) + if (DialogCurve::getCurve(_control, _value, _xmin, _xmax, _ymin, _ymax, _xlabel, _ylabel)) { applyValue(); } diff --git a/gui_qt/inputcurve.h b/gui_qt/inputcurve.h index e19ae7a..55c6882 100644 --- a/gui_qt/inputcurve.h +++ b/gui_qt/inputcurve.h @@ -11,7 +11,7 @@ class InputCurve:public BaseInput Q_OBJECT public: - InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax); + InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); public slots: virtual void updatePreview(); @@ -27,6 +27,8 @@ private: double _xmax; double _ymin; double _ymax; + QString _xlabel; + QString _ylabel; }; #endif diff --git a/gui_qt/widgetcurveeditor.cpp b/gui_qt/widgetcurveeditor.cpp index 31cc085..a1f4dba 100644 --- a/gui_qt/widgetcurveeditor.cpp +++ b/gui_qt/widgetcurveeditor.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "../lib_paysages/tools.h" WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double ymax) : QWidget(parent) @@ -18,6 +19,12 @@ WidgetCurveEditor::~WidgetCurveEditor() curveDelete(_curve); } +void WidgetCurveEditor::setAxisLabels(QString xlabel, QString ylabel) +{ + _xlabel = xlabel; + _ylabel = ylabel; +} + void WidgetCurveEditor::setCurve(Curve* curve) { curveCopy(curve, _curve); @@ -49,9 +56,35 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event) dwidth = (double)(width - 1); QPainter painter(this); - painter.fillRect(0, 0, width, height, QColor(255, 255, 255)); - painter.setPen(_pen); + painter.fillRect(rect(), Qt::white); + // Draw grid + painter.setPen(QPen(Qt::lightGray)); + for (int x = 0; x <= 10; x++) + { + int vx = (x == 10) ? width - 1 : x * width / 10; + painter.drawLine(vx, 0, vx, height -1); + vx = (x == 10) ? height - 1 : x * height / 10; + painter.drawLine(0, vx, width - 1, vx); + } + + // Draw labels + painter.setPen(QColor(50, 50, 50)); + if (not _xlabel.isEmpty()) + { + painter.drawText(rect(), Qt::AlignCenter | Qt::AlignBottom, _xlabel); + } + if (not _ylabel.isEmpty()) + { + painter.rotate(-90.0); + painter.translate(-height, 0.0); + painter.drawText(0, 0, height, 20, Qt::AlignCenter | Qt::AlignTop, _ylabel); + painter.translate(height, 0.0); + painter.rotate(90.0); + } + + // Draw curve path + painter.setPen(_pen); for (int x = 0; x < width; x++) { position = ((double)x) / dwidth; @@ -64,7 +97,9 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event) painter.drawPoint(x, height - 1 - (int)(value * dheight)); } + // Draw handles n = curveGetPointCount(_curve); + painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true); for (i = 0; i < n; i++) { curveGetPoint(_curve, i, &point); diff --git a/gui_qt/widgetcurveeditor.h b/gui_qt/widgetcurveeditor.h index 39913d8..19a1aee 100644 --- a/gui_qt/widgetcurveeditor.h +++ b/gui_qt/widgetcurveeditor.h @@ -13,6 +13,8 @@ public: WidgetCurveEditor(QWidget* parent, double xmin, double xmax, double ymin, double ymax); ~WidgetCurveEditor(); + void setAxisLabels(QString xlabel, QString ylabel); + void setCurve(Curve* curve); void getCurve(Curve* curve); @@ -34,6 +36,8 @@ private: Curve* _curve; int _dragged; QColor _pen; + QString _xlabel; + QString _ylabel; }; #endif diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index b7430e8..5e27483 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -101,22 +101,22 @@ Right click on a point to delete it. - + Validate Valider - + Revert - + Cancel Annuler - + Paysages 3D - Curve editor @@ -421,6 +421,16 @@ Maintenir Ctrl : Plus rapide Coverage by altitude + + + Altitude in cloud layer + + + + + Coverage value + + Shape noise @@ -665,6 +675,16 @@ Maintenir Ctrl : Plus rapide Zenith color Couleur du ciel au zénith + + + Distance to center of the sun + + + + + Light influence (halo opacity) + + Auto colors from daytime @@ -931,7 +951,7 @@ Maintenir Ctrl : Plus rapide InputCurve - + Edit Editer