Permalink
Browse files

Further refined AppleScript support; added a sample JSTalk script file

  • Loading branch information...
1 parent 3f64124 commit 4a2be77992ff87a56df44ea76b8ebd88b7abd8f7 @mattrajca mattrajca committed Jan 11, 2012
View
6 Pixel Art Core/Canvas/PXCanvas_ApplescriptAdditions.m
@@ -50,6 +50,12 @@ - (id)handleMoveLayerScriptCommand:(id)command
int atIndex = [[[command evaluatedArguments] objectForKey:@"atIndex"] intValue];
int toIndex = [[[command evaluatedArguments] objectForKey:@"toIndex"] intValue];
+ if (atIndex < 0)
+ atIndex = 0;
+
+ if (toIndex < 0)
+ toIndex = 0;
+
[self moveLayerAtIndex:atIndex toIndex:toIndex];
return nil;
View
3 Pixel Art Core/Canvas/PXCanvas_Layers.m
@@ -223,6 +223,9 @@ - (void)removeTempLayer:(PXLayer *)layer
- (void)moveLayerAtIndex:(NSUInteger)sourceIndex toIndex:(NSUInteger)targetIndex
{
+ if (sourceIndex >= [layers count])
+ sourceIndex = [layers count] - 1;
+
if (targetIndex == NSNotFound || targetIndex >= [layers count])
targetIndex = [layers count] - 1;
View
2 Pixel Art Core/Canvas/PXCanvas_Modifying.h
@@ -15,7 +15,7 @@
- (NSColor *) surfaceColorAtPoint:(NSPoint)aPoint;
- (NSColor*) colorAtPoint:(NSPoint) aPoint;
- (void)setColor:(NSColor *)aColor atPoint:(NSPoint)aPoint;
-- (void)setColor:(NSColor *)aColor atPoint:(NSPoint)aPoint onLayer:(PXLayer *)l;
+- (void)setColor:(NSColor *)aColor atPoint:(NSPoint)aPoint onLayer:(PXLayer *)layer;
- (void)setColor:(NSColor *)color atIndices:(NSArray *)indices updateIn:(NSRect)bounds;
- (void)setColor:(NSColor *)color atIndices:(NSArray *)indices updateIn:(NSRect)bounds onLayer:(PXLayer *)layer;
- (void)reduceColorsTo:(int)colors withTransparency:(BOOL)transparency matteColor:(NSColor *)matteColor;
View
20 Pixel Art Core/Canvas/PXCanvas_Modifying.m
@@ -58,14 +58,18 @@ - (NSPoint)correct:(NSPoint)aPoint
- (void)setColor:(NSColor *)color atPoint:(NSPoint)aPoint
{
- if(![self containsPoint:aPoint]) { return; }
+ if (![self containsPoint:aPoint])
+ return;
+
[self setColor:color atPoint:[self correct:aPoint] onLayer:activeLayer];
}
-- (void)setColor:(NSColor *)aColor atPoint:(NSPoint)aPoint onLayer:(PXLayer *)l
+- (void)setColor:(NSColor *)aColor atPoint:(NSPoint)aPoint onLayer:(PXLayer *)layer
{
- [self refreshPaletteDecreaseColorCount:[l colorAtPoint:aPoint] increaseColorCount:aColor];
- [l setColor:aColor atPoint:aPoint];
+ [self refreshPaletteDecreaseColorCount:[layer colorAtPoint:aPoint]
+ increaseColorCount:aColor];
+
+ [layer setColor:aColor atPoint:aPoint];
}
- (void)setColor:(NSColor *)color atIndices:(NSArray *)indices updateIn:(NSRect)bounds onLayer:(PXLayer *)layer
@@ -121,16 +125,14 @@ - (NSColor *) surfaceColorAtPoint:(NSPoint)aPoint
return [[NSColor clearColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
}
-
-- (NSColor*) colorAtPoint:(NSPoint)aPoint
+- (NSColor *)colorAtPoint:(NSPoint)aPoint
{
- if( ! [self containsPoint:aPoint] )
- return nil;
+ if (![self containsPoint:aPoint])
+ return nil;
return [activeLayer colorAtPoint:aPoint];
}
-
- (void)rotateByDegrees:(int)degrees
{
[self beginUndoGrouping];
View
34 Sample Scripts/General.jstalk
@@ -0,0 +1,34 @@
+// This script was written to test Pixen's AppleScript support
+// It should be run on a new document at least 4x4 px in size
+
+var pixen = [SBApplication applicationWithBundleIdentifier:"com.Pixen.Pixen"];
+var docs = [pixen documents];
+
+if ([docs count]) {
+ var canvas = [[docs objectAtIndex:0] canvas];
+
+ print("Width: " + [canvas width]);
+ print("Height: " + [canvas height]);
+ print("Active Layer: " + [canvas activeLayerName]);
+
+ [canvas addLayerNamed:"New Layer"];
+ print([canvas activeLayerName]); // should print 'New Layer'
+
+ [canvas removeLayerNamed:"New Layer"];
+ print([canvas activeLayerName]); // should print 'Main Layer'
+
+ [canvas addLayerNamed:"Square"];
+
+ for (var x = 0; x < 4; x++) {
+ for (var y = 0; y < 4; y++) {
+ [canvas setColorAtX:x atY:y toColor:[NSColor blueColor]];
+ }
+ }
+
+ print([canvas getColorAtX:0 atY:0]); // should be RGB 0 0 1
+
+ [canvas setActiveLayerName:"Main Layer"];
+ print([canvas getColorAtX:0 atY:0]); // should be RGB 0 0 0
+
+ [canvas moveLayerAtIndex:0 toIndex:1];
+}
View
1 Sample Scripts/README.md
@@ -0,0 +1 @@
+The JSTalk scripts in this folder utilize the Scripting Bridge API to talk to Pixen's AppleScript suite. See http://jstalk.org/ for more info.

0 comments on commit 4a2be77

Please sign in to comment.