Hi all,
I'm adding ruler markers to a horizontal ruler view, and setting the client of
the ruler to my custom view. When I drag the ruler markers, the client view
receives the client messages as documented.
What I want to do is move a vertical line in my view as the marker moves. So,
when I get the 'willmove' message, I invalidate the old and new locations. My
drawRect method then should draw the lines based on the list of markers. While
I see my -drawRect method getting called, and know it draws the right thing in
the normal case, during marker dragging nothing happens (i.e. the old line is
never erased and the new line never drawn).
The standard NSRulerMarker draws a black line in the client view as it is
dragged. This comes 'for free' but I wonder how on earth it works. There is
also no way to customise it that I can see. I'm wondering if this behaviour is
interfering with view updates in my client view, but since it's not mentioned
in the documentation I can only speculate. It seems to me NSRulerMarker is set
up for its use in NSTextView and though the design seems to be fine for the
more general case, in actual use the extra undocumented behaviours baked into
it for use in a text view make it hard to use and not work as documented.
So, simple question: how can I keep an associated line in my client view moving
as I drag a ruler marker?
relevant parts of the code:
- (CGFloat) rulerView:(NSRulerView*) aRulerView
willMoveMarker:(NSRulerMarker*) aMarker toLocation:(CGFloat) location
{
CGFloat oldLocation = [aMarker markerLocation];
// update the view where the old marker line was drawn
NSRect br = [self bounds];
br.origin.x = oldLocation - 1.0;
br.size.width = 2.0;
[self setNeedsDisplayInRect:br];
return location;
}
- (void) awakeFromNib
{
NSScrollView* sv = [self enclosingScrollView];
[sv setHasHorizontalRuler:YES];
NSRulerView* rv = [[self enclosingScrollView] horizontalRulerView];
[rv setClientView:self];
[sv setRulersVisible:YES];
// set up a ruler marker to represent events
[self addEventMarkerAtTime:1.0 forKey:@"One Second"]; // creates
NSRulerMarker and adds it to ruler view
}
// called within -drawRect: method of the view after erasing to the background
colour
- (void) drawEventMarkers
{
NSArray* markers = [[[self enclosingScrollView] horizontalRulerView]
markers];
for( NSRulerMarker* marker in markers )
[self drawEventMarker:marker];
}
- (void) drawEventMarker:(NSRulerMarker*) marker
{
CGFloat pos = [marker markerLocation];
NSPoint a, b;
NSRect br = [self bounds];
a.x = b.x = pos;
a.y = NSMinY( br );
b.y = NSMaxY( br );
[NSBezierPath setDefaultLineWidth:0.75];
[[NSColor yellowColor] set];
[NSBezierPath strokeLineFromPoint:a toPoint:b];
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]