-
Notifications
You must be signed in to change notification settings - Fork 5
/
MCBackgroundView.m
50 lines (41 loc) · 1.15 KB
/
MCBackgroundView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// MCBackgroundView.m
// BackToTheMac
//
// Created by Drew McCormack on 20/11/10.
// Copyright 2010 The Mental Faculty. All rights reserved.
//
#import "MCBackgroundView.h"
#import "MCImage.h"
@implementation MCBackgroundView
@synthesize image;
-(void)setImage:(NSImage *)newImage
{
if ( newImage != image ) {
image = newImage;
[self setNeedsDisplay:YES];
}
}
-(void)drawRect:(NSRect)dirtyRect
{
[image drawInRect:self.bounds];
}
-(void)setSize:(NSSize)newSize
{
NSRect superBounds = [[self superview] bounds];
NSRect newFrame = self.frame;
newFrame.size = newSize;
if ( self.superview ) {
newFrame.origin.x += NSMidX(superBounds) - NSMidX(newFrame);
newFrame.origin.x = MAX(newFrame.origin.x, 0.0f);
newFrame.origin.y += NSMidY(superBounds) - NSMidY(newFrame);
newFrame.origin.y -= MAX(0.0f, NSMaxY(newFrame) - NSMaxY(superBounds));
}
newFrame.origin.x = roundf(newFrame.origin.x);
newFrame.origin.y = roundf(newFrame.origin.y);
[self setFrame:newFrame];
}
-(void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {
[self setSize:self.frame.size];
}
@end