コード例 #1
0
ファイル: TMeterControl.cpp プロジェクト: osoumen/SFCEcho
//! The fun part of the control
//!
//!	XXX need to test with vertically oriented images
void TMeterControl::CompatibleDraw(RgnHandle inLimitRgn, CGContextRef inContext, bool inCompositing)
{
#pragma unused(inLimitRgn)
    TRect bounds = Bounds();
    CGContextRef context = inContext;
    SliderOrientation boundsOrientation = OrientationForRect(bounds);
    TRect backBounds = RectForCGImage(mBackImage);
    
    float scaleY = ScaleY();
    // draw slider thumb
    if (mThumbImage)
    {
        TRect thumbBounds = ScaledThumbBounds();
        
        // compute a thumb bounds oriented the same as the slider
        TRect orientedThumbBounds = thumbBounds;
        if (boundsOrientation != mImageOrientation)
        {
            float temp = orientedThumbBounds.Width();
            orientedThumbBounds.SetWidth(orientedThumbBounds.Height());
            orientedThumbBounds.SetHeight(temp);
        }
        // the thumb image is assumed to be of the same orientation as the
        // background image
        float slideDistance;
        if (boundsOrientation == TSliderControl::kVerticalOrientation)
            slideDistance = orientedThumbBounds.Height();
        else
            slideDistance = orientedThumbBounds.Width();
        slideDistance -= (mTopInset + mBottomInset) * scaleY;
        float position = (float(GetValue() - GetMinimum()) / float(GetMaximum() - GetMinimum())) * slideDistance;
        
        orientedThumbBounds.SetAroundCenter(bounds.CenterX(), bounds.CenterY(),
                                            orientedThumbBounds.Width(), orientedThumbBounds.Height());
#if 0
        float xOffset, yOffset;
        if (boundsOrientation == TSliderControl::kVerticalOrientation)
        {
            xOffset = bounds.CenterX() + mXInset - orientedThumbBounds.Width()/2.0;
            yOffset = bounds.MinY() + mTopInset + (bounds.Height() + slideDistance) / 2.0;
        }
        else
        {
            xOffset = bounds.MinX() + mTopInset + (bounds.Width() + slideDistance) / 2.0;
            yOffset = bounds.CenterY() + mXInset - - orientedThumbBounds.Height()/2.0;;
        }
#else
        float xOffset, yOffset;
        if (boundsOrientation == TSliderControl::kVerticalOrientation)
        {
            xOffset = bounds.CenterX() + mXInset - orientedThumbBounds.Width()/2.0;
            yOffset = bounds.CenterY() + mTopInset - slideDistance / 2.0;
        }
        else
        {
            yOffset = bounds.CenterY() + mXInset - orientedThumbBounds.Height()/2.0;;
            xOffset = bounds.CenterX() + mTopInset - slideDistance / 2.0;
        }
#endif
        CGContextTranslateCTM(context, xOffset, yOffset);
        orientedThumbBounds.SetOrigin(thumbBounds.Origin());
        if (boundsOrientation == TSliderControl::kHorizontalOrientation) {
            orientedThumbBounds.SetWidth(position);
        } else {
            orientedThumbBounds.MoveBy(0, orientedThumbBounds.Height()-position);
            orientedThumbBounds.SetHeight(position);
        }
        CGContextClipToRect(context, orientedThumbBounds);
        
        if (mImageOrientation != boundsOrientation)
        {
            CGContextRotateCTM(context, DegreesToRadians(90.0));
        }
        HIViewDrawCGImage(context, &thumbBounds, mThumbImage);
    }
}