From d4b17dc092e88a5d47472a1a44e4c6afd0dacf54 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 6 Sep 2014 23:38:09 +0200 Subject: [PATCH 01/10] Add ofxRadioList base code --- src/ui/ofxRadioList.cpp | 95 +++++++++++++++++++++++++++++++++++++++++ src/ui/ofxRadioList.h | 23 ++++++++++ 2 files changed, 118 insertions(+) create mode 100644 src/ui/ofxRadioList.cpp create mode 100644 src/ui/ofxRadioList.h diff --git a/src/ui/ofxRadioList.cpp b/src/ui/ofxRadioList.cpp new file mode 100644 index 0000000..655fbe7 --- /dev/null +++ b/src/ui/ofxRadioList.cpp @@ -0,0 +1,95 @@ +#include "ofxRadioList.h" + +ofxRadioList::ofxRadioList(){} + +ofxRadioList::ofxRadioList(vector &labels) +{ + setup(labels); +} + +ofxRadioList::~ofxRadioList() +{ + removeListeners(); + + int i; + for (i = 0; i < toggles.size(); i++) { + delete toggles[i]; + } + toggles.clear(); +} + +void ofxRadioList::setup(vector &labels) +{ + // Create toggles with labels from the labels arg + int i; + for (i = 0; i < labels.size(); i++) { + ofxToggle* toggle = new ofxToggle(); + toggle->setup(false); + toggle->setName(labels[i]); + toggle->setPosition(0, toggle->getHeight() * i); + toggles.push_back(toggle); + } + + addListeners(); +} + +void ofxRadioList::draw() +{ + int i; + for (i = 0; i < toggles.size(); i++) { + toggles[i]->draw(); + } +} + +void ofxRadioList::addListeners() +{ + if (toggles.size() <= 0) return; + + int i; + for (i = 0; i < toggles.size(); i++) { + toggles[i]->addListener(this, &ofxRadioList::onToggleClicked); + } +} + +void ofxRadioList::removeListeners() +{ + if (toggles.size() <= 0) return; + + int i; + for (i = 0; i < toggles.size(); i++) { + toggles[i]->removeListener(this, &ofxRadioList::onToggleClicked); + } +} + +void ofxRadioList::unselectAll() +{ + int i; + + removeListeners(); + + for (i = 0; i < toggles.size(); i++) { + ofParameter* paramPtr = static_cast*>(&toggles[i]->getParameter()); + *toggles[i] = false; + } + + addListeners(); +} + +void ofxRadioList::onToggleClicked(bool &toggleValue) +{ + unselectAll(); + + // Search for the actual toggle triggering the event + int i; + for (i = 0; i < toggles.size(); i++) { + ofParameter* paramPtr = static_cast*>(&toggles[i]->getParameter()); + + if (&(paramPtr->get()) == &toggleValue) { + removeListeners(); + *toggles[i] = true; + cout << toggles[i]->getName() << endl; + addListeners(); + break; + } + } +} diff --git a/src/ui/ofxRadioList.h b/src/ui/ofxRadioList.h new file mode 100644 index 0000000..fa1a34c --- /dev/null +++ b/src/ui/ofxRadioList.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ofGraphics.h" +#include "ofxToggle.h" + +class ofxRadioList +{ +public: + ofxRadioList(); + ofxRadioList(vector &labels); + ~ofxRadioList(); + + void setup(vector &labels); + void draw(); + +private: + vector toggles; + + void addListeners(); + void removeListeners(); + void unselectAll(); + void onToggleClicked(bool &toggleValue); +}; \ No newline at end of file From 022d31de5d8df5674a2fe237c64765194478a906 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 12:53:14 +0200 Subject: [PATCH 02/10] Add ofxGuiGroup as the container for toggles Add event that notifies its listeners about selected radio button/toggle --- src/ui/ofxRadioList.cpp | 82 ++++++++++++++++++++--------------------- src/ui/ofxRadioList.h | 15 ++++++-- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/ui/ofxRadioList.cpp b/src/ui/ofxRadioList.cpp index 655fbe7..9faddf2 100644 --- a/src/ui/ofxRadioList.cpp +++ b/src/ui/ofxRadioList.cpp @@ -9,13 +9,12 @@ ofxRadioList::ofxRadioList(vector &labels) ofxRadioList::~ofxRadioList() { - removeListeners(); - + int i; - for (i = 0; i < toggles.size(); i++) { - delete toggles[i]; + for (i = 0; i < guiGroup.getNumControls(); i++) { + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); } - toggles.clear(); } void ofxRadioList::setup(vector &labels) @@ -26,53 +25,51 @@ void ofxRadioList::setup(vector &labels) ofxToggle* toggle = new ofxToggle(); toggle->setup(false); toggle->setName(labels[i]); - toggle->setPosition(0, toggle->getHeight() * i); - toggles.push_back(toggle); + toggle->addListener(this, &ofxRadioList::onToggleClicked); + guiGroup.add(toggle); } - - addListeners(); } void ofxRadioList::draw() { - int i; - for (i = 0; i < toggles.size(); i++) { - toggles[i]->draw(); - } + guiGroup.draw(); } -void ofxRadioList::addListeners() +void ofxRadioList::setPosition(ofPoint p) { - if (toggles.size() <= 0) return; - - int i; - for (i = 0; i < toggles.size(); i++) { - toggles[i]->addListener(this, &ofxRadioList::onToggleClicked); - } + guiGroup.setPosition(p); } -void ofxRadioList::removeListeners() +void ofxRadioList::setPosition(float x, float y) { - if (toggles.size() <= 0) return; - - int i; - for (i = 0; i < toggles.size(); i++) { - toggles[i]->removeListener(this, &ofxRadioList::onToggleClicked); - } + guiGroup.setPosition(x, y); +} + +ofPoint ofxRadioList::getPosition() +{ + return guiGroup.getPosition(); +} + +float ofxRadioList::getWidth() +{ + return guiGroup.getWidth(); +} + +float ofxRadioList::getHeight() +{ + return guiGroup.getHeight(); } void ofxRadioList::unselectAll() { int i; - - removeListeners(); - - for (i = 0; i < toggles.size(); i++) { - ofParameter* paramPtr = static_cast*>(&toggles[i]->getParameter()); - *toggles[i] = false; + for (i = 0; i < guiGroup.getNumControls(); i++) { + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + *toggle = false; + toggle->addListener(this, &ofxRadioList::onToggleClicked); } - - addListeners(); } void ofxRadioList::onToggleClicked(bool &toggleValue) @@ -81,14 +78,17 @@ void ofxRadioList::onToggleClicked(bool &toggleValue) // Search for the actual toggle triggering the event int i; - for (i = 0; i < toggles.size(); i++) { - ofParameter* paramPtr = static_cast*>(&toggles[i]->getParameter()); + for (i = 0; i < guiGroup.getNumControls(); i++) { + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); if (&(paramPtr->get()) == &toggleValue) { - removeListeners(); - *toggles[i] = true; - cout << toggles[i]->getName() << endl; - addListeners(); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + *toggle = true; // Select the specific radio button + toggle->addListener(this, &ofxRadioList::onToggleClicked); + string name = toggle->getName(); + ofNotifyEvent(radioSelectedEvent, name, this); + //cout << toggle->getName() << endl; // debug break; } } diff --git a/src/ui/ofxRadioList.h b/src/ui/ofxRadioList.h index fa1a34c..c0aed7d 100644 --- a/src/ui/ofxRadioList.h +++ b/src/ui/ofxRadioList.h @@ -1,6 +1,7 @@ #pragma once #include "ofGraphics.h" +#include "ofxGuiGroup.h" #include "ofxToggle.h" class ofxRadioList @@ -12,12 +13,20 @@ public: void setup(vector &labels); void draw(); + void setPosition(ofPoint p); + void setPosition(float x, float y); + ofPoint getPosition(); + float getWidth(); + float getHeight(); + + // This event notifies about a toggle being selected and passes it's name to the listeners + // Use ofAddListener(ofxRadioListInstance.radioSelectedEvent, listenerClassPtr, &listenerClass::listenerMethod) + // to listen to this. Listner method void listenerMethod(string & radioName) + ofEvent radioSelectedEvent; private: - vector toggles; + ofxGuiGroup guiGroup; - void addListeners(); - void removeListeners(); void unselectAll(); void onToggleClicked(bool &toggleValue); }; \ No newline at end of file From 55cc4cfac6a43fe41c4c283a9712bf09dbeb3450 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 13:29:13 +0200 Subject: [PATCH 03/10] Add getTitle() method to ofxRadioList --- src/ui/ofxRadioList.cpp | 63 +++++++++++++++++++++++++++++++++++++++-- src/ui/ofxRadioList.h | 9 +++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/ui/ofxRadioList.cpp b/src/ui/ofxRadioList.cpp index 9faddf2..c32097f 100644 --- a/src/ui/ofxRadioList.cpp +++ b/src/ui/ofxRadioList.cpp @@ -1,17 +1,29 @@ #include "ofxRadioList.h" -ofxRadioList::ofxRadioList(){} +ofxRadioList::ofxRadioList() +{ + bHasTitle = false; +} ofxRadioList::ofxRadioList(vector &labels) { + bHasTitle = false; setup(labels); } -ofxRadioList::~ofxRadioList() +ofxRadioList::ofxRadioList(string title, vector &labels) { + bHasTitle = false; + setup(title, labels); +} +ofxRadioList::~ofxRadioList() +{ int i; for (i = 0; i < guiGroup.getNumControls(); i++) { + if (bHasTitle && i == 0) { + continue; + } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); toggle->removeListener(this, &ofxRadioList::onToggleClicked); } @@ -30,11 +42,41 @@ void ofxRadioList::setup(vector &labels) } } +void ofxRadioList::setup(string title, vector &labels) +{ + ofxLabel* label = new ofxLabel(title); + guiGroup.add(label); + bHasTitle = true; + setup(labels); +} + void ofxRadioList::draw() { guiGroup.draw(); } +void ofxRadioList::setTitle(string title) +{ + if (bHasTitle) { + ofxLabel* label = static_cast(guiGroup.getControl(0)); + label->setup(title); + } else { + ofxLabel* label = new ofxLabel(title); + vector toggles; + int i; + for (i = 0; i < guiGroup.getNumControls(); i++) { + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + toggles.push_back(toggle); + } + guiGroup.clear(); + guiGroup.add(label); + bHasTitle = true; + for (i = 0; i < toggles.size(); i++) { + guiGroup.add(toggles[i]); + } + } +} + void ofxRadioList::setPosition(ofPoint p) { guiGroup.setPosition(p); @@ -60,10 +102,24 @@ float ofxRadioList::getHeight() return guiGroup.getHeight(); } +string ofxRadioList::getTitle() +{ + if (bHasTitle) { + ofxLabel* label = static_cast(guiGroup.getControl(0)); + ofParameter* parameter = static_cast*>(&label->getParameter()); + return parameter->get(); + } else { + return ""; + } +} + void ofxRadioList::unselectAll() { int i; for (i = 0; i < guiGroup.getNumControls(); i++) { + if (bHasTitle && i == 0) { + continue; + } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); toggle->removeListener(this, &ofxRadioList::onToggleClicked); @@ -79,6 +135,9 @@ void ofxRadioList::onToggleClicked(bool &toggleValue) // Search for the actual toggle triggering the event int i; for (i = 0; i < guiGroup.getNumControls(); i++) { + if (bHasTitle && i == 0) { + continue; + } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); diff --git a/src/ui/ofxRadioList.h b/src/ui/ofxRadioList.h index c0aed7d..9954513 100644 --- a/src/ui/ofxRadioList.h +++ b/src/ui/ofxRadioList.h @@ -3,29 +3,36 @@ #include "ofGraphics.h" #include "ofxGuiGroup.h" #include "ofxToggle.h" +#include "ofxLabel.h" class ofxRadioList { public: ofxRadioList(); ofxRadioList(vector &labels); + ofxRadioList(string title, vector &labels); ~ofxRadioList(); void setup(vector &labels); + void setup(string title, vector &labels); void draw(); + void setTitle(string title); void setPosition(ofPoint p); void setPosition(float x, float y); ofPoint getPosition(); float getWidth(); float getHeight(); + string getTitle(); + string getItem(int index); - // This event notifies about a toggle being selected and passes it's name to the listeners + // This event notifies about a toggle being selected and passes it's name to the listeners. // Use ofAddListener(ofxRadioListInstance.radioSelectedEvent, listenerClassPtr, &listenerClass::listenerMethod) // to listen to this. Listner method void listenerMethod(string & radioName) ofEvent radioSelectedEvent; private: ofxGuiGroup guiGroup; + bool bHasTitle; void unselectAll(); void onToggleClicked(bool &toggleValue); From e040ea7d36447793ffab7af3262e19d69fed052f Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 14:34:04 +0200 Subject: [PATCH 04/10] Fix ofxRadioList to work with ofxSourcesEditor Add getItemName method Add enable and disable methods Add storedLabels and storedTitle variables for recreating toggles on enable Add clear method --- src/ui/ofxRadioList.cpp | 141 ++++++++++++++++++++++++++++++++++------ src/ui/ofxRadioList.h | 12 +++- 2 files changed, 130 insertions(+), 23 deletions(-) diff --git a/src/ui/ofxRadioList.cpp b/src/ui/ofxRadioList.cpp index c32097f..f86e63f 100644 --- a/src/ui/ofxRadioList.cpp +++ b/src/ui/ofxRadioList.cpp @@ -3,34 +3,32 @@ ofxRadioList::ofxRadioList() { bHasTitle = false; + storedTitle = ""; + storedSelectedItem = 0; } ofxRadioList::ofxRadioList(vector &labels) { - bHasTitle = false; + ofxRadioList(); setup(labels); } ofxRadioList::ofxRadioList(string title, vector &labels) { - bHasTitle = false; + ofxRadioList(); setup(title, labels); } ofxRadioList::~ofxRadioList() { - int i; - for (i = 0; i < guiGroup.getNumControls(); i++) { - if (bHasTitle && i == 0) { - continue; - } - ofxToggle* toggle = static_cast(guiGroup.getControl(i)); - toggle->removeListener(this, &ofxRadioList::onToggleClicked); - } + clear(); } void ofxRadioList::setup(vector &labels) { + // Copy incomming labels for later use + storedLabels = labels; + // Create toggles with labels from the labels arg int i; for (i = 0; i < labels.size(); i++) { @@ -44,6 +42,9 @@ void ofxRadioList::setup(vector &labels) void ofxRadioList::setup(string title, vector &labels) { + // Store title for later use + storedTitle = title; + ofxLabel* label = new ofxLabel(title); guiGroup.add(label); bHasTitle = true; @@ -87,6 +88,88 @@ void ofxRadioList::setPosition(float x, float y) guiGroup.setPosition(x, y); } +void ofxRadioList::selectItem(int index) +{ + if (bHasTitle) { + // We don't count the ofxLabel as an item, thus if title is set + // items in guiGroup start from index 1 + index += 1; + } + + if (index >= guiGroup.getNumControls()) { + return; + } + + unselectAll(); + + ofxToggle* toggle = static_cast(guiGroup.getControl(index)); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + *toggle = true; // Select the specific radio button + toggle->addListener(this, &ofxRadioList::onToggleClicked); + string name = toggle->getName(); + ofNotifyEvent(radioSelectedEvent, name, this); + + storedSelectedItem = index; +} + +void ofxRadioList::enable() +{ + if (guiGroup.getNumControls() >= 0) { + clear(); + } + + // Rebuild everyting + if (bHasTitle) { + setup(storedTitle, storedLabels); + } else { + setup(storedLabels); + } + + if (bHasTitle && storedSelectedItem == 0) { + return; + } + + // Select the stored selected item without throwing an event + ofxToggle* toggle = static_cast(guiGroup.getControl(storedSelectedItem)); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + *toggle = true; + toggle->addListener(this, &ofxRadioList::onToggleClicked); +} + +void ofxRadioList::disable() +{ + // Just remove everything + clear(); +} + +void ofxRadioList::clear() +{ + int i; + for (i = 0; i < guiGroup.getNumControls(); i++) { + if (bHasTitle && i == 0) { + continue; + } + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + } + guiGroup.clear(); +} + +void ofxRadioList::unselectAll() +{ + int i; + for (i = 0; i < guiGroup.getNumControls(); i++) { + if (bHasTitle && i == 0) { + continue; + } + ofxToggle* toggle = static_cast(guiGroup.getControl(i)); + ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); + toggle->removeListener(this, &ofxRadioList::onToggleClicked); + *toggle = false; + toggle->addListener(this, &ofxRadioList::onToggleClicked); + } +} + ofPoint ofxRadioList::getPosition() { return guiGroup.getPosition(); @@ -113,18 +196,26 @@ string ofxRadioList::getTitle() } } -void ofxRadioList::unselectAll() +string ofxRadioList::getItemName(int index) { - int i; - for (i = 0; i < guiGroup.getNumControls(); i++) { - if (bHasTitle && i == 0) { - continue; - } - ofxToggle* toggle = static_cast(guiGroup.getControl(i)); - ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); - toggle->removeListener(this, &ofxRadioList::onToggleClicked); - *toggle = false; - toggle->addListener(this, &ofxRadioList::onToggleClicked); + if (bHasTitle) { + index += 1; + } + + if (index >= guiGroup.getNumControls()) { + return ""; + } + + ofxToggle* toggle = static_cast(guiGroup.getControl(index)); + return toggle->getName(); +} + +int ofxRadioList::size() +{ + if (bHasTitle) { + return guiGroup.getNumControls() - 1; + } else { + return guiGroup.getNumControls(); } } @@ -142,12 +233,20 @@ void ofxRadioList::onToggleClicked(bool &toggleValue) ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); if (&(paramPtr->get()) == &toggleValue) { + /* toggle->removeListener(this, &ofxRadioList::onToggleClicked); *toggle = true; // Select the specific radio button toggle->addListener(this, &ofxRadioList::onToggleClicked); string name = toggle->getName(); ofNotifyEvent(radioSelectedEvent, name, this); //cout << toggle->getName() << endl; // debug + */ + if (bHasTitle) { + selectItem(i - 1); + } else { + selectItem(i); + } + break; } } diff --git a/src/ui/ofxRadioList.h b/src/ui/ofxRadioList.h index 9954513..df960bc 100644 --- a/src/ui/ofxRadioList.h +++ b/src/ui/ofxRadioList.h @@ -19,11 +19,17 @@ public: void setTitle(string title); void setPosition(ofPoint p); void setPosition(float x, float y); + void selectItem(int index); + void enable(); + void disable(); + void clear(); + void unselectAll(); ofPoint getPosition(); float getWidth(); float getHeight(); string getTitle(); - string getItem(int index); + string getItemName(int index); + int size(); // This event notifies about a toggle being selected and passes it's name to the listeners. // Use ofAddListener(ofxRadioListInstance.radioSelectedEvent, listenerClassPtr, &listenerClass::listenerMethod) @@ -31,9 +37,11 @@ public: ofEvent radioSelectedEvent; private: + vector storedLabels; + string storedTitle; ofxGuiGroup guiGroup; bool bHasTitle; + int storedSelectedItem; - void unselectAll(); void onToggleClicked(bool &toggleValue); }; \ No newline at end of file From 88d3b51bdfa808d56755b6ae66859458128af8a0 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 14:36:25 +0200 Subject: [PATCH 05/10] Fix ofxSourcesEditor to work with ofxRadioList --- src/ofxSourcesEditor.cpp | 55 ++++++++++++---------------------------- src/ofxSourcesEditor.h | 6 ++--- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 372f13d..34c9e07 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -28,9 +28,7 @@ void ofxSourcesEditor::unregisterAppEvents() void ofxSourcesEditor::setup(ofEventArgs& args) { - gui = new ofxUICanvas(); - gui->disable(); - gui->disableAppDrawCallback(); + gui = new ofxRadioList(); // read directory contents ofDirectory imgDir; @@ -44,11 +42,15 @@ void ofxSourcesEditor::setup(ofEventArgs& args) vnames.push_back(imgDir.getName(i)); } - gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); - ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); - radio->activateToggle("image0.png"); + gui->setup("Images", vnames); + ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent); + - ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); + //gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); + //ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); + //radio->activateToggle("image0.png"); + + //ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); } void ofxSourcesEditor::draw() @@ -83,29 +85,14 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager) void ofxSourcesEditor::selectImageSourceRadioButton(string name) { - vector widgets = gui->getWidgets(); - - // find radio list item - ofxUIRadio* radio; - for ( int i=0; igetKind(); - if ( widgetKind == OFX_UI_WIDGET_RADIO ){ - radio = (ofxUIRadio*)widgets[i]; - break; - } - } - if (name == "none") { - ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive(); - if ( toggle != NULL ) { - toggle->setValue(false); - } + gui->unselectAll(); return; } else { - for ( int i=0; igetName(); - if ( name == widgetName ) { - radio->activateToggle(name); + int i; + for (i = 0; i < gui->size(); i++) { + if (gui->getItemName(i) == name) { + gui->selectItem(i); return; } } @@ -126,24 +113,14 @@ ofTexture* ofxSourcesEditor::getTexture(int index) return &images[index]->getTextureReference(); } -void ofxSourcesEditor::guiEvent(ofxUIEventArgs &e) +void ofxSourcesEditor::guiEvent(string &imageName) { - string name = e.widget->getName(); - int kind = e.widget->getKind(); - - if(kind == OFX_UI_WIDGET_TOGGLE){ - ofxUIToggle *toggle = (ofxUIToggle *) e.widget; - cout << name << "\t value: " << toggle->getValue() << endl; - } + string name = imageName; if ( surfaceManager->getSelectedSurface() == NULL ) { return; } - if (name == "images") { - return; - } - stringstream ss; ss << defImgDir << name; cout << "attempt to load image: " << ss.str() << endl; diff --git a/src/ofxSourcesEditor.h b/src/ofxSourcesEditor.h index 7344e33..cab567e 100644 --- a/src/ofxSourcesEditor.h +++ b/src/ofxSourcesEditor.h @@ -3,8 +3,8 @@ #include "ofGraphics.h" #include "ofEvents.h" -#include "ofxUI.h" #include "ofxSurfaceManager.h" +#include "ofxRadioList.h" #define DEFAULT_IMAGES_DIR "sources/images/"; @@ -30,9 +30,9 @@ public: private: ofxSurfaceManager* surfaceManager; + ofxRadioList* gui; string defImgDir; - ofxUICanvas *gui; - void guiEvent(ofxUIEventArgs &e); + void guiEvent(string &imageName); vector images; vector imageNames; //ofxPanel imgSrcPanel; From c12a1c110e5e0694918eeb8b55ade4eaf78008a7 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 14:43:50 +0200 Subject: [PATCH 06/10] Not showing source list if there is no surface selected --- src/ofxSourcesEditor.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 34c9e07..0d5e2f5 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -44,17 +44,15 @@ void ofxSourcesEditor::setup(ofEventArgs& args) gui->setup("Images", vnames); ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent); - - - //gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); - //ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); - //radio->activateToggle("image0.png"); - - //ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); } void ofxSourcesEditor::draw() { + // Don't draw if there is no source selected + if ( surfaceManager->getSelectedSurface() == NULL ) { + return; + } + gui->draw(); } @@ -75,6 +73,12 @@ void ofxSourcesEditor::disable() void ofxSourcesEditor::enable() { + // Don't enable if there is no surface selected + if ( surfaceManager->getSelectedSurface() == NULL ) { + cout << "No surface selected. Not enable()ing source list." << endl; + return; + } + gui->enable(); } From f32fd852d933ec02fb231af92bf6593448e15fc8 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 14:47:19 +0200 Subject: [PATCH 07/10] Replace ofxUI dependency with ofxGui --- example/addons.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/addons.make b/example/addons.make index 802cd29..e98663f 100644 --- a/example/addons.make +++ b/example/addons.make @@ -1,3 +1,3 @@ ofxPiMapper -ofxUI +ofxGui ofxXmlSettings From 2d3d73082152391ebdc992a52c69ea4fb5dbe687 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 14:49:17 +0200 Subject: [PATCH 08/10] Fix link to A successgul Git branching model article --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffe8880..41ded08 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Development As the projects gets a bit more popular, I see that people want to add missing features. I have a whole bunch of features that I want to add in future releases, but right now I'm trying to understand how to keep it more or less organized. -Currently I have decided to use [A successful Git branching model](http://nvie.com/posts/a-successful-git) by [Vincent Driessen](https://twitter.com/nvie), so read this article and I do not doubt that it will help you with other Git related projects. +Currently I have decided to use [A successful Git branching model](http://nvie.com/posts/a-successful-git-branching-model/) by [Vincent Driessen](https://twitter.com/nvie), so read this article and I do not doubt that it will help you with other Git related projects. I'm still working on boosting my understanding about the issue tracking system on GitHub, I believe that it would be the best way how to keep new feature requests and bugfixes organized. From ef5ac3da5276e6441d07d48601b80fe9461141c8 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 15:13:44 +0200 Subject: [PATCH 09/10] Fix there is no need for a guiGroup label item as it has a header already --- src/ui/ofxRadioList.cpp | 89 ++++++----------------------------------- src/ui/ofxRadioList.h | 1 - 2 files changed, 12 insertions(+), 78 deletions(-) diff --git a/src/ui/ofxRadioList.cpp b/src/ui/ofxRadioList.cpp index f86e63f..e974284 100644 --- a/src/ui/ofxRadioList.cpp +++ b/src/ui/ofxRadioList.cpp @@ -2,7 +2,6 @@ ofxRadioList::ofxRadioList() { - bHasTitle = false; storedTitle = ""; storedSelectedItem = 0; } @@ -38,16 +37,15 @@ void ofxRadioList::setup(vector &labels) toggle->addListener(this, &ofxRadioList::onToggleClicked); guiGroup.add(toggle); } + + cout << "num items: " << guiGroup.getNumControls() << endl; } void ofxRadioList::setup(string title, vector &labels) { // Store title for later use storedTitle = title; - - ofxLabel* label = new ofxLabel(title); - guiGroup.add(label); - bHasTitle = true; + guiGroup.setName(title); setup(labels); } @@ -58,24 +56,8 @@ void ofxRadioList::draw() void ofxRadioList::setTitle(string title) { - if (bHasTitle) { - ofxLabel* label = static_cast(guiGroup.getControl(0)); - label->setup(title); - } else { - ofxLabel* label = new ofxLabel(title); - vector toggles; - int i; - for (i = 0; i < guiGroup.getNumControls(); i++) { - ofxToggle* toggle = static_cast(guiGroup.getControl(i)); - toggles.push_back(toggle); - } - guiGroup.clear(); - guiGroup.add(label); - bHasTitle = true; - for (i = 0; i < toggles.size(); i++) { - guiGroup.add(toggles[i]); - } - } + storedTitle = title; + guiGroup.setName(title); } void ofxRadioList::setPosition(ofPoint p) @@ -90,12 +72,6 @@ void ofxRadioList::setPosition(float x, float y) void ofxRadioList::selectItem(int index) { - if (bHasTitle) { - // We don't count the ofxLabel as an item, thus if title is set - // items in guiGroup start from index 1 - index += 1; - } - if (index >= guiGroup.getNumControls()) { return; } @@ -119,21 +95,15 @@ void ofxRadioList::enable() } // Rebuild everyting - if (bHasTitle) { - setup(storedTitle, storedLabels); - } else { - setup(storedLabels); - } - - if (bHasTitle && storedSelectedItem == 0) { - return; - } + setup(storedTitle, storedLabels); // Select the stored selected item without throwing an event ofxToggle* toggle = static_cast(guiGroup.getControl(storedSelectedItem)); toggle->removeListener(this, &ofxRadioList::onToggleClicked); *toggle = true; toggle->addListener(this, &ofxRadioList::onToggleClicked); + + cout << "num items after enable: " << guiGroup.getNumControls() << endl; } void ofxRadioList::disable() @@ -146,11 +116,9 @@ void ofxRadioList::clear() { int i; for (i = 0; i < guiGroup.getNumControls(); i++) { - if (bHasTitle && i == 0) { - continue; - } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); toggle->removeListener(this, &ofxRadioList::onToggleClicked); + delete toggle; } guiGroup.clear(); } @@ -159,9 +127,6 @@ void ofxRadioList::unselectAll() { int i; for (i = 0; i < guiGroup.getNumControls(); i++) { - if (bHasTitle && i == 0) { - continue; - } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); toggle->removeListener(this, &ofxRadioList::onToggleClicked); @@ -187,21 +152,11 @@ float ofxRadioList::getHeight() string ofxRadioList::getTitle() { - if (bHasTitle) { - ofxLabel* label = static_cast(guiGroup.getControl(0)); - ofParameter* parameter = static_cast*>(&label->getParameter()); - return parameter->get(); - } else { - return ""; - } + return guiGroup.getName(); } string ofxRadioList::getItemName(int index) { - if (bHasTitle) { - index += 1; - } - if (index >= guiGroup.getNumControls()) { return ""; } @@ -212,11 +167,7 @@ string ofxRadioList::getItemName(int index) int ofxRadioList::size() { - if (bHasTitle) { - return guiGroup.getNumControls() - 1; - } else { - return guiGroup.getNumControls(); - } + return guiGroup.getNumControls(); } void ofxRadioList::onToggleClicked(bool &toggleValue) @@ -226,27 +177,11 @@ void ofxRadioList::onToggleClicked(bool &toggleValue) // Search for the actual toggle triggering the event int i; for (i = 0; i < guiGroup.getNumControls(); i++) { - if (bHasTitle && i == 0) { - continue; - } ofxToggle* toggle = static_cast(guiGroup.getControl(i)); ofParameter* paramPtr = static_cast*>(&toggle->getParameter()); if (&(paramPtr->get()) == &toggleValue) { - /* - toggle->removeListener(this, &ofxRadioList::onToggleClicked); - *toggle = true; // Select the specific radio button - toggle->addListener(this, &ofxRadioList::onToggleClicked); - string name = toggle->getName(); - ofNotifyEvent(radioSelectedEvent, name, this); - //cout << toggle->getName() << endl; // debug - */ - if (bHasTitle) { - selectItem(i - 1); - } else { - selectItem(i); - } - + selectItem(i); break; } } diff --git a/src/ui/ofxRadioList.h b/src/ui/ofxRadioList.h index df960bc..2736352 100644 --- a/src/ui/ofxRadioList.h +++ b/src/ui/ofxRadioList.h @@ -40,7 +40,6 @@ private: vector storedLabels; string storedTitle; ofxGuiGroup guiGroup; - bool bHasTitle; int storedSelectedItem; void onToggleClicked(bool &toggleValue); From 39c5be41e0526ef50b45d2742f701c4f48226c00 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 7 Sep 2014 15:14:12 +0200 Subject: [PATCH 10/10] Position image source selector --- src/ofxSourcesEditor.cpp | 1 + src/ofxSourcesEditor.h | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 0d5e2f5..5b5603c 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -43,6 +43,7 @@ void ofxSourcesEditor::setup(ofEventArgs& args) } gui->setup("Images", vnames); + gui->setPosition(20, 20); ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent); } diff --git a/src/ofxSourcesEditor.h b/src/ofxSourcesEditor.h index cab567e..33aad38 100644 --- a/src/ofxSourcesEditor.h +++ b/src/ofxSourcesEditor.h @@ -35,9 +35,6 @@ private: void guiEvent(string &imageName); vector images; vector imageNames; - //ofxPanel imgSrcPanel; - - //void onSourceSelect(bool& value); }; #endif \ No newline at end of file