Affine transform not being applied to subviews
Affine transform not being applied to subviews
- Subject: Affine transform not being applied to subviews
- From: Ken Tozier <email@hidden>
- Date: Thu, 21 May 2009 22:52:39 -0400
Hi
I wrote a custom view that contains several other views and am having
problems when applying an affine transform to the main view. The main
view is a page and the two subviews are a crop view that displays page
margins and a column view that displays the page columns. I've checked
to make sure that the subviews are in fact children of the main view
and they definitely are. What it happening is that the page view
scales correctly but the subviews are drawing at their actual size.
Perhaps I'm not understanding how transforms are supposed to work, but
from my reading of the relevant drawing and transform documentation, I
got the impression that if a transform was applied to a view, it
treated the view and all it's subviews as a single unit. Is that not
the case?
Here's the code
This inits my custom document object
- (id) initWithModel:(PMXDocumentModel *) inModel
{
self = [super init];
if (self)
{
NSUInteger windowMask = NSTitledWindowMask | NSClosableWindowMask
| NSMiniaturizableWindowMask | NSResizableWindowMask,
pasteboardMask = NSViewWidthSizable | NSViewHeightSizable |
NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin |
NSViewMaxYMargin;
PMXPageModel *pageModel = [PMXPageModel pageModelWithDocument:
inModel];
PMXPageView *pageView;
NSRect defaultFrame = NSMakeRect(100, 100, 600, 600);
model = [inModel retain];
window = [[PMXWindow alloc] initWithFrame: defaultFrame styleMask:
windowMask];
// create pastebord
pasteBoard = [[PMXPasteBoardView alloc] initWithFrame: [[window
contentView] frame]];
[pasteBoard setAutoresizingMask: pasteboardMask];
[pasteBoard setVerticalMargin: 32];
pageView = [PMXPageView pageViewWithModel: pageModel pasteBoard:
pasteBoard];
[pageView setColumnCount: 6];
[pageView setGutterWidth: 12];
[pasteBoard addSubview: pageView];
[window setTitle: [inModel name]];
[[window contentView] addSubview: pasteBoard];
[self show];
}
return self;
}
Here's the code that creates a page view
- (id) initWithModel:(PMXPageModel *) inModel
pasteBoard:(PMXPasteBoardView *) inPasteBoard
{
PMXDocumentModel *docModel = [inModel documentModel];
NSSize pageSize = [docModel size];
NSRect selfFrame = NSMakeRect(0, 0, pageSize.width,
pageSize.height);
self = [super initWithFrame: selfFrame];
if (self)
{
pasteBoard = [inPasteBoard retain];
model = [inModel retain];
cropView = [[PMXPageCropView alloc] initWithPage: self];
columnView = [[PMXPageColumnView alloc] initWithPage: self];
[self setAutoresizesSubviews: YES];
[self addSubview: cropView];
[self addSubview: columnView];
}
return self;
}
Here's the draw method for the page view
- (void) drawRect:(NSRect) inRect
{
NSAffineTransform *transform = [self transform];
[transform concat];
[[NSColor whiteColor] set];
NSRectFillUsingOperation([self frame], NSCompositeSourceOver);
[[NSColor blackColor] set];
NSFrameRectWithWidthUsingOperation([self frame], 1,
NSCompositeSourceOver);
}
And here's the draw method for the crop view
- (void) drawRect:(NSRect) inRect
{
PMXInset margins = [[[page model] documentModel] margins];
NSRect selfFrame = [self bounds],
vcrop = NSMakeRect(left, 0, 1, selfFrame.size.height),
hcrop = NSMakeRect(0, top, selfFrame.size.width, 1);
// If I comment out the next line, the crop view draws at it's actual
size
[[page transform] concat];
[[PMXColors colorForKey: @"crop rules"] set];
NSRectFillUsingOperation(hcrop, NSCompositeSourceOver);
hcrop.origin.y = selfFrame.size.height - margins.bottom - 1;
NSRectFillUsingOperation(hcrop, NSCompositeSourceOver);
NSRectFillUsingOperation(vcrop, NSCompositeSourceOver);
vcrop.origin.x = selfFrame.size.width - margins.right - 1;
NSRectFillUsingOperation(vcrop, NSCompositeSourceOver);
}
_______________________________________________
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