Files
IJSVG/source/IJSVGImageLayer.m
T
2019-03-14 20:11:49 +00:00

56 lines
1.3 KiB
Objective-C

//
// IJSVGImageLayer.m
// IJSVGExample
//
// Created by Curtis Hard on 07/01/2017.
// Copyright © 2017 Curtis Hard. All rights reserved.
//
#import "IJSVGImageLayer.h"
@implementation IJSVGImageLayer
- (id)initWithImage:(NSImage *)image
{
NSRect rect = (NSRect){
.origin = NSZeroPoint,
.size = image.size
};
CGImageRef ref = [image CGImageForProposedRect:&rect
context:nil
hints:nil];
return [self initWithCGImage:ref];
}
- (id)initWithCGImage:(CGImageRef)imageRef
{
if((self = [super init]) != nil) {
// set the contents
self.contents = (id)imageRef;
// make sure we say we need help
self.requiresBackingScaleHelp = YES;
self.shouldRasterize = YES;
// set the frame, simple stuff
self.frame = (CGRect){
.origin = CGPointZero,
.size = CGSizeMake(CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef))
};
}
return self;
}
- (void)setNeedsDisplay
{
// swap the content around on call
// because set needs display discards previous
// content - yolo!
id oldContent = self.contents;
[super setNeedsDisplay];
self.contents = oldContent;
}
@end