From b5df5f730b4bed305b337090ef96c1b0ff6a8a8a Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Thu, 23 May 2013 14:07:04 -0700 Subject: [PATCH] Fixed: CGPath is wrong when creating an arc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously when creating a CGPath with an arc, the path was wrong. It added a line when it wasn't necessary and when it was necessary it added a line to a wrong point. Now CGPath works like in cocoa (If the specified path already contains a subpath, Quartz implicitly adds a line connecting the subpath’s current point to the beginning of the arc. If the path is empty, Quartz creates a new subpath with a starting point set to the starting point of the arc.) Test app in Tests/Manual/CGPath/AppController.j --- AppKit/CoreGraphics/CGPath.j | 8 +- Tests/Manual/CGPath/AppController.j | 92 ++++++++++++++++++ Tests/Manual/CGPath/Info.plist | 12 +++ Tests/Manual/CGPath/Jakefile | 98 +++++++++++++++++++ Tests/Manual/CGPath/Resources/spinner.gif | Bin 0 -> 1434 bytes Tests/Manual/CGPath/index-debug.html | 112 ++++++++++++++++++++++ Tests/Manual/CGPath/index.html | 83 ++++++++++++++++ Tests/Manual/CGPath/main.j | 18 ++++ 8 files changed, 420 insertions(+), 3 deletions(-) create mode 100644 Tests/Manual/CGPath/AppController.j create mode 100644 Tests/Manual/CGPath/Info.plist create mode 100644 Tests/Manual/CGPath/Jakefile create mode 100644 Tests/Manual/CGPath/Resources/spinner.gif create mode 100644 Tests/Manual/CGPath/index-debug.html create mode 100644 Tests/Manual/CGPath/index.html create mode 100644 Tests/Manual/CGPath/main.j diff --git a/AppKit/CoreGraphics/CGPath.j b/AppKit/CoreGraphics/CGPath.j index 05d1651d8..eff048332 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 { diff --git a/Tests/Manual/CGPath/AppController.j b/Tests/Manual/CGPath/AppController.j new file mode 100644 index 000000000..62d683374 --- /dev/null +++ b/Tests/Manual/CGPath/AppController.j @@ -0,0 +1,92 @@ +/* + * 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 label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; + + [label setStringValue:@"Hello World!"]; + [label setFont:[CPFont boldSystemFontOfSize:24.0]]; + + [label sizeToFit]; + + [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; + [label setCenter:[contentView center]]; + + [contentView addSubview:label]; + + var pathView = [[PathView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)]; + [contentView addSubview:pathView]; + + [theWindow orderFront:self]; + + // Uncomment the following line to turn on the standard menu bar. + //[CPMenu setMenuBarVisible:YES]; +} + +@end + +@implementation PathView : CPView +{ +} + +- (id)init +{ + if(self = [super init]) + { + } + return self; +} + +- (void)drawRect:(CGRect)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 0000000000000000000000000000000000000000..a5e705f6cbdf914e5e714c35a8dfef807f19e3c2 GIT binary patch literal 1434 zcmZvbdrVVj7{t$-UNOu86#VHu^|s&3rWfwHBbPG_8{SrlB{Tv1uvvj4t6zP!)#d!Ogc zP^62J^$0+~?-ZcXXpBaq%jFsw8L`=H2?+@R02Yg-*Xw;gACBV^i3CMahr>Z667S!? zk3LDe>VLEsU;sWo$Py~o!gWuaIAnaG3Sv``&tvc+8DJO!| zt4fcbQ8tW}a&xZfgtQ9BnFYLvGG|PvCNlg&uh@Q^w9Pz}+I^hCj`vu9JQADPqdkyk zR40xycD9geUgJu1e;$L`Fpa)?Wl-2&6hO@U*KrPqK(I1H=1h?2fce}6GhhP1oBZC# z1e@gt-qFa6lZrl%s1>bdxg*W)Ebt__O(4sj6(*2X@ciUClwHH#U(NRM7XAjS z+scDZ32J*PCoslsgS~#ZlCCGo`r>S6F)Ghw5wVlqHioFaw?ucD(XoLJ0j;28oPoPV z9A}dR$0SKn>uExfkl#j09o;v$BZ909R=*p{ATNq8BJW;YduX2QMOU7$a$_L5e!G^g zpbkx5G4&FZ%7m14rTN}5YB(;x7$5XOc_hf3E|Hw$TVg)P#qf~}nOn03uqsp>UG>vi zWThIoO)-1Q#@u#O;fMC#WAf@Xj70-0g9YZ;dA$HH1fW1q=9-c>>_yA0S$7M*5?}vi z)8MU`Q%P!7sEBBnd$DrKgFQ2?O%6LpdaC%F8Pn-)EC2t=j~ zoaLamla$FX!GQqWi!%s>sj-#5SJX0IF!TP=r21Z}s)k#btN0?=I7uD9C)Gb$fZ#sm zaVq7g`LwZ%PfNpN^_N-IGLHj@AV`s#4&va7_{Hw63G6BkSGXHdogTZ%QOiRb bDpZ@qYcJKM>x%b%*HX74c8MnqfHi*u-bC?g literal 0 HcmV?d00001 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); +}