Browse Source

Change owner of ProjectionEditorWidget to Gui

master
Krisjanis Rijnieks 9 years ago
parent
commit
198b4456c5
  1. 30
      src/Application/States/ProjectionMappingState.cpp
  2. 1
      src/Application/States/ProjectionMappingState.h
  3. 4
      src/Gui/Gui.cpp
  4. 3
      src/Gui/Gui.h
  5. 60
      src/Gui/Widgets/ProjectionEditorWidget.cpp
  6. 6
      src/Gui/Widgets/ProjectionEditorWidget.h
  7. 34
      src/Surfaces/SurfaceManagerGui.cpp
  8. 6
      src/Surfaces/SurfaceManagerGui.h

30
src/Application/States/ProjectionMappingState.cpp

@ -16,8 +16,13 @@ ProjectionMappingState * ProjectionMappingState::instance(){
return _instance; return _instance;
} }
void ProjectionMappingState::setup(Application *app){
Gui::instance()->getProjectionEditorWidget().setSurfaceManager(app->getSurfaceManager());
}
void ProjectionMappingState::update(Application * app){ void ProjectionMappingState::update(Application * app){
app->getGui()->getProjectionEditorWidget()->update(); //app->getGui()->getProjectionEditorWidget()->update();
Gui::instance()->getProjectionEditorWidget().update();
Gui::instance()->getScaleWidget().update(); Gui::instance()->getScaleWidget().update();
} }
@ -28,7 +33,8 @@ void ProjectionMappingState::draw(Application * app){
ofPopStyle(); ofPopStyle();
// TODO: Extract projection editor, make it a widget // TODO: Extract projection editor, make it a widget
app->getGui()->getProjectionEditorWidget()->draw(); //app->getGui()->getProjectionEditorWidget()->draw();
Gui::instance()->getProjectionEditorWidget().draw();
// Draw scale widget. The size of the widget is being set on surface select. // Draw scale widget. The size of the widget is being set on surface select.
BaseSurface * selectedSurface = app->getSurfaceManager()->getSelectedSurface(); BaseSurface * selectedSurface = app->getSurfaceManager()->getSelectedSurface();
@ -292,11 +298,14 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs
int hitJointIndex = -1; int hitJointIndex = -1;
BaseSurface * hitSurface = 0; BaseSurface * hitSurface = 0;
hitJoint = app->getGui()->getProjectionEditorWidget()->hitTestJoints(ofVec2f(args.x, args.y)); //hitJoint = app->getGui()->getProjectionEditorWidget()->hitTestJoints(ofVec2f(args.x, args.y));
hitJoint = Gui::instance()->getProjectionEditorWidget().hitTestJoints(ofVec2f(args.x, args.y));
if(hitJoint){ if(hitJoint){
for(int i = app->getGui()->getProjectionEditorWidget()->getJoints()->size() - 1; i >= 0 ; --i){ //for(int i = app->getGui()->getProjectionEditorWidget()->getJoints()->size() - 1; i >= 0 ; --i){
if((*app->getGui()->getProjectionEditorWidget()->getJoints())[i] == hitJoint){ for(int i = Gui::instance()->getProjectionEditorWidget().getJoints()->size() - 1; i >= 0 ; --i){
//if((*app->getGui()->getProjectionEditorWidget()->getJoints())[i] == hitJoint){
if((*Gui::instance()->getProjectionEditorWidget().getJoints())[i] == hitJoint){
hitJointIndex = i; hitJointIndex = i;
break; break;
} }
@ -327,19 +336,22 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs
void ProjectionMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ void ProjectionMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseReleased(args); Gui::instance()->onMouseReleased(args);
app->getGui()->stopDrag(); app->getGui()->stopDrag(); // TODO: handle this locally
app->getGui()->getProjectionEditorWidget()->stopDragJoints(); //app->getGui()->getProjectionEditorWidget()->stopDragJoints();
Gui::instance()->getProjectionEditorWidget().stopDragJoints();
} }
void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseDragged(args); Gui::instance()->onMouseDragged(args);
app->getGui()->getProjectionEditorWidget()->mouseDragged(args); //app->getGui()->getProjectionEditorWidget()->mouseDragged(args);
Gui::instance()->getProjectionEditorWidget().mouseDragged(args);
// TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally. // TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally.
if(app->getGui()->bDrag){ if(app->getGui()->bDrag){
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
ofVec2f distance = mousePosition - app->getGui()->clickPosition; ofVec2f distance = mousePosition - app->getGui()->clickPosition;
app->getGui()->getProjectionEditorWidget()->moveSelectedSurface(distance); //app->getGui()->getProjectionEditorWidget()->moveSelectedSurface(distance);
Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance);
app->getGui()->clickPosition = mousePosition; app->getGui()->clickPosition = mousePosition;
} }
} }

1
src/Application/States/ProjectionMappingState.h

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

4
src/Gui/Gui.cpp

@ -100,6 +100,10 @@ TextureEditorWidget & Gui::getTextureEditorWidget(){
return _textureEditorWidget; return _textureEditorWidget;
} }
ProjectionEditorWidget & Gui::getProjectionEditorWidget(){
return _projectionEditorWidget;
}
void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){ void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){
GuiEvent e; GuiEvent e;
e.args = event.args; e.args = event.args;

3
src/Gui/Gui.h

@ -9,6 +9,7 @@
#include "SurfaceHighlightWidget.h" #include "SurfaceHighlightWidget.h"
#include "TextureHighlightWidget.h" #include "TextureHighlightWidget.h"
#include "TextureEditorWidget.h" #include "TextureEditorWidget.h"
#include "ProjectionEditorWidget.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -69,6 +70,7 @@ class Gui {
SurfaceHighlightWidget & getSurfaceHighlightWidget(); SurfaceHighlightWidget & getSurfaceHighlightWidget();
TextureHighlightWidget & getTextureHighlightWidget(); TextureHighlightWidget & getTextureHighlightWidget();
TextureEditorWidget & getTextureEditorWidget(); TextureEditorWidget & getTextureEditorWidget();
ProjectionEditorWidget & getProjectionEditorWidget();
// Consider these as a part of the application states/modes. // Consider these as a part of the application states/modes.
void onMousePressed(ofMouseEventArgs & args); void onMousePressed(ofMouseEventArgs & args);
@ -90,6 +92,7 @@ class Gui {
SurfaceHighlightWidget _surfaceHighlightWidget; SurfaceHighlightWidget _surfaceHighlightWidget;
TextureHighlightWidget _textureHighlightWidget; TextureHighlightWidget _textureHighlightWidget;
TextureEditorWidget _textureEditorWidget; TextureEditorWidget _textureEditorWidget;
ProjectionEditorWidget _projectionEditorWidget;
}; };
} // piMapper } // piMapper

60
src/Gui/Widgets/ProjectionEditorWidget.cpp

@ -102,7 +102,31 @@ void ProjectionEditorWidget::gotMessage(ofMessage & msg){
} }
void ProjectionEditorWidget::setSurfaceManager(SurfaceManager * newSurfaceManager){ void ProjectionEditorWidget::setSurfaceManager(SurfaceManager * newSurfaceManager){
if(surfaceManager != 0){
ofRemoveListener(surfaceManager->vertexChangedEvent, this,
&ProjectionEditorWidget::onVertexChanged);
ofRemoveListener(surfaceManager->verticesChangedEvent, this,
&ProjectionEditorWidget::onVerticesChanged);
ofRemoveListener(surfaceManager->surfaceSelectedEvent, this,
&ProjectionEditorWidget::onSurfaceSelected);
ofRemoveListener(surfaceManager->vertexSelectedEvent, this,
&ProjectionEditorWidget::onVertexSelected);
ofRemoveListener(surfaceManager->vertexUnselectedEvent, this,
&ProjectionEditorWidget::onVertexUnselected);
}
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
ofAddListener(surfaceManager->vertexChangedEvent, this,
&ProjectionEditorWidget::onVertexChanged);
ofAddListener(surfaceManager->verticesChangedEvent, this,
&ProjectionEditorWidget::onVerticesChanged);
ofAddListener(surfaceManager->surfaceSelectedEvent, this,
&ProjectionEditorWidget::onSurfaceSelected);
ofAddListener(surfaceManager->vertexSelectedEvent, this,
&ProjectionEditorWidget::onVertexSelected);
ofAddListener(surfaceManager->vertexUnselectedEvent, this,
&ProjectionEditorWidget::onVertexUnselected);
} }
void ProjectionEditorWidget::clearJoints(){ void ProjectionEditorWidget::clearJoints(){
@ -183,6 +207,42 @@ vector <CircleJoint *> * ProjectionEditorWidget::getJoints(){
return &joints; return &joints;
} }
void ProjectionEditorWidget::onVertexChanged(int & i){
bool isDragged = getJoints()->at(i)->isDragged();
createJoints();
getJoints()->at(i)->select();
if(isDragged){
getJoints()->at(i)->startDrag();
}else{
getJoints()->at(i)->stopDrag();
}
}
void ProjectionEditorWidget::onVerticesChanged(vector<ofVec3f> & vertices){
createJoints();
}
void ProjectionEditorWidget::onSurfaceSelected(int & surfaceIndex){
createJoints();
}
void ProjectionEditorWidget::onVertexSelected(int & vertexIndex){
if(getJoints()->size() == 0){
return;
}
unselectAllJoints();
getJoints()->at(vertexIndex)->select();
}
void ProjectionEditorWidget::onVertexUnselected(int & vertexIndex){
if(getJoints()->size() == 0){
return;
}
unselectAllJoints();
}
void ProjectionEditorWidget::drawJoints(){ void ProjectionEditorWidget::drawJoints(){
for(int i = 0; i < joints.size(); i++){ for(int i = 0; i < joints.size(); i++){
joints[i]->draw(); joints[i]->draw();

6
src/Gui/Widgets/ProjectionEditorWidget.h

@ -32,6 +32,12 @@ class ProjectionEditorWidget {
void setSnapDistance(float newSnapDistance); void setSnapDistance(float newSnapDistance);
CircleJoint * hitTestJoints(ofVec2f pos); CircleJoint * hitTestJoints(ofVec2f pos);
vector <CircleJoint *> * getJoints(); vector <CircleJoint *> * getJoints();
void onVertexChanged(int & i);
void onVerticesChanged(vector<ofVec3f> & vertices);
void onSurfaceSelected(int & surfaceIndex);
void onVertexSelected(int & vertexIndex);
void onVertexUnselected(int & vertexIndex);
private: private:
SurfaceManager * surfaceManager; SurfaceManager * surfaceManager;

34
src/Surfaces/SurfaceManagerGui.cpp

@ -28,7 +28,7 @@ void SurfaceManagerGui::setSurfaceManager(SurfaceManager * newSurfaceManager){
ofAddListener(newSurfaceManager->vertexSelectedEvent, this, &SurfaceManagerGui::onVertexSelected); ofAddListener(newSurfaceManager->vertexSelectedEvent, this, &SurfaceManagerGui::onVertexSelected);
ofAddListener(newSurfaceManager->vertexUnselectedEvent, this, &SurfaceManagerGui::onVertexUnselected); ofAddListener(newSurfaceManager->vertexUnselectedEvent, this, &SurfaceManagerGui::onVertexUnselected);
projectionEditorWidget.setSurfaceManager(surfaceManager); // projectionEditorWidget.setSurfaceManager(surfaceManager);
sourcesEditor.setSurfaceManager(surfaceManager); sourcesEditor.setSurfaceManager(surfaceManager);
} }
@ -63,11 +63,13 @@ void SurfaceManagerGui::setMode(int newGuiMode){
sourcesEditor.disable(); sourcesEditor.disable();
} }
/*
if(guiMode == GuiMode::PROJECTION_MAPPING){ if(guiMode == GuiMode::PROJECTION_MAPPING){
projectionEditorWidget.enable(); projectionEditorWidget.enable();
}else{ }else{
projectionEditorWidget.disable(); projectionEditorWidget.disable();
} }
*/
} }
int SurfaceManagerGui::getMode(){ int SurfaceManagerGui::getMode(){
@ -82,48 +84,52 @@ void SurfaceManagerGui::stopDrag(){
bDrag = false; bDrag = false;
} }
ProjectionEditorWidget * SurfaceManagerGui::getProjectionEditorWidget(){ //ProjectionEditorWidget * SurfaceManagerGui::getProjectionEditorWidget(){
return &projectionEditorWidget; // return &projectionEditorWidget;
} //}
SourcesEditor * SurfaceManagerGui::getSourcesEditor(){ SourcesEditor * SurfaceManagerGui::getSourcesEditor(){
return &sourcesEditor; return &sourcesEditor;
} }
void SurfaceManagerGui::onVertexChanged(int & i){ void SurfaceManagerGui::onVertexChanged(int & i){
bool isDragged = projectionEditorWidget.getJoints()->at(i)->isDragged(); //bool isDragged = projectionEditorWidget.getJoints()->at(i)->isDragged();
projectionEditorWidget.createJoints(); //projectionEditorWidget.createJoints();
projectionEditorWidget.getJoints()->at(i)->select(); //projectionEditorWidget.getJoints()->at(i)->select();
if(isDragged){ //if(isDragged){
projectionEditorWidget.getJoints()->at(i)->startDrag(); // projectionEditorWidget.getJoints()->at(i)->startDrag();
}else{ //}else{
projectionEditorWidget.getJoints()->at(i)->stopDrag(); // projectionEditorWidget.getJoints()->at(i)->stopDrag();
} //}
} }
void SurfaceManagerGui::onVerticesChanged(vector<ofVec3f> & vertices){ void SurfaceManagerGui::onVerticesChanged(vector<ofVec3f> & vertices){
projectionEditorWidget.createJoints(); //projectionEditorWidget.createJoints();
} }
void SurfaceManagerGui::onSurfaceSelected(int & surfaceIndex){ void SurfaceManagerGui::onSurfaceSelected(int & surfaceIndex){
projectionEditorWidget.createJoints(); //projectionEditorWidget.createJoints();
} }
void SurfaceManagerGui::onVertexSelected(int & vertexIndex){ void SurfaceManagerGui::onVertexSelected(int & vertexIndex){
/*
if(projectionEditorWidget.getJoints()->size() == 0){ if(projectionEditorWidget.getJoints()->size() == 0){
return; return;
} }
projectionEditorWidget.unselectAllJoints(); projectionEditorWidget.unselectAllJoints();
projectionEditorWidget.getJoints()->at(vertexIndex)->select(); projectionEditorWidget.getJoints()->at(vertexIndex)->select();
*/
} }
void SurfaceManagerGui::onVertexUnselected(int & vertexIndex){ void SurfaceManagerGui::onVertexUnselected(int & vertexIndex){
/*
if(projectionEditorWidget.getJoints()->size() == 0){ if(projectionEditorWidget.getJoints()->size() == 0){
return; return;
} }
projectionEditorWidget.unselectAllJoints(); projectionEditorWidget.unselectAllJoints();
*/
} }
} // namespace piMapper } // namespace piMapper

6
src/Surfaces/SurfaceManagerGui.h

@ -6,7 +6,7 @@
#include "ofGraphics.h" #include "ofGraphics.h"
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "ProjectionEditorWidget.h" //#include "ProjectionEditorWidget.h"
#include "SourcesEditor.h" #include "SourcesEditor.h"
#include "GuiMode.h" #include "GuiMode.h"
#include "CmdManager.h" #include "CmdManager.h"
@ -35,7 +35,7 @@ class SurfaceManagerGui {
void startDrag(); void startDrag();
void stopDrag(); void stopDrag();
ProjectionEditorWidget * getProjectionEditorWidget(); //ProjectionEditorWidget * getProjectionEditorWidget();
SourcesEditor * getSourcesEditor(); SourcesEditor * getSourcesEditor();
void onVertexChanged(int & i); void onVertexChanged(int & i);
@ -50,7 +50,7 @@ class SurfaceManagerGui {
private: private:
SurfaceManager * surfaceManager; SurfaceManager * surfaceManager;
MediaServer * mediaServer; MediaServer * mediaServer;
ProjectionEditorWidget projectionEditorWidget; //ProjectionEditorWidget projectionEditorWidget;
SourcesEditor sourcesEditor; SourcesEditor sourcesEditor;
int guiMode; int guiMode;

Loading…
Cancel
Save