Ignore:
Timestamp:
03/02/08 13:51:58 (13 years ago)
Author:
Nicholas Riley
Message:

Compiler fixes; first pass at menu-style highlighting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEServicePrefController.m

    r425 r428  
    1515#import <objc/objc.h>
    1616#import <ApplicationEnhancer/ApplicationEnhancer.h>
     17#import <QuartzCore/QuartzCore.h>
    1718
    1819const int ICCF_SERVICE_UNKNOWN = 0;
     
    4647    if (keyEquivalent == nil) return 0;
    4748    NSMutableSet *setOrNil = (NSMutableSet *)[keyEquivalents objectForKey: keyEquivalent];
    48     return (setOrNil == nil) ? nil : [setOrNil count];
     49    return (setOrNil == nil) ? 0 : [setOrNil count];
    4950}
    5051
     
    246247        [checkBoxCell setImagePosition: NSImageOnly];
    247248        [checkBoxCell setAllowsMixedState: YES];
     249       
    248250        [[serviceOutline tableColumnWithIdentifier: @"show"] setDataCell: checkBoxCell];
    249251        [checkBoxCell release];
     
    274276    [keyEquivalents release];
    275277    [servicesMenu release];
     278    [closedTriangle release];
     279    [selectedClosedTriangle release];
     280    [openTriangle release];
     281    [selectedOpenTriangle release];
    276282    [super dealloc];
    277283}
     
    281287- (IBAction)showAll:(NSButton *)sender;
    282288{
    283     ICCF_PropagateServiceStateChange(servicesMenu, nil);
     289    ICCF_PropagateServiceStateChange(servicesMenu, 0);
    284290    [serviceOutline reloadData];
    285291}
     
    413419}
    414420
     421static NSImage *ICCF_InvertedImage(NSImage *image) {
     422    NSImage *invertedImage = [[NSImage alloc] initWithSize: [image size]];
     423    NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: [image TIFFRepresentation]];
     424    CIImage *source = [[CIImage alloc] initWithBitmapImageRep: imageRep];
     425    CIColor *black = [[CIColor alloc] initWithColor: [NSColor blackColor]];
     426                                                             
     427    CIFilter *monochromeFilter = [CIFilter filterWithName: @"CIColorMonochrome"];
     428    [monochromeFilter setValue: source forKey: @"inputImage"];
     429    [monochromeFilter setValue: [NSNumber numberWithFloat: 1.0] forKey: @"inputIntensity"];
     430    [monochromeFilter setValue: black forKey: @"inputColor"];
     431   
     432    CIFilter *invertFilter = [CIFilter filterWithName: @"CIColorInvert"];
     433    [invertFilter setValue: [monochromeFilter valueForKey: @"outputImage"] forKey: @"inputImage"];
     434   
     435    CIFilter *maskToAlphaFilter = [CIFilter filterWithName: @"CIMaskToAlpha"];
     436    [maskToAlphaFilter setValue: [invertFilter valueForKey: @"outputImage"] forKey: @"inputImage"];
     437   
     438    [invertedImage lockFocus];
     439    CIContext *context = [CIContext contextWithCGContext: [[NSGraphicsContext currentContext] graphicsPort]
     440                                                 options: nil];
     441    CIImage *result = [maskToAlphaFilter valueForKey: @"outputImage"];
     442    [context drawImage: result atPoint: CGPointZero fromRect: [result extent]];
     443    [invertedImage unlockFocus];
     444
     445    [source release];
     446    [black release];
     447
     448    return invertedImage;
     449}
     450
     451- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item;
     452{
     453    static BOOL isInverted = NO;
     454
     455    if (closedTriangle == nil) {
     456        closedTriangle = [[cell image] retain];
     457        openTriangle = [[cell alternateImage] retain];
     458        selectedClosedTriangle = ICCF_InvertedImage(closedTriangle);
     459        selectedOpenTriangle = ICCF_InvertedImage(openTriangle);
     460    }
     461   
     462    if (![outlineView isRowSelected: [outlineView rowForItem: item]] ||
     463        [[outlineView window] firstResponder] != outlineView || ![[outlineView window] isKeyWindow]) {
     464        if (!isInverted)
     465            return;
     466       
     467        [cell setImage: closedTriangle];
     468        [cell setAlternateImage: openTriangle];
     469        isInverted = NO;
     470        return;
     471    }
     472   
     473    // not checking for isInverted is intentional - images reset when triangle is flipped
     474    [cell setImage: selectedClosedTriangle];
     475    [cell setAlternateImage: selectedOpenTriangle];
     476    isInverted = YES;
     477}
     478
    415479@end
    416480
Note: See TracChangeset for help on using the changeset viewer.