Cocoa NSView: Making circles but they are getting cropped -


the outer edges of circle @ each point of compass getting cropped (presumably rect frame). how circle display within frame? (this getting created button click):

in appcontroller.m

#import "appcontroller.h" #import "makecircle.h"  @implementation appcontroller  - (ibaction)makecircle:(id)sender {       makecircle* newcircle = [[makecircle alloc] initwithframe:nsmakerect(100.0, 100.0, 30.0, 30.0)];      [[[[nsapplication sharedapplication] mainwindow] contentview] addsubview:newcircle];       [newcircle release]; }  @end 

in makecircle.m

- (void)drawrect:(nsrect)rect {       [self setneedsdisplay:yes];       [[nscolor blackcolor] setstroke];       // create our circle path      nsbezierpath* circlepath = [nsbezierpath bezierpath];      [circlepath appendbezierpathwithovalinrect: rect];       //give line thickness      [circlepath setlinewidth:4];       // outline , fill path      [circlepath stroke];     } 

thanks.

i think see half of edge, right? can calculate half of thickness of edge , subtract rectangle:

#define stroke_color    ([nscolor blackcolor]) #define stroke_width    (4.0) - (void)drawrect:(nsrect)dirtyrect {     nsbezierpath *path;     nsrect rectangle;      /* calculate rectangle */     rectangle = [self bounds];     rectangle.origin.x += stroke_width / 2.0;     rectangle.origin.y += stroke_width / 2.0;     rectangle.size.width -= stroke_width / 2.0;     rectangle.size.height -= stroke_width / 2.0;     path = [nsbezierpath path];     [path appendbezierpathwithovalinrect:rectangle];     [path setlinewidth:stroke_width];     [stroke_color setstroke];     [path stroke]; } 

i have no mac @ moment, can't test it, think should solve problem.

als don't call [self setneedsdisplay:yes]. method used when want redraw whole nsview, , calling drawing method little bit recursive. that's why i'm surprised code draws something.

and have tip: [[nsapplication sharedapplication] mainwindow] same [nsapp mainwindow]. nsapp global variable containing main application.

hope helps,
ief2


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -