Exemplo n.º 1
0
//-----------------------------------------------------------------------------
void MadShiftaNumberCircle::draw(DGGraphicsContext * inContext)
{
	// draw the outer edge of the background circle
	CGContextRef cgContext = inContext->getPlatformGraphicsContext();
	CGRect backgroundBounds = getBounds()->convertToCGRect( inContext->getPortHeight() );
	CGContextAddEllipseInRect(cgContext, backgroundBounds);
	inContext->setFillColor(kControlFillColor_alt);
	inContext->endPath();
	inContext->fillPath();

	// draw the inner filling of the background circle
	inContext->beginPath();
	inContext->setFillColor(kControlBackgroundColor);
	const CGFloat backgroundFrameWidth = 1.0f;
	CGRect fillBounds = CGRectInset(backgroundBounds, backgroundFrameWidth, backgroundFrameWidth);
	CGContextAddEllipseInRect(cgContext, fillBounds);
	inContext->endPath();
	inContext->fillPath();

	// draw the pie portion filling
	inContext->beginPath();
	inContext->setFillColor(kControlFillColor);
	CGFloat centerX = fillBounds.origin.x + (fillBounds.size.width * 0.5);
	CGFloat centerY = fillBounds.origin.y + (fillBounds.size.height * 0.5);
	SInt32 min = GetControl32BitMinimum( getCarbonControl() );
	SInt32 max = GetControl32BitMaximum( getCarbonControl() );
	SInt32 val = GetControl32BitValue( getCarbonControl() );
	if (val <= min)
	{
		inContext->setStrokeColor(kControlFillColor_alt);
		float linePosX = floorf(centerX) + 0.5f;	// CoreGraphics lines are positioned between pixels rather than on them
		float lineStartY = fillBounds.origin.y;
		float lineEndY = roundf(centerY);
		inContext->drawLine(linePosX, lineStartY, linePosX, lineEndY, 1.0f);
	}
	else if (val >= max)
	{
		CGContextAddEllipseInRect(cgContext, fillBounds);
		inContext->fillPath();
	}
	else
	{
		double paramValue_gen = getDfxGuiEditor()->getparameter_f( getParameterID() );
		const CAAUParameter auParam = getAUVP();
		paramValue_gen = AUParameterValueToLinear(paramValue_gen, &auParam);
		CGFloat radius = fillBounds.size.width * 0.5;
		CGFloat startAngle = 0.0;
		CGFloat angle = paramValue_gen * (kDFX_PI_d * 2.0);
startAngle = kDFX_PI_d * 0.5;
angle = kDFX_PI_d;
		CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0);
		inContext->endPath();
		inContext->fillPath();
		inContext->beginPath();
		if (paramValue_gen >= 0.5)
		{
			startAngle -= (paramValue_gen - 0.5) * (kDFX_PI_d * 2.0);
			CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0);
		}
		else
		{
			inContext->setFillColor(kControlBackgroundColor);
			radius += backgroundFrameWidth;
			startAngle -= paramValue_gen * (kDFX_PI_d * 2.0);
			CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0);
		}
		inContext->endPath();
		inContext->fillPath();
	}

	DGTextDisplay::draw(inContext);
}
Exemplo n.º 2
0
void	AUCarbonViewControl::ParameterToControl(Float32 paramValue)
{
#if !__LP64__
	++mInControlInitialization;
	switch (mType) {
	case kTypeContinuous:
		SetValueFract(AUParameterValueToLinear(paramValue, &mParam));
		break;
	case kTypeDiscrete:
		{
			long value = long(paramValue);
			
			// special case [1] -- menu parameters
			if (mParam.HasNamedParams()) {
				// if we're dealing with menus they behave differently!
				// becaue setting min and max doesn't work correctly for the control value
				// first menu item always reports a control value of 1
				ControlKind ctrlKind;
				if (GetControlKind(mControl, &ctrlKind) == noErr) {
					if ((ctrlKind.kind == kControlKindPopupArrow) 
						|| (ctrlKind.kind == kControlKindPopupButton))				
					{
						value = value - long(mParam.ParamInfo().minValue) + 1;
					}
				}
			}
			
			// special case [2] -- Write-only boolean parameters
			AudioUnitParameterInfo AUPI = mParam.ParamInfo();
			
			bool isWriteOnlyBoolParameter = (	(AUPI.unit == kAudioUnitParameterUnit_Boolean) &&
												(AUPI.flags & kAudioUnitParameterFlag_IsWritable) &&
												!(AUPI.flags & kAudioUnitParameterFlag_IsReadable)	);
			if (!isWriteOnlyBoolParameter) {
				SetValue (value);
			}
		}
		break;
	case kTypeText:
		{
			CFStringRef cfstr = mParam.GetStringFromValueCopy(&paramValue);

			if ( !(mParam.ParamInfo().flags & kAudioUnitParameterFlag_IsWritable)			//READ ONLY PARAMS
					&& (mParam.ParamInfo().flags & kAudioUnitParameterFlag_IsReadable)) 
			{
				if (mParam.GetParamTag()) {
					CFMutableStringRef str = CFStringCreateMutableCopy(NULL, 256, cfstr);
					CFRelease (cfstr);
					CFStringAppend (str, CFSTR(" "));
					CFStringAppend (str, mParam.GetParamTag());
					cfstr = str;
				}
			}
			SetTextValue(cfstr);
			CFRelease (cfstr);
		}
		break;
	}
	--mInControlInitialization;
#endif
}