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();
void SetText( RString str );
void SetSplash( const RageSurface *pSplash ) {}
void SetSplash( const RageSurface *pSplash );
void SetProgress( const int progress );
void SetTotalWork( const int totalWork );
void SetIndeterminate( bool indeterminate );
+44 -30
View File
@@ -3,6 +3,7 @@
#import "LoadingWindow_MacOSX.h"
#import "RageUtil.h"
#import "RageFile.h"
#include "ThemeManager.h"
@interface LoadingWindowHelper : NSObject
{
@@ -79,9 +80,11 @@
// Set subviews.
[view addSubview:m_Text];
[view addSubview:iView];
[m_Text release];
[view addSubview:iView];
[iView release];
[view addSubview:m_ProgressIndicator];
// Display the window.
@@ -107,35 +110,7 @@
static LoadingWindowHelper *g_Helper = nil;
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];
}
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 )
{
[g_Helper performSelectorOnMainThread:@selector(setProgress:) withObject:[NSNumber numberWithDouble:(double)progress] waitUntilDone:NO];