Browse Source

Move surface command executors to Application

master
Krisjanis Rijnieks 8 years ago
parent
commit
9996554b2f
  1. 50
      src/Application/Application.cpp
  2. 14
      src/Application/Application.h
  3. 8
      src/Application/Modes/ApplicationBaseMode.h
  4. 78
      src/Application/Modes/ProjectionMappingMode.cpp
  5. 16
      src/Application/Modes/ProjectionMappingMode.h
  6. 12
      src/ofxPiMapper.cpp

50
src/Application/Application.cpp

@ -308,6 +308,56 @@ bool Application::loadXmlSettings(string fileName){
return true;
}
void Application::selectSurface(int i){
if(getSurfaceManager()->size()){
if(getSurfaceManager()->getSelectedSurfaceIndex() == i){
return;
}
getCmdManager()->exec(
new SelSurfaceCmd(
getSurfaceManager(),
getSurfaceManager()->getSurface(i)));
}
}
void Application::selectNextSurface(){
if(getSurfaceManager()->size()){
if(getSurfaceManager()->size() == 1 &&
getSurfaceManager()->getSelectedSurface() ==
getSurfaceManager()->getSurface(0)){
return;
}
getCmdManager()->exec(new SelNextSurfaceCmd(getSurfaceManager()));
}
}
void Application::selectPrevSurface(){
if(getSurfaceManager()->size()){
if(getSurfaceManager()->size() == 1 &&
getSurfaceManager()->getSelectedSurface() ==
getSurfaceManager()->getSurface(0)){
return;
}
getCmdManager()->exec(new SelPrevSurfaceCmd(getSurfaceManager()));
}
}
void Application::selectNextVertex(){
if(getSurfaceManager()->getSelectedSurface() != 0){
getCmdManager()->exec(new SelNextVertexCmd(getSurfaceManager()));
}
}
void Application::selectPrevVertex(){
if(getSurfaceManager()->getSelectedSurface() != 0){
getCmdManager()->exec(new SelPrevVertexCmd(getSurfaceManager()));
}
}
void Application::moveSelection(ofVec2f by){
getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by));
}
void Application::setPresentationMode(){
_cmdManager.exec(
new ofx::piMapper::SetApplicationModeCmd(

14
src/Application/Application.h

@ -27,6 +27,13 @@
#include "RmGridRowCmd.h"
#include "AddGridColCmd.h"
#include "RmGridColCmd.h"
#include "SelNextSurfaceCmd.h"
#include "SelPrevSurfaceCmd.h"
#include "SelNextVertexCmd.h"
#include "SelPrevVertexCmd.h"
#include "SelVertexCmd.h"
#include "SelSurfaceCmd.h"
#include "MvSelectionCmd.h"
// Modes
#include "ApplicationBaseMode.h"
@ -92,6 +99,13 @@ class Application : public KeyListener {
TerminalListener consoleListener;
// Command executors
void selectSurface(int i);
void selectNextSurface();
void selectPrevSurface();
void selectNextVertex();
void selectPrevVertex();
void moveSelection(ofVec2f by);
void setPresentationMode();
void setTextureMode();
void setProjectionMode();

8
src/Application/Modes/ApplicationBaseMode.h

@ -31,14 +31,6 @@ class ApplicationBaseMode {
// These are only used by TextureMappingMode for now.
virtual ofPoint getTranslation(){ return ofPoint(0, 0); }
virtual void setTranslation(ofPoint p){}
// Undoable public methods
virtual void selectSurface(Application * app, int i){}
virtual void selectNextSurface(Application * app){}
virtual void selectPrevSurface(Application * app){}
virtual void selectNextVertex(Application * app){}
virtual void selectPrevVertex(Application * app){}
virtual void moveSelection(Application * app, ofVec2f by){}
};

78
src/Application/Modes/ProjectionMappingMode.cpp

@ -93,50 +93,50 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg
break;
case '.':
selectNextSurface(app);
app->selectNextSurface();
break;
case ',':
selectPrevSurface(app);
app->selectPrevSurface();
break;
case '>':
selectNextVertex(app);
app->selectNextVertex();
break;
case '<':
selectPrevVertex(app);
app->selectPrevVertex();
break;
case OF_KEY_UP:
if(app->isShiftKeyDown()){
moveSelection(app, ofVec2f(0.0f, -10.0f));
app->moveSelection(ofVec2f(0.0f, -10.0f));
}else{
moveSelection(app, ofVec2f(0.0f, -1.0f));
app->moveSelection(ofVec2f(0.0f, -1.0f));
}
break;
case OF_KEY_DOWN:
if(app->isShiftKeyDown()){
moveSelection(app, ofVec2f(0.0f, 10.0f));
app->moveSelection(ofVec2f(0.0f, 10.0f));
}else{
moveSelection(app, ofVec2f(0.0f, 1.0f));
app->moveSelection(ofVec2f(0.0f, 1.0f));
}
break;
case OF_KEY_LEFT:
if(app->isShiftKeyDown()){
moveSelection(app, ofVec2f(-10.0f, 0.0f));
app->moveSelection(ofVec2f(-10.0f, 0.0f));
}else{
moveSelection(app, ofVec2f(-1.0f, 0.0f));
app->moveSelection(ofVec2f(-1.0f, 0.0f));
}
break;
case OF_KEY_RIGHT:
if(app->isShiftKeyDown()){
moveSelection(app, ofVec2f(10.0f, 0.0f));
app->moveSelection(ofVec2f(10.0f, 0.0f));
}else{
moveSelection(app, ofVec2f(1.0f, 0.0f));
app->moveSelection(ofVec2f(1.0f, 0.0f));
}
break;
@ -239,7 +239,7 @@ void ProjectionMappingMode::onMouseReleased(Application * app, ofMouseEventArgs
Gui::instance()->getProjectionEditorWidget().stopDragJoints();
}
void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){
void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseDragged(args);
Gui::instance()->getProjectionEditorWidget().mouseDragged(args);
@ -303,57 +303,5 @@ void ProjectionMappingMode::onGuiEvent(Application * app, GuiEvent & e){
}
}
void ProjectionMappingMode::selectSurface(Application * app, int i){
if(app->getSurfaceManager()->size()){
if(app->getSurfaceManager()->getSelectedSurfaceIndex() == i){
return;
}
app->getCmdManager()->exec(
new SelSurfaceCmd(
app->getSurfaceManager(),
app->getSurfaceManager()->getSurface(i) ));
}
}
void ProjectionMappingMode::selectNextSurface(Application * app){
if(app->getSurfaceManager()->size()){
if( app->getSurfaceManager()->size() == 1 &&
app->getSurfaceManager()->getSelectedSurface() ==
app->getSurfaceManager()->getSurface(0)){
return;
}
app->getCmdManager()->exec(new SelNextSurfaceCmd(app->getSurfaceManager()));
}
}
void ProjectionMappingMode::selectPrevSurface(Application * app){
if(app->getSurfaceManager()->size()){
if( app->getSurfaceManager()->size() == 1 &&
app->getSurfaceManager()->getSelectedSurface() ==
app->getSurfaceManager()->getSurface(0)){
return;
}
app->getCmdManager()->exec(new SelPrevSurfaceCmd(app->getSurfaceManager()));
}
}
void ProjectionMappingMode::selectNextVertex(Application * app){
if(app->getSurfaceManager()->getSelectedSurface() != 0){
app->getCmdManager()->exec(new SelNextVertexCmd(app->getSurfaceManager()));
}
}
void ProjectionMappingMode::selectPrevVertex(Application * app){
if(app->getSurfaceManager()->getSelectedSurface() != 0){
app->getCmdManager()->exec(new SelPrevVertexCmd(app->getSurfaceManager()));
}
}
void ProjectionMappingMode::moveSelection(Application * app, ofVec2f by){
app->getCmdManager()->exec(
new MvSelectionCmd(
app->getSurfaceManager(), by));
}
} // namespace piMapper
} // namespace ofx

16
src/Application/Modes/ProjectionMappingMode.h

@ -3,20 +3,12 @@
#include "Application.h"
#include "ofLog.h"
#include "ofGraphics.h"
#include "SelNextSurfaceCmd.h"
#include "SelPrevSurfaceCmd.h"
#include "SelNextVertexCmd.h"
#include "SelPrevVertexCmd.h"
#include "SelVertexCmd.h"
#include "SelSurfaceCmd.h"
#include "MvSelectionCmd.h"
#include "StartDragSurfaceCmd.h"
#include "DeselectSurfaceCmd.h"
#include "ToggleAnimatedSourceCmd.h"
#include "MvSurfaceVertCmd.h"
#include "SurfaceType.h"
#include "Gui.h"
#include "ScaleWidget.h"
namespace ofx {
@ -39,14 +31,6 @@ class ProjectionMappingMode : public ApplicationBaseMode {
void onBackgroundPressed(Application * app, GuiBackgroundEvent & e);
void onGuiEvent(Application * app, GuiEvent & e);
// Undoable public methods
void selectSurface(Application * app, int i);
void selectNextSurface(Application * app);
void selectPrevSurface(Application * app);
void selectNextVertex(Application * app);
void selectPrevVertex(Application * app);
void moveSelection(Application * app, ofVec2f by);
private:
ProjectionMappingMode();

12
src/ofxPiMapper.cpp

@ -80,7 +80,7 @@ void ofxPiMapper::eraseActivePreset(){
}
void ofxPiMapper::selectSurface(int i){
_application.getState()->selectSurface(&_application, i);
_application.selectSurface(i);
}
void ofxPiMapper::togglePerspective(){
@ -88,11 +88,11 @@ void ofxPiMapper::togglePerspective(){
}
void ofxPiMapper::selectNextSurface(){
_application.getState()->selectNextSurface(&_application);
_application.selectNextSurface();
}
void ofxPiMapper::selectPrevSurface(){
_application.getState()->selectPrevSurface(&_application);
_application.selectPrevSurface();
}
void ofxPiMapper::duplicateSurface(){
@ -100,11 +100,11 @@ void ofxPiMapper::duplicateSurface(){
}
void ofxPiMapper::selectNextVertex(){
_application.getState()->selectNextVertex(&_application);
_application.selectNextVertex();
}
void ofxPiMapper::selectPrevVertex(){
_application.getState()->selectPrevVertex(&_application);
_application.selectPrevVertex();
}
void ofxPiMapper::moveLayerUp(){
@ -132,7 +132,7 @@ void ofxPiMapper::togglePauseForSurface(unsigned int i){
}
void ofxPiMapper::moveSelection(ofVec2f by){
_application.getState()->moveSelection(&_application, by);
_application.moveSelection(by);
}
void ofxPiMapper::createSurface(ofx::piMapper::SurfaceType type){

Loading…
Cancel
Save