ofParameter<ofColor> update on release only?

I’m using “ofParameter m_gridColorPicker” to create a color picker.

I’m using a class called “GridColorChangeAction”, with a method “onColorChange(ofColor & color)”

I’m linking both with this:

m_gridColorPicker.addListener(&m_gridColorChangeAction, GridColorChangeAction::onColorChange);

my method “onColorChange”:

void GridColorChangeAction::onColorChange(ofColor& newColor) {
	std::cout << "grid color changed" << std::endl;

This works, but i see my “cout” is called when i click inside the color picker, multiple times when i move the mouse, and on mous release. Is there any way to make the event trigger only on mouse release?

Although you can do it with an ofParameter it is easier if you instantiate an ofxColorSlider instead.

then after you have setup the color sliders

ofxColorSlider color;
for(int i =0 ; i < color.getNumControls(); i++){

	 auto* c = dynamic_cast <ofxSlider<unsigned char> *>(color.getControl(i));
         if(c){ c -> setUpdateOnReleaseOnly(true);}

It wouldnt be a bad idea to have setUpdateOnReleaseOnly as a function of the slider groups.

Let me know if this works. I have not tested it though.

1 Like

Tks for your help! I found a way to do what i wanted. My action had to listed to the color changed event and mouse release event (on the entire window). The 2 methods looks like this in my action:

void GridColorChangeAction::onColorChange(ofColor& newColor) {
	m_tempColor = newColor;

void GridColorChangeAction::onMouseRelease(ofMouseEventArgs& mouse) {
	if (m_tempColor != m_newColor) {
		m_newColor = m_tempColor;

Then i my window class, i added both listeners like this:


ofAddListener(ofEvents().mouseReleased, &m_gridColorChangeAction, 
              OF_EVENT_ORDER_BEFORE_APP - 100);
1 Like