All pastes #638025 Raw Edit

doom

public text v1 · immutable
#638025 ·published 2007-07-29 13:52 UTC
rendered paste body
- (void)drawRect:(NSRect)rect inCIContext:(CIContext *)ctx
{
    int i;
    int currentSelection = [[selections objectAtIndex:depth] intValue];
    NSImage *icon;
    CGLayerRef layer = [ctx createCGLayerWithSize:CGSizeMake(NSWidth([self bounds]), NSHeight([self bounds]))
                                             info:nil];
    CGContextRef cg = CGLayerGetContext(layer);
    NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
    [paraStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
    [NSGraphicsContext setCurrentContext:[[NSGraphicsContext graphicsContextWithGraphicsPort:cg flipped:NO] autorelease]];
    
    //CGContextSelectFont(cg,"Lucida Grande",[self bounds].size.height / 16,kCGEncodingMacRoman);
    //CGContextSetTextDrawingMode(cg,kCGTextFill);
    int minItems = (floor(currentPosition) > 4 ? floor(currentPosition) - 4 : 0);
    int maxItems = (ceil(currentPosition) < currentNumItems - 7 ? ceil(currentPosition) + 7 : currentNumItems);
    CGContextSetLineWidth(cg,6);
    CGContextSetLineCap(cg,kCGLineCapRound);
    CGContextSetLineJoin(cg,kCGLineJoinRound);
    for (i = minItems; i < maxItems; i++)
    {
        float currentOffset = (currentPosition - currentSelection) * MENU_ITEM_SPACING;
        float vertOffset = ((currentSelection - i) * MENU_ITEM_SPACING) + currentOffset;
        CCMenuItem *item = [currentContents objectAtIndex:i];
        float alpha;
        
        if (vertOffset > 0)
        {
            alpha = (3 * MENU_ITEM_SPACING - vertOffset) / (3 * MENU_ITEM_SPACING);
            CGContextSetRGBFillColor(cg,1.0,1.0,1.0,alpha);
            CGContextSetRGBStrokeColor(cg,1.0,1.0,1.0,alpha);
        }
        else
        {
            alpha = (6 * MENU_ITEM_SPACING + vertOffset) / (6 * MENU_ITEM_SPACING);
            CGContextSetRGBFillColor(cg,1.0,1.0,1.0,alpha);
            CGContextSetRGBStrokeColor(cg,1.0,1.0,1.0,alpha);
        }
        
        [[item name] drawWithRect:NSMakeRect([self bounds].size.width / 3,
                                             [self bounds].size.height / 3 * 2 + vertOffset,
                                             [self bounds].size.width / 3 * 2 - 160,
                                             0)
                          options:nil
                       attributes:[NSDictionary dictionaryWithObjects:
                           [NSArray arrayWithObjects:
                               [NSFont fontWithName:@"Lucida Grande" size:[self bounds].size.height / 16],
                               paraStyle,
                               [NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:alpha],
                               nil]
                                                              forKeys:
                           [NSArray arrayWithObjects:
                               NSFontAttributeName,
                               NSParagraphStyleAttributeName,
                               NSForegroundColorAttributeName,
                               nil]]];
        if ([[currentHasChildren objectAtIndex:i] boolValue])
        {
            CGContextBeginPath(cg);
            CGContextMoveToPoint(cg,[self bounds].size.width - 96,[self bounds].size.height / 3 * 2 + vertOffset);
            CGContextAddLineToPoint(cg,[self bounds].size.width - 80,[self bounds].size.height / 3 * 2 + vertOffset + 16);
            CGContextAddLineToPoint(cg,[self bounds].size.width - 96,[self bounds].size.height / 3 * 2 + vertOffset + 32);
            CGContextStrokePath(cg);
        }
        if (icon = [[currentContents objectAtIndex:i] miniIcon])
        {
            [icon drawInRect:NSMakeRect([self bounds].size.width - 144,[self bounds].size.height / 3 * 2 + vertOffset,32,32)
                    fromRect:NSMakeRect(0,0,[icon size].width,[icon size].height)
                   operation:NSCompositeSourceOver
                    fraction:alpha];
        }
    }
    if (icon = [[currentContents objectAtIndex:currentSelection] icon])
    {
        NSAffineTransform *skew = [NSAffineTransform transform];
        NSAffineTransform *scale = [NSAffineTransform transform];
        NSAffineTransformStruct tMatrix;
        tMatrix.m11 = 1.0;
        tMatrix.m12 = 0.2;
        tMatrix.m21 = 0.0;
        tMatrix.m22 = 1.0;
        tMatrix.tX = 0.0;
        tMatrix.tY = 0.0;
        [skew setTransformStruct:tMatrix];
        [scale scaleXBy:1.0 yBy:-1.0];
        [icon setSize:NSMakeSize(256.0, 256.0)];
        [skew concat];
        [icon drawInRect:NSMakeRect(48,[self bounds].size.height / 2, 256, 256)
                fromRect:NSMakeRect(0,0,[icon size].width,[icon size].height)
               operation:NSCompositeSourceOver
                fraction:1.0];
        [scale concat];
        [icon drawInRect:NSMakeRect(48,-([self bounds].size.height / 2), 256, 256)
                fromRect:NSMakeRect(0,0,[icon size].width,[icon size].height)
               operation:NSCompositeSourceOver
                fraction:0.05];
        [scale invert];
        [scale concat];
        [skew invert];
        [skew concat];
    }
    CGContextDrawImage(cg,CGRectMake([self bounds].size.width / 3 - 48,[self bounds].size.height / 3 * 2 - 22,
                                     48,71),leftImg);
    CGContextDrawImage(cg,CGRectMake([self bounds].size.width / 3,[self bounds].size.height / 3 * 2 - 22,
                                     [self bounds].size.width / 3 * 2 - 96,71),middleImg);
    CGContextDrawImage(cg,CGRectMake([self bounds].size.width - 96,[self bounds].size.height / 3 * 2 - 22,
                                     48,71),rightImg);
    
    currentImage = [[[CIImage alloc] initWithCGLayer:layer] autorelease];
    CFRelease(layer);
    
    [transition setValue:currentImage
                  forKey:@"inputTargetImage"];
    [ctx drawImage:[transition valueForKey:@"outputImage"]
		   atPoint:CGPointMake(0,0)
		  fromRect:CGRectMake([self bounds].origin.x, [self bounds].origin.y, [self bounds].size.width, [self bounds].size.height)];
    
}