minivmac4ios/Mini vMac/ScreenView.m

58 lines
1.4 KiB
Mathematica
Raw Normal View History

2016-05-01 17:05:36 +00:00
//
// ScreenView.m
// Mini vMac
//
// Created by Jesús A. Álvarez on 30/04/2016.
// Copyright © 2016 namedfork. All rights reserved.
//
#import "ScreenView.h"
2016-05-28 11:01:13 +00:00
#import "AppDelegate.h"
2016-05-01 17:05:36 +00:00
static ScreenView *sharedScreenView = nil;
@implementation ScreenView
{
CGImageRef screenImage;
CGRect screenBounds;
2016-05-01 21:44:47 +00:00
CGSize screenSize;
2016-05-20 22:12:15 +00:00
CALayer *videoLayer;
2016-05-01 17:05:36 +00:00
}
- (void)awakeFromNib {
[super awakeFromNib];
sharedScreenView = self;
2016-05-20 22:12:15 +00:00
videoLayer = [CALayer layer];
2016-05-28 11:01:13 +00:00
[AppDelegate sharedEmulator].screenLayer = videoLayer;
if ([AppDelegate sharedEmulator]) {
screenSize = [AppDelegate sharedEmulator].screenSize;
} else {
screenSize = CGSizeMake(1, 1);
}
2016-05-20 22:12:15 +00:00
[self.layer addSublayer:videoLayer];
2016-05-01 17:05:36 +00:00
}
+ (instancetype)sharedScreenView {
return sharedScreenView;
}
2016-05-01 21:44:47 +00:00
- (CGRect)screenBounds {
return screenBounds;
}
- (CGSize)screenSize {
return screenSize;
}
2016-05-01 17:05:36 +00:00
- (void)layoutSubviews {
2016-05-20 22:12:15 +00:00
[super layoutSubviews];
2016-05-01 17:05:36 +00:00
CGRect viewBounds = self.bounds;
CGFloat screenScale = MAX(screenSize.width / viewBounds.size.width, screenSize.height / viewBounds.size.height);
screenBounds = CGRectMake(0, 0, screenSize.width / screenScale, screenSize.height / screenScale);
screenBounds.origin.x = (viewBounds.size.width - screenBounds.size.width)/2;
screenBounds = CGRectIntegral(screenBounds);
2016-05-20 22:12:15 +00:00
videoLayer.frame = screenBounds;
2016-05-01 17:05:36 +00:00
}
@end