Browse Source

Rename `addFboSource()` to `registerFboSource()` and refactor a bit

master
Krisjanis Rijnieks 10 years ago
parent
commit
e425856a93
  1. 48
      src/ofxPiMapper.cpp
  2. 30
      src/ofxPiMapper.h

48
src/ofxPiMapper.cpp

@ -1,18 +1,17 @@
#include "ofxPiMapper.h" #include "ofxPiMapper.h"
ofxPiMapper::ofxPiMapper(): bShowInfo(false), isSetUp(false){ ofxPiMapper::ofxPiMapper() {
bShowInfo = false;
isSetUp = false;
} }
void ofxPiMapper::setup(){ void ofxPiMapper::setup() {
ofLogNotice("ofxPiMapper") << "Setting up..."; ofLogNotice("ofxPiMapper") << "Setting up...";
// Assign media server to other pi mapper components
surfaceManager.setMediaServer(&mediaServer); surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer); gui.setMediaServer(&mediaServer);
gui.setCmdManager(&cmdManager); gui.setCmdManager(&cmdManager);
// Check if we have user surfaces defined, if not - load default
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){ if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE; ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
@ -21,30 +20,20 @@ void ofxPiMapper::setup(){
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE); surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
} }
// The GUI needs something to interface with
gui.setSurfaceManager(&surfaceManager); gui.setSurfaceManager(&surfaceManager);
isSetUp = true; isSetUp = true;
ofLogNotice("ofxPiMapper") << "Done setting up"; ofLogNotice("ofxPiMapper") << "Done setting up";
_application = new ofx::piMapper::Application(this); _application = new ofx::piMapper::Application(this);
} }
void ofxPiMapper::stateSetup() { void ofxPiMapper::draw() {
// TODO: test state imp
}
void ofxPiMapper::draw(){
if (!isSetUp) { if (!isSetUp) {
return; return;
} }
// Draw the piMapper GUI
gui.draw(); gui.draw();
if (bShowInfo){ if (bShowInfo){
// Draw instructions
stringstream ss; stringstream ss;
ss << "There are 4 modes:\n\n"; ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n"; ss << " 1. Presentation mode\n";
@ -58,23 +47,19 @@ void ofxPiMapper::draw(){
ss << "Press <s> to save the composition\n"; ss << "Press <s> to save the composition\n";
ss << "Press <f> to toggle fullscreen\n"; ss << "Press <f> to toggle fullscreen\n";
ss << "Press <i> to hide this message"; ss << "Press <i> to hide this message";
ofDrawBitmapStringHighlight(ss.str(), 10, 20,
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100), ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200)); ofColor(255, 255, 255, 200));
} }
// TODO: remove undo test completely
//ofDrawBitmapStringHighlight(ofToString(undoTestValue), 200, 200);
_application->draw(); _application->draw();
} // draw } // draw
void ofxPiMapper::addFboSource(ofx::piMapper::FboSource &fboSource){ void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource) {
mediaServer.addFboSource(fboSource); mediaServer.addFboSource(fboSource);
} // addFboSource }
void ofxPiMapper::addTriangleSurface(){ void ofxPiMapper::addTriangleSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
@ -91,11 +76,9 @@ void ofxPiMapper::addTriangleSurface(){
// Select this surface right away // Select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addTriangleSurface } // addTriangleSurface
void ofxPiMapper::addQuadSurface(){ void ofxPiMapper::addQuadSurface() {
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
@ -115,7 +98,6 @@ void ofxPiMapper::addQuadSurface(){
// select this surface right away // select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addQuadSurface } // addQuadSurface
ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager() { ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager() {
@ -126,10 +108,10 @@ ofx::piMapper::SurfaceManagerGui & ofxPiMapper::getGui() {
return gui; return gui;
} }
ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer(){ ofx::piMapper::MediaServer & ofxPiMapper::getMediaServer() {
return mediaServer; return mediaServer;
} }
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager(){ ofx::piMapper::SurfaceManager & ofxPiMapper::getSurfaceManager() {
return surfaceManager; return surfaceManager;
} }

30
src/ofxPiMapper.h

@ -5,14 +5,10 @@
#include "SurfaceManagerGui.h" #include "SurfaceManagerGui.h"
#include "MediaServer.h" #include "MediaServer.h"
#include "FboSource.h" #include "FboSource.h"
// Command design pattern includes
#include "BaseCmd.h" #include "BaseCmd.h"
#include "CmdManager.h" #include "CmdManager.h"
#include "RmSurfaceCmd.h" #include "RmSurfaceCmd.h"
#include "Application.h"
// Main view with state design pattern
#include "Application.h" // Main application entry point
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml" #define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml" #define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
@ -23,34 +19,23 @@ namespace ofx {
} }
} }
class ofxPiMapper{ class ofxPiMapper {
public: public:
ofxPiMapper(); ofxPiMapper();
void setup(); void setup();
void stateSetup();
void draw(); void draw();
void registerFboSource(ofx::piMapper::FboSource & fboSource);
void addFboSource(ofx::piMapper::FboSource& fboSource);
void addTriangleSurface(); void addTriangleSurface();
void addQuadSurface(); void addQuadSurface();
// Toggle help / info
void showInfo() { bShowInfo = true; }; void showInfo() { bShowInfo = true; };
void hideInfo() { bShowInfo = false; }; void hideInfo() { bShowInfo = false; };
void toggleInfo() { bShowInfo = !bShowInfo; } void toggleInfo() { bShowInfo = !bShowInfo; }
// Getters
ofx::piMapper::CmdManager & getCmdManager(); ofx::piMapper::CmdManager & getCmdManager();
ofx::piMapper::SurfaceManagerGui & getGui(); ofx::piMapper::SurfaceManagerGui & getGui();
ofx::piMapper::MediaServer & getMediaServer();
// Discussion: ofx::piMapper::SurfaceManager & getSurfaceManager();
// Maybe these should be static as this would allow to access them
// from anywhere within ofxPiMapper.
ofx::piMapper::MediaServer& getMediaServer();
ofx::piMapper::SurfaceManager& getSurfaceManager();
ofx::piMapper::CmdManager cmdManager; ofx::piMapper::CmdManager cmdManager;
ofx::piMapper::SurfaceManager surfaceManager; ofx::piMapper::SurfaceManager surfaceManager;
@ -58,11 +43,6 @@ class ofxPiMapper{
bool isSetUp; bool isSetUp;
bool bShowInfo; bool bShowInfo;
ofx::piMapper::MediaServer mediaServer; ofx::piMapper::MediaServer mediaServer;
// Discussion: Here now the GUI points only to surface manager,
// maybe it should be as a separate layer?
ofx::piMapper::SurfaceManagerGui gui; ofx::piMapper::SurfaceManagerGui gui;
ofx::piMapper::Application * _application; ofx::piMapper::Application * _application;
}; };
Loading…
Cancel
Save