Example #1
0
bool ofxColorPicker_<ColorType>::mouseUpdate(ofMouseEventArgs& mouse){
	if(rectBackground.inside(mouse)){
		switch (state) {
			case ChangingScale:{
				int relY = mouse.y - rectColorScaleBar.y;
				float scale = 1.f - saturate(relY / rectColorScaleBar.height);
				setColorScale(scale);
				
				setNeedsRedraw();
				break;
			}
			case ChangingWheel:{
				auto p = mouse - rectColorWheel.position.xy();
				auto pc = getPolarCoordinate(p, colorWheelRadius);
				
				colorAngle	= pc.angle;
				colorRadius	= saturate(pc.radius);
				
				bSettingColor = true;
				color = getCircularColor<ColorType>(colorAngle, colorRadius, colorScale);
				bSettingColor = false;
				setNeedsRedraw();
				break;
			}
			default: return true;
		}
		return true;
	}
	return false;
}
void ofxColorPicker :: updateColor ()
{
	if( colorWheel.isMouseDown() )
	{
		mousePoint.x = colorWheel.getMouseX() - rectColorWheel.x;
		mousePoint.y = colorWheel.getMouseY() - rectColorWheel.y;
		
		PolCord pc;
		pc = getPolarCoordinate( mousePoint.x, mousePoint.y );
		
		colorAngle	= pc.angle;
		colorRadius	= pc.radius;
		colorRadius = MIN( 1, MAX( 0, colorRadius ) );				// constrain to the radius of color circle.
	}
}