diff --git a/AppKit/CoreGraphics/CGPath.j b/AppKit/CoreGraphics/CGPath.j index 05d1651d8..45c5d9062 100644 --- a/AppKit/CoreGraphics/CGPath.j +++ b/AppKit/CoreGraphics/CGPath.j @@ -120,12 +120,14 @@ function CGPathAddArc(aPath, aTransform, x, y, aRadius, aStartAngle, anEndAngle, The ending point of the arc becomes the new current point of the path. */ var arcEndX = x + aRadius * COS(anEndAngle), - arcEndY = y + aRadius * SIN(anEndAngle); + arcEndY = y + aRadius * SIN(anEndAngle), + arcStartX = x + aRadius * COS(aStartAngle), + arcStartY = y + aRadius * SIN(aStartAngle); if (aPath.count) { - if (aPath.current.x !== arcEndX || aPath.current.y !== arcEndY) - CGPathAddLineToPoint(aPath, aTransform, arcEndX, arcEndY); + if (aPath.current.x !== x || aPath.current.y !== y) + CGPathAddLineToPoint(aPath, aTransform, arcStartX, arcStartY); } else { @@ -136,7 +138,7 @@ function CGPathAddArc(aPath, aTransform, x, y, aRadius, aStartAngle, anEndAngle, } aPath.current = CGPointMake(arcEndX, arcEndY); - aPath.elements[aPath.count++] = { type:kCGPathElementAddArc, x:x, y:y, radius:aRadius, startAngle:aStartAngle, endAngle:anEndAngle, clockwise:isClockwise }; + aPath.elements[aPath.count++] = { type:kCGPathElementAddArc, x:x, y:y, radius:aRadius, startAngle:aStartAngle, endAngle:anEndAngle, isClockwise:isClockwise }; } function CGPathAddArcToPoint(aPath, aTransform, x1, y1, x2, y2, aRadius) @@ -233,7 +235,7 @@ function CGPathAddPath(aPath, aTransform, anotherPath) case kCGPathElementAddArc: CGPathAddArc(aPath, aTransform, element.x, element.y, element.radius, element.startAngle, - element.endAngle, element.clockwise); + element.endAngle, element.isClockwise); break; case kCGPathElementAddArcToPoint: @@ -438,7 +440,7 @@ function CGPathEqualToPath(aPath, anotherPath) element.radius !== anotherElement.radius || element.startAngle !== anotherElement.startAngle || element.endAngle !== anotherElement.endAngle || - element.clockwise !== anotherElement.clockwise) + element.isClockwise !== anotherElement.isClockwise) { return NO; } @@ -608,7 +610,23 @@ function CGPathGetBoundingBox(aPath) return CGRectMake(ox, oy, rx - ox, ry - oy); } +function CGPathContainsPoint(aPath, aTransform, point, eoFill) +{ + if (!aPath.count) + return NO; + + if (aTransform) + point = CGPointApplyAffineTransform(point, aTransform); + + var context = CGBitmapGraphicsContextCreate(); + + CGContextBeginPath(context); + CGContextAddPath(context, aPath); + CGContextClosePath(context); + + return context.isPointInPath(point.x, point.y); +} + /*! @} -*/ - +*/ \ No newline at end of file diff --git a/Tests/Manual/CGPath/AppController.j b/Tests/Manual/CGPath/AppController.j new file mode 100644 index 000000000..2d2ef9cbb --- /dev/null +++ b/Tests/Manual/CGPath/AppController.j @@ -0,0 +1,130 @@ +/* + * AppController.j + * CGPath + * + * Created by You on May 23, 2013. + * Copyright 2013, Your Company All rights reserved. + */ + +@import +@import + +@implementation AppController : CPObject +{ +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], + contentView = [theWindow contentView]; + + var pathView = [[PathView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)]; + [contentView addSubview:pathView]; + + var pathMouseOverView = [[PathMouseOverView alloc] initWithFrame:CGRectMake(500.0, 0.0, 500.0, 500.0)]; + [contentView addSubview:pathMouseOverView]; + + [theWindow orderFront:self]; +} + +@end + +@implementation PathMouseOverView : CPView +{ + id path1; + id path2; + id path3; +} + +- (void)drawRect:(CGRect)aRect +{ + [super drawRect:aRect]; + + var context = [[CPGraphicsContext currentContext] graphicsPort]; + + CGContextBeginPath(context); + path1 = CGPathCreateMutable(); + CGPathMoveToPoint(path1, nil, 100, 100); + CGPathAddLineToPoint(path1, nil, 150, 50); + CGPathAddLineToPoint(path1, nil, 200, 100); + CGContextAddPath(context, path1); + CGContextClosePath(context); + CGContextStrokePath(context); + + CGContextBeginPath(context); + path2 = CGPathCreateMutable(); + CGPathAddRect( path2, nil, CGRectMake(250, 50, 100, 100)); + CGContextAddPath(context, path2); + CGContextClosePath(context); + CGContextStrokePath(context); + + CGContextBeginPath(context); + path3 = CGPathWithEllipseInRect( CGRectMake(100, 150, 100, 100)) + CGContextAddPath(context, path3); + CGContextClosePath(context); + CGContextStrokePath(context); +} + +- (void)mouseMoved:(CPEvent)anEvent +{ + var location = [self convertPointFromBase:[anEvent locationInWindow]], + context = CGBitmapGraphicsContextCreate(); + + if (CGPathContainsPoint(path1, nil, location, nil)) + console.log("Mouse is in the triangle"); + + if (CGPathContainsPoint(path2, nil, location, nil)) + console.log("Mouse is in rectangle"); + + if (CGPathContainsPoint(path3, nil, location, nil)) + console.log("Mouse is in the circle"); +} + +@end + + + +@implementation PathView : CPView +{ + +} + +- (void)drawRect:(CGRect)aRect +{ + [super drawRect:aRect]; + + var context = [[CPGraphicsContext currentContext] graphicsPort]; + + // Test to create a pie chart + CGContextBeginPath(context); + var path = CGPathCreateMutable(); + CGPathMoveToPoint(path, nil, 100, 100); + CGPathAddArc(path, nil,100, 100, 70, 0, 2.615500255957057, YES); + CGPathAddLineToPoint(path, nil, 100, 100); + CGPathAddArc(path, nil,100, 100, 70, 2.615500255957057, 6.148960361810042, YES); + CGPathAddLineToPoint(path, nil, 100, 100); + CGPathAddArc(path, nil,100, 100, 70, 6.148960361810042, 0, YES); + CGPathAddLineToPoint(path, nil, 100, 100); + CGContextAddPath(context, path); + CGContextStrokePath(context); + CGContextClosePath(context); + + // Test to create an arc without a start point + CGContextBeginPath(context); + path = CGPathCreateMutable(); + CGPathAddArc(path, nil,300, 100, 70, 0, 2.615500255957057, YES); + CGContextAddPath(context, path); + CGContextStrokePath(context); + CGContextClosePath(context); + + // Test to create an arc with a start point + CGContextBeginPath(context); + path = CGPathCreateMutable(); + CGPathMoveToPoint(path, nil, 100, 250); + CGPathAddArc(path, nil,100, 300, 70, 0, 2.615500255957057, YES); + CGContextAddPath(context, path); + CGContextStrokePath(context); + CGContextClosePath(context); +} + +@end diff --git a/Tests/Manual/CGPath/Info.plist b/Tests/Manual/CGPath/Info.plist new file mode 100644 index 000000000..48b1a0402 --- /dev/null +++ b/Tests/Manual/CGPath/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + CGPath + CPPrincipalClass + CPApplication + + diff --git a/Tests/Manual/CGPath/Jakefile b/Tests/Manual/CGPath/Jakefile new file mode 100644 index 000000000..6d194c99d --- /dev/null +++ b/Tests/Manual/CGPath/Jakefile @@ -0,0 +1,98 @@ +/* + * Jakefile + * CGPath + * + * Created by You on May 23, 2013. + * Copyright 2013, Your Company All rights reserved. + */ + +var ENV = require("system").env, + FILE = require("file"), + JAKE = require("jake"), + task = JAKE.task, + FileList = JAKE.FileList, + app = require("cappuccino/jake").app, + configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug", + OS = require("os"); + +app ("CGPath", function(task) +{ + ENV["OBJJ_INCLUDE_PATHS"] = "Frameworks"; + + if (configuration === "Debug") + ENV["OBJJ_INCLUDE_PATHS"] = FILE.join(ENV["OBJJ_INCLUDE_PATHS"], configuration); + + task.setBuildIntermediatesPath(FILE.join("Build", "CGPath.build", configuration)); + task.setBuildPath(FILE.join("Build", configuration)); + + task.setProductName("CGPath"); + task.setIdentifier("com.yourcompany.CGPath"); + task.setVersion("1.0"); + task.setAuthor("Your Company"); + task.setEmail("feedback @nospam@ yourcompany.com"); + task.setSummary("CGPath"); + task.setSources(new FileList("**/*.j").exclude(FILE.join("Build", "**")).exclude(FILE.join("Frameworks", "Source", "**"))); + task.setResources(new FileList("Resources/**")); + task.setIndexFilePath("index.html"); + task.setInfoPlistPath("Info.plist"); + + if (configuration === "Debug") + task.setCompilerFlags("-DDEBUG -g"); + else + task.setCompilerFlags("-O"); +}); + +task ("default", ["CGPath"], function() +{ + printResults(configuration); +}); + +task ("build", ["default"]); + +task ("debug", function() +{ + ENV["CONFIGURATION"] = "Debug"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("release", function() +{ + ENV["CONFIGURATION"] = "Release"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("run", ["debug"], function() +{ + OS.system(["open", FILE.join("Build", "Debug", "CGPath", "index.html")]); +}); + +task ("run-release", ["release"], function() +{ + OS.system(["open", FILE.join("Build", "Release", "CGPath", "index.html")]); +}); + +task ("deploy", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Deployment", "CGPath")); + OS.system(["press", "-f", FILE.join("Build", "Release", "CGPath"), FILE.join("Build", "Deployment", "CGPath")]); + printResults("Deployment") +}); + +task ("desktop", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Desktop", "CGPath")); + require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CGPath"), FILE.join("Build", "Desktop", "CGPath", "CGPath.app")); + printResults("Desktop") +}); + +task ("run-desktop", ["desktop"], function() +{ + OS.system([FILE.join("Build", "Desktop", "CGPath", "CGPath.app", "Contents", "MacOS", "NativeHost"), "-i"]); +}); + +function printResults(configuration) +{ + print("----------------------------"); + print(configuration+" app built at path: "+FILE.join("Build", configuration, "CGPath")); + print("----------------------------"); +} diff --git a/Tests/Manual/CGPath/Resources/spinner.gif b/Tests/Manual/CGPath/Resources/spinner.gif new file mode 100644 index 000000000..a5e705f6c Binary files /dev/null and b/Tests/Manual/CGPath/Resources/spinner.gif differ diff --git a/Tests/Manual/CGPath/index-debug.html b/Tests/Manual/CGPath/index-debug.html new file mode 100644 index 000000000..80c7219c9 --- /dev/null +++ b/Tests/Manual/CGPath/index-debug.html @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + CGPath + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + diff --git a/Tests/Manual/CGPath/index.html b/Tests/Manual/CGPath/index.html new file mode 100644 index 000000000..1fa069702 --- /dev/null +++ b/Tests/Manual/CGPath/index.html @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + CGPath + + + + + + + + + + + + +
+
+ + + +
+
+ + + + diff --git a/Tests/Manual/CGPath/main.j b/Tests/Manual/CGPath/main.j new file mode 100644 index 000000000..a7bb6a144 --- /dev/null +++ b/Tests/Manual/CGPath/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * CGPath + * + * Created by You on May 23, 2013. + * Copyright 2013, Your Company All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +}