I would like to have colorised metal looking windows…
12/12/05 21:54
Is it possible to have windows with a colorized metal background on both Panther and Tiger ?
Tiger has a NSMetalPatternColor (hidden) class which is descendant of NSPatternColor another hidden class descendant of NSColor.
But Panther has no access to these classes, so an easy way to solve the problem is to generate an image with the gray metal pattern and use it as the source for calling [NSColor colorWithPatternImage:]
Colorising the metal image, is just a matter a drawing a solid colour with some transparency over it:
// assuming you have saved the metal pattern in a file Metal.tiff and added this file to your project
NSImage *metalImage = [NSImage imageNamed:@"Metal"] ;
NSSize imageSize = [metalImage size] ;
NSImage *coloredImage = [[NSImage alloc] initWithSize: imageSize] ;
NSRect frameRect = NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height);
[coloredImage lockFocus] ;
[metalImage drawAtPoint:NSZeroRect fromRect:frameRect operation:NSCompositeSourceOver fraction:1.0];
// inColor being a parameter you supply
[[inColor colorWithAlphaComponent:0.5] set] ; // set transparency level to your taste, make a parameter out of it...
[NSBezierPath fillRect:frameRect] ;
[coloredImage unlockFocus] ;
// inWindow being the window to colorise
[inWindow setBackgroundColor:[NSColor colorWithPatternImage:coloredImage]];
[coloredImage release] ;
[inWindow display] ;
If the window is a textured one, even the title bar will be colorised. If not, only the content will be "color-metal" looking.
But Panther has no access to these classes, so an easy way to solve the problem is to generate an image with the gray metal pattern and use it as the source for calling [NSColor colorWithPatternImage:]
Colorising the metal image, is just a matter a drawing a solid colour with some transparency over it:
// assuming you have saved the metal pattern in a file Metal.tiff and added this file to your project
NSImage *metalImage = [NSImage imageNamed:@"Metal"] ;
NSSize imageSize = [metalImage size] ;
NSImage *coloredImage = [[NSImage alloc] initWithSize: imageSize] ;
NSRect frameRect = NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height);
[coloredImage lockFocus] ;
[metalImage drawAtPoint:NSZeroRect fromRect:frameRect operation:NSCompositeSourceOver fraction:1.0];
// inColor being a parameter you supply
[[inColor colorWithAlphaComponent:0.5] set] ; // set transparency level to your taste, make a parameter out of it...
[NSBezierPath fillRect:frameRect] ;
[coloredImage unlockFocus] ;
// inWindow being the window to colorise
[inWindow setBackgroundColor:[NSColor colorWithPatternImage:coloredImage]];
[coloredImage release] ;
[inWindow display] ;
If the window is a textured one, even the title bar will be colorised. If not, only the content will be "color-metal" looking.