Re: Setting the origin of a GC
Re: Setting the origin of a GC
- Subject: Re: Setting the origin of a GC
- From: Jim Crafton <email@hidden>
- Date: Sun, 6 Jul 2003 18:31:45 -0400
On Sunday, July 6, 2003, at 06:00 PM, Alastair J.Houghton wrote:
>
On Sunday, July 6, 2003, at 10:13 pm, Jim Crafton wrote:
>
>
> I notice that when drawing in Cocoa (or Quartz for that matter) the
>
> origin is set to bottom left (0,0). Somewhere I read, but I can't
>
> remember now, that there is an easy way to set it to be top, left. Is
>
> this true? If it is not, what is the best way to accomplish this?
>
> (Any samples of this would be great!)
>
>
The normal way to do this is to have your NSView subclass return YES
>
in response to an isFlipped message. Since you're working outside of
>
the normal view architecture, the right way to do it in your case
>
would probably be to apply an NSAffineTransform to the graphics
>
context; you probably want to do:
>
>
NSAffineTransform *myTransform = [[NSAffineTransform transform]
>
scaleXBy:1.0 yBy:-1.0];
>
OK well I tried this, but unfortunately I don't see anything. Here's
how my code looks (using the VCF)
called from within a NSView's drawRect() method:
NSGraphicsContext* current = [NSGraphicsContext currentContext];
GraphicsContext ctx( (VCF::ulong32)current );
ctx.setStrokeWidth( 5 );
ctx.setColor( &Color(1.0, 1.0, 0.0) );
ctx.moveTo( 23, 34 );
ctx.lineTo( 200, 200 );
ctx.strokePath();
under the hood in strokePath(), in my code invokes the OSX peers
methods to set things up and apply the xfrm as you suggested. However
this xfrm will just make positive coordinates negative, correct? So the
points 23,34 and 200, 200,
become 23,-34 and 200,-200. Which means that they are offscreen! (I
think, my cartesion coordinate math may be rusty :) )
I think what I really want is to have to have the y coordinates altered
to
y = [view bounds].size.height - y;
Is there a way to get the View associate with a NSGraphicsContext, or
is there a way to determine the current "viewable" area for the NSGC?
>
>
You might also want to take account of the fact that co-ordinates fall
>
on the grid *between pixels* (at least by default); by default Quartz
>
will quite happily draw a two pixel wide line (50% in each side) if
>
asked to render a one pixel wide line at integer co-ordinates. This
>
is typically not what people expect if they're used to other systems,
>
and to fix it you need to translate the co-ordinate system by 0.5
>
pixels in each direction (to line the grid up with the centres of the
>
pixels).
OK this is good to know - I'll make sure to account for this.
Cheers
Jim
_______________________________________________
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.