forked from avibrazil/RDM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResMenuItem.mm
162 lines (132 loc) · 2.64 KB
/
ResMenuItem.mm
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "utils.h"
#import "ResMenuItem.h"
@implementation ResMenuItem : NSMenuItem
- (id) initWithDisplay: (CGDirectDisplayID) display andMode: (modes_D4*) mode
{
if((self = [super initWithTitle: @"" action: @selector(setMode:) keyEquivalent: @""]) && display && mode)
{
_display = display;
modeNum = mode->derived.mode;
scale = mode->derived.density;
width = mode->derived.width;
height = mode->derived.height;
refreshRate = mode->derived.freq;
colorDepth = (mode->derived.depth == 4) ? 32 : 16;
NSString* title;
if(scale == 2.0f)
{
if(refreshRate)
{
title = [NSString stringWithFormat: @"%d × %d ⚡️, %.0f Hz", width, height, refreshRate];
}
else
{
title = [NSString stringWithFormat: @"%d × %d ⚡️", width, height];
}
}
else
{
if(refreshRate)
{
title = [NSString stringWithFormat: @"%d × %d, %.0f Hz", width, height, refreshRate];
}
else
{
title = [NSString stringWithFormat: @"%d × %d", width, height];
}
}
[self setTitle: title];
return self;
}
else
{
return NULL;
}
}
- (void) setTextFormat: (int) textFormat
{
NSString* title = nil;
if(textFormat == 1)
{
if(scale == 2.0f)
{
title = [NSString stringWithFormat: @"%d × %d ⚡", width, height];
}
else
{
title = [NSString stringWithFormat: @"%d × %d", width, height];
}
}
if(textFormat == 2)
{
title = [NSString stringWithFormat: @"%.0f Hz", refreshRate];
}
if(title)
[self setTitle: title];
}
- (CGDirectDisplayID) display
{
return _display;
}
- (int) modeNum
{
return modeNum;
}
- (int) colorDepth
{
return colorDepth;
}
- (int) width
{
return width;
}
- (int) height
{
return height;
}
- (float) refreshRate
{
return refreshRate;
}
- (float) scale
{
return scale;
}
- (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem
{
{
int o_width = [otherItem width];
if(width < o_width)
return NSOrderedDescending;
else if(width > o_width)
return NSOrderedAscending;
// return NSOrderedSame;
}
{
int o_scale = [otherItem scale];
if(scale < o_scale)
return NSOrderedDescending;
else if(scale > o_scale)
return NSOrderedAscending;
// return NSOrderedSame;
}
{
int o_height = [otherItem height];
if(height < o_height)
return NSOrderedDescending;
else if(height > o_height)
return NSOrderedAscending;
// return NSOrderedSame;
}
{
int o_refreshRate = [otherItem refreshRate];
if(refreshRate < o_refreshRate)
return NSOrderedDescending;
else if(refreshRate > o_refreshRate)
return NSOrderedAscending;
return NSOrderedSame;
}
}
@end