Browse Source

Add undoable command test

- Add UndoableCommand base class
 - Add CommandManager that handles undoing
 - Add test to main ofxPiMapper files
master
Krisjanis Rijnieks 10 years ago
parent
commit
df840a293c
  1. 28
      example/example.xcodeproj/project.pbxproj
  2. 42
      src/Commands/BaseCommand.h
  3. 9
      src/Commands/Command.h
  4. 27
      src/Commands/CommandManager.cpp
  5. 23
      src/Commands/CommandManager.h
  6. 21
      src/Commands/TestCommand.cpp
  7. 28
      src/Commands/TestCommand.h
  8. 21
      src/Commands/TestUndoCommand.cpp
  9. 27
      src/Commands/TestUndoCommand.h
  10. 307
      src/ofxPiMapper.cpp
  11. 95
      src/ofxPiMapper.h

28
example/example.xcodeproj/project.pbxproj

@ -63,6 +63,9 @@
39C1248119F187D5005DF557 /* TextureEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1247A19F187D5005DF557 /* TextureEditor.cpp */; };
39C1248819F1EB75005DF557 /* SurfaceManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1248319F1EB75005DF557 /* SurfaceManager.cpp */; };
39C1248919F1EB75005DF557 /* SurfaceManagerGui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1248519F1EB75005DF557 /* SurfaceManagerGui.cpp */; };
39C787BD1AC2111B00691393 /* CommandManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C787BC1AC2111B00691393 /* CommandManager.cpp */; };
39C787C11AC2BBAE00691393 /* TestUndoCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C787BF1AC2BBAE00691393 /* TestUndoCommand.cpp */; };
39FDD9EE1AC00EAE00262205 /* TestCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39FDD9EC1AC00EAE00262205 /* TestCommand.cpp */; };
BBAB23CB13894F3D00AA2426 /* GLUT.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = BBAB23BE13894E4700AA2426 /* GLUT.framework */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
E45BE97B0E8CC7DD009D7055 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9710E8CC7DD009D7055 /* AGL.framework */; };
@ -246,6 +249,13 @@
39C1248519F1EB75005DF557 /* SurfaceManagerGui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SurfaceManagerGui.cpp; sourceTree = "<group>"; };
39C1248619F1EB75005DF557 /* SurfaceManagerGui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SurfaceManagerGui.h; sourceTree = "<group>"; };
39C1248719F1EB75005DF557 /* SurfaceType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SurfaceType.h; sourceTree = "<group>"; };
39C787BB1AC20D2400691393 /* CommandManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandManager.h; path = Commands/CommandManager.h; sourceTree = "<group>"; };
39C787BC1AC2111B00691393 /* CommandManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandManager.cpp; path = Commands/CommandManager.cpp; sourceTree = "<group>"; };
39C787BF1AC2BBAE00691393 /* TestUndoCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TestUndoCommand.cpp; path = Commands/TestUndoCommand.cpp; sourceTree = "<group>"; };
39C787C01AC2BBAE00691393 /* TestUndoCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestUndoCommand.h; path = Commands/TestUndoCommand.h; sourceTree = "<group>"; };
39FDD9EA1AC007BF00262205 /* BaseCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BaseCommand.h; path = Commands/BaseCommand.h; sourceTree = "<group>"; };
39FDD9EC1AC00EAE00262205 /* TestCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TestCommand.cpp; path = Commands/TestCommand.cpp; sourceTree = "<group>"; };
39FDD9ED1AC00EAE00262205 /* TestCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestCommand.h; path = Commands/TestCommand.h; sourceTree = "<group>"; };
BBAB23BE13894E4700AA2426 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../libs/glut/lib/osx/GLUT.framework; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
E45BE9710E8CC7DD009D7055 /* AGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AGL.framework; path = /System/Library/Frameworks/AGL.framework; sourceTree = "<absolute>"; };
@ -364,6 +374,7 @@
396E8A2F190FEDD900705899 /* src */ = {
isa = PBXGroup;
children = (
39FDD9E81AC0076200262205 /* Commands */,
39C1246D19F187D5005DF557 /* UserInterface */,
39C1246219F0AB96005DF557 /* Surfaces */,
39C1245619F086A9005DF557 /* Sources */,
@ -628,6 +639,20 @@
path = UserInterface;
sourceTree = "<group>";
};
39FDD9E81AC0076200262205 /* Commands */ = {
isa = PBXGroup;
children = (
39FDD9EA1AC007BF00262205 /* BaseCommand.h */,
39C787BB1AC20D2400691393 /* CommandManager.h */,
39C787BC1AC2111B00691393 /* CommandManager.cpp */,
39FDD9ED1AC00EAE00262205 /* TestCommand.h */,
39FDD9EC1AC00EAE00262205 /* TestCommand.cpp */,
39C787C01AC2BBAE00691393 /* TestUndoCommand.h */,
39C787BF1AC2BBAE00691393 /* TestUndoCommand.cpp */,
);
name = Commands;
sourceTree = "<group>";
};
BB4B014C10F69532006C3DED /* addons */ = {
isa = PBXGroup;
children = (
@ -807,6 +832,7 @@
buildActionMask = 2147483647;
files = (
3933D5D819BB87BD000ACA55 /* ofxSlider.cpp in Sources */,
39C787BD1AC2111B00691393 /* CommandManager.cpp in Sources */,
39C1247E19F187D5005DF557 /* ProjectionEditor.cpp in Sources */,
39C1244619EE9589005DF557 /* RecursiveDirectoryIteratorStategies.cpp in Sources */,
39C1243A19EE9589005DF557 /* Compression.cpp in Sources */,
@ -823,7 +849,9 @@
397EFC7F1A08FE720009286E /* FboSource.cpp in Sources */,
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */,
39C1244719EE9589005DF557 /* RegexPathFilter.cpp in Sources */,
39C787C11AC2BBAE00691393 /* TestUndoCommand.cpp in Sources */,
39C1247C19F187D5005DF557 /* BaseJoint.cpp in Sources */,
39FDD9EE1AC00EAE00262205 /* TestCommand.cpp in Sources */,
39C1245219EE95DD005DF557 /* MediaServer.cpp in Sources */,
39C1243D19EE9589005DF557 /* DirectoryUtils.cpp in Sources */,
39264843192224F90008A7F5 /* tinyxmlparser.cpp in Sources */,

42
src/Commands/BaseCommand.h

@ -0,0 +1,42 @@
// Command base class for separating ofxPiMapper available commands from the core.
// Created by Krisjanis Rijnieks 2015-03-23
// Good example
// http://gameprogrammingpatterns.com/command.html
#pragma once
namespace ofx{
namespace piMapper{
// Base class for all commands
class BaseCommand{
public:
virtual ~BaseCommand(){};
virtual void execute() = 0;
virtual bool isUndoable(){return false;}
protected:
BaseCommand(){};
};
// Base class for all undoable commands
class BaseUndoableCommand : public BaseCommand{
public:
virtual void undo() = 0;
virtual bool isUndoable(){return true;}
protected:
BaseUndoableCommand(){};
};
} // namespace piMapper
} // namespace ofx
// Ideas for command classes
// SelectSurfaceCommand
// MoveSurfaceCommand
// SelectSourceMapCommand
// MoveSourceMapCommand

9
src/Commands/Command.h

@ -1,9 +0,0 @@
// Command base class for separating ofxPiMapper available commands from the core.
// Created by Krisjanis Rijnieks 2015-03-23
#pragma once
class Command{
public:
virtual void execute() = 0;
};

27
src/Commands/CommandManager.cpp

@ -0,0 +1,27 @@
#include "CommandManager.h"
namespace ofx{
namespace piMapper{
void CommandManager::executeCommand(BaseCommand * cmd){
cmd->execute();
if (cmd->isUndoable()){
commandStack.push_back(static_cast<BaseUndoableCommand *>(cmd));
}
}
void CommandManager::undo(){
if (commandStack.size() > 0){
BaseUndoableCommand * cmd = commandStack.back();
cmd->undo();
// Delete last command for now
// TODO: Enable redo func and that means we do not destroy last command,
// we move the stack pointer instead.
delete commandStack.back();
commandStack.pop_back();
}
}
} // namespace piMapper
} // namespace ofx

23
src/Commands/CommandManager.h

@ -0,0 +1,23 @@
// CommandManager class to keep a stack of commands for undo functionality
// Created by Krisjanis Rijnieks 2015-03-24
#pragma once
#import <deque>
#import "BaseCommand.h"
namespace ofx{
namespace piMapper{
class CommandManager{
public:
void executeCommand(BaseCommand * cmd);
void undo();
private:
std::deque<BaseUndoableCommand *> commandStack;
};
} // namespace piMapper
} // namespace ofx

21
src/Commands/TestCommand.cpp

@ -1,10 +1,17 @@
# include "TestCommand.h"
TestCommand::TestCommand(ofxPiMapper * a){
_application = a;
}
namespace ofx{
namespace piMapper{
TestCommand::TestCommand(ofxPiMapper * a){
_application = a;
}
void TestCommand::execute(){
string name = "Hugo";
_application->testCommand(name);
}
} // namespace piMapper
} // namespace ofx
void TestCommand::execute(){
string name = "Hugo";
_application->testCommand(name);
}

28
src/Commands/TestCommand.h

@ -5,17 +5,23 @@
#pragma once
#include "ofxPiMapper.h"
#include "Command.h"
#include "BaseCommand.h"
class ofxPiMapper;
class TestCommand : public Command{
public:
TestCommand(ofxPiMapper * a);
~TestCommand();
virtual void execute();
private:
ofxPiMapper * _application;
};
namespace ofx{
namespace piMapper{
class TestCommand : public BaseCommand{
public:
TestCommand(ofxPiMapper * a);
void execute();
private:
ofxPiMapper * _application;
};
} // namespace piMapper
} // namespace ofx

21
src/Commands/TestUndoCommand.cpp

@ -0,0 +1,21 @@
#include "TestUndoCommand.h"
namespace ofx{
namespace piMapper{
TestUndoCommand::TestUndoCommand(ofxPiMapper * a){
_application = a;
}
void TestUndoCommand::execute(){
increase = 2;
_application->testUndoableCommand(increase);
}
void TestUndoCommand::undo(){
_application->testUndoableCommand(-increase);
}
} // namespace piMapper
} // namespace ofx

27
src/Commands/TestUndoCommand.h

@ -0,0 +1,27 @@
// Created by Krisjanis Rijnieks 2015-03-25
#pragma once
#include "ofxPiMapper.h"
#include "BaseCommand.h"
class ofxPiMapper;
namespace ofx{
namespace piMapper{
class TestUndoCommand : public BaseUndoableCommand{
public:
TestUndoCommand(ofxPiMapper * a);
void execute();
void undo();
private:
ofxPiMapper * _application;
int increase;
};
} // namespace piMapper
} // namespace ofx

307
src/ofxPiMapper.cpp

@ -1,173 +1,184 @@
#include "ofxPiMapper.h"
ofxPiMapper::ofxPiMapper():
bShowInfo(false),
isSetUp(false){
ofAddListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
ofxPiMapper::ofxPiMapper(): bShowInfo(false), isSetUp(false){
ofAddListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
}
ofxPiMapper::~ofxPiMapper() {
ofRemoveListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
ofxPiMapper::~ofxPiMapper(){
ofRemoveListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
}
void ofxPiMapper::setup() {
ofLogNotice("ofxPiMapper") << "Setting up...";
// Assign media server to other pi mapper components
surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer);
// Check if we have user surfaces defined, if not - load default
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)) {
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
} else {
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
}
// The GUI needs something to interface with
gui.setSurfaceManager(&surfaceManager);
isSetUp = true;
ofLogNotice("ofxPiMapper") << "Done setting up";
// Initialize TestCommand
ofxPiMapper * app = this;
aTestCommand = new TestCommand(app);
void ofxPiMapper::setup(){
ofLogNotice("ofxPiMapper") << "Setting up...";
// Assign media server to other pi mapper components
surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer);
// Check if we have user surfaces defined, if not - load default
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
} else {
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
}
// The GUI needs something to interface with
gui.setSurfaceManager(&surfaceManager);
isSetUp = true;
ofLogNotice("ofxPiMapper") << "Done setting up";
// Initialize undo test vars
undoTestValue = 0;
}
void ofxPiMapper::draw() {
if (!isSetUp) {
return;
}
// Draw the piMapper GUI
gui.draw();
if (bShowInfo) {
// Draw instructions
stringstream ss;
ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n";
ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n";
ss << " 4. Source selection mode\n\n";
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> "
"keys on the keyboard.\n\n";
ss << "Press <t> to add new triangle surface\n";
ss << "Press <q> to add new quad surface\n";
ss << "Press <s> to save the composition\n";
ss << "Press <f> to toggle fullscreen\n";
ss << "Press <i> to hide this message";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200));
}
void ofxPiMapper::draw(){
if (!isSetUp) {
return;
}
// Draw the piMapper GUI
gui.draw();
if (bShowInfo){
// Draw instructions
stringstream ss;
ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n";
ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n";
ss << " 4. Source selection mode\n\n";
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> "
"keys on the keyboard.\n\n";
ss << "Press <t> to add new triangle surface\n";
ss << "Press <q> to add new quad surface\n";
ss << "Press <s> to save the composition\n";
ss << "Press <f> to toggle fullscreen\n";
ss << "Press <i> to hide this message";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200));
}
ofDrawBitmapStringHighlight(ofToString(undoTestValue), 200, 200);
} // draw
void ofxPiMapper::keyPressed(ofKeyEventArgs &args) {
ofLogNotice("ofxPiMapper") << "Key pressed: " << static_cast<char>(args.key);
switch (args.key) {
case '1':
gui.setMode(ofx::piMapper::GuiMode::NONE);
break;
case '2':
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
break;
case '3':
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
break;
case '4':
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
break;
case 'i':
bShowInfo = !bShowInfo;
break;
case 'q':
addQuadSurface();
break;
case 't':
addTriangleSurface();
break;
case 'f':
ofToggleFullscreen();
break;
case 's':
surfaceManager.saveXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
// TODO: Remove the following case when Command test done.
case '0':
aTestCommand->execute();
break;
default:
break;
}
void ofxPiMapper::keyPressed(ofKeyEventArgs &args){
ofLogNotice("ofxPiMapper") << "Key pressed: " << static_cast<char>(args.key);
switch (args.key) {
case '1':
gui.setMode(ofx::piMapper::GuiMode::NONE);
break;
case '2':
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
break;
case '3':
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
break;
case '4':
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
break;
case 'i':
bShowInfo = !bShowInfo;
break;
case 'q':
addQuadSurface();
break;
case 't':
addTriangleSurface();
break;
case 'f':
ofToggleFullscreen();
break;
case 's':
surfaceManager.saveXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
// TODO: Remove the following case when Command test done.
case '9':
commandManager.executeCommand(new ofx::piMapper::TestUndoCommand((ofxPiMapper *)this));
break;
case '0':
commandManager.executeCommand(new ofx::piMapper::TestCommand((ofxPiMapper *)this));
break;
case 'u':
// undo
commandManager.undo();
break;
default:
break;
}
} // keyPressed
void ofxPiMapper::addFboSource(ofx::piMapper::FboSource &fboSource) {
mediaServer.addFboSource(fboSource);
void ofxPiMapper::addFboSource(ofx::piMapper::FboSource &fboSource){
mediaServer.addFboSource(fboSource);
} // addFboSource
void ofxPiMapper::addTriangleSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// Select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
void ofxPiMapper::addTriangleSurface(){
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// Select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addTriangleSurface
void ofxPiMapper::addQuadSurface() {
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
void ofxPiMapper::addQuadSurface(){
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addQuadSurface
ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer() {
return mediaServer;
ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer(){
return mediaServer;
}
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager() {
return surfaceManager;
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager(){
return surfaceManager;
}
// TODO: remove this when done testing and everything works
void ofxPiMapper::testCommand(string name){
ofLogNotice("ofxPiMapper", name);
ofLogNotice("ofxPiMapper", name);
}
void ofxPiMapper::testUndoableCommand(int increase){
undoTestValue += increase;
}

95
src/ofxPiMapper.h

@ -8,6 +8,9 @@
*
* Author: Krisjanis Rijnieks */
// On using prefixes like m or p (mMemberVariable, pMyPointer)
// http://stackoverflow.com/questions/1228161/why-use-prefixes-on-member-variables-in-c-classes
#pragma once
#include "ofMain.h"
@ -16,56 +19,56 @@
#include "MediaServer.h"
#include "FboSource.h"
#include "Command.h"
#include "BaseCommand.h"
#include "TestCommand.h" // TODO: Remove this line when done testing
#include "TestUndoCommand.h"
#include "CommandManager.h"
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
class ofxPiMapper {
public:
// These are here for adding and removing listeners on
// contruction and deconstruction
ofxPiMapper();
~ofxPiMapper();
// These are here to adapt to the openFrameworks ways
void setup();
void draw(); // Called manually to make custom layering possible
void keyPressed(ofKeyEventArgs& args);
class ofxPiMapper{
public:
ofxPiMapper();
~ofxPiMapper();
void setup();
void draw();
void keyPressed(ofKeyEventArgs& args);
void addFboSource(ofx::piMapper::FboSource& fboSource);
// Discussion:
// Maybe it makes more sense to use create prefix instead of add
// in addTriangleSurface and so on, so we get createTriangleSurface.
// TODO: Copy/move these methods to SurfaceManager (not sure)
void addTriangleSurface();
void addQuadSurface();
// Toggle help / info
void showInfo() { bShowInfo = true; };
void hideInfo() { bShowInfo = false; };
// Discussion:
// Maybe these should be static as this would allow to access them
// from anywhere within ofxPiMapper.
ofx::piMapper::MediaServer& getMediaServer();
ofx::piMapper::SurfaceManager& getSurfaceManager();
// Test first steps of the Command design pattern implementation.
void testCommand(string name);
void testUndoableCommand(int increase);
int undoTestValue;
ofx::piMapper::CommandManager commandManager;
private:
bool isSetUp;
bool bShowInfo;
ofx::piMapper::MediaServer mediaServer;
ofx::piMapper::SurfaceManager surfaceManager;
// Use this to add custom FBO source
void addFboSource(ofx::piMapper::FboSource& fboSource);
/* Discussion:
* Maybe it makes more sense to use create prefix instead of add
* in addTriangleSurface and so on, so we get createTriangleSurface.
* TODO: Copy/move these methods to SurfaceManager (not sure) */
void addTriangleSurface();
void addQuadSurface();
// Toggle help / info
void showInfo() { bShowInfo = true; };
void hideInfo() { bShowInfo = false; };
/* Discussion:
* Maybe these should be static as this would allow to access them
* from anywhere within ofxPiMapper. */
ofx::piMapper::MediaServer& getMediaServer();
ofx::piMapper::SurfaceManager& getSurfaceManager();
// Test first steps of the Command design pattern implementation.
void testCommand(string name);
Command * aTestCommand;
private:
bool isSetUp;
bool bShowInfo;
ofx::piMapper::MediaServer mediaServer;
ofx::piMapper::SurfaceManager surfaceManager;
/* Discussion: Here now the GUI points only to surface manager,
* maybe it should be as a separate layer? */
ofx::piMapper::SurfaceManagerGui gui;
// Discussion: Here now the GUI points only to surface manager,
// maybe it should be as a separate layer?
ofx::piMapper::SurfaceManagerGui gui;
};
Loading…
Cancel
Save