From b6feecae70758bbe2784c75fdf747d27c83aa3c4 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Tue, 19 Feb 2013 12:06:48 -0500 Subject: [PATCH 1/3] minor optimization so that newObject and includedKeys use the same code --- AppKit/CPDictionaryController.j | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/AppKit/CPDictionaryController.j b/AppKit/CPDictionaryController.j index 7475424b7..b22125735 100644 --- a/AppKit/CPDictionaryController.j +++ b/AppKit/CPDictionaryController.j @@ -57,13 +57,20 @@ while ([keys containsObject:newKey]) newKey = [CPString stringWithFormat:@"%@%i", _initialKey, ++count]; - [_contentDictionary setObject:_initialValue forKey:newKey]; + return [self _newObjectWithKey:newKey value:_initialValue]; +} - var keyValuePairProtocol = [_CPDictionaryControllerKeyValuePair new]; - keyValuePairProtocol._key = newKey; - keyValuePairProtocol._dictionary = _contentDictionary; - keyValuePairProtocol._controller = self; - return keyValuePairProtocol; +- (id)_newObjectWithKey:(CPString)aKey value:(id)aValue +{ + var aNewObject = [_CPDictionaryControllerKeyValuePair new]; + + aNewObject._dictionary = _contentDictionary; + aNewObject._controller = self; + aNewObject._key = aKey; + if (aValue !== nil) + [aNewObject setValue:aValue]; + + return aNewObject } - (CPDictionary)contentDictionary @@ -90,21 +97,13 @@ obj; while ((obj = [iter nextObject]) !== nil) - { if (![_excludedKeys containsObject:obj]) - { - var keyValuePairProtocol = [_CPDictionaryControllerKeyValuePair new]; - keyValuePairProtocol._key = obj; - keyValuePairProtocol._dictionary = _contentDictionary; - keyValuePairProtocol._controller = self; - [array addObject:keyValuePairProtocol]; - } - } + [array addObject:[self _newObjectWithKey:obj value:nil]]; + [super setContent:array]; } - @end @@ -138,6 +137,9 @@ var CPIncludedKeys = @"CPIncludedKeys", @end + + + @implementation _CPDictionaryControllerKeyValuePair : CPObject { CPString _key @accessors(property=key); From a774e52988e0b9f22f0093eff16a220f503444b0 Mon Sep 17 00:00:00 2001 From: Adam Radabaugh Date: Tue, 19 Feb 2013 14:10:39 -0700 Subject: [PATCH 2/3] Fixes formatting and style for missing CGCanvasContext functions. Adds CGCanvasContext test. --- AppKit/CoreGraphics/CGContext.j | 17 +++ AppKit/CoreGraphics/CGContextCanvas.j | 41 ++++--- AppKit/CoreGraphics/CGPath.j | 10 +- Tests/Manual/CGCanvasContext/AppController.j | 84 ++++++++++++++ Tests/Manual/CGCanvasContext/Info.plist | 12 ++ Tests/Manual/CGCanvasContext/Jakefile | 93 +++++++++++++++ .../CGCanvasContext/Resources/spinner.gif | Bin 0 -> 1434 bytes Tests/Manual/CGCanvasContext/index-debug.html | 107 ++++++++++++++++++ Tests/Manual/CGCanvasContext/index.html | 78 +++++++++++++ Tests/Manual/CGCanvasContext/main.j | 18 +++ 10 files changed, 441 insertions(+), 19 deletions(-) create mode 100644 Tests/Manual/CGCanvasContext/AppController.j create mode 100644 Tests/Manual/CGCanvasContext/Info.plist create mode 100644 Tests/Manual/CGCanvasContext/Jakefile create mode 100644 Tests/Manual/CGCanvasContext/Resources/spinner.gif create mode 100644 Tests/Manual/CGCanvasContext/index-debug.html create mode 100644 Tests/Manual/CGCanvasContext/index.html create mode 100644 Tests/Manual/CGCanvasContext/main.j diff --git a/AppKit/CoreGraphics/CGContext.j b/AppKit/CoreGraphics/CGContext.j index e749a75ce..b60d38c22 100644 --- a/AppKit/CoreGraphics/CGContext.j +++ b/AppKit/CoreGraphics/CGContext.j @@ -548,6 +548,23 @@ function CGContextFillPath(aContext) CGContextClosePath(aContext); } +/*! + Strokes a rectangle with the given dimensions and the given stroke width + @param aContext the CGContext to draw into + @param aRect the CGRect indicating the bounds of the rect to be drawn + @param aWidth the width with which to stroke the rect + @return void +*/ +function CGContextStrokeRectWithWidth(aContext, aRect, aWidth) +{ + CGContextSaveGState(aContext); + + CGContextSetLineWidth(aContext, aWidth); + CGContextStrokeRect(aContext, aRect); + + CGContextRestoreGState(aContext); +} + var KAPPA = 4.0 * ((SQRT2 - 1.0) / 3.0); /*! diff --git a/AppKit/CoreGraphics/CGContextCanvas.j b/AppKit/CoreGraphics/CGContextCanvas.j index 65deeb0cc..911fa6004 100644 --- a/AppKit/CoreGraphics/CGContextCanvas.j +++ b/AppKit/CoreGraphics/CGContextCanvas.j @@ -95,6 +95,21 @@ function CGContextAddCurveToPoint(aContext, cp1x, cp1y, cp2x, cp2y, x, y) _CGContextAddCurveToPointCanvas(aContext, cp1x, cp1y, cp2x, cp2y, x, y); } +function CGContextAddLines(aContext, points, count) +{ + // implementation mirrors that of CGPathAddLines() + if (count === null || count === undefined) + count = points.length; + + if (count < 1) + return; + + _CGContextMoveToPointCanvas(aContext, points[0].x, points[0].y); + + for (var i = 1; i < count; ++i) + _CGContextAddLineToPointCanvas(aContext, points[i].x, points[i].y); +} + function CGContextAddLineToPoint(aContext, x, y) { _CGContextAddLineToPointCanvas(aContext, x, y); @@ -106,7 +121,6 @@ function CGContextAddPath(aContext, aPath) return; var elements = aPath.elements, - i = 0, count = aPath.count; @@ -140,14 +154,17 @@ function CGContextAddRect(aContext, aRect) _CGContextAddRectCanvas(aContext, aRect); } +function CGContextAddQuadCurveToPoint(aContext, cpx, cpy, x, y) +{ + _CGContextAddQuadCurveToPointCanvas(aContext, cpx, cpy, x, y); +} + function CGContextAddRects(aContext, rects, count) { - var i = 0; + if (count === null || count === undefined) + count = rects.length; - if (count === NULL) - var count = rects.length; - - for (; i < count; ++i) + for (var i = 0; i < count; ++i) { var rect = rects[i]; _CGContextAddRectCanvas(aContext, rect); @@ -192,12 +209,10 @@ function CGContextFillRect(aContext, aRect) function CGContextFillRects(aContext, rects, count) { - var i = 0; + if (count === null || count === undefined) + count = rects.length; - if (count === NULL) - var count = rects.length; - - for (; i < count; ++i) + for (var i = 0; i < count; ++i) { var rect = rects[i]; _CGContextFillRectCanvas(aContext, rect); @@ -225,8 +240,8 @@ function CGContextClipToRect(aContext, aRect) function CGContextClipToRects(aContext, rects, count) { - if (count === NULL) - var count = rects.length; + if (count === null || count === undefined) + count = rects.length; _CGContextBeginPathCanvas(aContext); CGContextAddRects(aContext, rects, count); diff --git a/AppKit/CoreGraphics/CGPath.j b/AppKit/CoreGraphics/CGPath.j index af6b7dfa9..1b0cc3f59 100644 --- a/AppKit/CoreGraphics/CGPath.j +++ b/AppKit/CoreGraphics/CGPath.j @@ -150,17 +150,15 @@ function CGPathAddCurveToPoint(aPath, aTransform, cp1x, cp1y, cp2x, cp2y, x, y) function CGPathAddLines(aPath, aTransform, points, count) { - var i = 1; + if (count === null || count === undefined) + count = points.length; - if (count === NULL) - var count = points.length; - - if (!aPath || count < 2) + if (!aPath || count < 1) return; CGPathMoveToPoint(aPath, aTransform, points[0].x, points[0].y); - for (; i < count; ++i) + for (var i = 1; i < count; ++i) CGPathAddLineToPoint(aPath, aTransform, points[i].x, points[i].y); } diff --git a/Tests/Manual/CGCanvasContext/AppController.j b/Tests/Manual/CGCanvasContext/AppController.j new file mode 100644 index 000000000..3809ee395 --- /dev/null +++ b/Tests/Manual/CGCanvasContext/AppController.j @@ -0,0 +1,84 @@ +/* + * AppController.j + * NewApplication + * + * Created by You on November 16, 2011. + * Copyright 2011, Your Company All rights reserved. + */ + +@import + + +@implementation DiamondView : CPView +{ +} + +- (void)drawRect:(CGRect)aRect +{ + [super drawRect:aRect]; + + var points = [CPArray array]; + var minX = CGRectGetMinX(aRect); + var midX = CGRectGetMidX(aRect); + var maxX = CGRectGetMaxX(aRect); + var minY = CGRectGetMinY(aRect); + var midY = CGRectGetMidY(aRect); + var maxY = CGRectGetMaxY(aRect); + var quarterX = minX + (maxX - minX)/4; + [points addObject:CGPointMake(midX, minY)]; + [points addObject:CGPointMake(maxX, midY)]; + [points addObject:CGPointMake(midX, maxY)]; + [points addObject:CGPointMake(minX, midY)]; + [points addObject:CGPointMake(midX, minY)]; + + [self lockFocus]; + var context = [[CPGraphicsContext currentContext] graphicsPort]; + CGContextSetLineWidth(context, 2); + CGContextSetStrokeColor(context, [CPColor blueColor]); + + // test CGContextAddLines + CGContextAddLines(context, points, NULL); + + // test CGContextAddQuadCurveToPoint + CGContextAddQuadCurveToPoint(context, quarterX, midY, midX, maxY); + CGContextStrokePath(context); + + // test CGContextStrokeRectWithWidth + var innerRect = CGRectInset(aRect, CGRectGetWidth(aRect)/2 - 10, CGRectGetHeight(aRect)/2 - 10); + CGContextStrokeRectWithWidth(context, innerRect, 4); + + [self unlockFocus]; +} + +@end + + +@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]; + [contentView addSubview:[[DiamondView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]]; + + [theWindow orderFront:self]; + + // Uncomment the following line to turn on the standard menu bar. + //[CPMenu setMenuBarVisible:YES]; +} + +@end diff --git a/Tests/Manual/CGCanvasContext/Info.plist b/Tests/Manual/CGCanvasContext/Info.plist new file mode 100644 index 000000000..bd379bc6f --- /dev/null +++ b/Tests/Manual/CGCanvasContext/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + cgcanvascontext + CPPrincipalClass + CPApplication + + diff --git a/Tests/Manual/CGCanvasContext/Jakefile b/Tests/Manual/CGCanvasContext/Jakefile new file mode 100644 index 000000000..efdb3534e --- /dev/null +++ b/Tests/Manual/CGCanvasContext/Jakefile @@ -0,0 +1,93 @@ +/* + * Jakefile + * cgcanvascontext + * + * Created by You on February 19, 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 ("cgcanvascontext", function(task) +{ + task.setBuildIntermediatesPath(FILE.join("Build", "cgcanvascontext.build", configuration)); + task.setBuildPath(FILE.join("Build", configuration)); + + task.setProductName("cgcanvascontext"); + task.setIdentifier("com.yourcompany.cgcanvascontext"); + task.setVersion("1.0"); + task.setAuthor("Your Company"); + task.setEmail("feedback @nospam@ yourcompany.com"); + task.setSummary("cgcanvascontext"); + task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**"))); + 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", ["cgcanvascontext"], 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", "cgcanvascontext", "index.html")]); +}); + +task ("run-release", ["release"], function() +{ + OS.system(["open", FILE.join("Build", "Release", "cgcanvascontext", "index.html")]); +}); + +task ("deploy", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Deployment", "cgcanvascontext")); + OS.system(["press", "-f", FILE.join("Build", "Release", "cgcanvascontext"), FILE.join("Build", "Deployment", "cgcanvascontext")]); + printResults("Deployment") +}); + +task ("desktop", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Desktop", "cgcanvascontext")); + require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "cgcanvascontext"), FILE.join("Build", "Desktop", "cgcanvascontext", "cgcanvascontext.app")); + printResults("Desktop") +}); + +task ("run-desktop", ["desktop"], function() +{ + OS.system([FILE.join("Build", "Desktop", "cgcanvascontext", "cgcanvascontext.app", "Contents", "MacOS", "NativeHost"), "-i"]); +}); + +function printResults(configuration) +{ + print("----------------------------"); + print(configuration+" app built at path: "+FILE.join("Build", configuration, "cgcanvascontext")); + print("----------------------------"); +} diff --git a/Tests/Manual/CGCanvasContext/Resources/spinner.gif b/Tests/Manual/CGCanvasContext/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/CGCanvasContext/index-debug.html b/Tests/Manual/CGCanvasContext/index-debug.html new file mode 100644 index 000000000..adf426ade --- /dev/null +++ b/Tests/Manual/CGCanvasContext/index-debug.html @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + cgcanvascontext + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + diff --git a/Tests/Manual/CGCanvasContext/index.html b/Tests/Manual/CGCanvasContext/index.html new file mode 100644 index 000000000..09c72f701 --- /dev/null +++ b/Tests/Manual/CGCanvasContext/index.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + cgcanvascontext + + + + + + + + + + + + +
+
+ + + +
+
+ + + + diff --git a/Tests/Manual/CGCanvasContext/main.j b/Tests/Manual/CGCanvasContext/main.j new file mode 100644 index 000000000..3b34efd13 --- /dev/null +++ b/Tests/Manual/CGCanvasContext/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * cgcanvascontext + * + * Created by You on February 19, 2013. + * Copyright 2013, Your Company All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +} From 7d8e9dfc601886e1c4043ac216c820b4e8d700cc Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Wed, 20 Feb 2013 03:00:20 -0500 Subject: [PATCH 3/3] Formatting --- AppKit/CPDictionaryController.j | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AppKit/CPDictionaryController.j b/AppKit/CPDictionaryController.j index b22125735..da885d40b 100644 --- a/AppKit/CPDictionaryController.j +++ b/AppKit/CPDictionaryController.j @@ -44,6 +44,7 @@ _initialKey = @"key"; _initialValue = @"value"; } + return self; } @@ -63,14 +64,15 @@ - (id)_newObjectWithKey:(CPString)aKey value:(id)aValue { var aNewObject = [_CPDictionaryControllerKeyValuePair new]; - + aNewObject._dictionary = _contentDictionary; aNewObject._controller = self; aNewObject._key = aKey; + if (aValue !== nil) [aNewObject setValue:aValue]; - return aNewObject + return aNewObject; } - (CPDictionary)contentDictionary @@ -95,7 +97,7 @@ var iter = [[CPSet setWithArray:allKeys] objectEnumerator], obj; - + while ((obj = [iter nextObject]) !== nil) if (![_excludedKeys containsObject:obj]) [array addObject:[self _newObjectWithKey:obj value:nil]];