Le 31 déc. 04, à 14:57, M. Uli Kusterer a écrit :
Hi Quentin, Nicholas!
Happy new year, everybody !
I've attached a first design for an IKIcon class that would be the
central class for icon management. IKIconProvider would then only
return IKIcon objects.
IKIcon objects are mutable. If you create an icon using
initWithIdentifier: or initWithExtension:mimeType:attributes: you can
hold on to them and they will automatically update when the theme
changes.
If you want to composite an image onto an icon, you have to create
another IKIcon for it. That way, when the theme changes, all badges
provided by the current theme will update to the new theme.
ok
IKIcon *may* (but isn't guaranteed to) perform caching and return the
same objects for requests for the same icon (with the retainCount
increased).
ok
Quentin, this doesn't yet support any custom compositors. But I think
this could be added as needed by just adding a new
addIcon:toRect:withCompositor: variant when this is implemented.
I would prefer to have a method like -setCompositor: because the
compositor will be set only once (when you start to use the IconKit)
normally, and the default compositor may also depend on the target
platform (Cocoa or GNUstep).
Now IKIcon.h related comments :
typedef NSString* IKIconIdentifier; // Would be a struct
containing type/creator on Mac.
I don't think such typedef is really needed, in such case Cocoa or
GNUstep uses standard NSString.
//
-----------------------------------------------------------------------
------
// Constants:
//
-----------------------------------------------------------------------
------
// Any of these can go in anywhere an IKIconIdentifier is asked:
extern IKIconIdentifier IKIconGenericFolder; // Just a
plain icon for a directory.
extern IKIconIdentifier IKIconGenericDocument; // Plain icon
for a user-file.
extern IKIconIdentifier IKIconGenericApplication; // Plain icon
for an application.
extern IKIconIdentifier IKIconGenericPlugIn; // Plain icon
for a loadable plugin bundle.
// ...
extern IKIconIdentifier IKIconSymLinkBadge; // Icon for
badging symlink.
extern IKIconIdentifier IKIconForbiddenBadge; // Icon for
badging files for which the user has no permissions.
// ...
This icon identifiers should be moved to IKxxxProvider.h I think
extern NSString* IKIconChangedNotification; // Sent by the
IKIcon as the object whenever update is called.
//
-----------------------------------------------------------------------
------
// Classes:
//
-----------------------------------------------------------------------
------
@interface IKIcon : NSObject
{
// ...
}
+(id) iconWithIdentifier: (IKIconIdentifier)identifier;
+(id) iconWithExtension: (NSString*)suffix mimeType:
(NSString*)mime
attributes: (NSDictionary*)dict; /* any param may be
NIL */
These two methods should rely on IKxxxProvider classes for their
implementation.
+(id) iconWithSize: (NSSize)size;
+(id) iconWithImage: (NSImage*)image;
-(id) initWithIdentifier: (IKIconIdentifier)identifier;
-(id) initWithExtension: (NSString*)suffix mimeType:
(NSString*)mime
attributes: (NSDictionary*)dict; /* any param may be
NIL */
idem.
These two methods should rely on IKxxxProvider classes for their
implementation.
A method - (id) initWithPropertyList: (NSDictionary *)plist; needs to
be added here. With the IconKit, the compositing pipeline used by the
compositor can be loaded from a plist or saved to a plist. The
compositing pipeline is represented and manipulated with
IKCompositorOperation, more precisely a recursive chain of
IKCompositorOperation.
-(id) initWithSize: (NSSize)size;
-(id) initWithImage: (NSImage*)image; // sets baseImage.
-(NSSize) size;
-(NSImage*) image;
// Compositing:
-(void) addIcon: (IKIcon*)src toRect: (NSRect)pos;
-(void) addIcon: (IKIcon*)src toRect: (NSRect)pos
operation:(NSCompositingOperation)op
fraction:(float)delta;
We need few extras methods here to support standard compositing
position, take a look at IKCompositorOperation.h :
typedef enum _IKCompositedImagePosition
{
IKCompositedImagePositionCenter,
IKCompositedImagePositionLeft,
IKCompositedImagePositionTopLeft,
IKCompositedImagePositionTop,
IKCompositedImagePositionTopRight,
IKCompositedImagePositionRight,
IKCompositedImagePositionBottomRight,
IKCompositedImagePositionBottom,
IKCompositedImagePositionBottomLeft,
} IKCompositedImagePosition;
// Standard rects to use:
-(NSRect) badgeRect;
-(NSRect) subIconRect; // Anybody have a better name?
Theses methods should be class methods.
// For theme-switching:
-(void) update; // Reloads the icon, possibly from the
new theme.
You prefer -update to -render method name ?
-(NSImage*) baseImage; // The image of the icon before any
badges or compositing are applied.
-(void) setBaseImage: (NSImage*)img;
I my opinion, theses methods are not needed… -initWithImage: and
addIcon: blabla: are sufficient for this task, moreover I think the
base shouldn't be fixed (in the future we could want to switch the
compositing order on the fly).
Thanks UIi for your proposal.
Quentin
--
Quentin Mathé
[EMAIL PROTECTED]