Esempio n. 1
0
void	AUCarbonViewControl::SetValueFract(double value)
{
#if !__LP64__
	SInt32 minimum = GetControl32BitMinimum(mControl);
	SInt32 maximum = GetControl32BitMaximum(mControl);
	SInt32 cval = SInt32(value * (maximum - minimum) + minimum + 0.5);
	SetControl32BitValue(mControl, cval);
//	printf("set: value=%lf, min=%ld, max=%ld, ctl value=%ld\n", value, minimum, maximum, cval);
#endif
}
//----------------------------------------------------------------------------- 
void MadShiftaVerticalFillSlider::draw(DGGraphicsContext * inContext)
{
	// draw background
	inContext->setFillColor(kControlBackgroundColor);
	inContext->fillRect( getBounds() );

	// calculate coordinates of "on" portion
	inContext->setFillColor(kControlFillColor);
	SInt32 min = GetControl32BitMinimum(carbonControl);
	SInt32 max = GetControl32BitMaximum(carbonControl);
	SInt32 val = GetControl32BitValue(carbonControl);
	float valNorm = ((max-min) == 0) ? 0.0f : (float)(val-min) / (float)(max-min);
	DGRect onRect( getBounds() );
	long onBottom;
	if (valNorm > axis)
	{
		onRect.y = (long) (getBounds()->h * valNorm);
		onBottom = (long) (getBounds()->h * axis);
	}
	else
	{
		onRect.y = (long) (getBounds()->h * axis);
		onBottom = (long) (getBounds()->h * valNorm);
	}
	onRect.y = getBounds()->h - onRect.y;
	onBottom = getBounds()->h - onBottom;
	onRect.h = onBottom - onRect.y;
	if (onRect.h < 1)
	{
		onRect.h = 1;
		inContext->setFillColor(kControlFillColor_alt);
	}
	onRect.y += getBounds()->y;

	// draw "on" portion
	inContext->fillRect(&onRect);

	// draw the text display
	if (textProc != NULL)
	{
		char text[kDGTextDisplay_stringSize];
		text[0] = 0;
		textProc(getAUVP().GetValue(), text, NULL);

		DGRect textBounds( getBounds() );
		textBounds.y += textY;
		textBounds.h = textHeight;

		inContext->setFont(kValueDisplayTextFont, kSliderTextSize);
		inContext->setColor(kValueDisplayTextColor);
		inContext->drawText(&textBounds, text, kDGTextAlign_center);
	}
}
Esempio n. 3
0
double	AUCarbonViewControl::GetValueFract()
{
#if !__LP64__
	SInt32 minimum = GetControl32BitMinimum(mControl);
	SInt32 maximum = GetControl32BitMaximum(mControl);
	SInt32 cval = GetControl32BitValue(mControl);
	double result = double(cval - minimum) / double(maximum - minimum);
//	printf("get: min=%ld, max=%ld, value=%ld, result=%f\n", minimum, maximum, cval, result);
	return result;
#else
	return 0;
#endif
}
Esempio n. 4
0
pascal void actionFunctionScroll(ControlRef controlRef,ControlPartCode controlPartCode)
{
    SInt32 scrollDistance, controlValue, oldControlValue, controlMax;

    if(controlPartCode != kControlNoPart)
    {
        if(controlPartCode != kControlIndicatorPart)
        {
            switch(controlPartCode)
            {
            case kControlUpButtonPart:
            case kControlDownButtonPart:
                scrollDistance = 10;
                break;

            case kControlPageUpPart:
            case kControlPageDownPart:
                scrollDistance = 100;
                break;

            default:
                scrollDistance = 0;
                break;
            }

            if (scrollDistance)
            {
                if((controlPartCode == kControlDownButtonPart) ||
                   (controlPartCode == kControlPageDownPart))
                    scrollDistance = -scrollDistance;

                controlValue = GetControl32BitValue(controlRef);

                if(((controlValue == GetControl32BitMaximum(controlRef)) && scrollDistance < 0) ||
                   ((controlValue == GetControl32BitMinimum(controlRef)) && scrollDistance > 0))
                    return;

                oldControlValue = controlValue;
                controlMax = GetControl32BitMaximum(controlRef);
                controlValue = oldControlValue - scrollDistance;

                if(controlValue < 0)
                    controlValue = 0;
                else if(controlValue > controlMax)
                    controlValue = controlMax;

                SetControl32BitValue(controlRef,controlValue);
            }
        }
    }
}
// Tracking the mouse in a scroll control via callback
void
MyTrackActionProcedure( ControlRef controlRef, ControlPartCode partCode )
{
    OSStatus status;
    SInt32 value;
    SInt32 textViewDelta, controlDelta, controlMin, controlMax;
    TXNScrollUnit scrollUnits;
    ControlID controlID = {0,0};
    WindowRef window = NULL;

    // when user clicks on kControlPageUpPart or kControlPageDownPart
    // we need to know the viewRect height and width so we can update
    // the scrollbars with a delta of "one page" scrolled
    SInt32 viewHeight = 0;
    SInt32 viewWidth = 0;
    
    scrollUnits = kTXNScrollUnitsInPixels;
    textViewDelta = controlDelta = 0;
    
    // the controlID will tell us if it is a v or h scroller
    // based on the arbitrary signature we assigned it in the nib (Hscr or Vscr)
    status = GetControlID( controlRef, &controlID );
    require_noerr( status, CantGetControlID );
    
    // the window has cached scroll data we need, so we need to get the window
    window = GetControlOwner( controlRef );
    require( window != NULL, CantGetWindow );
  
    value = GetControl32BitValue( controlRef );
    
    controlMin = GetControl32BitMinimum( controlRef );
    controlMax = GetControl32BitMaximum( controlRef );
    
    // calc view width or height ( for page up/down/left/right )
    
    if( controlID.signature == kMyVerticalScrollBar )
        viewHeight = TextViewGetHeight( window, kMyMLTEDataStructProperty );
    else
        viewWidth = TextViewGetWidth( window, kMyMLTEDataStructProperty );
    
    // which part of the scroll control was hit?
    switch ( partCode )
    {
        case kControlDownButtonPart:
            textViewDelta = controlDelta = 1;
            scrollUnits = kTXNScrollUnitsInPixels; //kTXNScrollUnitsInLines;
            break;
        case kControlUpButtonPart:
            textViewDelta = controlDelta = -1;
            scrollUnits = kTXNScrollUnitsInPixels; //kTXNScrollUnitsInLines;
            break;
        case kControlPageUpPart:
            textViewDelta = -1; // units in viewRectHeight/Width(s)
            if( controlID.signature == kMyVerticalScrollBar )
                controlDelta = ( viewHeight <= kMyINT32_MAX ? viewHeight : kMyINT32_MAX );
            else
                controlDelta = ( viewWidth <= kMyINT32_MAX ? viewWidth : kMyINT32_MAX );
            scrollUnits = kTXNScrollUnitsInViewRects;
            controlDelta = -controlDelta;
            break;
        case kControlPageDownPart:
            textViewDelta = 1; // units in viewRectHeight/Width(s)
            if( controlID.signature == kMyVerticalScrollBar )
                controlDelta = ( viewHeight <= kMyINT32_MAX ? viewHeight : kMyINT32_MAX );
            else
                controlDelta = ( viewWidth <= kMyINT32_MAX ? viewWidth : kMyINT32_MAX );
            scrollUnits = kTXNScrollUnitsInViewRects;
            break;
        // we really do not want to do anything if the
        // kControlIndicatorPart is hit.  It should be
        // handled by the Live Tracking procedure instead.
        case kControlIndicatorPart:
        {
            SInt32 cacheValue = 0;
            scrollUnits = kTXNScrollUnitsInPixels;
            // Which scrollbar is getting called by this callback?
            if( controlID.signature == kMyVerticalScrollBar )
            {
                // we can find the degree of the change by comparing to
                // our last known value
                cacheValue = TextViewGetVertScrollCache( window, kMyMLTEDataStructProperty );
                textViewDelta = value - (cacheValue <= kMyINT32_MAX ? cacheValue : kMyINT32_MAX );
            }
            else // kMyHorizontalScrollBar
            {
                // we can find the degree of the change by comparing to
                // our last known value
                cacheValue = TextViewGetHorizScrollCache( window, kMyMLTEDataStructProperty );
                textViewDelta = value - (cacheValue <= kMyINT32_MAX ? cacheValue : kMyINT32_MAX );
            }
        }
            break;
            
        default:
            break;
    }
    if ( partCode != kControlIndicatorPart ) // only update the control for non-thumb hits
    {
        value += controlDelta;
        
        if( value < controlMin ) // don't go past max or min
            value = controlMin;
        if( value > controlMax )
            value = controlMax;
            
        SetControl32BitValue( controlRef, value );
    }

    status = TextViewCustomScroll( window, controlID.signature, scrollUnits,
                                   textViewDelta, value, kMyMLTEDataStructProperty );

    CantGetWindow:
    CantGetControlID:
    return;
}
//-----------------------------------------------------------------------------
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);
}
Esempio n. 7
0
void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) 
{
    if ( (ControlHandle) m_macControl == NULL )
        return ;
    
    int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
    int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
    int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
    
    wxEventType scrollEvent = wxEVT_NULL;
    int nScrollInc = 0;
    
    // all events have already been reported during mouse down, except for THUMBRELEASE
    if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
        return ;
    
    switch( controlpart )
    {
    case kControlUpButtonPart :
        nScrollInc = -1;
        scrollEvent = wxEVT_SCROLL_LINEUP;
        break ;
    case kControlDownButtonPart :
        nScrollInc = 1;
        scrollEvent = wxEVT_SCROLL_LINEDOWN;
        break ;
    case kControlPageUpPart :
        nScrollInc = -m_pageSize;
        scrollEvent = wxEVT_SCROLL_PAGEUP;
        break ;
    case kControlPageDownPart :
        nScrollInc = m_pageSize;
        scrollEvent = wxEVT_SCROLL_PAGEDOWN;
        break ;
    case kControlIndicatorPart :
        nScrollInc = 0 ;
        if ( mouseStillDown )
            scrollEvent = wxEVT_SCROLL_THUMBTRACK;
        else
            scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
        break ;
    default :
        wxFAIL_MSG(wxT("illegal scrollbar selector"));
        break ;
    }
    
    int new_pos = position + nScrollInc;
    
    if (new_pos < minPos)
        new_pos = minPos;
    if (new_pos > maxPos)
        new_pos = maxPos;
    if ( nScrollInc )
        SetThumbPosition(new_pos);
    
    wxScrollEvent event(scrollEvent, m_windowId);
    if ( m_windowStyle & wxHORIZONTAL )
    {
        event.SetOrientation( wxHORIZONTAL ) ;
    }
    else
    {
        event.SetOrientation( wxVERTICAL ) ;
    }
    event.SetPosition(new_pos);
    event.SetEventObject( this );
    wxWindow* window = GetParent() ;
    if (window && window->MacIsWindowScrollbar(this) )
    {
        // this is hardcoded
        window->MacOnScroll(event);
    }
    else
        GetEventHandler()->ProcessEvent(event);
}
/*****************************************************
*
* Handle_ControlValueFieldOrHiliteChanged(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to handle the change of the value or hilite of our custom view, we update the static text field
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*           inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_ControlValueFieldOrHiliteChanged(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status;
	HIViewRef customView = (HIViewRef)inUserData;
	
	// Finding our static text control
	HIViewRef statText;
	status = HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kStaticTextID, &statText);
	require_noerr(status, ExitValueFieldChanged);

	// Grabbing the fields that we are interested in
	CFStringRef theCFString = CFStringCreateWithFormat(NULL, NULL, CFSTR("Value: %ld, Min: %ld, Max: %ld, Hilite: %d"), GetControl32BitValue(customView), GetControl32BitMinimum(customView), GetControl32BitMaximum(customView), GetControlHilite(customView));
	require(theCFString != NULL, ExitValueFieldChanged);

	// Setting the text in the control
#ifdef MAC_OS_X_VERSION_10_4
	status = HIViewSetText(statText, theCFString);
#else
	status = SetControlData(statText, kControlEntireControl, kControlStaticTextCFStringTag, sizeof(theCFString), &theCFString);
#endif
	require_noerr(status, ExitValueFieldChanged);

	CFRelease(theCFString);

ExitValueFieldChanged:

	if (status == noErr) status = eventNotHandledErr;
	return status;
	}   // Handle_ControlValueFieldOrHiliteChanged