Browse Source

added ability to select a source by string name. Basically accessor functions to the SetSourceCmd class

master
Theodoros Papatheodorou 8 years ago
parent
commit
9357530b34
  1. 45
      src/Application/Application.cpp
  2. 35
      src/Application/Application.h
  3. 4
      src/ofxPiMapper.cpp
  4. 21
      src/ofxPiMapper.h

45
src/Application/Application.cpp

@ -7,16 +7,16 @@ namespace piMapper {
Application::Application(){
_keySequence = "";
_surfaceManager.setMediaServer(&_mediaServer);
// Set initial mode
setState(PresentationMode::instance());
ofHideCursor();
ofAddListener(Gui::instance()->jointPressedEvent, this, &Application::onJointPressed);
ofAddListener(Gui::instance()->surfacePressedEvent, this, &Application::onSurfacePressed);
ofAddListener(Gui::instance()->backgroundPressedEvent, this, &Application::onBackgroundPressed);
ofAddListener(Gui::instance()->guiEvent, this, &Application::onGuiEvent);
_lastSaveTime = 0.0f;
_autoSaveInterval = 60.0f;
}
@ -35,7 +35,7 @@ void Application::setup(){
throw runtime_error("ofxPiMapper: Failed to create default settings file.");
}
}
// Setup all states.
PresentationMode::instance()->setup(this);
TextureMappingMode::instance()->setup(this);
@ -49,7 +49,7 @@ void Application::setup(){
void Application::update(){
_mediaServer.update();
_state->update(this);
// Autosave, do it only of the mode is not presentation mode
if(_state != PresentationMode::instance()){
float timeNow = ofGetElapsedTimef();
@ -72,7 +72,7 @@ void Application::draw(){
// Here we handle application state changes only
void Application::onKeyPressed(ofKeyEventArgs & args){
// Key sequence based commands. Last three keys are taken into account.
_keySequence += args.key;
if(_keySequence.size() >= 3){
@ -100,11 +100,11 @@ void Application::onKeyPressed(ofKeyEventArgs & args){
case OF_KEY_SHIFT:
_shiftKeyDown = true;
break;
case '/':
_shiftKeyDown = !_shiftKeyDown;
break;
case '1':
setPresentationMode();
break;
@ -132,7 +132,7 @@ void Application::onKeyPressed(ofKeyEventArgs & args){
case 'z':
undo();
break;
case 'n':
setNextPreset();
break;
@ -325,14 +325,14 @@ void Application::selectPrevVertex(){
void Application::selectVertex(int surface, int vertex){
if(getSurfaceManager()->size()){
// TODO: use one command instead of two
getCmdManager()->exec(
new SelSurfaceCmd(
getSurfaceManager(),
getSurfaceManager()->getSurface(surface)));
getCmdManager()->exec(
new SelVertexCmd(
getSurfaceManager(),
@ -398,7 +398,7 @@ void Application::moveLayerUp(){
getSurfaceManager()->getActivePreset()->size() - 1)){
return;
}
getCmdManager()->exec(
new MvLayerUpCmd(
getSurfaceManager()->getActivePreset(),
@ -412,7 +412,7 @@ void Application::moveLayerDown(){
getSurfaceManager()->getActivePreset()->at(0)){
return;
}
getCmdManager()->exec(
new MvLayerDnCmd(
getSurfaceManager()->getActivePreset(),
@ -463,6 +463,19 @@ void Application::setNextSource(){
}
}
void Application::setFboSource(string sourceId){
if(getSurfaceManager()->getSelectedSurface() != 0){
getCmdManager()->exec(
new SetSourceCmd(
SourceType::SOURCE_TYPE_FBO,
sourceId,
getSurfaceManager()->getSelectedSurface(),
&Gui::instance()->getSourcesEditorWidget()));
}else{
getCmdManager()->exec(new SelNextSurfaceCmd(getSurfaceManager()));
}
}
void Application::addGridRow(){
if(getSurfaceManager()->getSelectedSurface() != 0){
if(getSurfaceManager()->getSelectedSurface()->getType() ==
@ -519,7 +532,7 @@ void Application::togglePause(){
if(getSurfaceManager()->getSelectedSurface() == 0){
return;
}
if(getSurfaceManager()->getSelectedSurface()->getSource()->getType() ==
SourceType::SOURCE_TYPE_VIDEO){
getCmdManager()->exec(
@ -535,7 +548,7 @@ void Application::moveTexCoord(int texCoordIndex, ofVec2f by){
getCmdManager()->exec(new MvAllTexCoordsCmd(
getSurfaceManager()->getSelectedSurface(),
&Gui::instance()->getTextureEditorWidget()));
Gui::instance()->getTextureEditorWidget().moveSelection(by);
}
}

35
src/Application/Application.h

@ -66,22 +66,22 @@ class Application {
void setup();
void update();
void draw();
void onKeyPressed(ofKeyEventArgs & args);
void onKeyReleased(ofKeyEventArgs & args);
// We use this to pass mouse events into the GUI layer
void onMousePressed(ofMouseEventArgs & args);
void onMouseReleased(ofMouseEventArgs & args);
void onMouseDragged(ofMouseEventArgs & args);
// Then we catch GUI events with this one and create commands
void onJointPressed(GuiJointEvent & e);
void onSurfacePressed(GuiSurfaceEvent & e);
void onBackgroundPressed(GuiBackgroundEvent & e);
void onGuiEvent(GuiEvent & e);
void addFboSource(FboSource & fboSource);
void addFboSource(FboSource * fboSource);
void createSurface(SurfaceType type);
@ -97,7 +97,7 @@ class Application {
SurfaceManager * getSurfaceManager(){ return &_surfaceManager; }
CmdManager * getCmdManager(){ return &_cmdManager; }
MediaServer * getMediaServer(){ return &_mediaServer; }
// Command executors
void selectSurface(int i);
void selectNextSurface();
@ -107,14 +107,14 @@ class Application {
void selectVertex(int surface, int vertex);
void selectNextTexCoord();
void selectPrevTexCoord();
/*
/*
Context sensitive move.
Moves vertex when in projection mapping mode.
Moves texture coordinate when in texture mapping mode.
*/
void moveSelection(ofVec2f by);
void setPresentationMode();
void setTextureMode();
void setProjectionMode();
@ -125,6 +125,7 @@ class Application {
void scaleDown();
void duplicateSurface();
void setNextSource();
void setFboSource(string sourceId);
void addGridRow();
void addGridColumn();
void removeGridRow();
@ -135,33 +136,33 @@ class Application {
// Make it so that other parts of the application react to the change.
void undo();
void deselect();
void setPreset(unsigned int i);
void setNextPreset();
// System commands
void reboot();
void shutdown();
protected:
void setState(ApplicationBaseMode * st);
private:
friend class ApplicationBaseMode;
friend class SetApplicationModeCmd;
ApplicationBaseMode * _state;
CmdManager _cmdManager;
MediaServer _mediaServer;
SurfaceManager _surfaceManager;
Info _info;
bool _shiftKeyDown;
float _lastSaveTime;
float _autoSaveInterval;
string _keySequence;
};

4
src/ofxPiMapper.cpp

@ -166,6 +166,10 @@ void ofxPiMapper::setNextSource(){
_application.setNextSource();
}
void ofxPiMapper::setFboSource(string sourceId){
_application.setFboSource(sourceId);
}
void ofxPiMapper::reboot(){
_application.reboot();
}

21
src/ofxPiMapper.h

@ -14,31 +14,31 @@ class ofxPiMapper {
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseDragged(int x, int y, int button);
void registerFboSource(ofx::piMapper::FboSource & fboSource);
void registerFboSource(ofx::piMapper::FboSource * fboSource);
// Application
void setInfoText(string text);
void toggleInfo();
void undo();
void deselect();
// Modes
void setMode(ofx::piMapper::Mode m);
ofx::piMapper::Mode getMode();
// Project
void saveProject();
bool loadProject(string filename);
// Presets
unsigned int getNumPresets();
unsigned int getActivePresetIndex();
@ -46,7 +46,7 @@ class ofxPiMapper {
void setNextPreset();
void cloneActivePreset();
void eraseActivePreset();
// Surfaces, active preset
unsigned int getNumSurfaces();
int getSelectedSurface();
@ -69,10 +69,11 @@ class ofxPiMapper {
void moveSelection(ofVec2f by);
void createSurface(ofx::piMapper::SurfaceType type);
void eraseSurface(int i);
// Sources, selected surface
void setNextSource();
void setFboSource(string sourceId);
// System commands
void reboot();
void shutdown();

Loading…
Cancel
Save