Re: Re: Bezier Path Arc Problem
Re: Re: Bezier Path Arc Problem
- Subject: Re: Re: Bezier Path Arc Problem
- From: "John Cassington" <email@hidden>
- Date: Thu, 5 Oct 2006 07:39:44 +1000
Hi here is my code
STEP 1: I create new instances of myView and insert them into the main
windows contentView. I also add a custom NSTextField which has a clear
background.
<CODE>
-(void)insertViews {
int i = 0;
for (i=0;i<[allItems count];i++) {
myView *newView = [[myView alloc]
initWithFrame:NSMakeRect(20,i*70,[mainWindow
frame].size.width-40,70)];
[myView setAutoresizingMask:NSViewWidthSizable];
[[mainWindow contentView] addSubview:myView];
[myView release];
}
myClearTextField *textField = [[myClearTextField alloc]
initWithFrame:NSMakeRect(50,[mainWindow frame].size.height -
(i*71),[mainWindow frame].size.width-40,20)];
[[mainWindow contentView] addSubview:textField];
}
</CODE>
STEP 2: The myView instances draw themselves using the following code.
This draws normally the first time. See
http://img433.imageshack.us/img433/11/picture1ca6.png
<CODE>
- (void)drawRect:(NSRect)rect
{
//erase whatever graphics were there before with clear (i have
tried using different combinations of these 3 lines, but all have the
same result)
NSEraseRect([self frame]);
[[NSColor blackColor] set];
NSRectFill([self frame]);
rect = NSInsetRect( rect, 5, 5 );
NSColor *bgColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.1];
NSRect bgRect = rect;
int minX = NSMinX(bgRect);
int midX = NSMidX(bgRect);
int maxX = NSMaxX(bgRect);
int minY = NSMinY(bgRect);
int midY = NSMidY(bgRect);
int maxY = NSMaxY(bgRect);
float radius = 10.0; // correct value to duplicate Panther's App Switcher
NSBezierPath *bgPath = [NSBezierPath bezierPath];
// Bottom edge and bottom-right curve
[bgPath moveToPoint:NSMakePoint(midX, minY)];
[bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, minY)
toPoint:NSMakePoint(maxX, midY)
radius:radius];
// Right edge and top-right curve
[bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, maxY)
toPoint:NSMakePoint(midX, maxY)
radius:radius];
// Top edge and top-left curve
[bgPath appendBezierPathWithArcFromPoint:NSMakePoint(minX, maxY)
toPoint:NSMakePoint(minX, midY)
radius:radius];
// Left edge and bottom-left curve
[bgPath appendBezierPathWithArcFromPoint:bgRect.origin
toPoint:NSMakePoint(midX, minY)
radius:radius];
[bgPath closePath];
[bgColor set];
[bgPath fill];
[bgPath setLineWidth:2.0];
[[NSColor colorWithCalibratedWhite:0.75 alpha:0.4] set];
[bgPath stroke];
}
</CODE>
STEP 3: When i drag a file onto a myView or click on the text field,
weird sections are drawn around the edges, assumingly fully
transparent. I guess that this is caused by the drawrect method being
called again. See
http://img242.imageshack.us/img242/8156/picture2dj3.png
Thanks for your help,
John
On 10/4/06, Stephen Deken <email@hidden> wrote:
I'm not sure what it is that's the problem. The lower rect looks
fine to me. How did you draw that one?
Post your entire code again please.
Stephen Deken
email@hidden
On Oct 3, 2006, at 4:25 PM, John Cassington wrote:
> ok. that worked . thank you
>
> but now when i redraw the view there are gaps in the transparency
>
> see at: http://img424.imageshack.us/img424/6128/picture1sr1.png
>
> at the moment i am using
>
> [[NSColor clearColor] set];
> NSRectFill([self frame]);
>
> to clear the view, but it makes no differency if i use nseraserect
> either
>
> any clues?
>
> john
>
> On 10/4/06, Stephen Deken <email@hidden> wrote:
>> > as you can see, the path i want is being stroked but around curves
>> > there is an added squareness?
>>
>> Your line is 10 pixels wide, but if you look at the size of the light
>> area, you can see that it's only five pixels wide. The 'added
>> squareness' is the rest of the stroke which is being drawn in the
>> area
>> that isn't clipped away by the graphics context.
>>
>> You need to offset the rect before you calculate your path.
>> Something
>> like this will work:
>>
>> rect = NSInsetRect( rect, 5, 5 );
>>
>> That will make the situation more clear. You'll probably want to
>> change your stroke to be fully opaque instead of alpha:0.3.
>>
>> --sjd;
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Cocoa-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40gmail.com
>>
>> This email sent to email@hidden
>>
_______________________________________________
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