From 77340cd9e45cada01cb1c54d397573e154918086 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 10 Jan 2016 16:01:32 +0100 Subject: [PATCH] Make use of `SurfaceFactory` in `AddSurfaceCmd` --- src/Commands/AddSurfaceCmd.cpp | 42 ++-------------------------------- src/Commands/AddSurfaceCmd.h | 1 + 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/src/Commands/AddSurfaceCmd.cpp b/src/Commands/AddSurfaceCmd.cpp index d9085e8..49539b4 100644 --- a/src/Commands/AddSurfaceCmd.cpp +++ b/src/Commands/AddSurfaceCmd.cpp @@ -9,11 +9,8 @@ AddSurfaceCmd::AddSurfaceCmd(ofxPiMapper * app, int surfaceType){ } void AddSurfaceCmd::exec(){ - if(_surfaceType == SurfaceType::TRIANGLE_SURFACE){ - addTriangleSurface(); - }else if(_surfaceType == SurfaceType::QUAD_SURFACE){ - addQuadSurface(); - } + BaseSurface * surface = SurfaceFactory::instance()->createSurface(_surfaceType); + _app->getSurfaceManager()->addSurface(surface); } void AddSurfaceCmd::undo(){ @@ -21,41 +18,6 @@ void AddSurfaceCmd::undo(){ _app->getSurfaceManager()->removeSurface(); } -void AddSurfaceCmd::addTriangleSurface(){ - int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; - - vector 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 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)); - _app->getSurfaceManager()->createSurface(surfaceType, vertices, texCoords); -} - -void AddSurfaceCmd::addQuadSurface(){ - int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; - - vector 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 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))); - - _app->getSurfaceManager()->createSurface(surfaceType, vertices, texCoords); -} - } // namespace piMapper } // namespace ofx diff --git a/src/Commands/AddSurfaceCmd.h b/src/Commands/AddSurfaceCmd.h index 283f654..a7444c4 100644 --- a/src/Commands/AddSurfaceCmd.h +++ b/src/Commands/AddSurfaceCmd.h @@ -4,6 +4,7 @@ #include "BaseCmd.h" #include "SurfaceType.h" #include "BaseSurface.h" +#include "SurfaceFactory.h" class ofxPiMapper;