NSBezierPath clipped by subviews of an NSView?
NSBezierPath clipped by subviews of an NSView?
- Subject: NSBezierPath clipped by subviews of an NSView?
- From: Keith Blount <email@hidden>
- Date: Thu, 23 Sep 2004 16:40:10 -0700 (PDT)
Hello,
I have set up a custom view by subclassing NSView, and
have drawn a frame around this view using
NSBezierPath, but am getting some strange problems and
would be very grateful for any advice.
The situation is this:
I have an NSView subclass. In its initWithFrame
method, I create a scroll view and set it as a subview
of the NSView. This is the same size as the frameRect
passed into the initWithFrame method, but adjusted so
that there is a 1 pixel border all around it to allow
for my custom border, and a 25 pixel gap on the right.
An NSImageView is set up as the document view of the
scrollview. A split view is set up as another subview
of the NSView, placed to the right of the scrollview.
In drawRect:, I use NSBezierPath's
strokeLineFromPoint:toPoint: to draw lines all around
the border of my view. I am trying to achieve a
similar look the bezel border that you can place
around a scroll view.
So far, so good. However, when I resize the view, the
slider - which is locked to the top right - clips the
border I have drawn. It's really odd. So the bottom
line, for instance, will stretch all the way from the
left to the right until it reaches the slider. Then it
stops and starts again on the other side of the
slider.
I am drawing the NSBezierPath line right at the end of
drawRect:, so I have no idea of why these lines drawn
in the view don't override and get drawn over the
view's subviews.
Can somebody please point me in the right direction to
solve this problem?
In case it helps, I have included my drawRect: method
below.
Many thanks in advance for any pointers,
Keith
- (void)drawRect:(NSRect)rect
{
// Paint the background - ie. the strip containing
the slider - grey
[[NSColor lightGrayColor] set];
[NSBezierPath fillRect:rect];
// Set the size of the image view
// Width and height will be either the same as the
image or the same as the scroll view content view -
whichever is bigger
NSSize imageSize, viewSize, setSize;
imageSize = [image size];
viewSize = [[scrollView contentView] frame].size;
setSize.width = (imageSize.width >= viewSize.width) ?
imageSize.width : viewSize.width;
setSize.height = (imageSize.height >=
viewSize.height) ? imageSize.height : viewSize.height;
[imageView setFrame:NSMakeRect(0.0, 0.0,
setSize.width, setSize.height)];
// Draw a frame around the view that is a bit like
the bezel border but fits in with the custom
header-style split view
NSPoint a, b;
NSRect bounds = [self bounds];
[NSBezierPath setDefaultLineWidth:1.0];
[scrollView
setFrame:NSMakeRect(bounds.origin.x+1.0,bounds.origin.y+1.0,bounds.size.width-25.0,bounds.size.height-2.0)];
/*
NSRect sliderRect;
sliderRect.origin.x = bounds.size.width - 23.0; //
Because side bar is 25 pixesl and slider width is 21 -
thus centred
sliderRect.origin.y = bounds.size.height - 120.0 -
[zoomIcon bounds].size.height;
sliderRect.size.width = 21.0;
sliderRect.size.height = 50.0;
[slider setFrame:sliderRect];
*/
// VERTICAL LINES (light grey)
a.x = bounds.origin.x + 0.5; // lines have to be
drawn on the 0.5 (centred on pixel)
a.y = bounds.origin.y;
b.x = a.x;
b.y = bounds.origin.y + bounds.size.height;
[[NSColor lightGrayColor] set];
[NSBezierPath strokeLineFromPoint:a toPoint:b]; //
Left
a.x = bounds.origin.x + bounds.size.width - 1.0;
b.x = a.x;
[NSBezierPath strokeLineFromPoint:a toPoint:b]; //
Right
// HORIZONTAL LINES (dark grey matching bezel frame
colours)
a.x = bounds.origin.x;
a.y = bounds.origin.y + 0.5;
b.x = bounds.origin.x + bounds.size.width;
b.y = a.y;
[[NSColor blackColor] set];
//[[NSColor colorWithCalibratedRed:(160.0/255.0)
green:(160.0/255.0) blue:(160.0/255.0) alpha:1.0]
set];
[NSBezierPath strokeLineFromPoint:a toPoint:b]; //
Top
a.y = bounds.origin.y + bounds.size.height - 0.5;
b.y = a.y;
[NSBezierPath strokeLineFromPoint:a toPoint:b]; //
Bottom
[slider setNeedsDisplay:NO];
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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