problem +colorWithPatternImage ( NOT -setPatternPhase )
problem +colorWithPatternImage ( NOT -setPatternPhase )
- Subject: problem +colorWithPatternImage ( NOT -setPatternPhase )
- From: arri <email@hidden>
- Date: Sun, 22 Jul 2007 05:52:13 +0200
hoi All,
i'm using [NSColor +colorWithPatternImage] to fill parts of an image,
that i use as the pattern for setting a windows' background color.
this works fine, except for one thing;
when composing the windows' background-color pattern-image while the
window resizes, setting [NSGraphicsContext setPatternPhase:] seems to
not work when the windows' width is smaller than 256 and the windows
height is smaller that 501.
is this an error in my code could it be a bug in NSColor/NSImage/
NSGraphicsContext ?
if i'm doing something wring, it should show in the code pasted below.
thanks,
arri
// notes:
// [self imageTiles] returns (creating if needed) an NSArray holding
9 NSImages (tiles)
// this happens only once (app launch) and always returns the correct
9 tiles (tested!)
//
// kTileSize is a constant used in -imageTiles and -drawBackground
(currently 30.0)
//
// ( winW-(kTileSize*2) ) and ( winH-(kTileSize*2) ) are never <= 0
//
// 'self' is a subclassed NSWindow with styleMask
'NSBorderlessWindowMask'
//
- (NSColor *)drawBackground {
NSImage * back = nil;
NSImage * part = nil;
float winW = 0;
float winH = 0;
NSRect patternRect = NSZeroRect;
NSRect winRect = [[self contentView] frame];
NSArray * parts = [self imageTiles];
winW = winRect.size.width;
winH = winRect.size.height;
back = [[NSImage alloc] initWithSize:winRect.size];
[back lockFocus];
NSGraphicsContext *context = [NSGraphicsContext currentContext];
[context setImageInterpolation:NSImageInterpolationNone];
// fill
patternRect = NSInsetRect( winRect, kTileSize, kTileSize);
[context setPatternPhase:patternRect.origin];
[[NSColor colorWithPatternImage:[parts objectAtIndex:4]] set];
NSRectFill( patternRect );
// bottom-left corner
part = [parts objectAtIndex:0];
[part compositeToPoint:NSZeroPoint operation:NSCompositeCopy
fraction:1];
// bottom edge
patternRect = NSMakeRect( kTileSize, 0, winW - (kTileSize*2),
kTileSize);
[context setPatternPhase:patternRect.origin];
[[NSColor colorWithPatternImage:[parts objectAtIndex:1]] set];
NSRectFill( patternRect );
// bottom-right coner
part = [parts objectAtIndex:2];
[part compositeToPoint:NSMakePoint( winW - kTileSize, 0)
operation:NSCompositeCopy fraction:1];
// right edge
patternRect = NSMakeRect( winW - kTileSize, kTileSize, kTileSize,
winH - (kTileSize*2) );
[context setPatternPhase:patternRect.origin];
[[NSColor colorWithPatternImage:[parts objectAtIndex:5]] set];
NSRectFill(patternRect);
// top-right corner
part = [parts objectAtIndex:8];
[part compositeToPoint:NSMakePoint( winW - kTileSize, winH -
kTileSize) operation:NSCompositeCopy fraction:1];
// top edge
patternRect = NSMakeRect(kTileSize, winH - kTileSize, winW -
(kTileSize*2), kTileSize);
[context setPatternPhase:patternRect.origin];
[[NSColor colorWithPatternImage:[parts objectAtIndex:7]] set];
NSRectFill(patternRect);
// top-left corner
part = [parts objectAtIndex:6];
[part compositeToPoint:NSMakePoint(0, winH - kTileSize)
operation:NSCompositeCopy fraction:1];
// left edge
patternRect = NSMakeRect(0, kTileSize, kTileSize, winH -
(kTileSize*2) );
[context setPatternPhase:patternRect.origin];
[[NSColor colorWithPatternImage:[parts objectAtIndex:3]] set];
NSRectFill(patternRect);
[back unlockFocus];
return [NSColor colorWithPatternImage:[back autorelease]];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden