paysages: Color gradation editor (WIP).
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@280 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
0585958073
commit
85f4017bf1
7 changed files with 184 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "dialogcolorgradation.h"
|
#include "dialogcolorgradation.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
@ -16,6 +17,8 @@
|
||||||
DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* gradation):
|
DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* gradation):
|
||||||
QDialog(parent)
|
QDialog(parent)
|
||||||
{
|
{
|
||||||
|
QWidget* buttons;
|
||||||
|
|
||||||
_base = gradation;
|
_base = gradation;
|
||||||
_current = colorGradationCreate();
|
_current = colorGradationCreate();
|
||||||
colorGradationCopy(_base, _current);
|
colorGradationCopy(_base, _current);
|
||||||
|
@ -24,31 +27,44 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad
|
||||||
|
|
||||||
_curve_editor = new WidgetCurveEditor(this);
|
_curve_editor = new WidgetCurveEditor(this);
|
||||||
layout()->addWidget(_curve_editor);
|
layout()->addWidget(_curve_editor);
|
||||||
|
connect(_curve_editor, SIGNAL(liveChanged()), this, SLOT(updateColors()));
|
||||||
|
|
||||||
_preview_red = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_RED);
|
_preview_red = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_RED);
|
||||||
_preview_red->setMinimumHeight(50);
|
_preview_red->setMinimumHeight(50);
|
||||||
connect(_preview_red, SIGNAL(clicked()), this, SLOT(selectRed()));
|
connect(_preview_red, SIGNAL(clicked()), this, SLOT(selectRed()));
|
||||||
layout()->addWidget(_preview_red);
|
layout()->addWidget(_preview_red);
|
||||||
|
|
||||||
_preview_green = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_GREEN);
|
_preview_green = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_GREEN);
|
||||||
_preview_green->setMinimumHeight(50);
|
_preview_green->setMinimumHeight(50);
|
||||||
connect(_preview_green, SIGNAL(clicked()), this, SLOT(selectGreen()));
|
connect(_preview_green, SIGNAL(clicked()), this, SLOT(selectGreen()));
|
||||||
layout()->addWidget(_preview_green);
|
layout()->addWidget(_preview_green);
|
||||||
|
|
||||||
_preview_blue = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_BLUE);
|
_preview_blue = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_BLUE);
|
||||||
_preview_blue->setMinimumHeight(50);
|
_preview_blue->setMinimumHeight(50);
|
||||||
connect(_preview_blue, SIGNAL(clicked()), this, SLOT(selectBlue()));
|
connect(_preview_blue, SIGNAL(clicked()), this, SLOT(selectBlue()));
|
||||||
layout()->addWidget(_preview_blue);
|
layout()->addWidget(_preview_blue);
|
||||||
|
|
||||||
_preview_final = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_FINAL);
|
_preview_final = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_FINAL);
|
||||||
_preview_final->setMinimumHeight(50);
|
_preview_final->setMinimumHeight(50);
|
||||||
layout()->addWidget(_preview_final);
|
layout()->addWidget(_preview_final);
|
||||||
|
|
||||||
_curve = curveCreate();
|
buttons = new QWidget(this);
|
||||||
|
layout()->addWidget(buttons);
|
||||||
|
buttons->setLayout(new QHBoxLayout());
|
||||||
|
|
||||||
/*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
|
_button_accept = new QPushButton(tr("Validate"), buttons);
|
||||||
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
|
buttons->layout()->addWidget(_button_accept);
|
||||||
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));*/
|
QObject::connect(_button_accept, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
|
|
||||||
|
_button_revert = new QPushButton(tr("Revert"), buttons);
|
||||||
|
buttons->layout()->addWidget(_button_revert);
|
||||||
|
QObject::connect(_button_revert, SIGNAL(clicked()), this, SLOT(revert()));
|
||||||
|
|
||||||
|
_button_cancel = new QPushButton(tr("Cancel"), buttons);
|
||||||
|
buttons->layout()->addWidget(_button_cancel);
|
||||||
|
QObject::connect(_button_cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
||||||
|
|
||||||
|
_curve = curveCreate();
|
||||||
|
|
||||||
setWindowTitle(tr("Paysages 3D - Color gradation editor"));
|
setWindowTitle(tr("Paysages 3D - Color gradation editor"));
|
||||||
|
|
||||||
|
@ -86,6 +102,7 @@ void DialogColorGradation::accept()
|
||||||
|
|
||||||
void DialogColorGradation::revert()
|
void DialogColorGradation::revert()
|
||||||
{
|
{
|
||||||
|
_selected = 0;
|
||||||
colorGradationCopy(_base, _current);
|
colorGradationCopy(_base, _current);
|
||||||
revertToCurrent();
|
revertToCurrent();
|
||||||
}
|
}
|
||||||
|
@ -94,21 +111,59 @@ void DialogColorGradation::selectRed()
|
||||||
{
|
{
|
||||||
colorGradationGetRedCurve(_current, _curve);
|
colorGradationGetRedCurve(_current, _curve);
|
||||||
_curve_editor->setCurve(_curve);
|
_curve_editor->setCurve(_curve);
|
||||||
|
_selected = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogColorGradation::selectGreen()
|
void DialogColorGradation::selectGreen()
|
||||||
{
|
{
|
||||||
colorGradationGetGreenCurve(_current, _curve);
|
colorGradationGetGreenCurve(_current, _curve);
|
||||||
_curve_editor->setCurve(_curve);
|
_curve_editor->setCurve(_curve);
|
||||||
|
_selected = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogColorGradation::selectBlue()
|
void DialogColorGradation::selectBlue()
|
||||||
{
|
{
|
||||||
colorGradationGetBlueCurve(_current, _curve);
|
colorGradationGetBlueCurve(_current, _curve);
|
||||||
_curve_editor->setCurve(_curve);
|
_curve_editor->setCurve(_curve);
|
||||||
|
_selected = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogColorGradation::updateColors()
|
||||||
|
{
|
||||||
|
Curve* curve;
|
||||||
|
|
||||||
|
curve = curveCreate();
|
||||||
|
_curve_editor->getCurve(curve);
|
||||||
|
|
||||||
|
switch (_selected)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
_preview_red->update();
|
||||||
|
_preview_green->update();
|
||||||
|
_preview_blue->update();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorGradationSetRedCurve(_current, curve);
|
||||||
|
_preview_red->update();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorGradationSetGreenCurve(_current, curve);
|
||||||
|
_preview_green->update();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
colorGradationSetBlueCurve(_current, curve);
|
||||||
|
_preview_blue->update();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
_preview_final->update();
|
||||||
|
|
||||||
|
curveDelete(curve);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogColorGradation::revertToCurrent()
|
void DialogColorGradation::revertToCurrent()
|
||||||
{
|
{
|
||||||
|
updateColors();
|
||||||
selectRed();
|
selectRed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _PAYSAGES_QT_DIALOGCOLORGRADATION_H_
|
#define _PAYSAGES_QT_DIALOGCOLORGRADATION_H_
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QPushButton>
|
||||||
#include "baseform.h"
|
#include "baseform.h"
|
||||||
#include "widgetcurveeditor.h"
|
#include "widgetcurveeditor.h"
|
||||||
#include "previewcolorgradation.h"
|
#include "previewcolorgradation.h"
|
||||||
|
@ -24,6 +25,7 @@ public slots:
|
||||||
void selectRed();
|
void selectRed();
|
||||||
void selectGreen();
|
void selectGreen();
|
||||||
void selectBlue();
|
void selectBlue();
|
||||||
|
void updateColors();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent* e);
|
virtual void closeEvent(QCloseEvent* e);
|
||||||
|
@ -40,6 +42,10 @@ private:
|
||||||
PreviewColorGradation* _preview_green;
|
PreviewColorGradation* _preview_green;
|
||||||
PreviewColorGradation* _preview_blue;
|
PreviewColorGradation* _preview_blue;
|
||||||
PreviewColorGradation* _preview_final;
|
PreviewColorGradation* _preview_final;
|
||||||
|
int _selected;
|
||||||
|
QPushButton* _button_accept;
|
||||||
|
QPushButton* _button_revert;
|
||||||
|
QPushButton* _button_cancel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#include "widgetcurveeditor.h"
|
#include "widgetcurveeditor.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include "../lib_paysages/tools.h"
|
||||||
|
|
||||||
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent) : QWidget(parent)
|
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
_curve = curveCreate();
|
_curve = curveCreate();
|
||||||
|
_dragged = -1;
|
||||||
|
|
||||||
setMinimumSize(500, 500);
|
setMinimumSize(500, 500);
|
||||||
setMaximumSize(500, 500);
|
setMaximumSize(500, 500);
|
||||||
|
@ -47,6 +50,85 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
curveGetPoint(_curve, i, &point);
|
curveGetPoint(_curve, i, &point);
|
||||||
painter.drawEllipse(QPoint((int)(point.position * 499.0), 499 - (int)(point.value * 499.0)), 4.0, 4.0);
|
painter.drawEllipse(QPointF((int)(point.position * 499.0), 499 - (int)(point.value * 499.0)), 4.0, 4.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WidgetCurveEditor::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
int i, n;
|
||||||
|
int nearest;
|
||||||
|
double mousex, mousey;
|
||||||
|
double distance, ndistance;
|
||||||
|
CurvePoint point;
|
||||||
|
|
||||||
|
n = curveGetPointCount(_curve);
|
||||||
|
if (n < 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mousex = ((double)event->x()) / 499.0;
|
||||||
|
mousey = 1.0 - ((double)event->y()) / 499.0;
|
||||||
|
nearest = -1;
|
||||||
|
|
||||||
|
// Find nearest point
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
curveGetPoint(_curve, i, &point);
|
||||||
|
ndistance = toolsGetDistance2D(point.position, point.value, mousex, mousey);
|
||||||
|
if (nearest < 0 || ndistance < distance)
|
||||||
|
{
|
||||||
|
distance = ndistance;
|
||||||
|
nearest = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distance < 0.015)
|
||||||
|
{
|
||||||
|
_dragged = nearest;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dragged = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
CurvePoint point;
|
||||||
|
|
||||||
|
if (_dragged >= 0)
|
||||||
|
{
|
||||||
|
point.position = ((double)event->x()) / 499.0;
|
||||||
|
point.value = 1.0 - ((double)event->y()) / 499.0;
|
||||||
|
|
||||||
|
point.position = (point.position < 0.0) ? 0.0 : point.position;
|
||||||
|
point.position = (point.position > 1.0) ? 1.0 : point.position;
|
||||||
|
point.value = (point.value < 0.0) ? 0.0 : point.value;
|
||||||
|
point.value = (point.value > 1.0) ? 1.0 : point.value;
|
||||||
|
|
||||||
|
curveSetPoint(_curve, _dragged, &point);
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
emit liveChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
if (_dragged >= 0)
|
||||||
|
{
|
||||||
|
_dragged = -1;
|
||||||
|
curveValidate(_curve);
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
|
@ -15,11 +15,18 @@ public:
|
||||||
void setCurve(Curve* curve);
|
void setCurve(Curve* curve);
|
||||||
void getCurve(Curve* curve);
|
void getCurve(Curve* curve);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void liveChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Curve* _curve;
|
Curve* _curve;
|
||||||
|
int _dragged;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,22 @@
|
||||||
<context>
|
<context>
|
||||||
<name>DialogColorGradation</name>
|
<name>DialogColorGradation</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/dialogcolorgradation.cpp" line="53"/>
|
<location filename="../gui_qt/dialogcolorgradation.cpp" line="55"/>
|
||||||
|
<source>Validate</source>
|
||||||
|
<translation>Valider</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui_qt/dialogcolorgradation.cpp" line="59"/>
|
||||||
|
<source>Revert</source>
|
||||||
|
<translation>Recommencer</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui_qt/dialogcolorgradation.cpp" line="63"/>
|
||||||
|
<source>Cancel</source>
|
||||||
|
<translation>Annuler</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui_qt/dialogcolorgradation.cpp" line="69"/>
|
||||||
<source>Paysages 3D - Color gradation editor</source>
|
<source>Paysages 3D - Color gradation editor</source>
|
||||||
<translation>Paysages 3D - Editeur de gradients de couleur</translation>
|
<translation>Paysages 3D - Editeur de gradients de couleur</translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "euclid.h"
|
#include "euclid.h"
|
||||||
|
@ -119,6 +120,13 @@ Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right
|
||||||
return v3Normalize(v3Cross(dz, dx));
|
return v3Normalize(v3Cross(dz, dx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double toolsGetDistance2D(double x1, double y1, double x2, double y2)
|
||||||
|
{
|
||||||
|
double dx = x2 - x1;
|
||||||
|
double dy = y2 - y1;
|
||||||
|
return sqrt(dx * dx + dy * dy);
|
||||||
|
}
|
||||||
|
|
||||||
void toolsSaveDouble(FILE* f, double* value)
|
void toolsSaveDouble(FILE* f, double* value)
|
||||||
{
|
{
|
||||||
uint64_t servalue;
|
uint64_t servalue;
|
||||||
|
|
|
@ -12,6 +12,7 @@ double toolsRandom();
|
||||||
double toolsBicubicInterpolate(double stencil[16], double x, double y);
|
double toolsBicubicInterpolate(double stencil[16], double x, double y);
|
||||||
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
|
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
|
||||||
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
|
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
|
||||||
|
double toolsGetDistance2D(double x1, double y1, double x2, double y2);
|
||||||
void toolsSaveDouble(FILE* f, double* value);
|
void toolsSaveDouble(FILE* f, double* value);
|
||||||
void toolsLoadDouble(FILE* f, double* value);
|
void toolsLoadDouble(FILE* f, double* value);
|
||||||
void toolsSaveInt(FILE* f, int* value);
|
void toolsSaveInt(FILE* f, int* value);
|
||||||
|
|
Loading…
Reference in a new issue