A loading window for OS X using Cocoa

This commit is contained in:
Steve Checkoway
2003-07-04 09:27:12 +00:00
parent 06b6924cb4
commit 8d935ab24d
2 changed files with 89 additions and 0 deletions
@@ -0,0 +1,31 @@
#ifndef LOADING_WINDOW_COCOA
#define LOADING_WINDOW_COCOA
/*
* LoadingWindow_Cocoa.h
* stepmania
*
* Created by Steve Checkoway on Thu Jul 03 2003.
* Copyright (c) 2003 Steve Checkoway. All rights reserved.
*
*/
#include "LoadingWindow_Null.h"
extern void MakeNewCocoaWindow();
extern void DisposeOfCocoaWindow();
extern void PaintCocoaWindow();
extern void SetCocoaWindowText(const char *s);
class LoadingWindow_Cocoa : public LoadingWindow {
public:
LoadingWindow_Cocoa() { MakeNewCocoaWindow(); }
~LoadingWindow_Cocoa() { DisposeOfCocoaWindow(); }
void Paint() {} /* Not needed */
void SetText(CString str) { SetCocoaWindowText(str.c_str()); }
};
#undef ARCH_LOADING_WINDOW
#define ARCH_LOADING_WINDOW LoadingWindow_Cocoa
#endif /* LOADING_WINDOW_COCOA */
@@ -0,0 +1,58 @@
/*
* LoadingWindow_Cocoa.m
* stepmania
*
* Created by Steve Checkoway on Thu Jul 03 2003.
* Copyright (c) 2003 Steve Checkoway. All rights reserved.
*
*/
#import <Cocoa/Cocoa.h>
static NSWindow *window;
static NSTextView *text;
void MakeNewCocoaWindow() {
NSImage *image = [NSImage imageNamed:@"loading"];
NSSize size = [image size];
float height = size.height;
NSImageView *iView = [[[NSImageView alloc] initWithFrame:NSMakeRect(0, height, size.width, height)] autorelease];
NSView *view;
NSRect rect;
rect.origin = NSMakePoint(0, height);
rect.size = size;
rect.size.height += height;
text = [[[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, rect.size.width, height)] autorelease];
[text setEditable:NO];
[text setSelectable:NO];
[text setDrawsBackground:YES];
[text setBackgroundColor:[NSColor lightGrayColor]];
[text setAlignment:NSCenterTextAlignment];
[iView setImage:image];
[iView setImageFrameStyle:NSImageFrameNone];
window = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
[window setOneShot:YES];
[window setReleasedWhenClosed:YES];
[window center];
[window useOptimizedDrawing:YES];
[window setViewsNeedDisplay:YES];
view = [window contentView];
[view addSubview:text]; /* This retains text */
[view addSubview:iView]; /* This retains iView */
[text setString:@"Initializing Hardware..."];
[window makeKeyAndOrderFront:nil];
}
void DisposeOfCocoaWindow() {
[window close]; /* Released by setReleasedWhenClosed */
}
void SetCocoaWindowText(const char *s) {
[text setString:[NSString stringWithCString:s]];
[text display];
}