On Feb 27, 2012, at 5:45 AM, Andrea3000 wrote: > Then, if I set my NSWindow non-opaque I correctly get rounded corners but the > window becomes very slow expecially during resize.
Mmm…. that doesn't sound right. You shouldn't notice anything being slow. > Therefore I'm looking for a way to mimic QuickTime X window which is (or > seems at least) a borderless window and still has rounded corners. QuickTime Player uses a custom NSFrameView. It's not a typical borderless window, it does private internal stuff to draw the titlebar as it pleases. > I've found some tutorials online that subclass NSThemeFrame in order to draw > the content view with rounded corners and then use the method of NSWindow: > -setBottomCornerRounded:YES. > Unfortunately this solution works only on a regular NSWindow. And uses private APIs so it wouldn't work for MAS and is generally a no no. So I posited a theory and it seems to hold true. This is a standard titled window, with a custom-drawn title bar using a custom view I simply added to the window: http://sethwillits.com/temp/upshot/upshot_o0V3gSE1.jpg This is *not* production code, but it proves a point. If you tweaked the standard window buttons to have a different look (which I belieeeeve is possible), then you could get closer to the QT look (which has dark shadows under the buttons, not light ones). { NSRect bounds = [[[_window contentView] superview] bounds]; BlackTitlebarView * view = [[BlackTitlebarView alloc] initWithFrame:bounds]; [view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; [[[_window contentView] superview] addSubview:view positioned:NSWindowBelow relativeTo:[[[[_window contentView] superview] subviews] objectAtIndex:0]]; } @implementation BlackTitlebarView - (void)drawRect:(NSRect)dirtyRect { NSRect windowFrame = [NSWindow frameRectForContentRect:[[[self window] contentView] bounds] styleMask:[[self window] styleMask]]; NSRect contentBounds = [[[self window] contentView] bounds]; NSRect titlebarRect = NSMakeRect(0, 0, self.bounds.size.width, windowFrame.size.height - contentBounds.size.height); titlebarRect.origin.y = self.bounds.size.height - titlebarRect.size.height; NSRect topHalf, bottomHalf; NSDivideRect(titlebarRect, &topHalf, &bottomHalf, floor(titlebarRect.size.height / 2.0), NSMaxYEdge); NSBezierPath * path = [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:4.0 yRadius:4.0]; [[NSBezierPath bezierPathWithRect:titlebarRect] addClip]; NSGradient * gradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.51 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:0.21 alpha:1.0]] autorelease]; [path addClip]; [[NSColor colorWithCalibratedWhite:0.13 alpha:1.0] set]; [path fill]; [gradient drawInRect:topHalf angle:270.0]; [NSGraphicsContext saveGraphicsState]; NSAffineTransform * xfm = [NSAffineTransform transform]; [xfm translateXBy:0.0 yBy:-1.0]; [xfm concat]; [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set]; [path setLineWidth:1.0]; [path stroke]; [NSGraphicsContext restoreGraphicsState]; [[NSColor blackColor] set]; [path setLineWidth:1.5]; [path stroke]; [[NSColor blackColor] set]; NSRectFill(NSMakeRect(0, 0, self.bounds.size.width, 1.0)); } @end -- Seth Willits _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
