Browse Source

Add MediaServer initialization

master
Krisjanis Rijnieks 11 years ago
parent
commit
4d484bfb3d
  1. 85
      src/SourcesEditor.cpp
  2. 10
      src/SourcesEditor.h

85
src/SourcesEditor.cpp

@ -2,29 +2,58 @@
namespace ofx {
namespace piMapper {
SourcesEditor::SourcesEditor() {
defImgDir = DEFAULT_IMAGES_DIR;
registerAppEvents();
}
SourcesEditor::SourcesEditor() {
init();
// Create new MediaServer instance,
// we will need to clear this in the deconstr
mediaServer = new MediaServer();
isMediaServerExternal = false;
}
SourcesEditor::~SourcesEditor() {
SourcesEditor::SourcesEditor(MediaServer* externalMediaServer) {
init();
// Assign external MediaServer instance pointer
mediaServer = externalMediaServer;
isMediaServerExternal = true;
}
SourcesEditor::~SourcesEditor() {
unregisterAppEvents();
delete gui;
while (images.size()) {
delete images.back();
images.pop_back();
}
}
void SourcesEditor::registerAppEvents() {
// If mediaServer is local, clear it
if (isMediaServerExternal) {
// Clear all loaded sources
//mediaServer->clear()
// Destroy the pointer and set it to NULL pointer
delete mediaServer;
mediaServer = NULL;
}
}
// Initialize instance variables
void SourcesEditor::init() {
mediaServer = NULL;
isMediaServerExternal = false;
defImgDir = DEFAULT_IMAGES_DIR;
registerAppEvents();
}
void SourcesEditor::registerAppEvents() {
ofAddListener(ofEvents().setup, this, &SourcesEditor::setup);
}
}
void SourcesEditor::unregisterAppEvents() {
void SourcesEditor::unregisterAppEvents() {
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup);
}
}
void SourcesEditor::setup(ofEventArgs& args) {
void SourcesEditor::setup(ofEventArgs& args) {
gui = new RadioList();
// read directory contents
@ -42,29 +71,29 @@ void SourcesEditor::setup(ofEventArgs& args) {
gui->setup("Images", vnames);
gui->setPosition(20, 20);
ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent);
}
}
void SourcesEditor::draw() {
void SourcesEditor::draw() {
// Don't draw if there is no source selected
if (surfaceManager->getSelectedSurface() == NULL) {
return;
}
gui->draw();
}
}
void SourcesEditor::loadImage(string name, string path) {
void SourcesEditor::loadImage(string name, string path) {
images.push_back(new ofImage());
images.back()->loadImage(path);
imageNames.push_back(name);
ofSendMessage("imageLoaded");
}
}
void SourcesEditor::disable() { gui->disable(); }
void SourcesEditor::disable() { gui->disable(); }
void SourcesEditor::enable() {
void SourcesEditor::enable() {
// Don't enable if there is no surface selected
if (surfaceManager->getSelectedSurface() == NULL) {
cout << "No surface selected. Not enable()ing source list." << endl;
@ -72,13 +101,13 @@ void SourcesEditor::enable() {
}
gui->enable();
}
}
void SourcesEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) {
void SourcesEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) {
surfaceManager = newSurfaceManager;
}
}
void SourcesEditor::selectImageSourceRadioButton(string name) {
void SourcesEditor::selectImageSourceRadioButton(string name) {
if (name == "none") {
gui->unselectAll();
return;
@ -91,19 +120,19 @@ void SourcesEditor::selectImageSourceRadioButton(string name) {
}
}
}
}
}
int SourcesEditor::getLoadedTexCount() { return images.size(); }
int SourcesEditor::getLoadedTexCount() { return images.size(); }
ofTexture* SourcesEditor::getTexture(int index) {
ofTexture* SourcesEditor::getTexture(int index) {
if (index >= images.size()) {
throw std::runtime_error("Texture index out of bounds.");
}
return &images[index]->getTextureReference();
}
}
void SourcesEditor::guiEvent(string& imageName) {
void SourcesEditor::guiEvent(string& imageName) {
string name = imageName;
if (surfaceManager->getSelectedSurface() == NULL) {
@ -116,6 +145,6 @@ void SourcesEditor::guiEvent(string& imageName) {
ofTexture* texture = surfaceManager->loadImageSource(name, ss.str());
surfaceManager->getSelectedSurface()->setTexture(texture);
surfaceManager->manageMemory();
}
}
}
}

10
src/SourcesEditor.h

@ -4,6 +4,7 @@
#include "ofEvents.h"
#include "SurfaceManager.h"
#include "RadioList.h"
#include "MediaServer.h"
#define DEFAULT_IMAGES_DIR "sources/images/";
@ -11,9 +12,16 @@ namespace ofx {
namespace piMapper {
class SourcesEditor {
public:
// Default contructor that initializes media server locally,
// thus requiring to delete the media server from memory on deconstr
SourcesEditor();
// Alternative constructor that allows to assign external media server
SourcesEditor(MediaServer* externalMediaServer);
~SourcesEditor();
// Init handles variable initialization in all constructors
void init();
void registerAppEvents();
void unregisterAppEvents();
@ -29,6 +37,8 @@ class SourcesEditor {
ofTexture* getTexture(int index);
private:
MediaServer* mediaServer;
bool isMediaServerExternal;
SurfaceManager* surfaceManager;
RadioList* gui;
string defImgDir;

Loading…
Cancel
Save