objective c - Rounded NSView in a Transparent Window -
i'm trying create transparent nswindow rounded view in there.
i'm trying have rounded view transparent window.
this looks now: (see little dots in corners)
here's illustration border radius set 10px (set in nsview drawrect):
i using code apple sample: https://developer.apple.com/library/mac/#samplecode/roundtransparentwindow/introduction/intro.html
specifically method in nswindow subclass:
- (id)initwithcontentrect:(nsrect)contentrect stylemask:(nsuinteger)astyle backing:(nsbackingstoretype)bufferingtype defer:(bool)flag { // using nsborderlesswindowmask results in window without title bar. self = [super initwithcontentrect:contentrect stylemask:nsborderlesswindowmask backing:nsbackingstorebuffered defer:no]; if (self != nil) { // start no transparency drawing window [self setalphavalue:1.0]; // turn off opacity parts of window not drawn transparent. [self setopaque:no]; [self setbackgroundcolor:[nscolor clearcolor]]; } homecoming self; }
and in nsview subclass:
- (void)drawrect:(nsrect)dirtyrect { [[nscolor redcolor] set]; nsbezierpath* thepath = [nsbezierpath bezierpath]; [thepath appendbezierpathwithroundedrect:dirtyrect xradius:3 yradius:3]; [thepath fill]; }
can tell me i'm missing here?
thanks.
are looking following, there's reddish outline (stroke), center area transparent?
if so, accomplish that, used next code:
- (void)drawrect:(nsrect)frame { frame = nsinsetrect(self.frame, 3.0, 3.0); [nsbezierpath setdefaultlinewidth:6.0]; nsbezierpath *path = [nsbezierpath bezierpathwithroundedrect:frame xradius:6.0 yradius:6.0]; [[nscolor redcolor] set]; [path stroke]; }
if that's you're looking for, can utilize starting point. you'll want create sure inset frame
rect 1 half of stroke line width, avoid problem clipping corners seeing.
objective-c cocoa nsview nswindow
No comments:
Post a Comment