From 2eaa2faac35eb57265a6374e308a876cdc018e12 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Mon, 5 Sep 2016 21:07:11 +0200 Subject: [PATCH] Add LayerPanelWidget as a separate class --- src/Application/Gui.cpp | 4 ++ src/Application/Gui.h | 3 ++ src/Application/LayerPanelWidget.cpp | 54 ++++++++++++++++++++++ src/Application/LayerPanelWidget.h | 31 +++++++++++++ src/Application/ProjectionMappingState.cpp | 43 +---------------- src/Application/ProjectionMappingState.h | 1 + 6 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 src/Application/LayerPanelWidget.cpp create mode 100644 src/Application/LayerPanelWidget.h diff --git a/src/Application/Gui.cpp b/src/Application/Gui.cpp index 934ebba..86fb958 100644 --- a/src/Application/Gui.cpp +++ b/src/Application/Gui.cpp @@ -84,6 +84,10 @@ ScaleWidget & Gui::getScaleWidget(){ return _scaleWidget; } +LayerPanelWidget & Gui::getLayerPanelWidget(){ + return _layerPanelWidget; +} + void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){ GuiEvent e; e.args = event.args; diff --git a/src/Application/Gui.h b/src/Application/Gui.h index 648b46e..e98f827 100644 --- a/src/Application/Gui.h +++ b/src/Application/Gui.h @@ -5,6 +5,7 @@ #include "GuiBaseWidget.h" #include "ScaleWidget.h" +#include "LayerPanelWidget.h" namespace ofx { namespace piMapper { @@ -61,6 +62,7 @@ class Gui { void notifyBackgroundPressed(ofMouseEventArgs & args); ScaleWidget & getScaleWidget(); + LayerPanelWidget & getLayerPanelWidget(); void onMousePressed(ofMouseEventArgs & args); void onMouseReleased(ofMouseEventArgs & args); @@ -77,6 +79,7 @@ class Gui { static Gui * _instance; ScaleWidget _scaleWidget; + LayerPanelWidget _layerPanelWidget; }; } // piMapper diff --git a/src/Application/LayerPanelWidget.cpp b/src/Application/LayerPanelWidget.cpp new file mode 100644 index 0000000..f9cb2ec --- /dev/null +++ b/src/Application/LayerPanelWidget.cpp @@ -0,0 +1,54 @@ +#include "LayerPanelWidget.h" + +namespace ofx{ +namespace piMapper{ + +LayerPanelWidget::LayerPanelWidget(){ + _sm = 0; +} + +void LayerPanelWidget::draw(){ + if(_sm == 0){ + return; + } + + int numSurfaces = _sm->size(); + + for(int i = 0; i < numSurfaces; ++i){ + BaseSurface * surface = _sm->getSurface(i); + BaseSurface * surfaceSelected = _sm->getSelectedSurface(); + + ofPushStyle(); + ofSetColor(255, 255, 255); + + if(surface == surfaceSelected){ + ofFill(); + }else{ + ofNoFill(); + } + + int layerIconWidth = 45; + int layerIconHeight = 20; + int offsetRight = 20; + int offsetTop = 40; + int verticalSpacing = 10; + int layerIconX = ofGetWidth() - offsetRight - layerIconWidth; + int layerIconY = offsetTop + ((layerIconHeight + verticalSpacing) * (numSurfaces - i - 1)); + + string label = "Layers"; + ofDrawBitmapString(label, ofGetWidth() - 66, 30); + + ofRectangle layerIcon = ofRectangle( + layerIconX, + layerIconY, + layerIconWidth, + layerIconHeight); + + ofDrawRectangle(layerIcon); + + ofPopStyle(); + } +} + +} // namespace piMapper +} // namespace ofx \ No newline at end of file diff --git a/src/Application/LayerPanelWidget.h b/src/Application/LayerPanelWidget.h new file mode 100644 index 0000000..22ed526 --- /dev/null +++ b/src/Application/LayerPanelWidget.h @@ -0,0 +1,31 @@ +#pragma once + +#include "GuiBaseWidget.h" +#include "SurfaceManager.h" + +namespace ofx { +namespace piMapper { + +class LayerPanelWidget : public GuiBaseWidget { + public: + LayerPanelWidget(); + + void setup(){} + void update(){} + void draw(); + + void onMousePressed(ofMouseEventArgs & args){} + void onMouseReleased(ofMouseEventArgs & args){} + void onMouseDragged(ofMouseEventArgs & args){} + + bool inside(float x, float y){ return false; } + + void setSurfaceManager(SurfaceManager * sm){ _sm = sm; } + + private: + SurfaceManager * _sm; + +}; + +} // namespace piMapper +} // namespace ofx \ No newline at end of file diff --git a/src/Application/ProjectionMappingState.cpp b/src/Application/ProjectionMappingState.cpp index 61f4441..25b95c5 100644 --- a/src/Application/ProjectionMappingState.cpp +++ b/src/Application/ProjectionMappingState.cpp @@ -27,47 +27,8 @@ void ProjectionMappingState::draw(Application * app){ Gui::instance()->getScaleWidget().draw(); } - /* - Draw layer panel / indicator consisting of layer icons. - If none of the surfaces is selected, use outlines to represent all surfaces. - If one of the surfaces is selected, use a filled rectangle to visualise its location - in the layer stack. - */ - int numSurfaces = app->getSurfaceManager()->size(); - - for(int i = 0; i < numSurfaces; ++i){ - BaseSurface * surface = app->getSurfaceManager()->getSurface(i); - BaseSurface * surfaceSelected = app->getSurfaceManager()->getSelectedSurface(); - - ofPushStyle(); - - if(surface == surfaceSelected){ - ofFill(); - }else{ - ofNoFill(); - } - - int layerIconWidth = 45; - int layerIconHeight = 20; - int offsetRight = 20; - int offsetTop = 40; - int verticalSpacing = 10; - int layerIconX = ofGetWidth() - offsetRight - layerIconWidth; - int layerIconY = offsetTop + ((layerIconHeight + verticalSpacing) * (numSurfaces - i - 1)); - - string label = "Layers"; - ofDrawBitmapString(label, ofGetWidth() - 66, 30); - - ofRectangle layerIcon = ofRectangle( - layerIconX, - layerIconY, - layerIconWidth, - layerIconHeight); - - ofDrawRectangle(layerIcon); - - ofPopStyle(); - } + Gui::instance()->getLayerPanelWidget().setSurfaceManager(app->getSurfaceManager()); + Gui::instance()->getLayerPanelWidget().draw(); } void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ diff --git a/src/Application/ProjectionMappingState.h b/src/Application/ProjectionMappingState.h index f5fa21b..23357c4 100644 --- a/src/Application/ProjectionMappingState.h +++ b/src/Application/ProjectionMappingState.h @@ -30,6 +30,7 @@ #include "Gui.h" #include "ScaleWidget.h" +//#include "LayerPanelWidget.h" namespace ofx { namespace piMapper {