diff --git a/src/interface/modeler/quickapp/WaterModeler.cpp b/src/interface/modeler/quickapp/WaterModeler.cpp index f5a1af9..ce905da 100644 --- a/src/interface/modeler/quickapp/WaterModeler.cpp +++ b/src/interface/modeler/quickapp/WaterModeler.cpp @@ -4,13 +4,27 @@ #include "Scenery.h" #include "TerrainDefinition.h" #include "FloatPropertyBind.h" +#include "OpenGLRenderer.h" +#include "OpenGLWater.h" -WaterModeler::WaterModeler(MainModelerWindow *main) +WaterModeler::WaterModeler(MainModelerWindow *ui): + ui(ui) { - prop_water_height = new FloatPropertyBind(main, "water_height", "value", main->getScenery()->getTerrain()->propWaterHeight()); + QObject *toggle_water = ui->findQmlObject("camera_toggle_water"); + if (toggle_water) + { + connect(toggle_water, SIGNAL(changed(bool)), this, SLOT(enableRendering(bool))); + } + + prop_water_height = new FloatPropertyBind(ui, "water_height", "value", ui->getScenery()->getTerrain()->propWaterHeight()); } WaterModeler::~WaterModeler() { delete prop_water_height; } + +void WaterModeler::enableRendering(bool enable) +{ + ui->getRenderer()->getWater()->setEnabled(enable); +} diff --git a/src/interface/modeler/quickapp/WaterModeler.h b/src/interface/modeler/quickapp/WaterModeler.h index b2b169e..d2840d5 100644 --- a/src/interface/modeler/quickapp/WaterModeler.h +++ b/src/interface/modeler/quickapp/WaterModeler.h @@ -1,18 +1,25 @@ #ifndef WATERMODELER_H #define WATERMODELER_H +#include + #include "modeler_global.h" namespace paysages { namespace modeler { -class WaterModeler +class WaterModeler: public QObject { + Q_OBJECT public: - WaterModeler(MainModelerWindow *main); + WaterModeler(MainModelerWindow *ui); ~WaterModeler(); +public slots: + void enableRendering(bool enable); + private: + MainModelerWindow *ui; FloatPropertyBind *prop_water_height; }; diff --git a/src/interface/modeler/quickapp/qml/CameraChoice.qml b/src/interface/modeler/quickapp/qml/CameraChoice.qml index ebbfbee..ca82ccb 100644 --- a/src/interface/modeler/quickapp/qml/CameraChoice.qml +++ b/src/interface/modeler/quickapp/qml/CameraChoice.qml @@ -19,6 +19,15 @@ Toolbar { hovertext: qsTr("Top-down camera") } + ToolbarButton { + id: camera_toggle_water + objectName: "camera_toggle_water" + toggle: true + selected: true + picture: "images/toggle_water.png" + hovertext: qsTr("Toggle water rendering") + } + states: [ State { name: "Render camera" diff --git a/src/interface/modeler/quickapp/qml/Toolbar.qml b/src/interface/modeler/quickapp/qml/Toolbar.qml index ad5e73d..9e9eddf 100644 --- a/src/interface/modeler/quickapp/qml/Toolbar.qml +++ b/src/interface/modeler/quickapp/qml/Toolbar.qml @@ -21,7 +21,10 @@ BaseRectangle { { for (var i = 0; i < children.length; i++) { - children[i].selected = false; + if (!children[i].toggle) + { + children[i].selected = false; + } } } } diff --git a/src/interface/modeler/quickapp/qml/ToolbarButton.qml b/src/interface/modeler/quickapp/qml/ToolbarButton.qml index cab0f34..5694866 100644 --- a/src/interface/modeler/quickapp/qml/ToolbarButton.qml +++ b/src/interface/modeler/quickapp/qml/ToolbarButton.qml @@ -2,23 +2,28 @@ import QtQuick 2.0 import QtGraphicalEffects 1.0 Item { + id: button property string picture property bool selected: false property bool hovered: false + property bool toggle: false property string helptext property string hovertext signal clicked + signal changed(bool value) width: image.width + 10 height: image.height + 10 + onSelectedChanged: changed(selected) + Rectangle { id: glow anchors.fill: parent - color: "#cccccc" + color: parent.toggle ? "#bbccbb" : "#cccccc" radius: 8 - opacity: parent.selected ? 1.0 : (parent.hovered ? 0.5 : 0.0) + opacity: button.selected ? 1.0 : (button.hovered ? 0.5 : 0.0) Behavior on opacity { PropertyAnimation { duration: 200 @@ -28,14 +33,14 @@ Item { anchors.fill: glow glowRadius: 8 spread: 0.2 - color: "white" + color: button.toggle ? "#99aa99" : "#ffffff" cornerRadius: glow.radius + glowRadius } } Image { id: image - source: parent.picture + source: button.picture anchors.centerIn: parent width: 32 height: 32 @@ -57,34 +62,37 @@ Item { cursorShape: Qt.PointingHandCursor onEntered: { - parent.hovered = true; + button.hovered = true; tooltip_widget.hovertext = hovertext; tooltip_widget.hovered = this; } onExited: { - parent.hovered = false; + button.hovered = false; tooltip_widget.hovertext = ""; } onClicked: { - parent.selected = !parent.selected; - if (parent.selected) + button.selected = !button.selected; + if (!button.toggle) { - var toolbar = parent.parent; - for (var i = 0; i < toolbar.children.length; ++i) + if (button.selected) { - var child = toolbar.children[i] - if (child !== parent) + var toolbar = button.parent; + for (var i = 0; i < toolbar.children.length; ++i) { - child.selected = false; + var child = toolbar.children[i] + if (child !== button && !child.toggle) + { + child.selected = false; + } } + tooltip_widget.helptext = helptext; + } + else + { + tooltip_widget.helptext = ""; } - tooltip_widget.helptext = helptext; } - else - { - tooltip_widget.helptext = ""; - } - parent.clicked(); + button.clicked(); } } } diff --git a/src/interface/modeler/quickapp/qml/app.qrc b/src/interface/modeler/quickapp/qml/app.qrc index db80c69..313a7f2 100644 --- a/src/interface/modeler/quickapp/qml/app.qrc +++ b/src/interface/modeler/quickapp/qml/app.qrc @@ -37,5 +37,6 @@ images/arrow_down.png images/arrow_up.png ClickableImage.qml + images/toggle_water.png diff --git a/src/interface/modeler/quickapp/qml/images/toggle_water.png b/src/interface/modeler/quickapp/qml/images/toggle_water.png new file mode 100644 index 0000000..0b66f39 Binary files /dev/null and b/src/interface/modeler/quickapp/qml/images/toggle_water.png differ diff --git a/src/render/opengl/OpenGLWater.cpp b/src/render/opengl/OpenGLWater.cpp index bdd8d29..81c6289 100644 --- a/src/render/opengl/OpenGLWater.cpp +++ b/src/render/opengl/OpenGLWater.cpp @@ -15,6 +15,7 @@ OpenGLWater::OpenGLWater(OpenGLRenderer *renderer): OpenGLPart(renderer) { vertices = new float[4 * 3]; + enabled = true; } OpenGLWater::~OpenGLWater() @@ -54,7 +55,10 @@ void OpenGLWater::update() void OpenGLWater::render() { - program->drawTriangleStrip(vertices, 4); + if (enabled) + { + program->drawTriangleStrip(vertices, 4); + } } void OpenGLWater::setVertex(int i, float x, float y, float z) @@ -71,3 +75,8 @@ void OpenGLWater::nodeChanged(const DefinitionNode *node, const DefinitionDiff * renderer->getSharedState()->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset()); } } + +void OpenGLWater::setEnabled(bool enabled) +{ + this->enabled = enabled; +} diff --git a/src/render/opengl/OpenGLWater.h b/src/render/opengl/OpenGLWater.h index c64ae2e..0edaf13 100644 --- a/src/render/opengl/OpenGLWater.h +++ b/src/render/opengl/OpenGLWater.h @@ -20,9 +20,15 @@ public: virtual void render() override; virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff) override; + + /** + * Enable or disable the water surface rendering. + */ + void setEnabled(bool enabled); private: void setVertex(int i, float x, float y, float z); + bool enabled; OpenGLShaderProgram* program; float* vertices; };