Browse Source

Add Command design pattern simple test

master
Krisjanis Rijnieks 10 years ago
parent
commit
798ff75c8f
  1. 9
      src/Commands/Command.h
  2. 10
      src/Commands/TestCommand.cpp
  3. 21
      src/Commands/TestCommand.h
  4. 13
      src/ofxPiMapper.cpp
  5. 37
      src/ofxPiMapper.h

9
src/Commands/Command.h

@ -0,0 +1,9 @@
// 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;
};

10
src/Commands/TestCommand.cpp

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

21
src/Commands/TestCommand.h

@ -0,0 +1,21 @@
// TestCommand class, extends Command base class. Used for Command design pattern implementation
// pre-tests. Will be removed as soon as possible.
// Created by Krisjanis Rijnieks 2015-03-23
#pragma once
#include "ofxPiMapper.h"
#include "Command.h"
class ofxPiMapper;
class TestCommand : public Command{
public:
TestCommand(ofxPiMapper * a);
~TestCommand();
virtual void execute();
private:
ofxPiMapper * _application;
};

13
src/ofxPiMapper.cpp

@ -32,6 +32,10 @@ void ofxPiMapper::setup() {
isSetUp = true;
ofLogNotice("ofxPiMapper") << "Done setting up";
// Initialize TestCommand
ofxPiMapper * app = this;
aTestCommand = new TestCommand(app);
}
void ofxPiMapper::draw() {
@ -98,6 +102,10 @@ void ofxPiMapper::keyPressed(ofKeyEventArgs &args) {
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
// TODO: Remove the following case when Command test done.
case '0':
aTestCommand->execute();
break;
default:
break;
}
@ -157,4 +165,9 @@ ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer() {
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager() {
return surfaceManager;
}
// TODO: remove this when done testing and everything works
void ofxPiMapper::testCommand(string name){
ofLogNotice("ofxPiMapper", name);
}

37
src/ofxPiMapper.h

@ -1,3 +1,13 @@
/* ofxPiMapper
*
* Description:
* Main ofxPiMapper class. Holds instances of all necessary parts of the tool:
* - MediaServer
* - SurfaceManager
* - SurfaceManagerGui (this asks for a different architecture)
*
* Author: Krisjanis Rijnieks */
#pragma once
#include "ofMain.h"
@ -6,22 +16,32 @@
#include "MediaServer.h"
#include "FboSource.h"
#include "Command.h"
#include "TestCommand.h" // TODO: Remove this line when done testing
#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);
// Use this to add custom FBO source
void addFboSource(ofx::piMapper::FboSource& fboSource);
// TODO: Copy/move these methods to SurfaceManager
/* 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();
@ -29,14 +49,23 @@ public:
void showInfo() { bShowInfo = true; };
void hideInfo() { bShowInfo = false; };
// Getters
/* 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;
};
Loading…
Cancel
Save