Browse Source

Make Gui the owner of TextureEditorWidget

master
Krisjanis Rijnieks 9 years ago
parent
commit
42e8a8590f
  1. 61
      src/Application/States/TextureMappingState.cpp
  2. 3
      src/Commands/SetApplicationStateCmd.cpp
  3. 1
      src/Commands/SetApplicationStateCmd.h
  4. 4
      src/Gui/Gui.cpp
  5. 4
      src/Gui/Gui.h
  6. 8
      src/Gui/Widgets/TextureEditorWidget.cpp
  7. 10
      src/Gui/Widgets/TextureEditorWidget.h
  8. 4
      src/Surfaces/SurfaceManagerGui.cpp
  9. 6
      src/Surfaces/SurfaceManagerGui.h

61
src/Application/States/TextureMappingState.cpp

@ -20,7 +20,8 @@ TextureMappingState::TextureMappingState(){
} }
void TextureMappingState::update(Application * app){ void TextureMappingState::update(Application * app){
app->getGui()->getTextureEditor()->update(); //app->getGui()->getTextureEditor()->update();
Gui::instance()->getTextureEditorWidget().update();
} }
void TextureMappingState::draw(Application * app){ void TextureMappingState::draw(Application * app){
@ -70,7 +71,8 @@ void TextureMappingState::draw(Application * app){
Gui::instance()->getTextureHighlightWidget().draw(); Gui::instance()->getTextureHighlightWidget().draw();
// TODO: Replace with a transform widget. // TODO: Replace with a transform widget.
app->getGui()->getTextureEditor()->draw(); //app->getGui()->getTextureEditor()->draw();
Gui::instance()->getTextureEditorWidget().draw();
ofPopMatrix(); ofPopMatrix();
} }
@ -88,29 +90,35 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args)
switch(args.key){ switch(args.key){
case OF_KEY_LEFT: case OF_KEY_LEFT:
app->getGui()->getTextureEditor()->moveSelection(ofVec2f(-moveStep, 0.0f)); //app->getGui()->getTextureEditor()->moveSelection(ofVec2f(-moveStep, 0.0f));
Gui::instance()->getTextureEditorWidget().moveSelection(ofVec2f(-moveStep, 0.0f));
break; break;
case OF_KEY_RIGHT: case OF_KEY_RIGHT:
app->getGui()->getTextureEditor()->moveSelection(ofVec2f(moveStep, 0.0f)); //app->getGui()->getTextureEditor()->moveSelection(ofVec2f(moveStep, 0.0f));
Gui::instance()->getTextureEditorWidget().moveSelection(ofVec2f(moveStep, 0.0f));
break; break;
case OF_KEY_UP: case OF_KEY_UP:
app->getGui()->getTextureEditor()->moveSelection(ofVec2f(0.0f, -moveStep)); //app->getGui()->getTextureEditor()->moveSelection(ofVec2f(0.0f, -moveStep));
Gui::instance()->getTextureEditorWidget().moveSelection(ofVec2f(0.0f, -moveStep));
break; break;
case OF_KEY_DOWN: case OF_KEY_DOWN:
app->getGui()->getTextureEditor()->moveSelection(ofVec2f(0.0f, moveStep)); //app->getGui()->getTextureEditor()->moveSelection(ofVec2f(0.0f, moveStep));
Gui::instance()->getTextureEditorWidget().moveSelection(ofVec2f(0.0f, moveStep));
break; break;
case '>': case '>':
app->getCmdManager()->exec( app->getCmdManager()->exec(
new SelNextTexCoordCmd(app->getGui()->getTextureEditor())); //new SelNextTexCoordCmd(app->getGui()->getTextureEditor()));
new SelNextTexCoordCmd(&Gui::instance()->getTextureEditorWidget()));
break; break;
case '<': case '<':
app->getCmdManager()->exec( app->getCmdManager()->exec(
new SelPrevTexCoordCmd(app->getGui()->getTextureEditor())); //new SelPrevTexCoordCmd(app->getGui()->getTextureEditor()));
new SelPrevTexCoordCmd(&Gui::instance()->getTextureEditorWidget()));
break; break;
case ' ': case ' ':
@ -151,8 +159,10 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args)
void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){
// Exec the command only if a joint is selected. // Exec the command only if a joint is selected.
bool selected = false; bool selected = false;
for(unsigned int i = 0; i < app->getGui()->getTextureEditor()->getJoints().size(); ++i){ //for(unsigned int i = 0; i < app->getGui()->getTextureEditor()->getJoints().size(); ++i){
if(app->getGui()->getTextureEditor()->getJoints()[i]->selected){ for(unsigned int i = 0; i < Gui::instance()->getTextureEditorWidget().getJoints().size(); ++i){
//if(app->getGui()->getTextureEditor()->getJoints()[i]->selected){
if(Gui::instance()->getTextureEditorWidget().getJoints()[i]->selected){
selected = true; selected = true;
break; break;
} }
@ -160,7 +170,8 @@ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEv
if(selected){ if(selected){
app->getCmdManager()->exec( app->getCmdManager()->exec(
new DeselectTexCoordCmd(app->getGui()->getTextureEditor())); //new DeselectTexCoordCmd(app->getGui()->getTextureEditor()));
new DeselectTexCoordCmd(&Gui::instance()->getTextureEditorWidget()));
} }
_bTranslateCanvas = true; _bTranslateCanvas = true;
@ -179,26 +190,32 @@ void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & a
} }
// Old code from SurfaceManagerGui // Old code from SurfaceManagerGui
CircleJoint * hitJoint = app->getGui()->getTextureEditor()->hitTestJoints(ofVec2f(args.x, args.y)); //CircleJoint * hitJoint = app->getGui()->getTextureEditor()->hitTestJoints(ofVec2f(args.x, args.y));
CircleJoint * hitJoint =
Gui::instance()->getTextureEditorWidget().hitTestJoints(ofVec2f(args.x, args.y));
if(hitJoint != 0){ if(hitJoint != 0){
hitJoint->mousePressed(args); hitJoint->mousePressed(args);
app->getGui()->getTextureEditor()->unselectAllJoints(); //app->getGui()->getTextureEditor()->unselectAllJoints();
Gui::instance()->getTextureEditorWidget().unselectAllJoints();
hitJoint->select(); hitJoint->select();
hitJoint->startDrag(); hitJoint->startDrag();
int jointIndex; int jointIndex;
for(int i = 0; i < app->getGui()->getTextureEditor()->getJoints().size(); i++){ //for(int i = 0; i < app->getGui()->getTextureEditor()->getJoints().size(); i++){
if(app->getGui()->getTextureEditor()->getJoints()[i] == hitJoint){ for(int i = 0; i < Gui::instance()->getTextureEditorWidget().getJoints().size(); i++){
//if(app->getGui()->getTextureEditor()->getJoints()[i] == hitJoint){
if(Gui::instance()->getTextureEditorWidget().getJoints()[i] == hitJoint){
jointIndex = i; jointIndex = i;
break; break;
} }
} }
app->getCmdManager()->exec( app->getCmdManager()->exec(
new MvTexCoordCmd(jointIndex, app->getGui()->getTextureEditor())); //new MvTexCoordCmd(jointIndex, app->getGui()->getTextureEditor()));
new MvTexCoordCmd(jointIndex, &Gui::instance()->getTextureEditorWidget()));
}else if(app->getSurfaceManager()->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y)){ }else if(app->getSurfaceManager()->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y)){
@ -208,7 +225,8 @@ void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & a
// TODO: emit event through the gui singleton // TODO: emit event through the gui singleton
app->getCmdManager()->exec(new MvAllTexCoordsCmd( app->getCmdManager()->exec(new MvAllTexCoordsCmd(
app->getSurfaceManager()->getSelectedSurface(), app->getSurfaceManager()->getSelectedSurface(),
app->getGui()->getTextureEditor())); //app->getGui()->getTextureEditor()));
&Gui::instance()->getTextureEditorWidget()));
}else{ }else{
Gui::instance()->notifyBackgroundPressed(args); Gui::instance()->notifyBackgroundPressed(args);
@ -233,7 +251,8 @@ void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs &
args.y -= _canvasTranslate.y; args.y -= _canvasTranslate.y;
app->getGui()->stopDrag(); app->getGui()->stopDrag();
app->getGui()->getTextureEditor()->stopDragJoints(); //app->getGui()->getTextureEditor()->stopDragJoints();
Gui::instance()->getTextureEditorWidget().stopDragJoints();
} }
// TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally. // TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally.
@ -241,12 +260,14 @@ void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & a
if(!_bTranslateCanvas){ if(!_bTranslateCanvas){
args.x -= _canvasTranslate.x; args.x -= _canvasTranslate.x;
args.y -= _canvasTranslate.y; args.y -= _canvasTranslate.y;
app->getGui()->getTextureEditor()->mouseDragged(args); //app->getGui()->getTextureEditor()->onMouseDragged(args);
Gui::instance()->getTextureEditorWidget().onMouseDragged(args);
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()->getTextureEditor()->moveTexCoords(distance); //app->getGui()->getTextureEditor()->moveTexCoords(distance);
Gui::instance()->getTextureEditorWidget().moveTexCoords(distance);
app->getGui()->clickPosition = mousePosition; app->getGui()->clickPosition = mousePosition;
} }
}else{ }else{

3
src/Commands/SetApplicationStateCmd.cpp

@ -24,6 +24,9 @@ void SetApplicationStateCmd::exec(){
_applicationState->setTranslation(ofPoint(0, 0)); _applicationState->setTranslation(ofPoint(0, 0));
_translation = _prevApplicationState->getTranslation(); _translation = _prevApplicationState->getTranslation();
Gui::instance()->getTextureEditorWidget().setSurface(
_application->getSurfaceManager()->getSelectedSurface());
// TODO: To be removed. // TODO: To be removed.
_prevGuiMode = _gui->getMode(); _prevGuiMode = _gui->getMode();
_gui->setMode(_mode); _gui->setMode(_mode);

1
src/Commands/SetApplicationStateCmd.h

@ -3,6 +3,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "Application.h" #include "Application.h"
#include "SurfaceManagerGui.h" #include "SurfaceManagerGui.h"
#include "Gui.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {

4
src/Gui/Gui.cpp

@ -96,6 +96,10 @@ TextureHighlightWidget & Gui::getTextureHighlightWidget(){
return _textureHighlightWidget; return _textureHighlightWidget;
} }
TextureEditorWidget & Gui::getTextureEditorWidget(){
return _textureEditorWidget;
}
void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){ void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){
GuiEvent e; GuiEvent e;
e.args = event.args; e.args = event.args;

4
src/Gui/Gui.h

@ -8,6 +8,7 @@
#include "LayerPanelWidget.h" #include "LayerPanelWidget.h"
#include "SurfaceHighlightWidget.h" #include "SurfaceHighlightWidget.h"
#include "TextureHighlightWidget.h" #include "TextureHighlightWidget.h"
#include "TextureEditorWidget.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -67,7 +68,9 @@ class Gui {
LayerPanelWidget & getLayerPanelWidget(); LayerPanelWidget & getLayerPanelWidget();
SurfaceHighlightWidget & getSurfaceHighlightWidget(); SurfaceHighlightWidget & getSurfaceHighlightWidget();
TextureHighlightWidget & getTextureHighlightWidget(); TextureHighlightWidget & getTextureHighlightWidget();
TextureEditorWidget & getTextureEditorWidget();
// Consider these as a part of the application states/modes.
void onMousePressed(ofMouseEventArgs & args); void onMousePressed(ofMouseEventArgs & args);
void onMouseReleased(ofMouseEventArgs & args); void onMouseReleased(ofMouseEventArgs & args);
void onMouseDragged(ofMouseEventArgs & args); void onMouseDragged(ofMouseEventArgs & args);
@ -86,6 +89,7 @@ class Gui {
LayerPanelWidget _layerPanelWidget; LayerPanelWidget _layerPanelWidget;
SurfaceHighlightWidget _surfaceHighlightWidget; SurfaceHighlightWidget _surfaceHighlightWidget;
TextureHighlightWidget _textureHighlightWidget; TextureHighlightWidget _textureHighlightWidget;
TextureEditorWidget _textureEditorWidget;
}; };
} // piMapper } // piMapper

8
src/Gui/Widgets/TextureEditorWidget.cpp

@ -79,13 +79,17 @@ void TextureEditorWidget::update(){
} // else } // else
} }
void TextureEditorWidget::mousePressed(ofMouseEventArgs & args){ void TextureEditorWidget::onMousePressed(ofMouseEventArgs & args){
for(unsigned int i = 0; i < joints.size(); ++i){ for(unsigned int i = 0; i < joints.size(); ++i){
joints[i]->mousePressed(args); joints[i]->mousePressed(args);
} }
} }
void TextureEditorWidget::mouseDragged(ofMouseEventArgs & args){ void TextureEditorWidget::onMouseReleased(ofMouseEventArgs & args){
// Nothing
}
void TextureEditorWidget::onMouseDragged(ofMouseEventArgs & args){
for(unsigned int i = 0; i < joints.size(); ++i){ for(unsigned int i = 0; i < joints.size(); ++i){
joints[i]->mouseDragged(args); joints[i]->mouseDragged(args);
} }

10
src/Gui/Widgets/TextureEditorWidget.h

@ -20,13 +20,9 @@ class TextureEditorWidget : public GuiBaseWidget {
void update(); // Maybe the Application pointer would make sense there. Not sure yet. void update(); // Maybe the Application pointer would make sense there. Not sure yet.
void draw(); void draw();
// These come from GuiBaseWidget void onMousePressed(ofMouseEventArgs & e);
void onMousePressed(ofMouseEventArgs & e){} void onMouseReleased(ofMouseEventArgs & e);
void onMouseReleased(ofMouseEventArgs & e){} void onMouseDragged(ofMouseEventArgs & e);
void onMouseDragged(ofMouseEventArgs & e){}
void mousePressed(ofMouseEventArgs & args);
void mouseDragged(ofMouseEventArgs & args);
bool inside(float x, float y){ return false; } bool inside(float x, float y){ return false; }

4
src/Surfaces/SurfaceManagerGui.cpp

@ -63,9 +63,11 @@ void SurfaceManagerGui::setMode(int newGuiMode){
sourcesEditor.disable(); sourcesEditor.disable();
} }
/*
if(guiMode == GuiMode::TEXTURE_MAPPING){ if(guiMode == GuiMode::TEXTURE_MAPPING){
textureEditor.setSurface(surfaceManager->getSelectedSurface()); textureEditor.setSurface(surfaceManager->getSelectedSurface());
} }
*/
if(guiMode == GuiMode::PROJECTION_MAPPING){ if(guiMode == GuiMode::PROJECTION_MAPPING){
projectionEditor.enable(); projectionEditor.enable();
@ -90,9 +92,11 @@ ProjectionEditor * SurfaceManagerGui::getProjectionEditor(){
return &projectionEditor; return &projectionEditor;
} }
/*
TextureEditorWidget * SurfaceManagerGui::getTextureEditor(){ TextureEditorWidget * SurfaceManagerGui::getTextureEditor(){
return &textureEditor; return &textureEditor;
} }
*/
SourcesEditor * SurfaceManagerGui::getSourcesEditor(){ SourcesEditor * SurfaceManagerGui::getSourcesEditor(){
return &sourcesEditor; return &sourcesEditor;

6
src/Surfaces/SurfaceManagerGui.h

@ -6,7 +6,7 @@
#include "ofGraphics.h" #include "ofGraphics.h"
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "TextureEditorWidget.h" //#include "TextureEditorWidget.h"
#include "ProjectionEditor.h" #include "ProjectionEditor.h"
#include "SourcesEditor.h" #include "SourcesEditor.h"
#include "GuiMode.h" #include "GuiMode.h"
@ -37,7 +37,7 @@ class SurfaceManagerGui {
void stopDrag(); void stopDrag();
ProjectionEditor * getProjectionEditor(); ProjectionEditor * getProjectionEditor();
TextureEditorWidget * getTextureEditor(); //TextureEditorWidget * getTextureEditor();
SourcesEditor * getSourcesEditor(); SourcesEditor * getSourcesEditor();
void onVertexChanged(int & i); void onVertexChanged(int & i);
@ -52,7 +52,7 @@ class SurfaceManagerGui {
private: private:
SurfaceManager * surfaceManager; SurfaceManager * surfaceManager;
MediaServer * mediaServer; MediaServer * mediaServer;
TextureEditorWidget textureEditor; //TextureEditorWidget textureEditor;
ProjectionEditor projectionEditor; ProjectionEditor projectionEditor;
SourcesEditor sourcesEditor; SourcesEditor sourcesEditor;

Loading…
Cancel
Save