Re: NSTextView custom cursor
Re: NSTextView custom cursor
- Subject: Re: NSTextView custom cursor
- From: Satoshi Matsumoto <email@hidden>
- Date: Thu, 02 Mar 2006 07:10:49 +0900
- Thread-topic: NSTextView custom cursor
Dear Thierry,
on 06.03.1 9:42 PM, Thierry Passeron at email@hidden wrote:
> I would like to have a totaly different one, more like the block
> cursor of Terminal.app but different :).
> Any example that you could point me to or any advice would be truly helpful.
You can change the insertion point shape by overriding following NSTextView
method.
------
- (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor
turnedOn:(BOOL)flag
Discussion
If flag is YES, draws the insertion point in aRect using aColor. If flag is
NO, this method erases the insertion point. The focus must be locked on the
receiver when this method is invoked.
------
This is a sample code for a block shape insertion point.
- (void)drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color
turnedOn:(BOOL)flag
{
//Block Cursor
if( flag )
{
NSPoint aPoint=NSMakePoint( rect.origin.x,
rect.origin.y+rect.size.height/2);
int glyphIndex = [[self layoutManager] glyphIndexForPoint:aPoint
inTextContainer:[self textContainer]];
NSRect glyphRect = [[self layoutManager]
boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1) inTextContainer:[self
textContainer]];
[color set ];
rect.size.width =rect.size.height/2;
if(glyphRect.size.width > 0 && glyphRect.size.width <
rect.size.width) rect.size.width=glyphRect.size.width;
NSRectFillUsingOperation( rect, NSCompositePlusDarker);
}
else
{
[self setNeedsDisplayInRect:[self visibleRect]
avoidAdditionalLayout:NO];
}
}
Satoshi
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden