Browse Source

Fix ScaleWidget not capturing new surface after duplicate

master
Krisjanis Rijnieks 9 years ago
parent
commit
038758ce33
  1. 7
      src/Application/Application.cpp
  2. 1
      src/Application/Application.h
  3. 1
      src/Application/States/ApplicationBaseState.h
  4. 5
      src/Application/States/ProjectionMappingState.cpp
  5. 1
      src/Application/States/ProjectionMappingState.h
  6. 4
      src/Commands/SelNextSurfaceCmd.cpp
  7. 4
      src/Commands/SelPrevSurfaceCmd.cpp
  8. 4
      src/Commands/SelSurfaceCmd.cpp
  9. 58
      src/Gui/Widgets/ScaleWidget.cpp
  10. 6
      src/Gui/Widgets/ScaleWidget.h
  11. 2
      src/Surfaces/SurfaceManager.cpp
  12. 4
      src/ofxPiMapper.cpp
  13. 1
      src/ofxPiMapper.h

7
src/Application/Application.cpp

@ -44,6 +44,13 @@ void Application::setup(){
if(_isSSHConnection){
consoleListener.setup(this);
}
// TODO: Consider whether this is the right place for it
Gui::instance()->getScaleWidget().setSurfaceManager(&_surfaceManager);
}
void Application::update(){
_state->update(this);
}
ApplicationBaseState * Application::getState(){

1
src/Application/Application.h

@ -39,6 +39,7 @@ class Application : public KeyListener {
ApplicationBaseState * getState();
void setup();
void update();
void draw();
void onKeyPressed(ofKeyEventArgs & args);

1
src/Application/States/ApplicationBaseState.h

@ -12,6 +12,7 @@ class Application;
class ApplicationBaseState {
public:
virtual void update(Application * app){}
virtual void draw(Application * app){}
virtual void setState(Application * app, ApplicationBaseState * st);

5
src/Application/States/ProjectionMappingState.cpp

@ -16,6 +16,10 @@ ProjectionMappingState * ProjectionMappingState::instance(){
return _instance;
}
void ProjectionMappingState::update(Application * app){
Gui::instance()->getScaleWidget().update();
}
void ProjectionMappingState::draw(Application * app){
ofPushStyle();
ofSetColor(255, 255, 255, 255);
@ -306,7 +310,6 @@ void ProjectionMappingState::onJointPressed(Application * app, GuiJointEvent & e
void ProjectionMappingState::onSurfacePressed(Application * app, GuiSurfaceEvent & e){
if(app->getSurfaceManager()->getSelectedSurface() != e.surface){
app->getCmdManager()->exec(new SelSurfaceCmd(app->getSurfaceManager(), e.surface ));
Gui::instance()->getScaleWidget().setSurface(app->getSurfaceManager()->getSelectedSurface());
}
app->getCmdManager()->exec(new StartDragSurfaceCmd(e.surface));

1
src/Application/States/ProjectionMappingState.h

@ -40,6 +40,7 @@ class ProjectionMappingState : public ApplicationBaseState {
public:
static ProjectionMappingState * instance();
void update(Application * app);
void draw(Application * app);
void onKeyPressed(Application * app, ofKeyEventArgs & args);
void onMousePressed(Application * app, ofMouseEventArgs & args);

4
src/Commands/SelNextSurfaceCmd.cpp

@ -10,15 +10,11 @@ SelNextSurfaceCmd::SelNextSurfaceCmd(SurfaceManager * surfaceManager){
void SelNextSurfaceCmd::exec(){
_prevSelectedSurface = _surfaceManager->getSelectedSurface();
_surfaceManager->selectNextSurface();
Gui::instance()->getScaleWidget().setSurface(_surfaceManager->getSelectedSurface());
}
void SelNextSurfaceCmd::undo(){
ofLogNotice("SelNextSurfaceCmd", "undo");
_surfaceManager->selectSurface(_prevSelectedSurface);
if(_prevSelectedSurface != 0){
Gui::instance()->getScaleWidget().setSurface(_prevSelectedSurface);
}
_prevSelectedSurface = 0;
}

4
src/Commands/SelPrevSurfaceCmd.cpp

@ -10,15 +10,11 @@ SelPrevSurfaceCmd::SelPrevSurfaceCmd(SurfaceManager * surfaceManager){
void SelPrevSurfaceCmd::exec(){
_prevSelectedSurface = _surfaceManager->getSelectedSurface();
_surfaceManager->selectPrevSurface();
Gui::instance()->getScaleWidget().setSurface(_surfaceManager->getSelectedSurface());
}
void SelPrevSurfaceCmd::undo(){
ofLogNotice("SelPrevSurfaceCmd", "undo");
_surfaceManager->selectSurface(_prevSelectedSurface);
if(_prevSelectedSurface != 0){
Gui::instance()->getScaleWidget().setSurface(_prevSelectedSurface);
}
_prevSelectedSurface = 0;
}

4
src/Commands/SelSurfaceCmd.cpp

@ -11,15 +11,11 @@ SelSurfaceCmd::SelSurfaceCmd(SurfaceManager * surfaceManager, BaseSurface * surf
void SelSurfaceCmd::exec(){
_prevSelectedSurface = _surfaceManager->getSelectedSurface();
_surfaceManager->selectSurface(_surfaceToSelect);
Gui::instance()->getScaleWidget().setSurface(_surfaceToSelect);
}
void SelSurfaceCmd::undo(){
ofLogNotice("SelSurfaceCmd", "undo");
_surfaceManager->selectSurface(_prevSelectedSurface);
if(_prevSelectedSurface != 0){
Gui::instance()->getScaleWidget().setSurface(_prevSelectedSurface);
}
_surfaceToSelect = 0;
_prevSelectedSurface = 0;
}

58
src/Gui/Widgets/ScaleWidget.cpp

@ -11,24 +11,37 @@ ScaleWidget::ScaleWidget(){
_handle.height = 20;
_scale = 1.0f;
_surface = 0;
_surfaceManager = 0;
_selectedSurface = 0;
}
void ScaleWidget::setup(){
}
void ScaleWidget::update(){
if(_surfaceManager == 0){
return;
}
if(_selectedSurface != _surfaceManager->getSelectedSurface()){
_selectedSurface = _surfaceManager->getSelectedSurface();
setRect(_surfaceManager->getSelectedSurface()->getBoundingBox());
}
}
void ScaleWidget::draw(){
if(_surface != 0){
ofPoint centroid = _surface->getBoundingBox().getCenter();
if(_surfaceManager == 0){
return;
}
if(_surfaceManager->getSelectedSurface() != 0){
ofPoint centroid = _surfaceManager->getSelectedSurface()->getBoundingBox().getCenter();
float lineLength = centroid.distance(
ofPoint(
_surface->getBoundingBox().x + _surface->getBoundingBox().width,
_surface->getBoundingBox().y));
_surfaceManager->getSelectedSurface()->getBoundingBox().x +
_surfaceManager->getSelectedSurface()->getBoundingBox().width,
_surfaceManager->getSelectedSurface()->getBoundingBox().y));
// Handle surface move
float dx = _line[0].x - centroid.x;
@ -92,36 +105,30 @@ void ScaleWidget::onMouseReleased(ofMouseEventArgs & args){
void ScaleWidget::onMouseDragged(ofMouseEventArgs & args){
if(_dragging){
if(_surface == 0){
cout << "No surface selected" << endl;
if(_surfaceManager == 0){
return;
}
ofRectangle box = _surface->getBoundingBox();
if(_surfaceManager->getSelectedSurface() == 0){
return;
}
ofRectangle box = _surfaceManager->getSelectedSurface()->getBoundingBox();
float boxAspect = box.width / box.height;
ofPolyline newLine = _line;
newLine[1].x = args.x;
newLine[1].y = args.y;
_scale = _surface->getScale() /
_scale = _surfaceManager->getSelectedSurface()->getScale() /
_line[0].distance(_line[1]) *
newLine[0].distance(newLine[1]);
//float lineAspect = (newLine[1].x - newLine[0].x) / (newLine[1].y - newLine[0].y);
//if(lineAspect < boxAspect){
// _line[1].x = args.x;
// _line[1].y = (_line[0].y - (_line[1].x - _line[0].x) / boxAspect);
//}
_line = newLine;
_handle.x = _line[1].x - (_handle.width / 2.0f);
_handle.y = _line[1].y - (_handle.height / 2.0f);
//_surface->scaleTo(_scale);
GuiWidgetEvent e;
e.args = args;
ofNotifyEvent(guiWidgetEvent, e, this);
@ -150,9 +157,14 @@ void ScaleWidget::setRect(ofRectangle rect){
_handle.y = rect.y - (_handle.height / 2.0f);
}
void ScaleWidget::setSurface(ofx::piMapper::BaseSurface * s){
_surface = s;
setRect(s->getBoundingBox());
void ScaleWidget::setSurfaceManager(SurfaceManager * sm){
_surfaceManager = sm;
if(_surfaceManager->getSelectedSurface() == 0){
return;
}
setRect(_surfaceManager->getSelectedSurface()->getBoundingBox());
}
} // namespace piMapper

6
src/Gui/Widgets/ScaleWidget.h

@ -5,6 +5,7 @@
#include "GuiBaseWidget.h"
#include "ofGraphics.h"
#include "BaseSurface.h"
#include "SurfaceManager.h"
namespace ofx {
namespace piMapper {
@ -24,7 +25,7 @@ class ScaleWidget : public GuiBaseWidget {
bool inside(float x, float y);
// This should be the size of the objet's bounding box
void setSurface(BaseSurface * s);
void setSurfaceManager(SurfaceManager * sm);
float getScale(){
return _scale;
@ -39,7 +40,8 @@ class ScaleWidget : public GuiBaseWidget {
bool _dragging;
BaseSurface * _surface;
BaseSurface * _selectedSurface;
SurfaceManager * _surfaceManager;
void setRect(ofRectangle rect);
};

2
src/Surfaces/SurfaceManager.cpp

@ -99,6 +99,8 @@ BaseSurface * SurfaceManager::selectSurface(int index){
}
BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){
cout << "SurfaceManager::selectSurface()" << endl;
for(int i = 0; i < SurfaceStack::instance()->size(); i++){
if(SurfaceStack::instance()->at(i) == surface){
selectedSurface = surface;

4
src/ofxPiMapper.cpp

@ -6,6 +6,10 @@ void ofxPiMapper::setup(){
_application.setup();
}
void ofxPiMapper::update(){
_application.update();
}
void ofxPiMapper::draw(){
_application.draw();
}

1
src/ofxPiMapper.h

@ -23,6 +23,7 @@ class ofxPiMapper {
ofxPiMapper();
void setup();
void update();
void draw();
void registerFboSource(ofx::piMapper::FboSource & fboSource);

Loading…
Cancel
Save