Drawing an underline like the one used to indicate spelling errors?
Drawing an underline like the one used to indicate spelling errors?
- Subject: Drawing an underline like the one used to indicate spelling errors?
- From: Evan Gross <email@hidden>
- Date: Mon, 13 May 2002 03:56:21 -0400
Hi,
I'm subclassing NSLayoutManager and implementing -drawUnderlineForGlyphRange
so that I can indicate various types of errors (not just spelling) in my own
NSTextView (this is NOT a global behavior I'm after - it's specific to my
app).
Ideally, I want the underline drawn just like it's done "normally", but I'll
be underlining in various colors.
Using Pixie, I can see that the underline is 3 pixels high, dashed (well, if
it's drawn using NSBezierPath) 3 on, 1 off.
This much I can *almost* get working - for some reason I just can't get the
line drawn to be 3 pixels high - it's always 2 or 4 (specifying
setLineWidth:3.0 yields a 4 pixel high line).
But there are other details that elude me (I've touched on many parts of
Cocoa with my project, but haven't done any actual drawing of my own - all
the widgets in my app draw themselves) - but this is my first venture into
the world of NSBezierPath et. al.
Specifically, the underline drawn for spelling errors appears to have a
gradient of some sort - light red at the top, darkest in the middle,
medium-light at the bottom.
So far, I've got this:
float thePattern [2] = {3.0, 1.0};
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
[theColor set];
[thePath setLineDash:thePattern count:2 phase:0.0];
[thePath setLineWidth:3.0];
[thePath moveToPoint:theStartPt];
[thePath lineToPoint:theEndPt];
[thePath stroke];
But this looks really lame in comparison.
Also, I worry about performance a little, but I'm sure there are ways to
deal with that issue once I get the look I want.
So does anyone know the "magic incantation" to draw this type of underline?
Thanks for any insight!
Evan Gross
Rainmaker Research Inc.
_______________________________________________
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.