2013-02-17 3 views
0

모양을 그려야하고 그 위에 작은 투명 모양을 그렸습니다. NSWindow에서 블랙홀/패치가 발생하는 합성 드로잉 모드 설정하기

-(void) drawRect:(NSRect)dirtyRect 
{ 
    //clear everything 
    { 
     [[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]; 
} 

As a result of above program I'm getting the Blue Oval and a black Oval at the center of blue Oval.

나는 또한 NSImage FORST 그것을 시도하고 다음 뷰 만, 여전히 동일한 결과를 얻는.

-(void) drawRect:(NSRect)dirtyRect 
{ 
    //clear everything 
    { 
     [[NSColor whiteColor] set]; 
     [[NSBezierPath bezierPathWithRect:dirtyRect] fill]; 
    } 


    NSImage* image = [[NSImage alloc] initWithSize:self.frame.size]; 

    [image lockFocus]; 

    //clear everything 
    { 
     [[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]; 
} 

답변

2

기본적으로 창은 불투명하기 때문에 타원은 검은 색으로 보입니다. 창에서 타원형 트랙을 성공적으로 자르지 만 창문이 불투명하기 때문에 산업 레이저없이 모니터에서 동일한 타원형을 자르면 Mac에서 일부를 색으로 표시해야합니다. 그것이 나타내는 색은 clearColor : 검정색입니다.

해결 방법은 창 opaqueNO으로 설정하는 것입니다.

기본은 좋은 효율적입니다 만 (잘, 실제로 때문에) 그것을 통해 보여주는에서 다른 창 '의 내용을 방지하기 YES이다. NO으로 설정하면 얇은 타원형 트랙을 통해 창 뒤에 무엇이 있는지 볼 수 있습니다. (당신이 타원을 채우는 경우는 자신에게 큰 창을 제공, 더 잘 작동합니다 ... 어 ... 창을여십시오.)

This is how it looks with the window's opaque turned off.

이 (왜 회색으로 가득 트랙 생겼는데? 그건 윈도우의의 그림자를 보려고하면 실제 윈도우를 움직일 때 트랙을 통해 시스템의 다른 창을 볼 수 있습니다.)

+0

멋진 설명을 가져 주셔서 감사합니다. 솔리드 모양 위에 투명 모양을 그리는 방법이 있는지, 결과에 창 그림자 나 블랙홀이 표시되어서는 안된다는 사실을 알고 싶었습니다. – Omkar

+0

@Omkar : "투명"과 "창 그림자를 표시하면 안됩니다"는 투명성 때문에 투명도는 창 뒤의 내용을 볼 수있게하고 그림자는 창 뒤에 있습니다. 창 그림자를 끌 수는 있지만 창 주위에는 보이지 않습니다. –