SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
HexFiend/HFRepresenterTextView.h
1 //
2 // HFRepresenterTextView.h
3 // HexFiend_2
4 //
5 // Copyright 2007 ridiculous_fish. All rights reserved.
6 //
7
8 #import <Cocoa/Cocoa.h>
9 #import <HexFiend/HFGlyphTrie.h>
10
11 /* Bytes per column philosophy
12
13 _hftvflags.bytesPerColumn is the number of bytes that should be displayed consecutively, as one column. A space separates one column from the next. HexFiend 1.0 displayed 1 byte per column, and setting bytesPerColumn to 1 in this version reproduces that behavior. The vertical guidelines displayed by HexFiend 1.0 are only drawn when bytesPerColumn is set to 1.
14
15 We use some number of bits to hold the number of bytes per column, so the highest value we can store is ((2 ^ numBits) - 1). We can't tell the user that the max is not a power of 2, so we pin the value to the highest representable power of 2, or (2 ^ (numBits - 1)). We allow integral values from 0 to the pinned maximum, inclusive; powers of 2 are not required. The setter method uses HFTV_BYTES_PER_COLUMN_MAX_VALUE to stay within the representable range.
16
17 Since a value of zero is nonsensical, we can use it to specify no spaces at all.
18 */
19
20 #define HFTV_BYTES_PER_COLUMN_MAX_VALUE (1 << (HFTV_BYTES_PER_COLUMN_BITFIELD_SIZE - 1))
21
22 @class HFTextRepresenter;
23
24
25 /* The base class for HFTextRepresenter views - such as the hex or ASCII text view */
26 @interface HFRepresenterTextView : NSView {
27 @private;
28 HFTextRepresenter *representer;
29 NSArray *cachedSelectedRanges;
30 CGFloat verticalOffset;
31 CGFloat horizontalContainerInset;
32 CGFloat defaultLineHeight;
33 NSTimer *caretTimer;
34 NSWindow *pulseWindow;
35 NSRect pulseWindowBaseFrameInScreenCoordinates;
36 NSRect lastDrawnCaretRect;
37 NSRect caretRectToDraw;
38 NSUInteger bytesBetweenVerticalGuides;
39 NSUInteger startingLineBackgroundColorIndex;
40 NSArray *rowBackgroundColors;
41 NSMutableDictionary *callouts;
42
43 void (^byteColoring)(uint8_t byte, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a);
44
45 struct {
46 unsigned antialias:1;
47 unsigned drawCallouts:1;
48 unsigned editable:1;
49 unsigned caretVisible:1;
50 unsigned registeredForAppNotifications:1;
51 unsigned withinMouseDown:1;
52 unsigned receivedMouseUp:1;
53 } _hftvflags;
54 }
55
56 - (instancetype)initWithRepresenter:(HFTextRepresenter *)rep;
57 - (void)clearRepresenter;
58
59 - (HFTextRepresenter *)representer;
60
61 @property (nonatomic, copy) NSFont *font;
62
63 /* Set and get data. setData: will invalidate the correct regions (perhaps none) */
64 @property (nonatomic, copy) NSData *data;
65 @property (nonatomic) CGFloat verticalOffset;
66 @property (nonatomic) NSUInteger startingLineBackgroundColorIndex;
67 @property (nonatomic, getter=isEditable) BOOL editable;
68 @property (nonatomic, copy) NSArray *styles;
69 @property (nonatomic) BOOL shouldAntialias;
70
71 - (BOOL)behavesAsTextField;
72 - (BOOL)showsFocusRing;
73 - (BOOL)isWithinMouseDown;
74
75 - (NSRect)caretRect;
76
77 @property (nonatomic) BOOL shouldDrawCallouts;
78
79 - (void)setByteColoring:(void (^)(uint8_t byte, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a))coloring;
80
81 - (NSPoint)originForCharacterAtByteIndex:(NSInteger)index;
82 - (NSUInteger)indexOfCharacterAtPoint:(NSPoint)point;
83
84 /* The amount of padding space to inset from the left and right side. */
85 @property (nonatomic) CGFloat horizontalContainerInset;
86
87 /* The number of bytes between vertical guides. 0 means no drawing of guides. */
88 @property (nonatomic) NSUInteger bytesBetweenVerticalGuides;
89
90 /* To be invoked from drawRect:. */
91 - (void)drawCaretIfNecessaryWithClip:(NSRect)clipRect;
92 - (void)drawSelectionIfNecessaryWithClip:(NSRect)clipRect;
93
94 /* For font substitution. An index of 0 means the default (base) font. */
95 - (NSFont *)fontAtSubstitutionIndex:(uint16_t)idx;
96
97 /* Uniformly "rounds" the byte range so that it contains an integer number of characters. The algorithm is to "floor:" any character intersecting the min of the range are included, and any character extending beyond the end of the range is excluded. If both the min and the max are within a single character, then an empty range is returned. */
98 - (NSRange)roundPartialByteRange:(NSRange)byteRange;
99
100 - (void)drawTextWithClip:(NSRect)clipRect restrictingToTextInRanges:(NSArray *)restrictingToRanges;
101
102 /* Must be overridden */
103 - (void)extractGlyphsForBytes:(const unsigned char *)bytes count:(NSUInteger)numBytes offsetIntoLine:(NSUInteger)offsetIntoLine intoArray:(struct HFGlyph_t *)glyphs advances:(CGSize *)advances resultingGlyphCount:(NSUInteger *)resultGlyphCount;
104
105 - (void)extractGlyphsForBytes:(const unsigned char *)bytePtr range:(NSRange)byteRange intoArray:(struct HFGlyph_t *)glyphs advances:(CGSize *)advances withInclusionRanges:(NSArray *)restrictingToRanges initialTextOffset:(CGFloat *)initialTextOffset resultingGlyphCount:(NSUInteger *)resultingGlyphCount;
106
107 /* Must be overridden - returns the max number of glyphs for a given number of bytes */
108 - (NSUInteger)maximumGlyphCountForByteCount:(NSUInteger)byteCount;
109
110 - (void)updateSelectedRanges;
111 - (void)terminateSelectionPulse; // Start fading the pulse.
112
113 /* Given a rect edge, return an NSRect representing the maximum edge in that direction. The dimension in the direction of the edge is 0 (so if edge is NSMaxXEdge, the resulting width is 0). The returned rect is in the coordinate space of the receiver's view. If the byte range is not displayed, returns NSZeroRect.
114 */
115 - (NSRect)furthestRectOnEdge:(NSRectEdge)edge forRange:(NSRange)range;
116
117 /* The background color for the line at the given index. You may override this to return different colors. You may return nil to draw no color in this line (and then the empty space color will appear) */
118 - (NSColor *)backgroundColorForLine:(NSUInteger)line;
119 - (NSColor *)backgroundColorForEmptySpace;
120
121 /* Defaults to 1, may override */
122 - (NSUInteger)bytesPerCharacter;
123
124 /* Cover method for [[self representer] bytesPerLine] and [[self representer] bytesPerColumn] */
125 - (NSUInteger)bytesPerLine;
126 - (NSUInteger)bytesPerColumn;
127
128 - (CGFloat)lineHeight;
129
130 /* Following two must be overridden */
131 - (CGFloat)advanceBetweenColumns;
132 - (CGFloat)advancePerCharacter;
133
134 - (CGFloat)advancePerColumn;
135 - (CGFloat)totalAdvanceForBytesInRange:(NSRange)range;
136
137 /* Returns the number of lines that could be shown in this view at its given height (expressed in its local coordinate space) */
138 - (double)maximumAvailableLinesForViewHeight:(CGFloat)viewHeight;
139
140 - (NSUInteger)maximumBytesPerLineForViewWidth:(CGFloat)viewWidth;
141 - (CGFloat)minimumViewWidthForBytesPerLine:(NSUInteger)bytesPerLine;
142
143 - (IBAction)selectAll:sender;
144
145
146 @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.