Files
cappuccino/Tests/Manual/CGCanvasContext/AppController.j
T
Aparajita Fishman a011596231 CGContext fixes/enhancements
- NEW: Retrieve the underlying Image element from a CPImage with -image.
- NEW: You can now render any arbitrary drawing to a pattern context and use that as a fill or stroke pattern. See CGContextCreatePatternContext, CGContextSetFillPattern and CGContextSetStrokePattern. Works in all canvas-enabled browsers, including IE 9+.
- NEW: An example of using a custom rendered pattern is in Tests/Manual/PatternFillTest.
- NEW: Test if a CPImage is a single image (vs. three/nine part) with -isSingleImage.
- FIXED: With canvas, we have to track ourselves whether the context has a path or not.
- FIXED: All shapes except rects may not be added to a path with no context. If you attempt to do so, an error is logged.
- FIXED: CGPath was not setting the start and current point correctly in some cases.
- FIXED: CGContextAddPath was not moving to the path's start point at the beginning.
- FIXED: Removed superfluous CGContextClosePath commands, fixed some drawing sequences.
- FIXED: Misc. formatting.

Sorry, these changes are canvas only (including IE 9+)! I am not going to spend the time to port these fixes to VML (IE 8).
2013-02-23 13:53:20 -05:00

87 lines
2.4 KiB
Plaintext

/*
* AppController.j
* NewApplication
*
* Created by You on November 16, 2011.
* Copyright 2011, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@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
CGContextBeginPath(context);
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