Monday, 15 September 2014

objective c - Setting composite drawing mode causing black holes/patches on NSWindow -



objective c - Setting composite drawing mode causing black holes/patches on NSWindow -

i wanted draw shape, on wanted draw smaller transparent shape.

-(void) drawrect:(nsrect)dirtyrect { //clear { [[nscolor whitecolor] set]; [[nsbezierpath bezierpathwithrect:dirtyrect] fill]; } nsbezierpath *thepath = [nsbezierpath bezierpathwithovalinrect: self.bounds]; [thepath setlinewidth: 30]; [[nscolor bluecolor] set]; [thepath stroke]; [[nsgraphicscontext currentcontext] setcompositingoperation: nscompositecopy]; [[nscolor clearcolor] set]; [thepath setlinewidth: 4]; [thepath stroke]; }

i've tried nsimage forst , on view, still getting same result.

-(void) drawrect:(nsrect)dirtyrect { //clear { [[nscolor whitecolor] set]; [[nsbezierpath bezierpathwithrect:dirtyrect] fill]; } nsimage* image = [[nsimage alloc] initwithsize:self.frame.size]; [image lockfocus]; //clear { [[nscolor whitecolor] set]; [[nsbezierpath bezierpathwithrect:dirtyrect] fill]; } nsbezierpath *thepath = [nsbezierpath bezierpathwithovalinrect: self.bounds]; [thepath setlinewidth: 30]; [[nscolor bluecolor] set]; [thepath stroke]; [[nsgraphicscontext currentcontext] setcompositingoperation: nscompositecopy]; [[nscolor clearcolor] set]; [thepath setlinewidth: 4]; [thepath stroke]; [image unlockfocus]; [image drawinrect:self.frame fromrect:nszerorect operation:nscompositecopy fraction:1.0]; }

the oval appears black because windows opaque default. you've cutting oval track in window, because window opaque, without industrial laser cutting same oval in monitor, mac has show some color there instead. color shows color of clearcolor: black.

the solution set window's opaque no.

the default yes, nice , efficient (well, actually, because) prevents other windows' contents showing through. setting no allow see behind window through lean oval track. (it'll work improve if fill oval, giving larger window in the… er… window.)

(why track filled gray? that's window's shadow you're seeing there. when seek real, you'll able see other windows on scheme through track move window around.)

objective-c cocoa drawing quartz-2d

No comments:

Post a Comment