diff --git a/gui_gtk/tab_water.c b/gui_gtk/tab_water.c index 2cd4773..d57c5a6 100644 --- a/gui_gtk/tab_water.c +++ b/gui_gtk/tab_water.c @@ -136,12 +136,12 @@ static void _cbTransparencyDepthChanged(GtkRange* range, gpointer data) static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data) { - GdkRGBA col; + GdkColor col; - gtk_color_button_get_rgba(colorbutton, &col); - _definition.main_color.r = col.red; - _definition.main_color.g = col.green; - _definition.main_color.b = col.blue; + gtk_color_button_get_color(colorbutton, &col); + _definition.main_color.r = (double)col.red / 65535.0; + _definition.main_color.g = (double)col.green / 65535.0; + _definition.main_color.b = (double)col.blue / 65535.0; _definition.main_color.a = 1.0; guiPreviewRedraw(_preview_render); @@ -150,12 +150,12 @@ static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data) static void _cbColorDepthChanged(GtkColorButton* colorbutton, gpointer data) { - GdkRGBA col; + GdkColor col; - gtk_color_button_get_rgba(colorbutton, &col); - _definition.depth_color.r = col.red; - _definition.depth_color.g = col.green; - _definition.depth_color.b = col.blue; + gtk_color_button_get_color(colorbutton, &col); + _definition.depth_color.r = (double)col.red / 65535.0; + _definition.depth_color.g = (double)col.green / 65535.0; + _definition.depth_color.b = (double)col.blue / 65535.0; _definition.depth_color.a = 1.0; guiPreviewRedraw(_preview_render); @@ -164,7 +164,7 @@ static void _cbColorDepthChanged(GtkColorButton* colorbutton, gpointer data) static void _cbRevertConfig(GtkWidget* widget, gpointer data) { - GdkRGBA col; + GdkColor col; waterCopyDefinition(waterGetDefinition(), &_definition); @@ -172,16 +172,14 @@ static void _cbRevertConfig(GtkWidget* widget, gpointer data) gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency")), _definition.transparency); gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_reflection")), _definition.reflection); gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency_depth")), _definition.transparency_depth); - col.red = _definition.main_color.r; - col.green = _definition.main_color.g; - col.blue = _definition.main_color.b; - col.alpha = 1.0; - gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col); - col.red = _definition.depth_color.r; - col.green = _definition.depth_color.g; - col.blue = _definition.depth_color.b; - col.alpha = 1.0; - gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color_depth")), &col); + col.red = _definition.main_color.r * 65535.0; + col.green = _definition.main_color.g * 65535.0; + col.blue = _definition.main_color.b * 65535.0; + gtk_color_button_set_color(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col); + col.red = _definition.depth_color.r * 65535.0; + col.green = _definition.depth_color.g * 65535.0; + col.blue = _definition.depth_color.b * 65535.0; + gtk_color_button_set_color(GTK_COLOR_BUTTON(GET_WIDGET("water_color_depth")), &col); guiPreviewRedraw(_preview_render); guiPreviewRedraw(_preview_coverage); diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index a0d6c6c..95b5f87 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -1,46 +1,10 @@ #include "baseform.h" +#include "inputdouble.h" #include #include #include #include -#include - -class DoubleSliderWidget:public QWidget -{ -public: - DoubleSliderWidget(QWidget* parent, double* value, double min, double max, double small_step, double large_step): - QWidget(parent), - value(value), min(min), max(max), small_step(small_step), large_step(large_step) - { - setObjectName("_form_doubleslider_"); - - setLayout(new QHBoxLayout()); - - slider = new QSlider(this); - slider->setOrientation(Qt::Horizontal); - slider->setMinimum(min / small_step); - slider->setMaximum(max / small_step); - slider->setValue(*value / small_step); - slider->setTickInterval(large_step / small_step); - slider->setTickPosition(QSlider::TicksBelow); - - layout()->addWidget(slider); - } - - void revert() - { - slider->setValue(*value / small_step); - } - -private: - QSlider* slider; - double* value; - double min; - double max; - double small_step; - double large_step; -}; BaseForm::BaseForm(QWidget* parent) : QWidget(parent) @@ -72,19 +36,24 @@ BaseForm::BaseForm(QWidget* parent) : this->setLayout(vlayout); } -void BaseForm::revertConfig() +void BaseForm::applyConfigPreview() { QList list_previews = previews->findChildren("_form_preview_"); for (int i = 0; i < list_previews.size(); i++) { list_previews[i]->redraw(); } +} - QList list_doubles = form->findChildren("_form_doubleslider_"); +void BaseForm::revertConfig() +{ + QList list_doubles = form->findChildren("_form_doubleslider_"); for (int i = 0; i < list_doubles.size(); i++) { list_doubles[i]->revert(); } + + BaseForm::applyConfigPreview(); } void BaseForm::addPreview(Preview* preview, QString label) @@ -94,11 +63,19 @@ void BaseForm::addPreview(Preview* preview, QString label) preview->setObjectName("_form_preview_"); } -void BaseForm::addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step) +void BaseForm::addInput(BaseInput* input) { QGridLayout* layout = (QGridLayout*)form->layout(); int row = layout->rowCount(); - layout->addWidget(new QLabel(label, form), row, 0); - layout->addWidget(new DoubleSliderWidget(form, value, min, max, small_step, large_step), row, 1); + layout->addWidget(input->label(), row, 0); + layout->addWidget(input->preview(), row, 1); + layout->addWidget(input->control(), row, 2); + + connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview())); +} + +void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step) +{ + addInput(new InputDouble(form, label, value, min, max, small_step, large_step)); } diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 274950f..625864e 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -3,18 +3,23 @@ #include #include "preview.h" +#include "baseinput.h" class BaseForm:public QWidget { + Q_OBJECT + public: BaseForm(QWidget* parent); public slots: virtual void revertConfig(); + virtual void applyConfigPreview(); protected: void addPreview(Preview* preview, QString label); - void addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step); + void addInput(BaseInput* input); + void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step); private: QWidget* previews; diff --git a/gui_qt/baseinput.cpp b/gui_qt/baseinput.cpp new file mode 100644 index 0000000..44d0f33 --- /dev/null +++ b/gui_qt/baseinput.cpp @@ -0,0 +1,9 @@ +#include "baseinput.h" + +#include + +BaseInput::BaseInput(QWidget* form, QString label): + QObject(form) +{ + _label = new QLabel(label); +} diff --git a/gui_qt/baseinput.h b/gui_qt/baseinput.h new file mode 100644 index 0000000..223e946 --- /dev/null +++ b/gui_qt/baseinput.h @@ -0,0 +1,32 @@ +#ifndef _GUI_QT_BASEINPUT_H_ +#define _GUI_QT_BASEINPUT_H_ + +#include +#include + +class BaseInput:public QObject +{ + Q_OBJECT + +public: + BaseInput(QWidget* form, QString label); + inline QWidget* label() {return _label;} + inline QWidget* preview() {return _preview;} + inline QWidget* control() {return _control;} + +public slots: + virtual void revert() = 0; + +protected slots: + virtual void applyValue() = 0; + +signals: + void valueChanged(); + +protected: + QWidget* _label; + QWidget* _preview; + QWidget* _control; +}; + +#endif // _GUI_QT_BASEINPUT_H_ diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 6e60a9a..cd9c42f 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -131,33 +131,22 @@ FormWater::FormWater(QWidget *parent) : addPreview(previewCoverage, QString("Coverage preview")); addPreview(previewColor, QString("Color preview")); - addDoubleSlider("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0); - addDoubleSlider("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1); - addDoubleSlider("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1); - addDoubleSlider("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0); + addInputDouble("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0); + addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1); + addInputDouble("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1); + addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0); revertConfig(); } -void FormWater::configChange() -{ - /*_definition.height = (double)findChild("water_height")->value() / 10.0; - _definition.transparency = (double)findChild("water_transparency")->value() / 1000.0; - _definition.reflection = (double)findChild("water_reflection")->value() / 1000.0; - _definition.transparency_depth = (double)findChild("water_depth_limit")->value() / 10.0; - - previewCoverage->redraw(); - previewColor->redraw();*/ -} - -void FormWater::applyConfig() -{ - waterSetDefinition(_definition); - //guiUpdate(); -} - void FormWater::revertConfig() { waterCopyDefinition(waterGetDefinition(), &_definition); BaseForm::revertConfig(); } + +/*void FormWater::applyConfig() +{ + waterSetDefinition(_definition); + //guiUpdate(); +}*/ diff --git a/gui_qt/formwater.h b/gui_qt/formwater.h index 7aa596c..e40c408 100644 --- a/gui_qt/formwater.h +++ b/gui_qt/formwater.h @@ -14,8 +14,6 @@ public: public slots: virtual void revertConfig(); - void configChange(); - void applyConfig(); private: Preview* previewCoverage; diff --git a/gui_qt/inputcolor.cpp b/gui_qt/inputcolor.cpp new file mode 100644 index 0000000..f5e2d84 --- /dev/null +++ b/gui_qt/inputcolor.cpp @@ -0,0 +1,22 @@ +#include "inputcolor.h" + +#include + +InputColor::InputColor(QWidget* form, QString label, Color color): + BaseInput(form, label), + _color(color) +{ + setObjectName("_inputcolor_"); + + _preview = new QLabel(form); + _control = new QLabel(form); +} + +void InputColor::applyValue() +{ + emit(valueChanged()); +} + +void InputColor::revert() +{ +} diff --git a/gui_qt/inputcolor.h b/gui_qt/inputcolor.h new file mode 100644 index 0000000..f998e96 --- /dev/null +++ b/gui_qt/inputcolor.h @@ -0,0 +1,26 @@ +#ifndef _GUI_QT_INPUTCOLOR_H_ +#define _GUI_QT_INPUTCOLOR_H_ + +#include +#include "baseinput.h" + +#include "../lib_paysages/shared/types.h" + +class InputColor:public BaseInput +{ + Q_OBJECT + +public: + InputColor(QWidget* form, QString label, Color value); + +public slots: + virtual void revert(); + +protected slots: + virtual void applyValue(); + +private: + Color _color; +}; + +#endif // _GUI_QT_INPUTCOLOR_H_ diff --git a/gui_qt/inputdouble.cpp b/gui_qt/inputdouble.cpp new file mode 100644 index 0000000..1840702 --- /dev/null +++ b/gui_qt/inputdouble.cpp @@ -0,0 +1,40 @@ +#include "inputdouble.h" + +#include + +InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step): + BaseInput(form, label), + value(value), min(min), max(max), small_step(small_step), large_step(large_step) +{ + setObjectName("_form_doubleslider_"); + + slider = new QSlider(form); + + slider->setOrientation(Qt::Horizontal); + slider->setMinimumWidth(150); + slider->setMaximumWidth(400); + + slider->setMinimum(min / small_step); + slider->setMaximum(max / small_step); + slider->setValue(*value / small_step); + + slider->setTickInterval(large_step / small_step); + slider->setTickPosition(QSlider::TicksBelow); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue())); + + _preview = new QLabel(form); + _control = slider; +} + +void InputDouble::applyValue() +{ + *value = ((double)slider->value()) * small_step; + ((QLabel*)_preview)->setText(QString("%1").arg(*value)); + emit(valueChanged()); +} + +void InputDouble::revert() +{ + slider->setValue(*value / small_step); +} diff --git a/gui_qt/inputdouble.h b/gui_qt/inputdouble.h new file mode 100644 index 0000000..b706609 --- /dev/null +++ b/gui_qt/inputdouble.h @@ -0,0 +1,30 @@ +#ifndef _GUI_QT_INPUTDOUBLE_H_ +#define _GUI_QT_INPUTDOUBLE_H_ + +#include +#include +#include "baseinput.h" + +class InputDouble:public BaseInput +{ + Q_OBJECT + +public: + InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step); + +public slots: + virtual void revert(); + +protected slots: + virtual void applyValue(); + +private: + QSlider* slider; + double* value; + double min; + double max; + double small_step; + double large_step; +}; + +#endif // _GUI_QT_INPUTDOUBLE_H_ diff --git a/gui_qt/main.cc b/gui_qt/main.cc deleted file mode 100644 index 279d6fa..0000000 --- a/gui_qt/main.cc +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "mainwindow.h" -#include "preview.h" - -#include "../lib_paysages/shared/functions.h" - -int main(int argc, char** argv) -{ - paysagesInit(); - - QApplication app(argc, argv); - MainWindow window; - - window.show(); - - Preview::startUpdater(); - - return app.exec(); -} diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index aff3226..606ab59 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -1,20 +1,30 @@ +#include #include "mainwindow.h" #include "formwater.h" -#include "ui_mainwindow.h" + +#include "../lib_paysages/shared/functions.h" + +int main(int argc, char** argv) +{ + paysagesInit(); + + QApplication app(argc, argv); + MainWindow window; + + window.show(); + + Preview::startUpdater(); + + return app.exec(); +} MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) + QMainWindow(parent) { QTabWidget* tabs; - ui->setupUi(this); - - tabs = this->findChild("tabWidget"); + tabs = new QTabWidget(this); tabs->addTab(new FormWater(tabs), "Water"); -} -MainWindow::~MainWindow() -{ - delete ui; + setCentralWidget(tabs); } diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index c9fd6a9..fb5c048 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -13,10 +13,6 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private: - Ui::MainWindow *ui; }; #endif // MAINWINDOW_H diff --git a/gui_qt/mainwindow.ui b/gui_qt/mainwindow.ui deleted file mode 100644 index 71ff3f9..0000000 --- a/gui_qt/mainwindow.ui +++ /dev/null @@ -1,105 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 744 - 673 - - - - - 0 - 0 - - - - - 744 - 673 - - - - - 744 - 673 - - - - - 744 - 673 - - - - Paysages - - - - - - 0 - 0 - 741 - 621 - - - - -1 - - - - - - - 0 - 0 - 744 - 25 - - - - - File - - - - - - - - - About... - - - - - - - - - New - - - - - Save - - - - - Load - - - - - Quit - - - - - - diff --git a/gui_qt/paysages-qt.pro b/gui_qt/paysages-qt.pro index a34cda8..105f403 100644 --- a/gui_qt/paysages-qt.pro +++ b/gui_qt/paysages-qt.pro @@ -15,10 +15,16 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \ mainwindow.h \ formwater.h \ preview.h \ - baseform.h -FORMS += mainwindow.ui -SOURCES += main.cc \ + baseform.h \ + inputdouble.h \ + baseinput.h \ + inputcolor.h +FORMS += +SOURCES += \ mainwindow.cpp \ formwater.cpp \ preview.cpp \ - baseform.cpp + baseform.cpp \ + inputdouble.cpp \ + baseinput.cpp \ + inputcolor.cpp diff --git a/gui_qt/preview.h b/gui_qt/preview.h index 6fdc690..c1439e2 100644 --- a/gui_qt/preview.h +++ b/gui_qt/preview.h @@ -7,6 +7,8 @@ class Preview:public QWidget { + Q_OBJECT + public: Preview(QWidget* parent); static void startUpdater();