fix Loading Window splash image for OS X

This commit allows OS X users to enjoy their current theme's custom splash graphic if it is available at ./Graphics/Common splash.png
I have been wanting to fix this for a fairly long time.

My fix is probably not the cleanest or proper way to do this.  StepMania.cpp already looks up the current theme's "Common splash.png" and passes it off to the arch-appropriate LoadingWindow as a RageSurface.  This fix repeats the lookup in LoadingWindow_MacOSX.mm, and loads the splash image into a Ragefile which is easily loaded into an NSImage.

Still, my fix does work, and if you actually know how to work with a Ragesurface and can help out here, I'll give you a cookie. :)
This commit is contained in:
Dan Guzek
2015-05-15 08:28:34 -04:00
parent f5aec7ed4b
commit 40f1554724
2 changed files with 57 additions and 43 deletions
@@ -9,7 +9,7 @@ public:
LoadingWindow_MacOSX(); LoadingWindow_MacOSX();
~LoadingWindow_MacOSX(); ~LoadingWindow_MacOSX();
void SetText( RString str ); void SetText( RString str );
void SetSplash( const RageSurface *pSplash ) {} void SetSplash( const RageSurface *pSplash );
void SetProgress( const int progress ); void SetProgress( const int progress );
void SetTotalWork( const int totalWork ); void SetTotalWork( const int totalWork );
void SetIndeterminate( bool indeterminate ); void SetIndeterminate( bool indeterminate );
@@ -23,7 +23,7 @@ public:
* @author Steve Checkoway (c) 2003-2005, 2008 * @author Steve Checkoway (c) 2003-2005, 2008
* @section LICENSE * @section LICENSE
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the * copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
@@ -33,7 +33,7 @@ public:
* copyright notice(s) and this permission notice appear in all copies of * copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this * the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation. * permission notice appear in supporting documentation.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+54 -40
View File
@@ -3,6 +3,7 @@
#import "LoadingWindow_MacOSX.h" #import "LoadingWindow_MacOSX.h"
#import "RageUtil.h" #import "RageUtil.h"
#import "RageFile.h" #import "RageFile.h"
#include "ThemeManager.h"
@interface LoadingWindowHelper : NSObject @interface LoadingWindowHelper : NSObject
{ {
@@ -25,7 +26,7 @@
NSRect viewRect, windowRect; NSRect viewRect, windowRect;
float height = 0.0f; float height = 0.0f;
float padding = 5.0f; float padding = 5.0f;
NSRect progressIndicatorRect; NSRect progressIndicatorRect;
progressIndicatorRect = NSMakeRect(padding, padding, size.width-padding*2.0f, 0); progressIndicatorRect = NSMakeRect(padding, padding, size.width-padding*2.0f, 0);
m_ProgressIndicator = [[NSProgressIndicator alloc] initWithFrame:progressIndicatorRect]; m_ProgressIndicator = [[NSProgressIndicator alloc] initWithFrame:progressIndicatorRect];
@@ -36,7 +37,7 @@
[m_ProgressIndicator setDoubleValue:0]; [m_ProgressIndicator setDoubleValue:0];
progressIndicatorRect = [m_ProgressIndicator frame]; progressIndicatorRect = [m_ProgressIndicator frame];
float progressHeight = progressIndicatorRect.size.height; float progressHeight = progressIndicatorRect.size.height;
NSFont *font = [NSFont systemFontOfSize:0.0f]; NSFont *font = [NSFont systemFontOfSize:0.0f];
NSRect textRect; NSRect textRect;
// Just give it a size until it is created. // Just give it a size until it is created.
@@ -45,7 +46,7 @@
[m_Text setFont:font]; [m_Text setFont:font];
height = [[m_Text layoutManager] defaultLineHeightForFont:font]*3 + 4; height = [[m_Text layoutManager] defaultLineHeightForFont:font]*3 + 4;
textRect = NSMakeRect( 0, progressHeight + padding, size.width, height ); textRect = NSMakeRect( 0, progressHeight + padding, size.width, height );
[m_Text setFrame:textRect]; [m_Text setFrame:textRect];
[m_Text setEditable:NO]; [m_Text setEditable:NO];
[m_Text setSelectable:NO]; [m_Text setSelectable:NO];
@@ -55,20 +56,20 @@
[m_Text setHorizontallyResizable:NO]; [m_Text setHorizontallyResizable:NO];
[m_Text setVerticallyResizable:NO]; [m_Text setVerticallyResizable:NO];
[m_Text setString:@"Initializing Hardware..."]; [m_Text setString:@"Initializing Hardware..."];
viewRect = NSMakeRect( 0, height + progressHeight + padding, size.width, size.height ); viewRect = NSMakeRect( 0, height + progressHeight + padding, size.width, size.height );
NSImageView *iView = [[NSImageView alloc] initWithFrame:viewRect]; NSImageView *iView = [[NSImageView alloc] initWithFrame:viewRect];
[iView setImage:image]; [iView setImage:image];
[iView setImageFrameStyle:NSImageFrameNone]; [iView setImageFrameStyle:NSImageFrameNone];
windowRect = NSMakeRect( 0, 0, size.width, size.height + height + progressHeight + padding); windowRect = NSMakeRect( 0, 0, size.width, size.height + height + progressHeight + padding);
m_Window = [[NSWindow alloc] initWithContentRect:windowRect m_Window = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:NSTitledWindowMask styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]; defer:YES];
NSView *view = [m_Window contentView]; NSView *view = [m_Window contentView];
// Set some properties. // Set some properties.
[m_Window setOneShot:YES]; [m_Window setOneShot:YES];
[m_Window setReleasedWhenClosed:YES]; [m_Window setReleasedWhenClosed:YES];
@@ -79,14 +80,16 @@
// Set subviews. // Set subviews.
[view addSubview:m_Text]; [view addSubview:m_Text];
[view addSubview:iView];
[m_Text release]; [m_Text release];
[view addSubview:iView];
[iView release]; [iView release];
[view addSubview:m_ProgressIndicator]; [view addSubview:m_ProgressIndicator];
// Display the window. // Display the window.
[m_Window makeKeyAndOrderFront:nil]; [m_Window makeKeyAndOrderFront:nil];
} }
- (void) setProgress:(NSNumber *)progress - (void) setProgress:(NSNumber *)progress
{ {
@@ -107,35 +110,7 @@
static LoadingWindowHelper *g_Helper = nil; static LoadingWindowHelper *g_Helper = nil;
LoadingWindow_MacOSX::LoadingWindow_MacOSX() LoadingWindow_MacOSX::LoadingWindow_MacOSX() {}
{
RageFile f;
RString data;
vector<RString> vs;
GetDirListing( "Data/splash*.png", vs, false, true );
if( vs.empty() || !f.Open(vs[0]) )
return;
f.Read( data );
if( data.empty() )
return;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *image = nil;
NSData *d = [[NSData alloc] initWithBytes:data.data() length:data.length()];
image = [[NSImage alloc] initWithData:d];
[d release];
if( !image )
{
[pool release];
return;
}
g_Helper = [[LoadingWindowHelper alloc] init];
g_Helper->m_Pool = pool;
[g_Helper performSelectorOnMainThread:@selector(setupWindow:) withObject:image waitUntilDone:YES];
[image release];
}
LoadingWindow_MacOSX::~LoadingWindow_MacOSX() LoadingWindow_MacOSX::~LoadingWindow_MacOSX()
{ {
@@ -157,6 +132,45 @@ void LoadingWindow_MacOSX::SetText( RString str )
[s release]; [s release];
} }
void LoadingWindow_MacOSX::SetSplash( const RageSurface *pSplash )
{
RageFile f;
RString data;
vector<RString> vs;
// Try to load a custom splash from the current theme, first.
GetDirListing( THEME->GetPathG( "Common", "splash"), vs, false, true );
// if no Common splash file was found in the theme...
if( vs.empty() || !f.Open(vs[0]) )
{
// then try the stock splash.png from ./Data/
GetDirListing( "Data/splash*.png", vs, false, true );
}
if( vs.empty() || !f.Open(vs[0]) )
return;
f.Read( data );
if( data.empty() )
return;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *image = nil;
NSData *d = [[NSData alloc] initWithBytes:data.data() length:data.length()];
image = [[NSImage alloc] initWithData:d];
[d release];
if( !image )
{
[pool release];
return;
}
g_Helper = [[LoadingWindowHelper alloc] init];
g_Helper->m_Pool = pool;
[g_Helper performSelectorOnMainThread:@selector(setupWindow:) withObject:image waitUntilDone:NO];
[image release];
}
void LoadingWindow_MacOSX::SetProgress( const int progress ) void LoadingWindow_MacOSX::SetProgress( const int progress )
{ {
[g_Helper performSelectorOnMainThread:@selector(setProgress:) withObject:[NSNumber numberWithDouble:(double)progress] waitUntilDone:NO]; [g_Helper performSelectorOnMainThread:@selector(setProgress:) withObject:[NSNumber numberWithDouble:(double)progress] waitUntilDone:NO];
@@ -176,7 +190,7 @@ void LoadingWindow_MacOSX::SetIndeterminate( bool indeterminate )
/* /*
* (c) 2003-2006, 2008 Steve Checkoway * (c) 2003-2006, 2008 Steve Checkoway
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the * copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
@@ -186,7 +200,7 @@ void LoadingWindow_MacOSX::SetIndeterminate( bool indeterminate )
* copyright notice(s) and this permission notice appear in all copies of * copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this * the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation. * permission notice appear in supporting documentation.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF