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;
}
void ProjectionMappingState::setup(Application *app){
Gui::instance()->getProjectionEditorWidget().setSurfaceManager(app->getSurfaceManager());
}
void ProjectionMappingState::update(Application * app){
app->getGui()->getProjectionEditorWidget()->update();
//app->getGui()->getProjectionEditorWidget()->update();
Gui::instance()->getProjectionEditorWidget().update();
Gui::instance()->getScaleWidget().update();
}
@ -28,7 +33,8 @@ void ProjectionMappingState::draw(Application * app){
ofPopStyle();
// 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.
BaseSurface * selectedSurface = app->getSurfaceManager()->getSelectedSurface();
@ -292,11 +298,14 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs
int hitJointIndex = -1;
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){
for(int i = app->getGui()->getProjectionEditorWidget()->getJoints()->size() - 1; i >= 0 ; --i){
if((*app->getGui()->getProjectionEditorWidget()->getJoints())[i] == hitJoint){
//for(int i = app->getGui()->getProjectionEditorWidget()->getJoints()->size() - 1; i >= 0 ; --i){
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;
break;
}
@ -327,19 +336,22 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs
void ProjectionMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseReleased(args);
app->getGui()->stopDrag();
app->getGui()->getProjectionEditorWidget()->stopDragJoints();
app->getGui()->stopDrag(); // TODO: handle this locally
//app->getGui()->getProjectionEditorWidget()->stopDragJoints();
Gui::instance()->getProjectionEditorWidget().stopDragJoints();
}
void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs & 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.
if(app->getGui()->bDrag){
ofVec2f mousePosition = ofVec2f(args.x, args.y);
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;
}
}

1
src/Application/States/ProjectionMappingState.h

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

4
src/Gui/Gui.cpp

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

3
src/Gui/Gui.h

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

60
src/Gui/Widgets/ProjectionEditorWidget.cpp

@ -102,7 +102,31 @@ void ProjectionEditorWidget::gotMessage(ofMessage & msg){
}
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;
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(){
@ -183,6 +207,42 @@ vector <CircleJoint *> * ProjectionEditorWidget::getJoints(){
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(){
for(int i = 0; i < joints.size(); i++){
joints[i]->draw();

6
src/Gui/Widgets/ProjectionEditorWidget.h

@ -32,6 +32,12 @@ class ProjectionEditorWidget {
void setSnapDistance(float newSnapDistance);
CircleJoint * hitTestJoints(ofVec2f pos);
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:
SurfaceManager * surfaceManager;

34
src/Surfaces/SurfaceManagerGui.cpp

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

6
src/Surfaces/SurfaceManagerGui.h

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

Loading…
Cancel
Save