Browse Source

Add LayerPanelWidget as a separate class

master
Krisjanis Rijnieks 9 years ago
parent
commit
2eaa2faac3
  1. 4
      src/Application/Gui.cpp
  2. 3
      src/Application/Gui.h
  3. 54
      src/Application/LayerPanelWidget.cpp
  4. 31
      src/Application/LayerPanelWidget.h
  5. 43
      src/Application/ProjectionMappingState.cpp
  6. 1
      src/Application/ProjectionMappingState.h

4
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;

3
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

54
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

31
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

43
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){

1
src/Application/ProjectionMappingState.h

@ -30,6 +30,7 @@
#include "Gui.h"
#include "ScaleWidget.h"
//#include "LayerPanelWidget.h"
namespace ofx {
namespace piMapper {

Loading…
Cancel
Save