2 changed files with 239 additions and 222 deletions
@ -1,183 +1,199 @@ |
|||||
#include "RadioList.h" |
#include "RadioList.h" |
||||
|
|
||||
namespace ofx { |
namespace ofx{ |
||||
namespace piMapper { |
namespace piMapper{ |
||||
RadioList::RadioList() { |
RadioList::RadioList(){ |
||||
storedTitle = ""; |
storedTitle = ""; |
||||
storedSelectedItem = 0; |
storedSelectedItem = 0; |
||||
} |
} |
||||
|
|
||||
RadioList::RadioList(vector<string>& labels, vector<string>& values) { |
RadioList::RadioList(vector<string> & labels, vector<string> & values){ |
||||
RadioList(); |
RadioList(); |
||||
setup(labels, values); |
setup(labels, values); |
||||
} |
} |
||||
|
|
||||
RadioList::RadioList(string title, vector<string>& labels, vector<string>& values) { |
RadioList::RadioList(string title, vector<string> & labels, vector<string> & values){ |
||||
RadioList(); |
RadioList(); |
||||
setup(title, labels, values); |
setup(title, labels, values); |
||||
} |
} |
||||
|
|
||||
RadioList::~RadioList() { clear(); } |
RadioList::~RadioList(){ |
||||
|
clear(); |
||||
void RadioList::setup(vector<string>& labels, vector<string>& values) { |
} |
||||
// Copy incomming labels for later use
|
|
||||
storedLabels = labels; |
void RadioList::setup(vector<string> & labels, vector<string> & values){ |
||||
storedValues = values; |
|
||||
|
// Copy incomming labels for later use
|
||||
// Create toggles with labels from the labels arg
|
storedLabels = labels; |
||||
int i; |
storedValues = values; |
||||
for (i = 0; i < labels.size(); i++) { |
|
||||
ofxToggle* toggle = new ofxToggle(); |
// Create toggles with labels from the labels arg
|
||||
toggle->setup(false); |
int i; |
||||
toggle->setName(labels[i]); |
for(i = 0; i < labels.size(); i++){ |
||||
toggle->addListener(this, &RadioList::onToggleClicked); |
ofxToggle * toggle = new ofxToggle(); |
||||
guiGroup.add(toggle); |
toggle->setup(false); |
||||
|
toggle->setName(labels[i]); |
||||
|
toggle->addListener(this, &RadioList::onToggleClicked); |
||||
|
guiGroup.add(toggle); |
||||
#if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0) |
#if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0) |
||||
toggle->registerMouseEvents(); |
toggle->registerMouseEvents(); |
||||
#endif |
#endif |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void RadioList::setup(string title, vector<string>& labels, vector<string>& values) { |
void RadioList::setup(string title, vector<string> & labels, vector<string> & values){ |
||||
// Store title for later use
|
|
||||
storedTitle = title; |
// Store title for later use
|
||||
guiGroup.setName(title); |
storedTitle = title; |
||||
setup(labels, values); |
guiGroup.setName(title); |
||||
} |
setup(labels, values); |
||||
|
} |
||||
void RadioList::draw() { guiGroup.draw(); } |
|
||||
|
void RadioList::draw(){ |
||||
void RadioList::setTitle(string title) { |
guiGroup.draw(); |
||||
storedTitle = title; |
} |
||||
guiGroup.setName(title); |
|
||||
} |
void RadioList::setTitle(string title){ |
||||
|
storedTitle = title; |
||||
void RadioList::setPosition(ofPoint p) { guiGroup.setPosition(p); } |
guiGroup.setName(title); |
||||
|
} |
||||
void RadioList::setPosition(float x, float y) { guiGroup.setPosition(x, y); } |
|
||||
|
void RadioList::setPosition(ofPoint p){ |
||||
void RadioList::selectItem(int index) { |
guiGroup.setPosition(p); |
||||
if (index >= guiGroup.getNumControls()) { |
} |
||||
return; |
|
||||
} |
void RadioList::setPosition(float x, float y){ |
||||
|
guiGroup.setPosition(x, y); |
||||
unselectAll(); |
} |
||||
|
|
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(index)); |
void RadioList::selectItem(int index){ |
||||
toggle->removeListener(this, &RadioList::onToggleClicked); |
if(index >= guiGroup.getNumControls()){ |
||||
*toggle = true; // Select the specific radio button
|
return; |
||||
toggle->addListener(this, &RadioList::onToggleClicked); |
} |
||||
//string name = toggle->getName();
|
|
||||
// Throw event with value that is image path instead of name
|
unselectAll(); |
||||
string value = storedValues[index]; |
|
||||
ofNotifyEvent(onRadioSelected, value, this); |
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); |
||||
storedSelectedItem = index; |
toggle->removeListener(this, &RadioList::onToggleClicked); |
||||
} |
*toggle = true; // Select the specific radio button
|
||||
|
toggle->addListener(this, &RadioList::onToggleClicked); |
||||
bool RadioList::selectItemByValue(std::string itemValue) { |
//string name = toggle->getName();
|
||||
if (itemValue == "") { |
// Throw event with value that is image path instead of name
|
||||
ofLogNotice("RadioList") << "Item value empty"; |
string value = storedValues[index]; |
||||
return false; |
ofNotifyEvent(onRadioSelected, value, this); |
||||
} |
storedSelectedItem = index; |
||||
unselectAll(); |
} |
||||
int itemIndex = -1; |
|
||||
for (int i = 0; i < storedValues.size(); i++) { |
bool RadioList::selectItemByValue(std::string itemValue){ |
||||
if (itemValue == storedValues[i]) { |
if(itemValue == ""){ |
||||
itemIndex = i; |
ofLogNotice("RadioList") << "Item value empty"; |
||||
break; |
return false; |
||||
} |
} |
||||
} |
unselectAll(); |
||||
if (itemIndex >= 0) { |
int itemIndex = -1; |
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(itemIndex)); |
for(int i = 0; i < storedValues.size(); i++){ |
||||
toggle->removeListener(this, &RadioList::onToggleClicked); |
if(itemValue == storedValues[i]){ |
||||
*toggle = true; // Select the specific radio button
|
itemIndex = i; |
||||
toggle->addListener(this, &RadioList::onToggleClicked); |
break; |
||||
return true; |
} |
||||
} |
} |
||||
ofLogNotice("RadioList") << "Item with value " << itemValue << " not found"; |
if(itemIndex >= 0){ |
||||
return false; |
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(itemIndex)); |
||||
} |
toggle->removeListener(this, &RadioList::onToggleClicked); |
||||
|
*toggle = true; // Select the specific radio button
|
||||
void RadioList::enable() { |
toggle->addListener(this, &RadioList::onToggleClicked); |
||||
if (guiGroup.getNumControls() >= 0) { |
return true; |
||||
clear(); |
} |
||||
} |
ofLogNotice("RadioList") << "Item with value " << itemValue << " not found"; |
||||
|
return false; |
||||
// Rebuild everyting
|
} |
||||
setup(storedTitle, storedLabels, storedValues); |
|
||||
|
void RadioList::enable(){ |
||||
// Select the stored selected item without throwing an event
|
if(guiGroup.getNumControls() > 0){ |
||||
ofxToggle* toggle = |
clear(); |
||||
static_cast<ofxToggle*>(guiGroup.getControl(storedSelectedItem)); |
} |
||||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|
||||
*toggle = true; |
// Rebuild everyting
|
||||
toggle->addListener(this, &RadioList::onToggleClicked); |
setup(storedTitle, storedLabels, storedValues); |
||||
|
|
||||
cout << "num items after enable: " << guiGroup.getNumControls() << endl; |
// Select the stored selected item without throwing an event
|
||||
} |
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(storedSelectedItem)); |
||||
|
toggle->removeListener(this, &RadioList::onToggleClicked); |
||||
void RadioList::disable() { |
*toggle = true; |
||||
// Just remove everything
|
toggle->addListener(this, &RadioList::onToggleClicked); |
||||
clear(); |
|
||||
} |
cout << "num items after enable: " << guiGroup.getNumControls() << endl; |
||||
|
} |
||||
void RadioList::clear() { |
|
||||
int i; |
void RadioList::disable(){ |
||||
for (i = 0; i < guiGroup.getNumControls(); i++) { |
// Just remove everything
|
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); |
clear(); |
||||
toggle->removeListener(this, &RadioList::onToggleClicked); |
} |
||||
delete toggle; |
|
||||
} |
void RadioList::clear(){ |
||||
guiGroup.clear(); |
int i; |
||||
} |
for(i = 0; i < guiGroup.getNumControls(); i++){ |
||||
|
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
||||
void RadioList::unselectAll() { |
toggle->removeListener(this, &RadioList::onToggleClicked); |
||||
int i; |
delete toggle; |
||||
for (i = 0; i < guiGroup.getNumControls(); i++) { |
} |
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); |
guiGroup.clear(); |
||||
ofParameter<bool>* paramPtr = |
} |
||||
static_cast<ofParameter<bool>*>(&toggle->getParameter()); |
|
||||
toggle->removeListener(this, &RadioList::onToggleClicked); |
void RadioList::unselectAll(){ |
||||
*toggle = false; |
int i; |
||||
toggle->addListener(this, &RadioList::onToggleClicked); |
for(i = 0; i < guiGroup.getNumControls(); i++){ |
||||
} |
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
||||
} |
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); |
||||
|
toggle->removeListener(this, &RadioList::onToggleClicked); |
||||
ofPoint RadioList::getPosition() { return guiGroup.getPosition(); } |
*toggle = false; |
||||
|
toggle->addListener(this, &RadioList::onToggleClicked); |
||||
float RadioList::getWidth() { return guiGroup.getWidth(); } |
} |
||||
|
} |
||||
float RadioList::getHeight() { return guiGroup.getHeight(); } |
|
||||
|
ofPoint RadioList::getPosition(){ |
||||
string RadioList::getTitle() { return guiGroup.getName(); } |
return guiGroup.getPosition(); |
||||
|
} |
||||
string RadioList::getItemName(int index) { |
|
||||
if (index >= guiGroup.getNumControls()) { |
float RadioList::getWidth(){ |
||||
return ""; |
return guiGroup.getWidth(); |
||||
} |
} |
||||
|
|
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(index)); |
float RadioList::getHeight(){ |
||||
return toggle->getName(); |
return guiGroup.getHeight(); |
||||
} |
} |
||||
|
|
||||
int RadioList::size() { return storedValues.size(); } |
string RadioList::getTitle(){ |
||||
|
return guiGroup.getName(); |
||||
void RadioList::onToggleClicked(bool& toggleValue) |
} |
||||
{ |
|
||||
unselectAll(); |
string RadioList::getItemName(int index){ |
||||
|
if(index >= guiGroup.getNumControls()){ |
||||
// Search for the actual toggle triggering the event
|
return ""; |
||||
int i; |
} |
||||
for (i = 0; i < guiGroup.getNumControls(); i++) { |
|
||||
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); |
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); |
||||
ofParameter<bool>* paramPtr = |
return toggle->getName(); |
||||
static_cast<ofParameter<bool>*>(&toggle->getParameter()); |
} |
||||
|
|
||||
if (&(paramPtr->get()) == &toggleValue) { |
int RadioList::size(){ |
||||
selectItem(i); |
return storedValues.size(); |
||||
break; |
} |
||||
} |
|
||||
} |
void RadioList::onToggleClicked(bool & toggleValue){ |
||||
} |
unselectAll(); |
||||
} |
|
||||
} |
// Search for the actual toggle triggering the event
|
||||
|
int i; |
||||
|
for(i = 0; i < guiGroup.getNumControls(); i++){ |
||||
|
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
||||
|
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); |
||||
|
|
||||
|
if(&(paramPtr->get()) == &toggleValue){ |
||||
|
selectItem(i); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
||||
|
Loading…
Reference in new issue