SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
HexFiend/HFTextVisualStyleRun.m
1 //
2 // HFTextVisualStyleRun.m
3 // HexFiend_2
4 //
5 // Copyright 2009 ridiculous_fish. All rights reserved.
6 //
7
8 #import "HFTextVisualStyleRun.h"
9
10
11 @implementation HFTextVisualStyleRun
12
13 - (instancetype)init {
14 self = [super init];
15 _scale = 1.;
16 _shouldDraw = YES;
17 return self;
18 }
19
20 - (void)dealloc {
21 [_foregroundColor release];
22 [_backgroundColor release];
23 [_bookmarkStarts release];
24 [_bookmarkExtents release];
25 [_bookmarkEnds release];
26 [super dealloc];
27 }
28
29 - (void)set {
30 [_foregroundColor set];
31 if (_scale != (CGFloat)1.0) {
32 CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
33 CGAffineTransform tm = CGContextGetTextMatrix(ctx);
34 /* Huge hack - adjust downward a little bit if we are scaling */
35 tm = CGAffineTransformTranslate(tm, 0, -.25 * (_scale - 1));
36 tm = CGAffineTransformScale(tm, _scale, _scale);
37 CGContextSetTextMatrix(ctx, tm);
38 }
39 }
40
41 static inline NSUInteger flip(NSUInteger x) {
42 return _Generic(x, unsigned: NSSwapInt, unsigned long: NSSwapLong, unsigned long long: NSSwapLongLong)(x);
43 }
44 static inline NSUInteger rol(NSUInteger x, unsigned char r) {
45 r %= sizeof(NSUInteger)*8;
46 return (x << r) | (x << (sizeof(NSUInteger)*8 - r));
47 }
48 - (NSUInteger)hash {
49 NSUInteger A = 0;
50 // All these hashes tend to have only low bits, except the double which has only high bits.
51 #define Q(x, r) rol(x, sizeof(NSUInteger)*r/6)
52 A ^= flip([_foregroundColor hash] ^ Q([_backgroundColor hash], 2)); // skew high
53 A ^= Q(_range.length ^ flip(_range.location), 2); // skew low
54 A ^= flip([_bookmarkStarts hash]) ^ Q([_bookmarkEnds hash], 3) ^ Q([_bookmarkExtents hash], 4); // skew high
55 A ^= _shouldDraw ? 0 : (NSUInteger)-1;
56 A ^= *(NSUInteger*)&_scale; // skew high
57 return A;
58 #undef Q
59 }
60
61 - (BOOL)isEqual:(HFTextVisualStyleRun *)run {
62 if(![run isKindOfClass:[self class]]) return NO;
63 /* Check each field for equality. */
64 if(!NSEqualRanges(_range, run->_range)) return NO;
65 if(_scale != run->_scale) return NO;
66 if(_shouldDraw != run->_shouldDraw) return NO;
67 if(!!_foregroundColor != !!run->_foregroundColor) return NO;
68 if(!!_backgroundColor != !!run->_backgroundColor) return NO;
69 if(!!_bookmarkStarts != !!run->_bookmarkStarts) return NO;
70 if(!!_bookmarkExtents != !!run->_bookmarkExtents) return NO;
71 if(!!_bookmarkEnds != !!run->_bookmarkEnds) return NO;
72 if(![_foregroundColor isEqual: run->_foregroundColor]) return NO;
73 if(![_backgroundColor isEqual: run->_backgroundColor]) return NO;
74 if(![_bookmarkStarts isEqual: run->_bookmarkStarts]) return NO;
75 if(![_bookmarkExtents isEqual: run->_bookmarkExtents]) return NO;
76 if(![_bookmarkEnds isEqual: run->_bookmarkEnds]) return NO;
77 return YES;
78 }
79
80 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.