• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Borderless NSWindow contentView problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Borderless NSWindow contentView problem


  • Subject: Borderless NSWindow contentView problem
  • From: Matt Ball <email@hidden>
  • Date: Tue, 8 Nov 2005 19:49:40 -0500

I am attempting to create a borderless window shaped like a rounded
rectangle. I modify the attributes of the window like so:

- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned
int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
    NSPanel* result = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
defer:NO];
    [result setBackgroundColor: [NSColor clearColor]];
    [result setLevel: NSModalPanelWindowLevel];

	HUDPanelContentView* theContentView = [[HUDPanelContentView alloc]
initWithFrame:contentRect];
	[result setContentView:theContentView];
	[[result contentView] display];

    [result setAlphaValue:1.0];
	[result setOpaque:NO];
	[result setHasShadow: YES];
	[result setMovableByWindowBackground:YES];
    return result;
}

I then set up my contentView:

- (void)drawRoundRectWithFrame:(NSRect)rect {
	[self lockFocus];
	[[NSColor blueColor] set];
	NSBezierPath *borderRect = [self bezierPathWithRoundRectInRect:rect
radius:6.0 top:YES bottom:YES];
	[borderRect fill];
	[self unlockFocus];
}

- (void)drawRect:(NSRect)rect {
	if(rect.size.width == [self frame].size.width && rect.size.height ==
[self frame].size.height) {
		[self drawRoundRectWithFrame:[self bounds]];
	}
}

- (NSBezierPath*)bezierPathWithRoundRectInRect:(NSRect)aRect
radius:(float)radius top:(BOOL)topIsRound bottom:(BOOL)bottomIsRound
{
	NSBezierPath* path = [[NSBezierPath alloc] init];
	NSRect rect = NSInsetRect(aRect, radius, radius);
	[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMinY(rect)) radius:radius startAngle:180.0 endAngle:270.0];
	[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMinY(rect)) radius:radius startAngle:270.0 endAngle:360.0];
	[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMaxY(rect)) radius:radius startAngle:  0.0 endAngle: 90.0];
	[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMaxY(rect)) radius:radius startAngle: 90.0 endAngle:180.0];

	[path closePath];
	return [path autorelease];
}


-------

However, this doesn't work. When I show my custom window, it is
completely transparent. I know that it exists because if I change the
window's background color from clearColor to redColor, I get a red
square. Additionally, I know that both my drawRect: and
drawRoundRectWithFrame: methods are getting called. Can someone please
tell me why this isn't working?

Thanks,
Matt Ball
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Borderless NSWindow contentView problem
      • From: Uli Kusterer <email@hidden>
    • Re: Borderless NSWindow contentView problem
      • From: Ricky Sharp <email@hidden>
  • Prev by Date: Re: NSBroswer_NSTableView
  • Next by Date: Re: Memory not being freed
  • Previous by thread: [Meet] Next Seattle XCoders meeting, Thursday, November 10th
  • Next by thread: Re: Borderless NSWindow contentView problem
  • Index(es):
    • Date
    • Thread