-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathACPlugin.h
More file actions
440 lines (289 loc) · 11.1 KB
/
ACPlugin.h
File metadata and controls
440 lines (289 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#import <Cocoa/Cocoa.h>
enum {
ACBitmapLayer = 1,
ACShapeLayer = 2,
ACGroupLayer = 3,
// …
ACMaskLayer = 5,
};
enum {
ACRectangleGraphic = 1,
ACOvalGraphic = 2,
ACLineGraphic = 3,
ACTextGraphic = 4,
ACImageGraphic = 5,
ACBezierGraphic = 6,
};
#define ACPLUGIN_SUPPORT 1
// forward decl.
@protocol ACBitmapTool;
@protocol ACImageIOProvider;
@protocol ACLayer;
@protocol ACMaskLayer;
@protocol ACPluginManager
- (BOOL)addFilterMenuTitle:(NSString*)menuTitle
withSuperMenuTitle:(NSString*)superMenuTitle
target:(id)target
action:(SEL)selector
keyEquivalent:(NSString*)keyEquivalent
keyEquivalentModifierMask:(NSUInteger)mask
userObject:(id)userObject;
- (BOOL)addActionMenuTitle:(NSString*)menuTitle
withSuperMenuTitle:(NSString*)superMenuTitle
target:(id)target
action:(SEL)selector
keyEquivalent:(NSString*)keyEquivalent
keyEquivalentModifierMask:(NSUInteger)mask
userObject:(id)userObject;
- (void)registerIOProviderForReading:(id<ACImageIOProvider>)provider forUTI:(NSString*)uti;
- (void)registerIOProviderForWriting:(id<ACImageIOProvider>)provider forUTI:(NSString*)uti;
- (void)registerFilterName:(NSString*)filterName constructor:(Class)filterClass;
@end
@interface NSApplication (ACPluginManagerAdditions)
- (id<ACPluginManager>)sharedPluginManager;
@end
@protocol ACPlugin
/*
This will create an instance of our plugin. You really shouldn't need to
worry about this at all.
*/
+ (id)plugin;
/*
This gets called right before the plugin manager registers your plugin.
I'm honestly not sure what you would use it for, but it seemed like a good
idea at the time.
*/
- (void)willRegister:(id<ACPluginManager>)thePluginManager;
/*
didRegister is called right after your plugin is all ready to go.
*/
- (void)didRegister;
/*
Can we handle shape layers? If yes, then our action is handed the layer instead of a CIImage
return [NSNumber numberWithBool:YES];
NSNumber is used to be friendly with scripting languages.
*/
- (NSNumber*)worksOnShapeLayers:(id)userObject;
/*
How about a more general type of "do you work on this type of layer" question:
return [NSNumber numberWithBool:YES];
NSNumber is used to be friendly with scripting languages.
Added in version 3.5
*/
- (NSNumber*)validateForLayer:(id<ACLayer>)layer;
@end
@protocol ACLayer <NSObject>
/* There are currently three types of layers. "Bitmap" layers which contain pixels,
and "Shape" layers which contain Text. And then Group layers, which is a group of layers.
And maybe other things eventually.
Check out the ACLayerType enum for the constants to tell which is which.
*/
- (int)layerType;
// grab a CIImage representation of the layer.
- (CIImage*)CIImage;
// grab a CIImage representation of the layer, with opacity, layer styles, mask, and other such things applied to it.
// Added in 4.0
- (CIImage*)renderedCIImage;
// opaqueBounds returns the bounds of the image, not counting any 100% transparent pixels along the edges. If you have a layer style that expands the image size (such as a drop shadow) this is not included in this calculation.
// Added in 3.5
- (NSRect)opaqueBounds;
// set a layer's mask with the given CIImage. If a layer mask doesn't already exist, one will be created.
// Added in 3.5
- (void)setLayerMaskImage:(CIImage*)ciimage;
// similar to setLayerMaskImage, the following two methods will set the mask of a layer with a URL or a path to an image.
// Added in 3.5
- (void)setLayerMaskWithImageAtURL:(NSURL*)url;
- (void)setLayerMaskWithImageAtPath:(NSString*)path;
// Get the layer mask (if it exists already). Note that this returns an ACMaskLayer, not a CIImage
// Added in 3.5
- (id <ACMaskLayer>)mask;
// Added in 3.5
- (BOOL)maskIsLinked;
// Added in 3.5
- (void)setMaskIsLinked:(BOOL)value;
// Added in 4.5 - just adds an empty mask, or one based on the current selection.
- (void)addMask;
@property (assign) BOOL visible;
@property (assign) float opacity;
@property (assign) CGBlendMode compositingMode; // aka, also the blend mode.
@property (retain, nonatomic) NSString *layerName;
@end
@protocol ACShapeLayer <ACLayer>
- (NSArray *)selectedGraphics;
- (NSArray *)graphics;
- (id)addRectangleWithBounds:(NSRect)bounds;
- (id)addOvalWithBounds:(NSRect)bounds;
- (id)addTextWithBounds:(NSRect)bounds;
/* added in 3.2.2 */
- (id)addBezierPath:(NSBezierPath*)path;
/* added in 5.2 */
- (void)moveGraphic:(id)graphic toIndex:(NSUInteger)newIndex;
@end
@protocol ACBitmapLayer <ACLayer>
// set a CIImage on the layer, to be a "preview". Make sure to set it to nil when you are
// done with whatever it is you are doing.
- (void)setPreviewCIImage:(CIImage*)img;
// apply a ciimage to the layer.
- (void)applyCIImageFromFilter:(CIImage*)img;
- (void)applyCIImageFromFilter:(CIImage*)img shouldClipToSelection:(BOOL)clipToSelection;
// get a CGBitmapContext that we can draw on.
- (CGContextRef)drawableContext;
// commit the changes we made to the context, for undo support
- (void)commitFrameOfDrawableContext:(NSRect)r;
// find out where on our layer the current mouse event is pointing to
- (NSPoint)layerPointFromEvent:(NSEvent*)theEvent;
// tell the layer it needs to be updated
- (void)setNeedsDisplayInRect:(NSRect)invalidRect;
// what the origin of the bottom left corner of the layer is. It's a silly name, which is why I've added setFrameOrigin: and frameOrigin below.
@property (assign) NSPoint drawDelta;
// same as drawDelta, but with a better name.
- (void)setFrameOrigin:(NSPoint)newOrigin;
- (NSPoint)frameOrigin;
@end
@protocol ACGroupLayer <ACLayer>
- (NSArray *)layers;
- (void)addLayer:(id<ACLayer>)l atIndex:(NSInteger)idx;
- (id<ACBitmapLayer>)insertCGImage:(CGImageRef)img atIndex:(NSUInteger)idx withName:(NSString*)layerName;
// Added in Acorn 5.0.1
- (id<ACBitmapLayer>)insertImageWithPath:(NSString*)path atIndex:(NSUInteger)idx withName:(NSString*)layerName;
- (id<ACShapeLayer>)addShapeLayer;
- (id<ACBitmapLayer>)addBitmapLayer;
- (id<ACGroupLayer>)addGroupLayer;
@end
@protocol ACMaskLayer <ACBitmapLayer>
@end
@protocol ACGraphic <NSObject>
- (int)graphicType;
- (void)setDrawsFill:(BOOL)flag;
- (BOOL)drawsFill;
- (void)setFillColor:(NSColor *)fillColor;
- (NSColor *)fillColor;
- (void)setDrawsStroke:(BOOL)flag;
- (BOOL)drawsStroke;
- (void)setStrokeColor:(NSColor *)strokeColor;
- (NSColor *)strokeColor;
- (void)setStrokeWidth:(CGFloat)width;
- (CGFloat)strokeWidth;
- (NSRect)bounds;
- (BOOL)hasCornerRadius;
- (void)setHasCornerRadius:(BOOL)flag;
- (CGFloat)cornerRadius;
- (void)setCornerRadius:(CGFloat)newCornerRadius;
- (BOOL)hasShadow;
- (void)setHasShadow:(BOOL)flag;
- (CGFloat)shadowBlurRadius;
- (void)setShadowBlurRadius:(CGFloat)newShadowBlurRadius;
- (NSSize)shadowOffset;
- (void)setShadowOffset:(NSSize)newShadowOffset;
- (NSBezierPath *)bezierPath;
- (void)scaleXBy:(CGFloat)xScale yBy:(CGFloat)yScale;
@end
@protocol ACTextGraphic <ACGraphic>
// added in 3.0.1
- (void)setHTMLString:(NSString*)html;
// added in 5.0.1
- (void)setString:(NSString*)s;
@end
@protocol ACDocument <NSObject> // this inherits from NSDocument
// grab an array of layers in the document.
- (NSArray*)layers;
// grab the current layer.
- (id<ACLayer>)currentLayer;
// crop to the given rect.
- (void)cropToRect:(NSRect)cropRect;
// start cropping with the given bounds.
- (void)beginCroppingWithRect:(NSRect)cropBounds;
// scale the image to the given size.
- (void)scaleImageToSize:(NSSize)newSize;
- (void)scaleImageToHeight:(CGFloat)newHeight;
- (void)scaleImageToWidth:(CGFloat)newWidth;
- (void)scaleImageWithPercentage:(CGFloat)a; // new in 5.1.1.
// resize the image to the given size.
- (void)resizeImageToSize:(NSSize)newSize;
// find the size of the canvas
- (NSSize)canvasSize;
- (void)setCanvasSize:(NSSize)s;
- (void)setCanvasSize:(NSSize)newSize usingAnchor:(NSString *)anchor;
// new in 2.0
// returns the base group, which contains all the base layers.
- (id<ACGroupLayer>)baseGroup;
- (NSSize)dpi;
- (void)setDpi:(NSSize)newDpi;
- (CGColorSpaceRef)colorSpace;
// new in 2.2:
- (void)askToCommitCurrentAccessory;
// new in 3.3:
- (id<ACLayer>)firstLayerWithName:(NSString*)layerName;
// new in 5.0: returns a composite of all the layers.
- (CIImage *)CIImage;
// new in 5.0: write to a file.
- (BOOL)writeToFile:(NSString*)path withUTI:(NSString*)uti;
// new in 5.6.5
// set the bits per _pixel_ for the document. The only correct values here are 32, 64, and 128.
- (void)setBitsPerPixel:(size_t)bitsPerPixel;
// new in 5.6.5
// Get the number of bits per pixel. Since Acorn 5 only works 4 color components (rgba), you can divide this value by 4 to get the number of channels.
- (size_t)bitsPerPixel;
// new in 5.6.5
// Acorn 5 will always return 4 here. But why not have this here for future proofing?
- (size_t)numberOfComponents;
// new in 5.6.5
- (CGImageRef)newCGImage __attribute__((cf_returns_retained));
@end
@protocol ACToolPalette <NSObject>
- (NSColor *)frontColor;
- (void)setFrontColor:(NSColor *)newFrontColor;
- (NSColor *)backColor;
- (void)setBackColor:(NSColor *)newBackColor;
@end
@protocol ACImageIOProvider <NSObject>
- (BOOL)writeDocument:(id<ACDocument>)document toURL:(NSURL *)absoluteURL ofType:(NSString *)type forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError;
- (BOOL)readImageForDocument:(id<ACDocument>)document fromURL:(NSURL *)absoluteURL ofType:(NSString *)type error:(NSError **)outError;
@end
@protocol ACUtilities <NSObject>
- (BOOL)crushPNGData:(NSData*)pngData toPath:(NSString*)path;
@end
@interface NSApplication (AcornAdditions)
- (id<ACToolPalette>)toolPalette;
- (id<ACUtilities>)utilitiesHelper;
@end
// This guy is a nice little helper for drawing to a bitmap for use later on.
#ifndef FMDrawContextAvailable
@interface FMDrawContext : NSObject
+ (id)drawContextWithSize:(NSSize)s;
+ (id)drawContextWithSize:(NSSize)s scale:(CGFloat)scale;
- (CIImage*)CIImage;
- (CGImageRef)CGImage __attribute__((cf_returns_retained));
- (NSImage*)NSImage;
- (NSBitmapImageRep*)bitmapImageRep;
- (NSData*)dataOfType:(NSString*)uti;
- (void)drawInContextWithBlock:(void (^)())r;
- (CGContextRef)context;
- (void)lockFocus;
- (void)unlockFocus;
@end
#endif
/*
CTGradient is in Acorn, it's just got a different name- "TSGradient".
For more info on CTGradient, visit here:
http://blog.oofn.net/2006/01/15/gradients-in-cocoa/
You can use it like so:
id fade = [NSClassFromString(@"TSGradient") gradientWithBeginningColor:[NSColor clearColor] endingColor:[NSColor blackColor]];
*/
@interface NSObject (TSGradientTrustMeItsThere)
+ (id)gradientWithBeginningColor:(NSColor *)begin endingColor:(NSColor *)end;
- (void)fillRect:(NSRect)rect angle:(CGFloat)angle;
@end
@interface CIImage (PXNSImageAdditions)
- (NSImage *)NSImageFromRect:(CGRect)r;
- (NSImage *)NSImage;
// new in Acorn 3.5
- (BOOL)writeToURL:(NSURL*)fileURL withUTI:(NSString*)uti;
@end
@interface NSImage (PXNSImageAdditions)
- (CIImage *)CIImage;
@end
@interface NSDocumentController (ACNSDocumentControllerAdditions)
- (id)makeUntitledDocumentWithData:(NSData*)data;
- (id)makeUntitledDocumentWithSize:(NSSize)s;
@end