From 989a76fe6ebbff3d6dca43a16b2bd409282233f9 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 20 Feb 2014 16:56:40 -0800 Subject: [PATCH 1/5] Hooked up Clipboard preview --- interface/src/ui/ClipboardOverlay.cpp | 42 +++++++++++++++++++++++++++ interface/src/ui/ClipboardOverlay.h | 25 ++++++++++++++++ interface/src/ui/Overlays.cpp | 7 ++++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 interface/src/ui/ClipboardOverlay.cpp create mode 100644 interface/src/ui/ClipboardOverlay.h diff --git a/interface/src/ui/ClipboardOverlay.cpp b/interface/src/ui/ClipboardOverlay.cpp new file mode 100644 index 0000000000..1eaf5e75f0 --- /dev/null +++ b/interface/src/ui/ClipboardOverlay.cpp @@ -0,0 +1,42 @@ +// +// ClipboardOverlay.cpp +// hifi +// +// Created by Clément Brisset on 2/20/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" + +#include +#include + +#include "ClipboardOverlay.h" +#include "../Application.h" + +ClipboardOverlay::ClipboardOverlay() { +} + +ClipboardOverlay::~ClipboardOverlay() { +} + +void ClipboardOverlay::render() { + if (!_visible) { + return; // do nothing if we're not visible + } + + VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem(); + VoxelTree* clipboard = Application::getInstance()->getClipboard(); + if (voxelSystem->getTree() != clipboard) { + voxelSystem->changeTree(clipboard); + } + + glPushMatrix(); + glTranslatef(_position.x, _position.y, _position.z); + glScalef(_size, _size, _size); + + voxelSystem->render(); + + glPopMatrix(); +} \ No newline at end of file diff --git a/interface/src/ui/ClipboardOverlay.h b/interface/src/ui/ClipboardOverlay.h new file mode 100644 index 0000000000..49daa73c20 --- /dev/null +++ b/interface/src/ui/ClipboardOverlay.h @@ -0,0 +1,25 @@ +// +// ClipboardOverlay.h +// hifi +// +// Created by Clément Brisset on 2/20/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__ClipboardOverlay__ +#define __interface__ClipboardOverlay__ + +#include "Volume3DOverlay.h" + +class ClipboardOverlay : public Volume3DOverlay { + Q_OBJECT + +public: + ClipboardOverlay(); + ~ClipboardOverlay(); + + virtual void render(); +}; + + +#endif /* defined(__interface__ClipboardOverlay__) */ diff --git a/interface/src/ui/Overlays.cpp b/interface/src/ui/Overlays.cpp index c35c4fc5ec..e247486e8e 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -12,7 +12,7 @@ #include "Overlays.h" #include "Sphere3DOverlay.h" #include "TextOverlay.h" - +#include "ClipboardOverlay.h" unsigned int Overlays::_nextOverlayID = 1; @@ -73,6 +73,11 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope thisOverlay->setProperties(properties); created = true; is3D = true; + } else if (type == "clipboard") { + thisOverlay = new ClipboardOverlay(); + thisOverlay->init(_parent); + thisOverlay->setProperties(properties); + created = true; } if (created) { From fc7692417f6baf709cec2a78aaa83368dc13d727 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 21 Feb 2014 15:15:16 -0800 Subject: [PATCH 2/5] Fix is3D not set to true --- interface/src/ui/Overlays.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/Overlays.cpp b/interface/src/ui/Overlays.cpp index e247486e8e..84944332f1 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -78,6 +78,7 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope thisOverlay->init(_parent); thisOverlay->setProperties(properties); created = true; + is3D = true; } if (created) { From e8c9dc50d0871eb774f4f669069e2f2ec8ea23f4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 21 Feb 2014 15:23:28 -0800 Subject: [PATCH 3/5] Hack to get preview working --- interface/src/ui/ClipboardOverlay.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/interface/src/ui/ClipboardOverlay.cpp b/interface/src/ui/ClipboardOverlay.cpp index 1eaf5e75f0..12c72c7690 100644 --- a/interface/src/ui/ClipboardOverlay.cpp +++ b/interface/src/ui/ClipboardOverlay.cpp @@ -15,6 +15,8 @@ #include "ClipboardOverlay.h" #include "../Application.h" +static int lastVoxelCount = 0; + ClipboardOverlay::ClipboardOverlay() { } @@ -36,6 +38,15 @@ void ClipboardOverlay::render() { glTranslatef(_position.x, _position.y, _position.z); glScalef(_size, _size, _size); + qDebug() << "[DEBUG] " << voxelSystem->getVoxelsRendered() << " " + << clipboard->getOctreeElementsCount(); + + // TODO : replace that hack to get the preview working corectly + if (lastVoxelCount != clipboard->getOctreeElementsCount()) { + voxelSystem->forceRedrawEntireTree(); + lastVoxelCount = clipboard->getOctreeElementsCount(); + } + voxelSystem->render(); glPopMatrix(); From e66ec6b702e603b34a1326859c90046cba8b8117 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 21 Feb 2014 15:47:40 -0800 Subject: [PATCH 4/5] Final fix for clipboard preview --- interface/src/ui/ClipboardOverlay.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/interface/src/ui/ClipboardOverlay.cpp b/interface/src/ui/ClipboardOverlay.cpp index 12c72c7690..7eee318ec9 100644 --- a/interface/src/ui/ClipboardOverlay.cpp +++ b/interface/src/ui/ClipboardOverlay.cpp @@ -38,10 +38,7 @@ void ClipboardOverlay::render() { glTranslatef(_position.x, _position.y, _position.z); glScalef(_size, _size, _size); - qDebug() << "[DEBUG] " << voxelSystem->getVoxelsRendered() << " " - << clipboard->getOctreeElementsCount(); - - // TODO : replace that hack to get the preview working corectly + // We only force the redraw when the clipboard content has changed if (lastVoxelCount != clipboard->getOctreeElementsCount()) { voxelSystem->forceRedrawEntireTree(); lastVoxelCount = clipboard->getOctreeElementsCount(); From 6fb2d57e403ebcc1b29d076feb4771cce5282ad4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 21 Feb 2014 16:04:15 -0800 Subject: [PATCH 5/5] Add clipboardOverlay example to OverlaysExample --- examples/overlaysExample.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/overlaysExample.js b/examples/overlaysExample.js index b57f82e7e9..d97ec9e8fd 100644 --- a/examples/overlaysExample.js +++ b/examples/overlaysExample.js @@ -156,6 +156,13 @@ var line3d = Overlays.addOverlay("line3d", { lineWidth: 5 }); +// this will display the content of your clipboard at the origin of the domain +var clipboardPreview = Overlays.addOverlay("clipboard", { + position: { x: 0, y: 0, z: 0}, + size: 1 / 32, + visible: true + }); + // When our script shuts down, we should clean up all of our overlays function scriptEnding() { @@ -170,6 +177,7 @@ function scriptEnding() { Overlays.deleteOverlay(solidCube); Overlays.deleteOverlay(sphere); Overlays.deleteOverlay(line3d); + Overlays.deleteOverlay(clipboardPreview); } Script.scriptEnding.connect(scriptEnding);