From 28c9c08d7434ee338e3749c7d6a953a56a5917af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 21 Aug 2015 00:25:34 +0200 Subject: [PATCH] Added water rendering toggle in opengl --- .../modeler/quickapp/WaterModeler.cpp | 18 ++++++- src/interface/modeler/quickapp/WaterModeler.h | 11 ++++- .../modeler/quickapp/qml/CameraChoice.qml | 9 ++++ .../modeler/quickapp/qml/Toolbar.qml | 5 +- .../modeler/quickapp/qml/ToolbarButton.qml | 46 ++++++++++-------- src/interface/modeler/quickapp/qml/app.qrc | 1 + .../quickapp/qml/images/toggle_water.png | Bin 0 -> 788 bytes src/render/opengl/OpenGLWater.cpp | 11 ++++- src/render/opengl/OpenGLWater.h | 6 +++ 9 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 src/interface/modeler/quickapp/qml/images/toggle_water.png 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 0000000000000000000000000000000000000000..0b66f39ddcd06fedfa8b88c78e83a1006d1e5cc1 GIT binary patch literal 788 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=oCO|{#S9GM>p_@t!U859pdfpR zr>`sfeGXARAp!AgOS>5um^OR5IEGZ*dV4K;#j;?T;~)DiQ&M6iCgo-oothA+aeR{J zvWs^n6)sdWh=HV?nN41XejCbgNFLZ_@1v8Z2J?~_em}Mzj-4YdlFOr zk@I%xmhT+f_s%%vb1XkmRqX7=Z$dGh_DT6x-~ONZVJTzE|NC=Vaap2y-oZ!<9`y$+ zS$>+!9pbfkTz|t(&N}!E`v$(%N&mBIB!36*&@WysZuB#k^Ff}>oip>h&rkZna_?NZ zY~9i1{|CQW{@|5=cw^b$X%9vJOue67u~qYnoXxHP)*W)wO&&KFL^u6p$ez7by}0JP z$?k7?en(F=-sRr>@7#h7>Bo+h?@0PEfA=h<@)<|Uat;Y@&baBSd82T#jz|3ybN*-M zYB%k6@PDioe(~eOuSZ|2fJa_yVQx@?n0hxKA+zYjMrwCmY; z?ApuD#B(xp@4b)ga)0!ubj^WlY9IOZA5B*IUi~ajuH#nk%==QaZU5$eX7)RKXX1}N zo^@KUt3T!*n|#CILt*y5{aI7gAKCor(QW?8TVbqZW_)Ag>{)U4mTNCRJlNQ~^{j63 z37vi0pGe&^&FC$ZnUx>*plQo%lXns#PitcA<}>L?%3N1W*1YuFx52o=@}U27*^PD6 zo>(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; };