/* NSImage.h Load, manipulate and display images Copyright (C) 1996-2016 Free Software Foundation, Inc. Written by: Adam Fedor Date: Feb 1996 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. If not, see or write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GNUstep_H_NSImage #define _GNUstep_H_NSImage #import #import #import #import @class NSString; @class NSMutableArray; @class NSData; @class NSURL; @class NSPasteboard; @class NSImageRep; @class NSColor; @class NSView; /* Named images */ APPKIT_EXPORT NSString *NSImageNameMultipleDocuments; #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) APPKIT_EXPORT NSString *NSImageNameUserAccounts; APPKIT_EXPORT NSString *NSImageNamePreferencesGeneral; APPKIT_EXPORT NSString *NSImageNameAdvanced; APPKIT_EXPORT NSString *NSImageNameInfo; APPKIT_EXPORT NSString *NSImageNameFontPanel; APPKIT_EXPORT NSString *NSImageNameColorPanel; #endif #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST) APPKIT_EXPORT NSString *NSImageNameTrashEmpty; APPKIT_EXPORT NSString *NSImageNameTrashFull; APPKIT_EXPORT NSString *NSImageNameCaution; #endif /** Defines how an NSImage is to be cached. Possible values are: * * NSImageCacheDefault * NSImageCacheAlways * NSImageCacheBySize * NSImageCacheNever * *

See Also:

* * -setCacheMode: * -cacheMode * */ typedef enum { NSImageCacheDefault, NSImageCacheAlways, NSImageCacheBySize, NSImageCacheNever } NSImageCacheMode; @interface NSImage : NSObject { // Attributes NSString *_name; NSString *_fileName; NSSize _size; struct __imageFlags { unsigned archiveByName: 1; unsigned scalable: 1; unsigned dataRetained: 1; unsigned flipDraw: 1; unsigned sizeWasExplicitlySet: 1; unsigned useEPSOnResolutionMismatch: 1; unsigned colorMatchPreferred: 1; unsigned multipleResolutionMatching: 1; unsigned cacheSeparately: 1; unsigned unboundedCacheDepth: 1; unsigned syncLoad: 1; } _flags; NSMutableArray *_reps; NSColor *_color; NSView *_lockedView; id _delegate; NSImageCacheMode _cacheMode; } // // Initializing a New NSImage Instance // /** Initializes and returns a NSImage from the NSString fileName. */ - (id) initByReferencingFile: (NSString*)fileName; /** Initializes and returns a new NSImage from the file * fileName. fileName should be an absolute path. *

See Also:

* * [NSImageRep+imageRepsWithContentsOfFile:] * */ - (id) initWithContentsOfFile: (NSString*)fileName; /** Initializes and returns a new NSImage from the NSData data. *

See Also:

* * [NSBitmapImageRep+imageRepWithData:] * [NSEPSImageRep+imageRepWithData:] * */ - (id) initWithData: (NSData*)data; /** Initializes and returns a new NSImage from the data in pasteboard. * The pasteboard types can be whose defined in * [NSImageRep+imagePasteboardTypes] or NSFilenamesPboardType *

See Also:

* * [NSImageRep+imageRepsWithPasteboard:] * */ - (id) initWithPasteboard: (NSPasteboard*)pasteboard; /** Initialize and returns a new NSImage with aSize as specified * size. *

See Also:

* * -setSize: * -size * */ - (id) initWithSize: (NSSize)aSize; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (id)initWithBitmapHandle:(void *)bitmap; - (id)initWithContentsOfURL:(NSURL *)anURL; - (id)initWithIconHandle:(void *)icon; #endif // // Setting the Size of the Image // /** Sets the NSImage size to aSize. Changing the size recreate * the cache. *

See Also:

* * -size * -initWithSize: * */ - (void) setSize: (NSSize)aSize; /** Returns NSImage size if the size have been set. Returns the * size of the best representation otherwise. *

See Also:

* * -setSize: * -initWithSize: * */ - (NSSize) size; // // Referring to Images by Name // /** Returns the NSImage named aName. The search is done in the main bundle * first and then in the usual images directories. */ + (id) imageNamed: (NSString*)aName; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) #if OS_API_VERSION(GS_API_NONE, GS_API_NONE) + (NSImage*) _standardImageWithName: (NSString*)name; #endif #endif /** Sets aName as the name of the receiver. */ - (BOOL) setName: (NSString*)aName; /** Returns the name of the receiver. */ - (NSString*) name; // // Specifying the Image // /** Adds the NSImageRep imageRep to the NSImage's representations array. *

See Also:

* * -addRepresentations: * -removeRepresentation: * */ - (void) addRepresentation: (NSImageRep*)imageRep; /** Adds the NSImageRep array imageRepArray to the NSImage's * representations array. *

See Also:

* * -addRepresentation: * -removeRepresentation: * */ - (void) addRepresentations: (NSArray*)imageRepArray; /** Locks the focus on the best representation. *

See Also:

* * -lockFocusOnRepresentation: * */ - (void) lockFocus; /** Locks the focus in the imageRep. If imageRep is nil this method * locks the focus on the best representation. */ - (void) lockFocusOnRepresentation: (NSImageRep*)imageRep; /** Unlocks the focus on the receiver. *

See Also:

* * -lockFocus * */ - (void) unlockFocus; // // Using the Image // - (void) compositeToPoint: (NSPoint)aPoint operation: (NSCompositingOperation)op; - (void) compositeToPoint: (NSPoint)aPoint fromRect: (NSRect)aRect operation: (NSCompositingOperation)op; - (void) dissolveToPoint: (NSPoint)aPoint fraction: (CGFloat)aFloat; - (void) dissolveToPoint: (NSPoint)aPoint fromRect: (NSRect)aRect fraction: (CGFloat)aFloat; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (void) compositeToPoint: (NSPoint)aPoint fromRect: (NSRect)srcRect operation: (NSCompositingOperation)op fraction: (CGFloat)delta; - (void) compositeToPoint: (NSPoint)aPoint operation: (NSCompositingOperation)op fraction: (CGFloat)delta; #endif // // Choosing Which Image Representation to Use // /** Sets the preferred representation of a NSImage. *

See Also:

* * -prefersColorMatch * -bestRepresentationForDevice: * */ - (void) setPrefersColorMatch: (BOOL)flag; /** Returns YES if color matching is the preferred representation * and NO otherwise. */ - (BOOL) prefersColorMatch; - (void) setUsesEPSOnResolutionMismatch: (BOOL)flag; - (BOOL) usesEPSOnResolutionMismatch; - (void) setMatchesOnMultipleResolution: (BOOL)flag; - (BOOL) matchesOnMultipleResolution; // // Getting the Representations // /** Finds the best representation for deviceDescription. If * deviceDescription is nil, it guesses where drawing is taking * place and finds the best representation. */ - (NSImageRep*) bestRepresentationForDevice: (NSDictionary*)deviceDescription; #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST) /** * Finds the best representation for drawing in the specified rect. * * context and hints are currently ignored. */ - (NSImageRep *)bestRepresentationForRect: (NSRect)rect context: (NSGraphicsContext *)context hints: (NSDictionary *)hints; #endif - (NSArray*) representations; /** Remove the NSImageRep imageRep from the NSImage's representations * array *

See Also:

* * -addRepresentations: * -addRepresentation: * */ - (void) removeRepresentation: (NSImageRep*)imageRep; // // Determining How the Image is Stored // - (void) setCachedSeparately: (BOOL)flag; - (BOOL) isCachedSeparately; - (void) setDataRetained: (BOOL)flag; - (BOOL) isDataRetained; - (void) setCacheDepthMatchesImageDepth: (BOOL)flag; - (BOOL) cacheDepthMatchesImageDepth; - (void) setCacheMode: (NSImageCacheMode)mode; - (NSImageCacheMode) cacheMode; // // Drawing // - (BOOL) drawRepresentation: (NSImageRep*)imageRep inRect: (NSRect)aRect; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) /** Calls -drawAtPoint:fromRect:operation:fraction: with * dstRect given by point and the size of * srcRect. */ - (void) drawAtPoint: (NSPoint)point fromRect: (NSRect)srcRect operation: (NSCompositingOperation)op fraction: (CGFloat)delta; /**

Takes the part of the receiver given by srcRect and * draws it in dstRect in the current coordinate system, * transforming the image as necessary. *

* The image is drawn as if it was drawn to a cleared window, then * dissolved using the fraction delta to another cleared * window, and finally composited using op to the * destination. *

* Note that compositing and dissolving doesn't work on all devices * (printers, in particular). *

*/ - (void) drawInRect: (NSRect)dstRect fromRect: (NSRect)srcRect operation: (NSCompositingOperation)op fraction: (CGFloat)delta; #endif #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST) - (void) drawInRect: (NSRect)dstRect fromRect: (NSRect)srcRect operation: (NSCompositingOperation)op fraction: (CGFloat)delta respectFlipped: (BOOL)respectFlipped hints: (NSDictionary*)hints; #endif /** *

Draws the entire image in rect scaling if needed.
* Drawing is done using NSCompositeSourceOver. *

*/ #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST) - (void) drawInRect: (NSRect)rect; #endif // // Determining How the Image is Drawn // - (BOOL) isValid; - (void) setScalesWhenResized: (BOOL)flag; - (BOOL) scalesWhenResized; /** Sets the color of the NSImage's background to aColor. *

See Also:

* * -backgroundColor * */ - (void) setBackgroundColor: (NSColor*)aColor; /** Returns the color of the NSImage's background. *

See Also:

* * -setBackgroundColor: * */ - (NSColor*) backgroundColor; - (void) recache; - (void) setFlipped: (BOOL)flag; - (BOOL) isFlipped; // // Assigning a Delegate // - (void) setDelegate: (id)anObject; - (id) delegate; // // Producing TIFF Data for the Image // - (NSData*) TIFFRepresentation; - (NSData*) TIFFRepresentationUsingCompression: (NSTIFFCompression)comp factor: (float)aFloat; // // Managing NSImageRep Subclasses // + (NSArray*) imageUnfilteredFileTypes; + (NSArray*) imageUnfilteredPasteboardTypes; // // Testing Image Data Sources // + (BOOL) canInitWithPasteboard: (NSPasteboard*)pasteboard; + (NSArray*) imageFileTypes; + (NSArray*) imagePasteboardTypes; @end @interface NSBundle (NSImageAdditions) - (NSString*) pathForImageResource: (NSString*)name; @end #if OS_API_VERSION(GS_API_NONE, GS_API_NONE) /* * A formal protocol that duplicates the informal protocol for delegates. */ @protocol GSImageDelegateProtocol - (NSImage*) imageDidNotDraw: (id)sender inRect: (NSRect)aRect; @end #endif #endif // _GNUstep_H_NSImage