Files
MapLibreParticleLab/platform/macos/src/MLNAnnotationImage.m
mwilsnd 20d9e1028c Platform flattening overhaul (#1393)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
2023-07-26 17:50:34 +02:00

64 lines
2.2 KiB
Objective-C

#import "MLNAnnotationImage_Private.h"
@interface MLNAnnotationImage ()
@property (nonatomic) NSImage *image;
@property (nonatomic) NSString *reuseIdentifier;
@property (nonatomic, strong, nullable) NSString *styleIconIdentifier;
@end
@implementation MLNAnnotationImage
+ (instancetype)annotationImageWithImage:(NSImage *)image reuseIdentifier:(NSString *)reuseIdentifier {
return [[self alloc] initWithImage:image reuseIdentifier:reuseIdentifier];
}
- (instancetype)initWithImage:(NSImage *)image reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super init]) {
_image = image;
_reuseIdentifier = [reuseIdentifier copy];
_selectable = YES;
}
return self;
}
+ (BOOL)supportsSecureCoding {
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
_image = [decoder decodeObjectOfClass:[NSImage class] forKey:@"image"];
_reuseIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"reuseIdentifier"];
_cursor = [decoder decodeObjectOfClass:[NSCursor class] forKey:@"cursor"];
_selectable = [decoder decodeBoolForKey:@"selectable"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:_image forKey:@"image"];
[coder encodeObject:_reuseIdentifier forKey:@"reuseIdentifier"];
[coder encodeObject:_cursor forKey:@"cursor"];
[coder encodeBool:_selectable forKey:@"selectable"];
}
- (BOOL)isEqual:(id)other {
if (self == other) return YES;
if (![other isKindOfClass:[MLNAnnotationImage class]]) return NO;
MLNAnnotationImage *otherAnnotationImage = other;
return ((!_reuseIdentifier && !otherAnnotationImage.reuseIdentifier) || [_reuseIdentifier isEqualToString:otherAnnotationImage.reuseIdentifier])
&& _selectable == otherAnnotationImage.selectable
&& ((!_cursor && !otherAnnotationImage.cursor) || [_cursor isEqual:otherAnnotationImage.cursor])
&& (_image == otherAnnotationImage.image || [[_image TIFFRepresentation] isEqualToData:[otherAnnotationImage.image TIFFRepresentation]]);
}
- (NSUInteger)hash {
return _reuseIdentifier.hash + @(_selectable).hash + _image.hash;
}
@end