Re: Quartz 2D drawing problems
Re: Quartz 2D drawing problems
- Subject: Re: Quartz 2D drawing problems
- From: Michael Schmidt <email@hidden>
- Date: Thu, 13 Nov 2003 08:34:40 +0100
- Organization: AbsInt GmbH
On Tue, 11 Nov 2003 14:23:32 -0800
John Randolph <email@hidden> wrote:
>
There's not enough information here for anyone to help you. Show us
>
the code.
Ok, I figured out a minimum example. I've done the following steps:
- created a new cocoa-application project in Xcode
- created a subclass of NSView
- put a custom view of this class into the app window
The drawRect function of my NSView subclass looks like this:
static float BlackColor[] = { 0.0, 0.0, 0.0, 1.0 };
static float BlueColor[] = { 0.4, 0.4, 0.8, 1.0 };
- (void)drawRect:(NSRect)rect
{
CGContextRef cg_ctx;
CGColorSpaceRef cg_space;
CGRect cg_rect;
cg_ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
cg_space = CGColorSpaceCreateDeviceRGB ();
CGContextSetFillColorSpace (cg_ctx, cg_space);
CGContextSetStrokeColorSpace (cg_ctx, cg_space);
// (1) stroke a line
CGContextSetLineWidth(cg_ctx, 1.0);
CGContextSetStrokeColor (cg_ctx, BlackColor);
CGContextBeginPath(cg_ctx);
CGContextMoveToPoint (cg_ctx, 104.5, 155.5);
CGContextAddLineToPoint(cg_ctx, 104.5, 164.5);
CGContextAddLineToPoint(cg_ctx, 120.5, 164.5);
CGContextAddLineToPoint(cg_ctx, 120.5, 173.5);
CGContextStrokePath(cg_ctx);
// (2) fill and stroke a rectangle
cg_rect.origin.x = 137.5;
cg_rect.origin.y = 169.5;
cg_rect.size.width = 21.0;
cg_rect.size.height = 7.0;
CGContextSetFillColor (cg_ctx, BlueColor);
CGContextSetStrokeColor (cg_ctx, BlueColor);
CGContextFillRect (cg_ctx, cg_rect);
CGContextStrokeRect (cg_ctx, cg_rect);
}
A screenshot of the window can be found here:
http://www.absint.com/cocoa/result.jpg
One can see a small blue line from the beginning to the end of the path
defined in (1). This line is drawn when the FillRect function is called.
My system is an iBook late 2001 (no QE), OS X 10.3.1
--
Michael Schmidt
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.