forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplashScreen.m
249 lines (193 loc) · 5.96 KB
/
SplashScreen.m
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
*****************************************************************/
#import "SplashScreen.h"
#include <mach/mach.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <mach/machine.h>
#include <sys/sysctl.h>
extern NSString *checkSN64String;
BOOL IsPPC()
{
host_basic_info_data_t hostInfo;
mach_msg_type_number_t infoCount;
infoCount = HOST_BASIC_INFO_COUNT;
host_info(mach_host_self(), HOST_BASIC_INFO,
(host_info_t)&hostInfo, &infoCount);
return (hostInfo.cpu_type == CPU_TYPE_POWERPC);
}
int GetAltiVecTypeAvailable( void )
{
int sels[2] = { CTL_HW, HW_VECTORUNIT };
int vType = 0; //0 == scalar only
size_t length = sizeof(vType);
int error = sysctl(sels, 2, &vType, &length, NULL, 0);
if( 0 == error ) return vType;
return 0;
}
long vramSize()
{
int i = 0;
short MAXDISPLAYS = 8;
io_service_t dspPorts[MAXDISPLAYS];
CGDirectDisplayID displays[MAXDISPLAYS];
CFTypeRef typeCode;
CGDisplayCount displayCount = 0;
// First we're going to grab the online displays
CGGetOnlineDisplayList(MAXDISPLAYS, displays, &displayCount);
// Now we iterate through them
for(i = 0; i < displayCount; i++)
dspPorts[i] = CGDisplayIOServicePort(displays[i]);
// Ask for the physical size of VRAM of the primary display
typeCode = IORegistryEntryCreateCFProperty(dspPorts[0], CFSTR("IOFBMemorySize"), kCFAllocatorDefault, kNilOptions);
// Validate our data and make sure we're getting the right type
if(typeCode)
{
SInt32 vramStorage = 0;
if( CFGetTypeID(typeCode) == CFNumberGetTypeID())
{
// Convert this to a useable number
CFNumberGetValue(typeCode, kCFNumberSInt32Type, &vramStorage);
}
CFRelease( typeCode);
return vramStorage;
}
return 0;
}
BOOL useQuartz() {
return NO; // Disable quartz about screen: DDP (060224)
if (vramSize() >= 32)
return YES;
else
return NO;
if (!IsPPC())
return YES;
return GetAltiVecTypeAvailable();
}
@implementation SplashScreen
- (void)windowDidLoad
{
[[self window] center];
versionType = 0;
[self switchVersion: self];
[[self window] setDelegate:self];
[[self window] setAlphaValue:0.0];
// if (useQuartz())
// [view setAutostartsRendering:YES];
}
- (IBAction) switchVersion:(id) sender
{
NSMutableString *currVersionNumber = nil;
switch( versionType)
{
case 0:
currVersionNumber = [NSMutableString stringWithString:[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleGetInfoString"]];
if( sizeof(long) == 8)
[currVersionNumber appendString:@" 64-bit"];
else
[currVersionNumber appendString:@" 32-bit"];
break;
case 1:
currVersionNumber = [NSMutableString stringWithString:[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleVersion"]];
[currVersionNumber insertString:@"Revision " atIndex:0];
break;
case 2:
currVersionNumber = [NSMutableString stringWithString:[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"GitHash"]];
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] writeObjects:[NSArray arrayWithObject: currVersionNumber]];
break;
case 3:
currVersionNumber = [[checkSN64String mutableCopy] autorelease];
break;
}
[version setTitle: currVersionNumber];
versionType++;
if( checkSN64String.length)
{
if( versionType >= 4)
versionType = 0;
}
else
{
if( versionType >= 3)
versionType = 0;
}
}
- (IBAction)showWindow:(id)sender{
[super showWindow:sender];
// if (useQuartz())
// [self startRendering];
//
//NSLog(@"show Splash screen");
}
//- (void)startRendering
//{
// NSString *path = [[NSBundle mainBundle] pathForResource:@"About" ofType:@"qtz"];
// [view loadCompositionFromFile:path];
// [view setAutostartsRendering:YES];
// [view startRendering];
//}
- (void) affiche
{
timerIn = [[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(fadeIn:) userInfo:nil repeats:YES] retain];
// [[NSRunLoop currentRunLoop] addTimer:timerIn forMode:NSModalPanelRunLoopMode];
// [[NSRunLoop currentRunLoop] addTimer:timerIn forMode:NSEventTrackingRunLoopMode];
}
-(id) init
{
if (useQuartz())
self = [super initWithWindowNibName:@"SplashQtz"];
else
self = [super initWithWindowNibName:@"Splash"];
return self;
}
- (BOOL)windowShouldClose:(id)sender
{
[timerIn invalidate];
[timerIn release];
timerIn = nil;
// Set up our timer to periodically call the fade: method.
timerOut = [[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(fade:) userInfo:nil repeats:YES] retain];
// [[NSRunLoop currentRunLoop] addTimer:timerOut forMode:NSModalPanelRunLoopMode];
// [[NSRunLoop currentRunLoop] addTimer:timerOut forMode:NSEventTrackingRunLoopMode];
// [timer fire];
// Don't close just yet.
return NO;
}
- (void)fade:(NSTimer *)theTimer
{
if ([[self window] alphaValue] > 0.0)
{
[[self window] setAlphaValue:[[self window] alphaValue] - 0.1];
}
else
{
[timerOut invalidate];
[timerOut release];
timerOut = nil;
[[self window] close];
}
}
- (void)fadeIn:(NSTimer *)theTimer
{
if ([[self window] alphaValue] < 1.0)
{
[[self window] setAlphaValue:[[self window] alphaValue] + 0.1];
}
else
{
[timerIn invalidate];
[timerIn release];
timerIn = nil;
[[self window] setAlphaValue:1.0];
}
}
@end