ofxUI : changing state of multiple buttons in different canvas

Hi,

Another challenge for you guys ! :wink:

I designed an interface to control video projectors. This interface is made of :

  • one master canvas which commands selected projectors.
  • multiple canvas (one per projector) with personal commands for each projector itself.

Here is my problem :

In my master canvas i have, among others, one button to select all projectors and another one to unselect them.
Let’s say i have an interface controling 3 projectors (i.e. 1 master canvas + 3 command interfaces)

When i click “SELECT ALL” every LabelButton state for each command canvas have to be set to “true”.
When i click “SELECT ALL” every LabelButton state for each command canvas have to be set to “false”.

Some info :

Projectors : vector of ofxPJCtrl
Master canvas : ofxUICanvas
command GUIs : vector of ofxUICanvas

  
  
vector<ofxPJCtrl *> projectors;  
ofxUICanvas *masterGUI;  
vector<ofxUICanvas *> commandGUI;  
  

Excerpt of my ofxPJCtrl.h :

  
  
class ofxPJCtrl {  
  
	public :  
  
    ofxPJCtrl();  
    ~ofxPJCtrl();  
  
        ...  
	bool isSelected();  
        string getProjectorName();  
        ...  
  
  private :  
  
	...  
	bool selected;  
        string projectorName;  
        ...  
};  
  

in my testApp.cpp these lines add widgets in master GUI :

  
  
	masterGUI->addSpacer();  
	masterGUI->addLabelButton("SELECT ALL", false);  
	masterGUI->addLabelButton("SELECT NONE", false);  
	masterGUI->addSpacer();  
  

in my testApp.cpp this line adds label toggle in each command canvas which is used to select the projector :

  
  
	gui->addToggle(proj->getProjectorName(), false, 16, 16);  
        ...  
        commandGUI.push_back(gui);  
  

This is my attempt to set every “select” button of command guis :

  
  
	else if(e.widget->getName() == "SELECT ALL")  
	{	  
		vector<ofxUICanvas *>::iterator it;  
		for(it = commandGUI.begin(); it != commandGUI.end(); it++)  
		{  
			(*it)->e.widget->getName() == (*it)->getProjectorName();  
			ofxUILabelButton *btn = (ofxUILabelButton *) e.widget;  
			(*it)->btn->setValue(true);  
		}  
	}  
  

I can’t figure out how to retrieve each select button ID to set their value to true or false.

I hope you have enough information to help me. If not, don’t hesitate to ask me more.

Attached, a screenshot to make it a bit easier to understand…

Thanks a lot

![](http://forum.openframeworks.cc/uploads/default/2911/Capture d’écran 2013-05-13 à 19.01.26.png)

Ok,

Here is my solution. Don’t know if it’s the best way but it works… it seems !

Can you tell me if this is a good approach or the code could be cleaner ? like the counter “i” to iterate the projectors is ok but is there any cleaner approach ?

Would it be better to make

  
vector<ofxUICanvas *> commandGUI;  

a member of class ofxPJCtrl ?

  
  
	else if(e.widget->getName() == "SELECT ALL")  
	{	  
		int i = 0;  
		vector<ofxUICanvas *>::iterator it;  
		for(it = commandGUI.begin(); it != commandGUI.end(); it++)  
		{			  
			ofxUILabelButton *btn = (ofxUILabelButton *)(*it)->getWidget((projectors[i]->getProjectorName()));  
			btn->setValue(true);  
			projectors[i]->setIsSelectedValue(true);  
			i++;  
		}  
		  
	}  
	else if(e.widget->getName() == "SELECT NONE")  
	{	  
		int i = 0;  
		vector<ofxUICanvas *>::iterator it;  
		for(it = commandGUI.begin(); it != commandGUI.end(); it++)  
		{			  
			ofxUILabelButton *btn = (ofxUILabelButton *)(*it)->getWidget((projectors[i]->getProjectorName()));  
			btn->setValue(false);  
			projectors[i]->setIsSelectedValue(false);  
			i++;  
		}  
	}  
  

Thanks for reading