mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 07:10:59 +00:00
Corrected some methods on this class so that subclasses may use
them. Moved all the class methods to the front of the file. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10113 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7a995b5964
commit
e8448db22a
1 changed files with 200 additions and 179 deletions
|
@ -44,7 +44,8 @@
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
#include <AppKit/DPSOperators.h>
|
#include <AppKit/DPSOperators.h>
|
||||||
|
|
||||||
static NSMutableArray* imageReps = NULL;
|
static NSMutableArray *imageReps = nil;
|
||||||
|
static Class NSImageRep_class = NULL;
|
||||||
|
|
||||||
@implementation NSImageRep
|
@implementation NSImageRep
|
||||||
|
|
||||||
|
@ -55,6 +56,8 @@ static NSMutableArray* imageReps = NULL;
|
||||||
if (self == [NSImageRep class])
|
if (self == [NSImageRep class])
|
||||||
{
|
{
|
||||||
id obj;
|
id obj;
|
||||||
|
|
||||||
|
NSImageRep_class = self;
|
||||||
imageReps = [[NSMutableArray alloc] initWithCapacity: 2];
|
imageReps = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||||
obj = [[NSUserDefaults standardUserDefaults]
|
obj = [[NSUserDefaults standardUserDefaults]
|
||||||
stringForKey: @"ImageCompositing"];
|
stringForKey: @"ImageCompositing"];
|
||||||
|
@ -64,331 +67,6 @@ static NSMutableArray* imageReps = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating an NSImageRep
|
|
||||||
+ (id) imageRepWithContentsOfFile: (NSString *)filename
|
|
||||||
{
|
|
||||||
NSArray* array;
|
|
||||||
|
|
||||||
array = [self imageRepsWithContentsOfFile: filename];
|
|
||||||
if ([array count])
|
|
||||||
return [array objectAtIndex: 0];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageRepsWithContentsOfFile: (NSString *)filename
|
|
||||||
{
|
|
||||||
int i, count;
|
|
||||||
NSString *ext;
|
|
||||||
NSMutableArray *array;
|
|
||||||
|
|
||||||
ext = [filename pathExtension];
|
|
||||||
// FIXME: Should this be an exception? Should we even check this?
|
|
||||||
if (!ext)
|
|
||||||
{
|
|
||||||
NSLog(@"Extension missing from filename - '%@'", filename);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
array = [NSMutableArray arrayWithCapacity: 1];
|
|
||||||
count = [imageReps count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
Class rep = [imageReps objectAtIndex: i];
|
|
||||||
if ([[rep imageFileTypes] indexOfObject: ext] != NSNotFound)
|
|
||||||
{
|
|
||||||
// This is some GNUstep extension for special file types
|
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithFile:)])
|
|
||||||
[array addObjectsFromArray: [rep imageRepsWithFile: filename]];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSData* data;
|
|
||||||
|
|
||||||
data = [NSData dataWithContentsOfFile: filename];
|
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
|
||||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
|
||||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
|
||||||
{
|
|
||||||
NSImageRep *imageRep = [rep imageRepWithData: data];
|
|
||||||
|
|
||||||
if (rep != nil)
|
|
||||||
[array addObject: imageRep];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (NSArray *)array;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (id) imageRepWithPasteboard: (NSPasteboard *)pasteboard
|
|
||||||
{
|
|
||||||
NSArray* array;
|
|
||||||
|
|
||||||
array = [self imageRepsWithPasteboard: pasteboard];
|
|
||||||
if ([array count])
|
|
||||||
return [array objectAtIndex: 0];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageRepsWithPasteboard: (NSPasteboard *)pasteboard
|
|
||||||
{
|
|
||||||
int i, count;
|
|
||||||
NSMutableArray* array;
|
|
||||||
|
|
||||||
array = [NSMutableArray arrayWithCapacity: 1];
|
|
||||||
|
|
||||||
count = [imageReps count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
NSString* ptype;
|
|
||||||
Class rep = [imageReps objectAtIndex: i];
|
|
||||||
|
|
||||||
ptype = [pasteboard availableTypeFromArray: [rep imagePasteboardTypes]];
|
|
||||||
if (ptype != nil)
|
|
||||||
{
|
|
||||||
NSData* data = [pasteboard dataForType: ptype];
|
|
||||||
|
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
|
||||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
|
||||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
|
||||||
{
|
|
||||||
NSImageRep *imageRep = [rep imageRepWithData: data];
|
|
||||||
|
|
||||||
if (rep != nil)
|
|
||||||
[array addObject: imageRep];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (NSArray *)array;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (id)imageRepWithContentsOfURL:(NSURL *)anURL
|
|
||||||
{
|
|
||||||
NSArray* array;
|
|
||||||
|
|
||||||
array = [self imageRepsWithContentsOfURL: anURL];
|
|
||||||
if ([array count])
|
|
||||||
return [array objectAtIndex: 0];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *)imageRepsWithContentsOfURL:(NSURL *)anURL
|
|
||||||
{
|
|
||||||
int i, count;
|
|
||||||
NSString *ext;
|
|
||||||
NSMutableArray *array;
|
|
||||||
|
|
||||||
ext = [[anURL path] pathExtension];
|
|
||||||
// FIXME: Should this be an exception? Should we even check this?
|
|
||||||
if (!ext)
|
|
||||||
{
|
|
||||||
NSLog(@"Extension missing from URL - '%@'", [anURL path]);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
array = [NSMutableArray arrayWithCapacity: 1];
|
|
||||||
count = [imageReps count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
Class rep = [imageReps objectAtIndex: i];
|
|
||||||
if ([[rep imageFileTypes] indexOfObject: ext] != NSNotFound)
|
|
||||||
{
|
|
||||||
NSData* data;
|
|
||||||
|
|
||||||
data = [anURL resourceDataUsingCache: YES];
|
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
|
||||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
|
||||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
|
||||||
{
|
|
||||||
NSImageRep *imageRep = [rep imageRepWithData: data];
|
|
||||||
|
|
||||||
if (rep != nil)
|
|
||||||
[array addObject: imageRep];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (NSArray *)array;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone *)zone
|
|
||||||
{
|
|
||||||
NSImageRep *copy;
|
|
||||||
|
|
||||||
copy = (NSImageRep*)NSCopyObject(self, 0, zone);
|
|
||||||
copy->_colorSpace = RETAIN(_colorSpace);
|
|
||||||
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
RELEASE(_colorSpace);
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking Data Types
|
|
||||||
+ (BOOL) canInitWithData: (NSData *)data
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (BOOL) canInitWithPasteboard: (NSPasteboard *)pasteboard
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageFileTypes
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imagePasteboardTypes
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageUnfilteredFileTypes
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageUnfilteredPasteboardTypes
|
|
||||||
{
|
|
||||||
/* Subclass responsibility */
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting the Size of the Image
|
|
||||||
- (void) setSize: (NSSize)aSize
|
|
||||||
{
|
|
||||||
_size = aSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSSize) size
|
|
||||||
{
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specifying Information about the Representation
|
|
||||||
- (int) bitsPerSample
|
|
||||||
{
|
|
||||||
return _bitsPerSample;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *) colorSpaceName
|
|
||||||
{
|
|
||||||
return _colorSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) hasAlpha
|
|
||||||
{
|
|
||||||
return _hasAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) isOpaque
|
|
||||||
{
|
|
||||||
return _isOpaque;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) pixelsWide
|
|
||||||
{
|
|
||||||
return _pixelsWide;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) pixelsHigh
|
|
||||||
{
|
|
||||||
return _pixelsHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setAlpha: (BOOL)flag
|
|
||||||
{
|
|
||||||
_hasAlpha = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setBitsPerSample: (int)anInt
|
|
||||||
{
|
|
||||||
_bitsPerSample = anInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setColorSpaceName: (NSString *)aString
|
|
||||||
{
|
|
||||||
ASSIGN(_colorSpace, aString);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setOpaque: (BOOL)flag
|
|
||||||
{
|
|
||||||
_isOpaque = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setPixelsWide: (int)anInt
|
|
||||||
{
|
|
||||||
_pixelsWide = anInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setPixelsHigh: (int)anInt
|
|
||||||
{
|
|
||||||
_pixelsHigh = anInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drawing the Image
|
|
||||||
- (BOOL) draw
|
|
||||||
{
|
|
||||||
return YES; /* Subclass should implement this. */
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) drawAtPoint: (NSPoint)aPoint
|
|
||||||
{
|
|
||||||
BOOL ok, reset;
|
|
||||||
NSGraphicsContext *ctxt;
|
|
||||||
|
|
||||||
if (_size.width == 0 && _size.height == 0)
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
NSDebugLLog(@"NSImage", @"Drawing at point %f %f\n", aPoint.x, aPoint.y);
|
|
||||||
reset = 0;
|
|
||||||
ctxt = GSCurrentContext();
|
|
||||||
if (aPoint.x != 0 || aPoint.y != 0)
|
|
||||||
{
|
|
||||||
if ([[ctxt focusView] isFlipped])
|
|
||||||
aPoint.y -= _size.height;
|
|
||||||
DPSmatrix(ctxt); DPScurrentmatrix(ctxt);
|
|
||||||
DPStranslate(ctxt, aPoint.x, aPoint.y);
|
|
||||||
reset = 1;
|
|
||||||
}
|
|
||||||
ok = [self draw];
|
|
||||||
if (reset)
|
|
||||||
DPSsetmatrix(ctxt);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) drawInRect: (NSRect)aRect
|
|
||||||
{
|
|
||||||
NSSize scale;
|
|
||||||
BOOL ok;
|
|
||||||
NSGraphicsContext *ctxt;
|
|
||||||
|
|
||||||
NSDebugLLog(@"NSImage", @"Drawing in rect (%f %f %f %f)\n",
|
|
||||||
NSMinX(aRect), NSMinY(aRect), NSWidth(aRect), NSHeight(aRect));
|
|
||||||
if (_size.width == 0 && _size.height == 0)
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
ctxt = GSCurrentContext();
|
|
||||||
scale = NSMakeSize(NSWidth(aRect) / _size.width,
|
|
||||||
NSHeight(aRect) / _size.height);
|
|
||||||
if ([[ctxt focusView] isFlipped])
|
|
||||||
aRect.origin.y -= NSHeight(aRect);
|
|
||||||
DPSmatrix(ctxt); DPScurrentmatrix(ctxt);
|
|
||||||
DPStranslate(ctxt, NSMinX(aRect), NSMinY(aRect));
|
|
||||||
DPSscale(ctxt, scale.width, scale.height);
|
|
||||||
ok = [self draw];
|
|
||||||
DPSsetmatrix(ctxt);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Managing NSImageRep Subclasses
|
// Managing NSImageRep Subclasses
|
||||||
+ (Class) imageRepClassForData: (NSData *)data
|
+ (Class) imageRepClassForData: (NSData *)data
|
||||||
{
|
{
|
||||||
|
@ -472,6 +150,349 @@ static NSMutableArray* imageReps = NULL;
|
||||||
object: self];
|
object: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creating an NSImageRep
|
||||||
|
+ (id) imageRepWithContentsOfFile: (NSString *)filename
|
||||||
|
{
|
||||||
|
NSArray* array;
|
||||||
|
|
||||||
|
array = [self imageRepsWithContentsOfFile: filename];
|
||||||
|
if ([array count])
|
||||||
|
return [array objectAtIndex: 0];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imageRepsWithContentsOfFile: (NSString *)filename
|
||||||
|
{
|
||||||
|
NSString *ext;
|
||||||
|
Class rep;
|
||||||
|
|
||||||
|
// Is the file extension already the file type?
|
||||||
|
ext = [filename pathExtension];
|
||||||
|
if (!ext)
|
||||||
|
{
|
||||||
|
// FIXME: Should this be an exception?
|
||||||
|
NSLog(@"Extension missing from image filename - '%@'", filename);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self == NSImageRep_class)
|
||||||
|
{
|
||||||
|
rep = [self imageRepClassForFileType: ext];
|
||||||
|
}
|
||||||
|
else if ([[self imageFileTypes] containsObject: ext])
|
||||||
|
{
|
||||||
|
rep = self;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
// This is a GNUstep extension for special file types
|
||||||
|
if ([rep respondsToSelector: @selector(imageRepsWithFile:)])
|
||||||
|
return [rep imageRepsWithFile: filename];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSData* data;
|
||||||
|
|
||||||
|
data = [NSData dataWithContentsOfFile: filename];
|
||||||
|
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||||
|
return [rep imageRepsWithData: data];
|
||||||
|
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||||
|
{
|
||||||
|
NSImageRep *imageRep = [rep imageRepWithData: data];
|
||||||
|
|
||||||
|
if (imageRep != nil)
|
||||||
|
return [NSArray arrayWithObject: imageRep];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id)imageRepWithContentsOfURL:(NSURL *)anURL
|
||||||
|
{
|
||||||
|
NSArray* array;
|
||||||
|
|
||||||
|
array = [self imageRepsWithContentsOfURL: anURL];
|
||||||
|
if ([array count])
|
||||||
|
return [array objectAtIndex: 0];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *)imageRepsWithContentsOfURL:(NSURL *)anURL
|
||||||
|
{
|
||||||
|
Class rep;
|
||||||
|
NSData* data;
|
||||||
|
|
||||||
|
// FIXME: Should we use the file type for URLs or only check the data?
|
||||||
|
data = [anURL resourceDataUsingCache: YES];
|
||||||
|
|
||||||
|
if (self == NSImageRep_class)
|
||||||
|
{
|
||||||
|
rep = [self imageRepClassForData: data];
|
||||||
|
}
|
||||||
|
else if ([self canInitWithData: data])
|
||||||
|
{
|
||||||
|
rep = self;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||||
|
return [rep imageRepsWithData: data];
|
||||||
|
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||||
|
{
|
||||||
|
NSImageRep *imageRep = [rep imageRepWithData: data];
|
||||||
|
|
||||||
|
if (imageRep != nil)
|
||||||
|
return [NSArray arrayWithObject: imageRep];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id) imageRepWithPasteboard: (NSPasteboard *)pasteboard
|
||||||
|
{
|
||||||
|
NSArray* array;
|
||||||
|
|
||||||
|
array = [self imageRepsWithPasteboard: pasteboard];
|
||||||
|
if ([array count])
|
||||||
|
return [array objectAtIndex: 0];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imageRepsWithPasteboard: (NSPasteboard *)pasteboard
|
||||||
|
{
|
||||||
|
int i, count;
|
||||||
|
NSMutableArray* array;
|
||||||
|
NSArray *reps;
|
||||||
|
|
||||||
|
if (self == NSImageRep_class)
|
||||||
|
{
|
||||||
|
reps = imageReps;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reps = [NSArray arrayWithObject: self];
|
||||||
|
}
|
||||||
|
|
||||||
|
array = [NSMutableArray arrayWithCapacity: 1];
|
||||||
|
|
||||||
|
count = [reps count];
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
NSString* ptype;
|
||||||
|
Class rep = [reps objectAtIndex: i];
|
||||||
|
|
||||||
|
ptype = [pasteboard availableTypeFromArray: [rep imagePasteboardTypes]];
|
||||||
|
if (ptype != nil)
|
||||||
|
{
|
||||||
|
NSData* data = [pasteboard dataForType: ptype];
|
||||||
|
|
||||||
|
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||||
|
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
||||||
|
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||||
|
{
|
||||||
|
NSImageRep *imageRep = [rep imageRepWithData: data];
|
||||||
|
|
||||||
|
if (rep != nil)
|
||||||
|
[array addObject: imageRep];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([array count] == 0)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
return (NSArray *)array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checking Data Types
|
||||||
|
+ (BOOL) canInitWithData: (NSData *)data
|
||||||
|
{
|
||||||
|
/* Subclass responsibility */
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL) canInitWithPasteboard: (NSPasteboard *)pasteboard
|
||||||
|
{
|
||||||
|
NSArray *pbTypes = [pasteboard types];
|
||||||
|
NSArray *myTypes = [self imageUnfilteredPasteboardTypes];
|
||||||
|
|
||||||
|
return ([pbTypes firstObjectCommonWithArray: myTypes] != nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imageFileTypes
|
||||||
|
{
|
||||||
|
// FIXME: We should check what conversions are defined by services.
|
||||||
|
return [self imageUnfilteredFileTypes];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imagePasteboardTypes
|
||||||
|
{
|
||||||
|
// FIXME: We should check what conversions are defined by services.
|
||||||
|
return [self imageUnfilteredPasteboardTypes];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imageUnfilteredFileTypes
|
||||||
|
{
|
||||||
|
/* Subclass responsibility */
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *) imageUnfilteredPasteboardTypes
|
||||||
|
{
|
||||||
|
/* Subclass responsibility */
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Instance methods
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(_colorSpace);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting the Size of the Image
|
||||||
|
- (void) setSize: (NSSize)aSize
|
||||||
|
{
|
||||||
|
_size = aSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSSize) size
|
||||||
|
{
|
||||||
|
return _size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specifying Information about the Representation
|
||||||
|
- (int) bitsPerSample
|
||||||
|
{
|
||||||
|
return _bitsPerSample;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *) colorSpaceName
|
||||||
|
{
|
||||||
|
return _colorSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) hasAlpha
|
||||||
|
{
|
||||||
|
return _hasAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isOpaque
|
||||||
|
{
|
||||||
|
return _isOpaque;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) pixelsWide
|
||||||
|
{
|
||||||
|
return _pixelsWide;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) pixelsHigh
|
||||||
|
{
|
||||||
|
return _pixelsHigh;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setAlpha: (BOOL)flag
|
||||||
|
{
|
||||||
|
_hasAlpha = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setBitsPerSample: (int)anInt
|
||||||
|
{
|
||||||
|
_bitsPerSample = anInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setColorSpaceName: (NSString *)aString
|
||||||
|
{
|
||||||
|
ASSIGN(_colorSpace, aString);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setOpaque: (BOOL)flag
|
||||||
|
{
|
||||||
|
_isOpaque = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setPixelsWide: (int)anInt
|
||||||
|
{
|
||||||
|
_pixelsWide = anInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setPixelsHigh: (int)anInt
|
||||||
|
{
|
||||||
|
_pixelsHigh = anInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drawing the Image
|
||||||
|
- (BOOL) draw
|
||||||
|
{
|
||||||
|
/* Subclass should implement this. */
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) drawAtPoint: (NSPoint)aPoint
|
||||||
|
{
|
||||||
|
BOOL ok, reset;
|
||||||
|
NSGraphicsContext *ctxt;
|
||||||
|
|
||||||
|
if (_size.width == 0 && _size.height == 0)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
NSDebugLLog(@"NSImage", @"Drawing at point %f %f\n", aPoint.x, aPoint.y);
|
||||||
|
reset = 0;
|
||||||
|
ctxt = GSCurrentContext();
|
||||||
|
if (aPoint.x != 0 || aPoint.y != 0)
|
||||||
|
{
|
||||||
|
if ([[ctxt focusView] isFlipped])
|
||||||
|
aPoint.y -= _size.height;
|
||||||
|
DPSmatrix(ctxt); DPScurrentmatrix(ctxt);
|
||||||
|
DPStranslate(ctxt, aPoint.x, aPoint.y);
|
||||||
|
reset = 1;
|
||||||
|
}
|
||||||
|
ok = [self draw];
|
||||||
|
if (reset)
|
||||||
|
DPSsetmatrix(ctxt);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) drawInRect: (NSRect)aRect
|
||||||
|
{
|
||||||
|
NSSize scale;
|
||||||
|
BOOL ok;
|
||||||
|
NSGraphicsContext *ctxt;
|
||||||
|
|
||||||
|
NSDebugLLog(@"NSImage", @"Drawing in rect (%f %f %f %f)\n",
|
||||||
|
NSMinX(aRect), NSMinY(aRect), NSWidth(aRect), NSHeight(aRect));
|
||||||
|
if (_size.width == 0 && _size.height == 0)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
ctxt = GSCurrentContext();
|
||||||
|
scale = NSMakeSize(NSWidth(aRect) / _size.width,
|
||||||
|
NSHeight(aRect) / _size.height);
|
||||||
|
if ([[ctxt focusView] isFlipped])
|
||||||
|
aRect.origin.y -= NSHeight(aRect);
|
||||||
|
DPSmatrix(ctxt); DPScurrentmatrix(ctxt);
|
||||||
|
DPStranslate(ctxt, NSMinX(aRect), NSMinY(aRect));
|
||||||
|
DPSscale(ctxt, scale.width, scale.height);
|
||||||
|
ok = [self draw];
|
||||||
|
DPSsetmatrix(ctxt);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NSCopying protocol
|
||||||
|
- (id) copyWithZone: (NSZone *)zone
|
||||||
|
{
|
||||||
|
NSImageRep *copy;
|
||||||
|
|
||||||
|
copy = (NSImageRep*)NSCopyObject(self, 0, zone);
|
||||||
|
copy->_colorSpace = RETAIN(_colorSpace);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
// NSCoding protocol
|
// NSCoding protocol
|
||||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue