From f479af8417b5d0fea332dd2f4d0d32ed27fc4521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 8 Mar 2012 15:56:44 +0000 Subject: [PATCH] paysages : Curve editor (WIP). git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@277 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/dialogcolorgradation.cpp | 6 +++++- gui_qt/dialogcolorgradation.h | 2 ++ gui_qt/widgetcurveeditor.cpp | 20 ++++++++++++++++++++ gui_qt/widgetcurveeditor.h | 3 +++ lib_paysages/curve.c | 8 ++++++++ lib_paysages/curve.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gui_qt/dialogcolorgradation.cpp b/gui_qt/dialogcolorgradation.cpp index 8b2fd00..54b694a 100644 --- a/gui_qt/dialogcolorgradation.cpp +++ b/gui_qt/dialogcolorgradation.cpp @@ -25,6 +25,8 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad _curve_editor = new WidgetCurveEditor(this); layout()->addWidget(_curve_editor); + _curve = curveCreate(); + /*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert())); QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));*/ @@ -37,6 +39,7 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad DialogColorGradation::~DialogColorGradation() { colorGradationDelete(_current); + curveDelete(_curve); } bool DialogColorGradation::getGradation(QWidget* parent, ColorGradation* gradation) @@ -70,5 +73,6 @@ void DialogColorGradation::revert() void DialogColorGradation::revertToCurrent() { - // TODO + colorGradationGetRedCurve(_current, _curve); + _curve_editor->setCurve(_curve); } diff --git a/gui_qt/dialogcolorgradation.h b/gui_qt/dialogcolorgradation.h index 0205120..87f27d8 100644 --- a/gui_qt/dialogcolorgradation.h +++ b/gui_qt/dialogcolorgradation.h @@ -6,6 +6,7 @@ #include "widgetcurveeditor.h" #include "../lib_paysages/color.h" +#include "../lib_paysages/curve.h" class DialogColorGradation : public QDialog { @@ -29,6 +30,7 @@ private: private: ColorGradation* _base; ColorGradation* _current; + Curve* _curve; WidgetCurveEditor* _curve_editor; }; diff --git a/gui_qt/widgetcurveeditor.cpp b/gui_qt/widgetcurveeditor.cpp index 9132810..3ae9582 100644 --- a/gui_qt/widgetcurveeditor.cpp +++ b/gui_qt/widgetcurveeditor.cpp @@ -15,8 +15,21 @@ WidgetCurveEditor::~WidgetCurveEditor() curveDelete(_curve); } +void WidgetCurveEditor::setCurve(Curve* curve) +{ + curveCopy(curve, _curve); + update(); +} + +void WidgetCurveEditor::getCurve(Curve* curve) +{ + curveCopy(_curve, curve); +} + void WidgetCurveEditor::paintEvent(QPaintEvent* event) { + int i, n; + CurvePoint point; double position, value; QPainter painter(this); @@ -29,4 +42,11 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event) value = curveGetValue(_curve, position); painter.drawPoint(x, 499 - (int)(value * 499.0)); } + + n = curveGetPointCount(_curve); + for (i = 0; i < n; i++) + { + curveGetPoint(_curve, i, &point); + painter.drawEllipse(QPoint((int)(point.position * 499.0), 499 - (int)(point.value * 499.0)), 4.0, 4.0); + } } diff --git a/gui_qt/widgetcurveeditor.h b/gui_qt/widgetcurveeditor.h index 52139dd..7e395c3 100644 --- a/gui_qt/widgetcurveeditor.h +++ b/gui_qt/widgetcurveeditor.h @@ -12,6 +12,9 @@ public: WidgetCurveEditor(QWidget* parent); ~WidgetCurveEditor(); + void setCurve(Curve* curve); + void getCurve(Curve* curve); + protected: void paintEvent(QPaintEvent* event); diff --git a/lib_paysages/curve.c b/lib_paysages/curve.c index e03f879..b3c19ce 100644 --- a/lib_paysages/curve.c +++ b/lib_paysages/curve.c @@ -96,6 +96,14 @@ void curveGetPoint(Curve* curve, int number, CurvePoint* point) } } +void curveSetPoint(Curve* curve, int number, CurvePoint* point) +{ + if (number >= 0 && number < curve->nbpoints) + { + curve->points[number] = *point; + } +} + int _point_compare(const void* part1, const void* part2) { if (((CurvePoint*)part1)->position > ((CurvePoint*)part2)->position) diff --git a/lib_paysages/curve.h b/lib_paysages/curve.h index 1f1642c..fb89786 100644 --- a/lib_paysages/curve.h +++ b/lib_paysages/curve.h @@ -25,6 +25,7 @@ int curveAddPoint(Curve* curve, CurvePoint* point); int curveQuickAddPoint(Curve* curve, double position, double value); int curveGetPointCount(Curve* curve); void curveGetPoint(Curve* curve, int number, CurvePoint* point); +void curveSetPoint(Curve* curve, int number, CurvePoint* point); void curveValidate(Curve* curve); double curveGetValue(Curve* curve, double position);