diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 1c4f630..c804eab 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -11,13 +11,14 @@ #include #include -BaseForm::BaseForm(QWidget* parent) : - QWidget(parent) +BaseForm::BaseForm(QWidget* parent, bool auto_apply) : QWidget(parent) { QWidget* hwidget; QVBoxLayout* vlayout; QHBoxLayout* hlayout; + this->auto_apply = auto_apply; + vlayout = new QVBoxLayout(); hlayout = new QHBoxLayout(); @@ -50,18 +51,31 @@ BaseForm::BaseForm(QWidget* parent) : button_revert = addButton("Revert"); button_revert->setEnabled(false); connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig())); + + if (auto_apply) + { + button_apply->hide(); + button_revert->hide(); + } } void BaseForm::configChangeEvent() { + if (auto_apply) + { + applyConfig(); + } + else + { + button_apply->setEnabled(true); + button_revert->setEnabled(true); + } + QList list_previews = previews->findChildren("_form_preview_"); for (int i = 0; i < list_previews.size(); i++) { list_previews[i]->redraw(); } - - button_apply->setEnabled(true); - button_revert->setEnabled(true); } void BaseForm::revertConfig() @@ -80,7 +94,9 @@ void BaseForm::revertConfig() void BaseForm::applyConfig() { - revertConfig(); + button_apply->setEnabled(false); + button_revert->setEnabled(false); + emit(configApplied()); } diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index d760503..a098447 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -13,7 +13,7 @@ class BaseForm:public QWidget Q_OBJECT public: - BaseForm(QWidget* parent); + BaseForm(QWidget* parent, bool auto_apply=false); signals: void configApplied(); @@ -36,6 +36,7 @@ protected: void addInputNoise(QString label, NoiseGenerator* value); private: + bool auto_apply; QWidget* previews; QWidget* form; QWidget* buttons; diff --git a/gui_qt/dialogwanderer.cpp b/gui_qt/dialogwanderer.cpp index 1c8da18..7709755 100644 --- a/gui_qt/dialogwanderer.cpp +++ b/gui_qt/dialogwanderer.cpp @@ -1,21 +1,53 @@ #include "dialogwanderer.h" +#include +#include #include #include "widgetwanderer.h" -DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera): - QDialog(parent) +DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera, bool camera_validable) : QDialog(parent) { + QWidget* panel; + QPushButton* button; + setModal(true); setWindowTitle("Paysages 3D - Explore"); - setLayout(new QVBoxLayout()); + setLayout(new QHBoxLayout()); - layout()->addWidget(new WidgetWanderer(this, camera)); + _wanderer = new WidgetWanderer(this, camera); + layout()->addWidget(_wanderer); - resize(700, 530); + panel = new QWidget(this); + panel->setLayout(new QVBoxLayout()); + panel->setMaximumWidth(200); + + button = new QPushButton("Reset camera", panel); + panel->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), _wanderer, SLOT(resetCamera())); + + if (camera_validable) + { + button = new QPushButton("Validate as render camera", panel); + panel->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), this, SLOT(validateCamera())); + } + + button = new QPushButton("Close", panel); + panel->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject())); + + layout()->addWidget(panel); + + resize(900, 600); } DialogWanderer::~DialogWanderer() { } +void DialogWanderer::validateCamera() +{ + _wanderer->validateCamera(); + reject(); +} + diff --git a/gui_qt/dialogwanderer.h b/gui_qt/dialogwanderer.h index f21d664..34176ec 100644 --- a/gui_qt/dialogwanderer.h +++ b/gui_qt/dialogwanderer.h @@ -2,14 +2,21 @@ #define _PAYSAGES_QT_DIALOGWANDERER_H_ #include +#include "widgetwanderer.h" #include "../lib_paysages/camera.h" class DialogWanderer : public QDialog { Q_OBJECT public: - explicit DialogWanderer(QWidget *parent, CameraDefinition* camera); + explicit DialogWanderer(QWidget *parent, CameraDefinition* camera, bool camera_validable); ~DialogWanderer(); + +protected slots: + void validateCamera(); + +private: + WidgetWanderer* _wanderer; }; #endif diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 629362a..0e3f472 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -2,20 +2,24 @@ #include #include - #include "dialogrender.h" +#include "inputcamera.h" #include "../lib_paysages/render.h" +#include "../lib_paysages/scenery.h" #include "../lib_paysages/shared/functions.h" /**************** Form ****************/ FormRender::FormRender(QWidget *parent) : - BaseForm(parent), - _quality(5), - _width(800), - _height(600) + BaseForm(parent, true) { QPushButton* button; + _quality = 5; + _width = 800; + _height = 600; + _camera = cameraCreateDefinition(); + + addInput(new InputCamera(this, "Camera", &_camera)); addInputInt("Quality", &_quality, 1, 10, 1, 1); addInputInt("Image width", &_width, 100, 2000, 10, 100); addInputInt("Image height", &_height, 100, 2000, 10, 100); @@ -30,6 +34,24 @@ FormRender::FormRender(QWidget *parent) : revertConfig(); } +void FormRender::revertConfig() +{ + sceneryGetCamera(&_camera); + BaseForm::revertConfig(); +} + +void FormRender::applyConfig() +{ + scenerySetCamera(&_camera); + BaseForm::applyConfig(); +} + +void FormRender::configChangeEvent() +{ + cameraValidateDefinition(&_camera); + BaseForm::configChangeEvent(); +} + void FormRender::startRender() { DialogRender* dialog = new DialogRender(this); diff --git a/gui_qt/formrender.h b/gui_qt/formrender.h index ba14f53..5657b9a 100644 --- a/gui_qt/formrender.h +++ b/gui_qt/formrender.h @@ -2,6 +2,7 @@ #define _PAYSAGES_QT_FORMRENDER_H_ #include "baseform.h" +#include "../lib_paysages/camera.h" class FormRender : public BaseForm { @@ -10,6 +11,13 @@ class FormRender : public BaseForm public: explicit FormRender(QWidget *parent = 0); +public slots: + virtual void revertConfig(); + virtual void applyConfig(); + +protected slots: + virtual void configChangeEvent(); + private slots: void startRender(); void showRender(); @@ -19,6 +27,7 @@ private: int _quality; int _width; int _height; + CameraDefinition _camera; }; #endif // _PAYSAGES_QT_FORMRENDER_H_ diff --git a/gui_qt/inputcamera.cpp b/gui_qt/inputcamera.cpp new file mode 100644 index 0000000..ffd5cc1 --- /dev/null +++ b/gui_qt/inputcamera.cpp @@ -0,0 +1,50 @@ +#include "inputcamera.h" + +#include +#include +#include +#include + +#include "dialogwanderer.h" + +#include "../lib_paysages/shared/functions.h" + +InputCamera::InputCamera(QWidget* form, QString label, CameraDefinition* value):BaseInput(form, label) +{ + _value = value; + + _preview = new QWidget(form); + + _control = new QPushButton("Edit", form); + _control->setMaximumWidth(150); + + connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editCamera())); +} + +void InputCamera::updatePreview() +{ + //_preview->update(); + + BaseInput::updatePreview(); +} + +void InputCamera::applyValue() +{ + BaseInput::applyValue(); +} + +void InputCamera::revert() +{ + BaseInput::revert(); +} + +void InputCamera::editCamera() +{ + DialogWanderer* dialog = new DialogWanderer(_control, _value, true); + dialog->exec(); + + delete dialog; + + // TODO Only if camera was edited + applyValue(); +} diff --git a/gui_qt/inputcamera.h b/gui_qt/inputcamera.h new file mode 100644 index 0000000..d616185 --- /dev/null +++ b/gui_qt/inputcamera.h @@ -0,0 +1,28 @@ +#ifndef _PAYSAGES_QT_INPUTCAMERA_H_ +#define _PAYSAGES_QT_INPUTCAMERA_H_ + +#include +#include "baseinput.h" + +#include "../lib_paysages/camera.h" + +class InputCamera:public BaseInput +{ + Q_OBJECT + +public: + InputCamera(QWidget* form, QString label, CameraDefinition* value); + +public slots: + virtual void updatePreview(); + virtual void applyValue(); + virtual void revert(); + +private slots: + void editCamera(); + +private: + CameraDefinition* _value; +}; + +#endif // _PAYSAGES_QT_INPUTNOISE_H_ diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index d6ccd62..6976ce5 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -138,7 +138,7 @@ void MainWindow::explore3D() sceneryGetCamera(&camera); - DialogWanderer* dialog = new DialogWanderer(this, &camera); + DialogWanderer* dialog = new DialogWanderer(this, &camera, false); dialog->exec(); delete dialog; diff --git a/gui_qt/paysages-qt.pro b/gui_qt/paysages-qt.pro index a4c6673..d895109 100644 --- a/gui_qt/paysages-qt.pro +++ b/gui_qt/paysages-qt.pro @@ -29,6 +29,7 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \ formterrain.h \ formtextures.h \ formwater.h \ + inputcamera.h \ inputcolor.h \ inputcolorgradation.h \ inputdouble.h \ @@ -53,6 +54,7 @@ SOURCES += \ formterrain.cpp \ formtextures.cpp \ formwater.cpp \ + inputcamera.cpp \ inputcolor.cpp \ inputcolorgradation.cpp \ inputdouble.cpp \ diff --git a/gui_qt/widgetwanderer.cpp b/gui_qt/widgetwanderer.cpp index 1902f73..e30e317 100644 --- a/gui_qt/widgetwanderer.cpp +++ b/gui_qt/widgetwanderer.cpp @@ -11,7 +11,8 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): setMinimumSize(400, 300); setFocusPolicy(Qt::StrongFocus); - cameraCopyDefinition(camera, &this->camera); + _base_camera = camera; + cameraCopyDefinition(camera, &_current_camera); this->terrain = terrainCreateDefinition(); sceneryGetTerrain(&terrain); @@ -23,6 +24,17 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): last_mouse_y = 0; } +void WidgetWanderer::resetCamera() +{ + cameraCopyDefinition(_base_camera, &_current_camera); + updateGL(); +} + +void WidgetWanderer::validateCamera() +{ + cameraCopyDefinition(&_current_camera, _base_camera); +} + void WidgetWanderer::keyPressEvent(QKeyEvent* event) { double factor; @@ -43,32 +55,32 @@ void WidgetWanderer::keyPressEvent(QKeyEvent* event) if (event->key() == Qt::Key_Up) { - cameraStrafeForward(&camera, 0.1 * factor); + cameraStrafeForward(&_current_camera, 0.1 * factor); updateGL(); } else if (event->key() == Qt::Key_Down) { - cameraStrafeForward(&camera, -0.1 * factor); + cameraStrafeForward(&_current_camera, -0.1 * factor); updateGL(); } else if (event->key() == Qt::Key_Right) { - cameraStrafeRight(&camera, 0.1 * factor); + cameraStrafeRight(&_current_camera, 0.1 * factor); updateGL(); } else if (event->key() == Qt::Key_Left) { - cameraStrafeRight(&camera, -0.1 * factor); + cameraStrafeRight(&_current_camera, -0.1 * factor); updateGL(); } else if (event->key() == Qt::Key_PageUp) { - cameraStrafeUp(&camera, 0.1 * factor); + cameraStrafeUp(&_current_camera, 0.1 * factor); updateGL(); } else if (event->key() == Qt::Key_PageDown) { - cameraStrafeUp(&camera, -0.1 * factor); + cameraStrafeUp(&_current_camera, -0.1 * factor); updateGL(); } else @@ -105,14 +117,14 @@ void WidgetWanderer::mouseMoveEvent(QMouseEvent* event) if (event->buttons() & Qt::LeftButton) { - cameraStrafeRight(&camera, (double)(last_mouse_x - event->x()) * factor); - cameraStrafeUp(&camera, (double)(event->y() - last_mouse_y) * factor); + cameraStrafeRight(&_current_camera, (double)(last_mouse_x - event->x()) * factor); + cameraStrafeUp(&_current_camera, (double)(event->y() - last_mouse_y) * factor); updateGL(); event->accept(); } else if (event->buttons() & Qt::RightButton) { - cameraRotateYaw(&camera, (double)(event->x() - last_mouse_x) * factor * 0.1); + cameraRotateYaw(&_current_camera, (double)(event->x() - last_mouse_x) * factor * 0.1); updateGL(); event->accept(); } @@ -145,7 +157,7 @@ void WidgetWanderer::wheelEvent(QWheelEvent* event) if (event->orientation() == Qt::Vertical) { - cameraStrafeForward(&camera, (double)event->delta() * factor); + cameraStrafeForward(&_current_camera, (double)event->delta() * factor); updateGL(); } @@ -255,7 +267,7 @@ void WidgetWanderer::paintGL() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - gluLookAt(camera.location.x, camera.location.y, camera.location.z, camera.target.x, camera.target.y, camera.target.z, camera.up.x, camera.up.y, camera.up.z); + gluLookAt(_current_camera.location.x, _current_camera.location.y, _current_camera.location.z, _current_camera.target.x, _current_camera.target.y, _current_camera.target.z, _current_camera.up.x, _current_camera.up.y, _current_camera.up.z); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -268,5 +280,5 @@ void WidgetWanderer::paintGL() glVertex3f(500.0, water.height, -500.0); glEnd(); - _renderTerrain(&terrain, &camera, 3); + _renderTerrain(&terrain, &_current_camera, 3); } diff --git a/gui_qt/widgetwanderer.h b/gui_qt/widgetwanderer.h index ca574c4..f0b4ef6 100644 --- a/gui_qt/widgetwanderer.h +++ b/gui_qt/widgetwanderer.h @@ -12,6 +12,10 @@ class WidgetWanderer : public QGLWidget public: WidgetWanderer(QWidget* parent, CameraDefinition* camera); +public slots: + void resetCamera(); + void validateCamera(); + protected: void keyPressEvent(QKeyEvent* event); void mousePressEvent(QMouseEvent* event); @@ -23,7 +27,9 @@ protected: void paintGL(); private: - CameraDefinition camera; + CameraDefinition _current_camera; + CameraDefinition* _base_camera; + TerrainDefinition terrain; WaterDefinition water;