cocoa - NSView won't draw through bezierpath -
dear fellow cocoa programmers,
what i'd accomplish:
i have checkbox, popupbutton(which hidden) , nsview on canvas. if mycheckbox checked -> show popupbutton , draw line through bezierpath on nsview. if mycheckbox unchecked -> hide popupbutton again , "undraw" path
the code:
- (ibaction)ischecked:(id)sender { //if mychekcbox checked, show pop button if ([sender state]==nsonstate) { nslog(@"checked"); [mypopup sethidden:no]; } else { //if checkbox unchecked, hide popupbutton [mypopup sethidden:yes]; nslog(@"unchecked"); } //reload drawrect method (reload view) [self setneedsdisplay:yes]; } - (void)drawrect:(nsrect)dirtyrect { //if checkedbutton checked, draw line if ([mycheckbox state]==nsonstate) { nsbezierpath *mypath = [nsbezierpath bezierpath]; [mypath movetopoint:nsmakepoint(10, 20)]; [mypath linetopoint:nsmakepoint(50, 20)]; [mypath setlinewidth:2]; [mypath stroke]; } }
the problem:
if checked state = nsonstate popupbutton visible line won't draw , wonder why... think it's connection(s) problem.
i uploaded project file (it's rather small-35kb) here:drawing.zip
globally: i've read nsview documentation , it's saying there 1 way draw view , it's through drawrect method. true? descent way draw view? (if function in view , setneedsdisplay:yes in method)
thanks in advance, ben
you need nscolor
instance , call setstroke
on set current stroke color. not know color use stroke path @ start of drawrect:
, have tell it.
Comments
Post a Comment