-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNavView.mm
More file actions
139 lines (111 loc) · 4.54 KB
/
Copy pathNavView.mm
File metadata and controls
139 lines (111 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#import "NavView.h"
@implementation NavView
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
// Add initialization code here
}
return self;
}
/** Re-draw the navigation display.
*/
- (void)drawRect:(NSRect)rect
{
CGRect region = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextSetGrayFillColor(context, 0.6, 1.0);
CGContextFillRect(context, region);
NeoCharacter *character = [neoFontEditor character];
NeoFont *font = [neoFontEditor font];
int character_width = character->width();
int character_height = character->height();
float display_width = region.size.width;
float display_height = region.size.height;
float pixel_size = 2;
if ((pixel_size * character_width) + 1 >= display_width)
{
pixel_size = (display_width - 1) / character_width;
}
if ((pixel_size * character_height) + 1 >= display_height)
{
pixel_size = (display_height - 1) / character_height;
}
float horizontal_offset = (display_width - ((float)character_width * pixel_size)) / 2.0;
float vertical_offset = (display_height - ((float)character_height * pixel_size)) / 2.0;
/* Render the current character.
*/
CGContextSetGrayFillColor(context, 0.0, 1.0);
[neoFontEditor renderCharacter:character context:context x:horizontal_offset y:vertical_offset size:pixel_size];
/* Render following and preceeding characters.
*/
CGContextSetGrayFillColor(context, 0.4, 1.0);
float x = horizontal_offset;
int character_number = [neoFontEditor characterNumber];
for (unsigned int i = 1; i <= 32; i++)
{
x += (character->width() + 2.0) * pixel_size;
if (x >= display_width) break; // off right hand edge of visible display
character = font->character((character_number + i) % kNeoFontCharacterCount);
[neoFontEditor renderCharacter:character context:context x:x y:vertical_offset size:pixel_size];
}
x = horizontal_offset;
for (unsigned int i = 1; i <= 32; i++)
{
character = font->character((character_number - i) % kNeoFontCharacterCount);
if (x < 0.0) break; // off left hand edge of visible display
x -= (character->width() + 2.0) * pixel_size;
[neoFontEditor renderCharacter:character context:context x:x y:vertical_offset size:pixel_size];
}
}
- (void)mouseDown:(NSEvent *)event
{
NSRect rect = [self bounds];
CGRect region = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
NSPoint eventLocation = [event locationInWindow];
NSPoint hit = [self convertPoint:eventLocation fromView:nil];
NeoCharacter *character = [neoFontEditor character];
NeoFont *font = [neoFontEditor font];
int character_width = character->width();
int character_height = character->height();
float display_width = region.size.width;
float display_height = region.size.height;
float pixel_size = 2;
if ((pixel_size * character_width) + 1 >= display_width)
{
pixel_size = (display_width - 1) / character_width;
}
if ((pixel_size * character_height) + 1 >= display_height)
{
pixel_size = (display_height - 1) / character_height;
}
float horizontal_offset = (display_width - ((float)character_width * pixel_size)) / 2.0;
float x = horizontal_offset;
int character_number = [neoFontEditor characterNumber];
int matched_character = -1;
for (unsigned int i = 1; matched_character < 0 && i <= 32; i++)
{
x += (character->width() + 2.0) * pixel_size;
if (x >= display_width) break; // off right hand edge of visible display
character = font->character((character_number + i) % kNeoFontCharacterCount);
if (hit.x >= x && hit.x < (x + (character->width() + 2.0) * pixel_size))
{
matched_character = character_number + i;
}
}
x = horizontal_offset;
for (unsigned int i = 1; matched_character < 0 && i <= 32; i++)
{
character = font->character((character_number - i) % kNeoFontCharacterCount);
if (x < 0.0) break; // off left hand edge of visible display
x -= (character->width() + 2.0) * pixel_size;
if (hit.x >= x && hit.x < (x + (character->width() + 2.0) * pixel_size))
{
matched_character = character_number - i;
}
}
if (matched_character >= 0)
{
[neoFontEditor setCharacterNumber:matched_character];
}
}
@end