diff --git a/ChangeLog b/ChangeLog index 4599bc201..2c26d863f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-07-09 Fred Kiefer + + * Headers/AppKit/NSGraphicsContext.h, + * Source/NSGraphicsContext.m: Added new methods + [-GScomposite:toPoint:fromRect:operation:fraction:] and + [-GSSetPatterColor:]. + * Source/NSImage.m (-compositeToPoint:...fraction:): Implemented. + * Source/NSColor.m (GSPatternColor -set): Implemented. + 2005-07-04 Adam Fedor * Documentation/ReleaseNotes.gsdoc: Update. diff --git a/Headers/AppKit/NSGraphicsContext.h b/Headers/AppKit/NSGraphicsContext.h index 4eb369f5e..cc20eacb5 100644 --- a/Headers/AppKit/NSGraphicsContext.h +++ b/Headers/AppKit/NSGraphicsContext.h @@ -233,6 +233,8 @@ APPKIT_EXPORT NSGraphicsContext *GSCurrentContext(void); - (void) DPSsethsbcolor: (float)h : (float)s : (float)b; - (void) DPSsetrgbcolor: (float)r : (float)g : (float)b; +- (void) GSSetPatterColor: (NSImage*)image; + - (void) GSSetFillColorspace: (void *)spaceref; - (void) GSSetStrokeColorspace: (void *)spaceref; - (void) GSSetFillColor: (const float *)values; @@ -359,6 +361,11 @@ APPKIT_EXPORT NSGraphicsContext *GSCurrentContext(void); - (void) DPSdissolve: (float)x : (float)y : (float)w : (float)h : (int)gstateNum : (float)dx : (float)dy : (float)delta; +- (void) GScomposite: (int)gstateNum + toPoint: (NSPoint)aPoint + fromRect: (NSRect)srcRect + operation: (NSCompositingOperation)op + fraction: (float)delta; - (void) GSDrawImage: (NSRect)rect : (void *)imageref; /* ----------------------------------------------------------------------- */ diff --git a/Source/NSColor.m b/Source/NSColor.m index 85ffbd45f..14a2e7047 100644 --- a/Source/NSColor.m +++ b/Source/NSColor.m @@ -2743,7 +2743,7 @@ systemColorWithName(NSString *name) - (void) set { - // FIXME: We need another PS command for this + [GSCurrentContext() GSSetPatterColor: _pattern]; } // diff --git a/Source/NSGraphicsContext.m b/Source/NSGraphicsContext.m index b2df3ef1a..377a29fb3 100644 --- a/Source/NSGraphicsContext.m +++ b/Source/NSGraphicsContext.m @@ -770,6 +770,11 @@ NSGraphicsContext *GSCurrentContext(void) [self subclassResponsibility: _cmd]; } +- (void) GSSetPatterColor: (NSImage*)image +{ + [self subclassResponsibility: _cmd]; +} + /**

Sets the colorspace for fill operations based on values in the supplied dictionary dict.

@@ -1438,6 +1443,19 @@ NSGraphicsContext *GSCurrentContext(void) [self subclassResponsibility: _cmd]; } +/* + As currently not all backends support mixed composite and dissolve operations, + this method is here to dispatch to the best suited one implemented + */ +- (void) GScomposite: (int)gstateNum + toPoint: (NSPoint)aPoint + fromRect: (NSRect)srcRect + operation: (NSCompositingOperation)op + fraction: (float)delta +{ + [self subclassResponsibility: _cmd]; +} + /** Generic method to draw an image into a rect. The image is defined by imageref, an opaque structure. Support for this method hasn't been implemented yet, so it should not be used anywhere. */ diff --git a/Source/NSImage.m b/Source/NSImage.m index 096108ee4..253dbe503 100644 --- a/Source/NSImage.m +++ b/Source/NSImage.m @@ -714,6 +714,12 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) fromRect: (NSRect)aRect operation: (NSCompositingOperation)op { +#if 0 + [self compositeToPoint: aPoint + fromRect: aRect + operation: op + fraction: 1.0]; +#else NSImageRep *rep = nil; NS_DURING @@ -762,6 +768,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) } } NS_ENDHANDLER +#endif } - (void) compositeToPoint: (NSPoint)aPoint @@ -777,11 +784,61 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) } - (void) compositeToPoint: (NSPoint)aPoint - fromRect: (NSRect)srcRect + fromRect: (NSRect)aRect operation: (NSCompositingOperation)op fraction: (float)delta { -// FIXME We need another PS command for this + NSImageRep *rep = nil; + + NS_DURING + { + if ([GSCurrentContext() isDrawingToScreen] == YES) + rep = [self _doImageCache]; + if (rep + &&_cacheMode != NSImageCacheNever + && [rep isKindOfClass: cachedClass]) + { + NSRect rect; + + rect = [(NSCachedImageRep *)rep rect]; + NSDebugLLog(@"NSImage", @"composite rect %@ in %@", + NSStringFromRect(rect), NSStringFromRect(aRect)); + // Move the drawing rectangle to the origin of the image rep + // and intersect the two rects. + aRect.origin.x += rect.origin.x; + aRect.origin.y += rect.origin.y; + rect = NSIntersectionRect(aRect, rect); + + [GSCurrentContext() GScomposite: [[(NSCachedImageRep *)rep window] gState] + toPoint: aPoint + fromRect: rect + operation: op + fraction: delta]; + } + else + { + NSRect rect; + rep = [self bestRepresentationForDevice: nil]; + rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height); + [self drawRepresentation: rep inRect: rect]; + } + } + NS_HANDLER + { + NSLog(@"NSImage: compositeToPoint:fromRect:operation:fraction: failed due to %@: %@", + [localException name], [localException reason]); + if ([_delegate respondsToSelector: @selector(imageDidNotDraw:inRect:)]) + { + NSImage *image = [_delegate imageDidNotDraw: self inRect: aRect]; + + if (image != nil) + [image compositeToPoint: aPoint + fromRect: aRect + operation: op + fraction: delta]; + } + } + NS_ENDHANDLER } - (void) dissolveToPoint: (NSPoint)aPoint fraction: (float)aFloat @@ -797,6 +854,12 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) fromRect: (NSRect)aRect fraction: (float)aFloat { +#if 0 + [self compositeToPoint: aPoint + fromRect: aRect + operation: NSCompositeSourceOver + fraction: aFloat]; +#else NSImageRep *rep = nil; NS_DURING @@ -845,6 +908,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) } } NS_ENDHANDLER +#endif } - (BOOL) drawRepresentation: (NSImageRep *)imageRep inRect: (NSRect)aRect