Re: Custom NSWindow drawing
Re: Custom NSWindow drawing
- Subject: Re: Custom NSWindow drawing
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 02 Jan 2010 13:14:50 -0800
On Jan 2, 2010, at 10:44 AM, PCWiz wrote:
The only reason I dont want to completely draw the whole window is
that resizing is not easily implemented with a custom window.
Sure it is. This is how I did it in the "Core Data Stickies" example:
#import "StickyResizeCornerView.h"
@implementation StickyResizeCornerView
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
[[NSColor brownColor] set];
[NSBezierPath strokeLineFromPoint:NSZeroPoint
toPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
return YES;
}
- (void)mouseDragged:(NSEvent *)theEvent
{
NSWindow *window = [self window];
NSRect frame = [window frame];
float newHeight = frame.size.height + [theEvent deltaY];
float newWidth = frame.size.width + [theEvent deltaX];
NSSize minSize = [window minSize];
if (newHeight >= minSize.height) {
frame.size.height = newHeight;
frame.origin.y -= [theEvent deltaY];
}
if (newWidth >= minSize.width)
frame.size.width = newWidth;
[window setFrame:frame display:YES];
}
-jcr
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden