From 5fa1e3d2a0b064e6c54e2e20abd43ce358b4d4f0 Mon Sep 17 00:00:00 2001 From: phantom Date: Tue, 1 Jan 2013 17:40:29 +0100 Subject: [PATCH] Splash should show up properly now. --- src/RageSurfaceUtils.cpp | 2 +- src/RageSurfaceUtils.h | 2 +- src/StepMania.cpp | 13 +++-- src/arch/LoadingWindow/LoadingWindow.h | 2 +- src/arch/LoadingWindow/LoadingWindow_Gtk.cpp | 4 +- src/arch/LoadingWindow/LoadingWindow_Gtk.h | 2 +- .../LoadingWindow/LoadingWindow_GtkModule.cpp | 35 ++++++++++-- .../LoadingWindow/LoadingWindow_GtkModule.h | 2 +- src/arch/LoadingWindow/LoadingWindow_MacOSX.h | 2 +- src/arch/LoadingWindow/LoadingWindow_Null.h | 2 +- .../LoadingWindow/LoadingWindow_Win32.cpp | 53 +++++++++---------- src/arch/LoadingWindow/LoadingWindow_Win32.h | 2 +- 12 files changed, 73 insertions(+), 48 deletions(-) diff --git a/src/RageSurfaceUtils.cpp b/src/RageSurfaceUtils.cpp index 48d4a2542c..539491bdf1 100644 --- a/src/RageSurfaceUtils.cpp +++ b/src/RageSurfaceUtils.cpp @@ -141,7 +141,7 @@ void RageSurfaceUtils::CopySurface( const RageSurface *src, RageSurface *dest ) Blit( src, dest, -1, -1 ); } -bool RageSurfaceUtils::ConvertSurface( RageSurface *src, RageSurface *&dst, +bool RageSurfaceUtils::ConvertSurface( const RageSurface *src, RageSurface *&dst, int width, int height, int bpp, uint32_t R, uint32_t G, uint32_t B, uint32_t A ) { diff --git a/src/RageSurfaceUtils.h b/src/RageSurfaceUtils.h index 877591958d..533d74e11a 100644 --- a/src/RageSurfaceUtils.h +++ b/src/RageSurfaceUtils.h @@ -28,7 +28,7 @@ namespace RageSurfaceUtils void GetBitsPerChannel( const RageSurfaceFormat *fmt, uint32_t bits[4] ); void CopySurface( const RageSurface *src, RageSurface *dest ); - bool ConvertSurface( RageSurface *src, RageSurface *&dst, + bool ConvertSurface( const RageSurface *src, RageSurface *&dst, int width, int height, int bpp, uint32_t R, uint32_t G, uint32_t B, uint32_t A ); void ConvertSurface( RageSurface *&image, int width, int height, int bpp, uint32_t R, uint32_t G, uint32_t B, uint32_t A ); diff --git a/src/StepMania.cpp b/src/StepMania.cpp index f68e0ef9ce..47c607bfce 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -1093,11 +1093,14 @@ int main(int argc, char* argv[]) /* Now that THEME is loaded, load the icon and splash for the current * theme into the loading window. */ RString sError; - RageSurface *pIcon = RageSurfaceUtils::LoadFile( THEME->GetPathG( "Common", "window icon" ), sError ); - if( pIcon ) - pLoadingWindow->SetIcon( pIcon ); - delete pIcon; - pLoadingWindow->SetSplash( THEME->GetPathG("Common","splash") ); + RageSurface *pSurface = RageSurfaceUtils::LoadFile( THEME->GetPathG( "Common", "window icon" ), sError ); + if( pSurface != NULL ) + pLoadingWindow->SetIcon( pSurface ); + delete pSurface; + pSurface = RageSurfaceUtils::LoadFile( THEME->GetPathG("Common","splash"), sError ); + if( pSurface != NULL ) + pLoadingWindow->SetSplash( pSurface ); + delete pSurface; } if( PREFSMAN->m_iSoundWriteAhead ) diff --git a/src/arch/LoadingWindow/LoadingWindow.h b/src/arch/LoadingWindow/LoadingWindow.h index 8dc34d984e..63dcb963c4 100644 --- a/src/arch/LoadingWindow/LoadingWindow.h +++ b/src/arch/LoadingWindow/LoadingWindow.h @@ -13,7 +13,7 @@ public: virtual void SetText( RString str ) = 0; virtual void SetIcon( const RageSurface *pIcon ) { } - virtual void SetSplash( const RString sPath ) { } + virtual void SetSplash( const RageSurface *pSplash ) { } virtual void SetProgress( const int progress ) { m_progress=progress; } virtual void SetTotalWork( const int totalWork ) { m_totalWork=totalWork; } virtual void SetIndeterminate( bool indeterminate ) { m_indeterminate=indeterminate; } diff --git a/src/arch/LoadingWindow/LoadingWindow_Gtk.cpp b/src/arch/LoadingWindow/LoadingWindow_Gtk.cpp index 7e1d3187d9..a41bfe410e 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Gtk.cpp +++ b/src/arch/LoadingWindow/LoadingWindow_Gtk.cpp @@ -90,9 +90,9 @@ void LoadingWindow_Gtk::SetIcon( const RageSurface *pIcon ) //Module_SetIcon( pIcon ); } -void LoadingWindow_Gtk::SetSplash( const RString str ) +void LoadingWindow_Gtk::SetSplash( const RageSurface *pSplash ) { - Module_SetSplash( FILEMAN->ResolvePath(str) ); + Module_SetSplash( pSplash ); } void LoadingWindow_Gtk::SetProgress( const int progress ) diff --git a/src/arch/LoadingWindow/LoadingWindow_Gtk.h b/src/arch/LoadingWindow/LoadingWindow_Gtk.h index 25bfb95b9c..952638d414 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Gtk.h +++ b/src/arch/LoadingWindow/LoadingWindow_Gtk.h @@ -13,7 +13,7 @@ public: ~LoadingWindow_Gtk(); void SetText( RString str ); void SetIcon( const RageSurface *pIcon ); - void SetSplash( const RString str ); + void SetSplash( const RageSurface *pSplash ); void SetProgress( const int progress ); void SetTotalWork( const int totalWork ); void SetIndeterminate( bool indeterminate ); diff --git a/src/arch/LoadingWindow/LoadingWindow_GtkModule.cpp b/src/arch/LoadingWindow/LoadingWindow_GtkModule.cpp index 18578bf5a4..e82d212f39 100644 --- a/src/arch/LoadingWindow/LoadingWindow_GtkModule.cpp +++ b/src/arch/LoadingWindow/LoadingWindow_GtkModule.cpp @@ -26,7 +26,7 @@ extern "C" const char *Init( int *argc, char ***argv ) gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_CENTER ); gtk_widget_set_size_request(window,468,-1); gtk_window_set_deletable( GTK_WINDOW(window), FALSE ); - gtk_window_set_policy(GTK_WINDOW(window),FALSE,FALSE,TRUE); + gtk_window_set_resizable(GTK_WINDOW(window),FALSE); gtk_window_set_role( GTK_WINDOW(window), "sm-startup" ); //gtk_window_set_icon( GTK_WINDOW(window), ); gtk_widget_realize(window); @@ -54,7 +54,7 @@ extern "C" const char *Init( int *argc, char ***argv ) extern "C" void Shutdown() { - gtk_widget_hide_all(window); + gtk_widget_hide(window); g_signal_emit_by_name (G_OBJECT (window), "destroy"); while( gtk_events_pending() ) gtk_main_iteration_do(FALSE); @@ -66,6 +66,27 @@ extern "C" void SetText( const char *s ) gtk_widget_show(label); gtk_main_iteration_do(FALSE); } + +void DeletePixels( guchar *pixels, gpointer data ) +{ + delete[] (uint8_t *)pixels; +} + +GdkPixbuf *MakePixbuf( const RageSurface *pSrc ) +{ + RageSurface *pSurface; + if( !RageSurfaceUtils::ConvertSurface( pSrc, pSurface, pSrc->w, pSrc->h, 32, + 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 ) ) + { + return NULL; + } + GdkPixbuf *pBuf = gdk_pixbuf_new_from_data( pSurface->pixels, GDK_COLORSPACE_RGB, + true, 8, pSurface->w, pSurface->h , pSurface->pitch, DeletePixels, NULL); + if( pBuf != NULL ) + pSurface->pixels_owned = false; + delete pSurface; + return pBuf; +} /* extern "C" void SetIcon( const RageSurface *pSrcImg ) { @@ -94,9 +115,15 @@ extern "C" void SetIcon( const RageSurface *pSrcImg ) gtk_main_iteration_do(FALSE); } */ -extern "C" void SetSplash( const char *s ) + +extern "C" void SetSplash( const RageSurface *pSplash ) { - gtk_image_set_from_file(GTK_IMAGE(splash), s); + GdkPixbuf *pBuf = MakePixbuf( pSplash ); + if( pBuf != NULL ) + { + gtk_image_set_from_pixbuf(GTK_IMAGE(splash), pBuf); + g_object_unref(pBuf); + } gtk_main_iteration_do(FALSE); } diff --git a/src/arch/LoadingWindow/LoadingWindow_GtkModule.h b/src/arch/LoadingWindow/LoadingWindow_GtkModule.h index 410461ebef..e176f4b543 100644 --- a/src/arch/LoadingWindow/LoadingWindow_GtkModule.h +++ b/src/arch/LoadingWindow/LoadingWindow_GtkModule.h @@ -7,7 +7,7 @@ typedef const char *(*INIT)(int *argc, char ***argv); typedef void (*SHUTDOWN)(); typedef void (*SETTEXT)( const char *s ); //typedef void (*SETICON)( const RageSurface *pSrcImg ); -typedef void (*SETSPLASH)( const char *s ); +typedef void (*SETSPLASH)( const RageSurface *pSplash ); typedef void (*SETPROGRESS)( int progress, int totalWork ); typedef void (*SETINDETERMINATE)( bool indeterminate ); diff --git a/src/arch/LoadingWindow/LoadingWindow_MacOSX.h b/src/arch/LoadingWindow/LoadingWindow_MacOSX.h index 37694a9a93..fa2a839351 100644 --- a/src/arch/LoadingWindow/LoadingWindow_MacOSX.h +++ b/src/arch/LoadingWindow/LoadingWindow_MacOSX.h @@ -9,7 +9,7 @@ public: LoadingWindow_MacOSX(); ~LoadingWindow_MacOSX(); void SetText( RString str ); - void SetSplash( const RString path ) {} + void SetSplash( const RageSurface *pSplash ) {} void SetProgress( const int progress ); void SetTotalWork( const int totalWork ); void SetIndeterminate( bool indeterminate ); diff --git a/src/arch/LoadingWindow/LoadingWindow_Null.h b/src/arch/LoadingWindow/LoadingWindow_Null.h index 6d8f48b664..efaed7ea49 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Null.h +++ b/src/arch/LoadingWindow/LoadingWindow_Null.h @@ -7,7 +7,7 @@ class LoadingWindow_Null: public LoadingWindow { public: void SetText( RString str ) { } - void SetSplash( const RString str ) { } + void SetSplash( const RageSurface *pSplash ) { } }; #define USE_LOADING_WINDOW_NULL diff --git a/src/arch/LoadingWindow/LoadingWindow_Win32.cpp b/src/arch/LoadingWindow/LoadingWindow_Win32.cpp index d23951f6b4..82de0c98f6 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Win32.cpp +++ b/src/arch/LoadingWindow/LoadingWindow_Win32.cpp @@ -20,9 +20,28 @@ static HBITMAP g_hBitmap = NULL; /* Load a RageSurface into a GDI surface. */ -static HBITMAP LoadWin32Surface( RageSurface *&s ) +static HBITMAP LoadWin32Surface( const RageSurface *pSplash, HWND hwnd ) { - RageSurfaceUtils::ConvertSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ); + RageSurface *s; + if( !RageSurfaceUtils::ConvertSurface( pSplash, s, + pSplash->w, pSplash->h, 32, + 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ) ) + { + return NULL; + } + + /* Resize the splash image to fit the dialog. Stretch to fit horizontally, + * maintaining aspect ratio. */ + { + RECT r; + GetClientRect( hWnd, &r ); + + int iWidth = r.right; + float fRatio = (float) iWidth / s->w; + int iHeight = lrintf( s->h * fRatio ); + + RageSurfaceUtils::Zoom( s, iWidth, iHeight ); + } HDC hScreen = GetDC(NULL); ASSERT_M( hScreen != NULL, werr_ssprintf(GetLastError(), "hScreen") ); @@ -50,34 +69,10 @@ static HBITMAP LoadWin32Surface( RageSurface *&s ) ReleaseDC( NULL, hScreen ); + delete s; return bitmap; } -static HBITMAP LoadWin32Surface( RString sFile, HWND hWnd ) -{ - RString error; - RageSurface *pSurface = RageSurfaceUtils::LoadFile( sFile, error ); - if( pSurface == NULL ) - return NULL; - - /* Resize the splash image to fit the dialog. Stretch to fit horizontally, - * maintaining aspect ratio. */ - { - RECT r; - GetClientRect( hWnd, &r ); - - int iWidth = r.right; - float fRatio = (float) iWidth / pSurface->w; - int iHeight = lrintf( pSurface->h * fRatio ); - - RageSurfaceUtils::Zoom( pSurface, iWidth, iHeight ); - } - - HBITMAP ret = LoadWin32Surface( pSurface ); - delete pSurface; - return ret; -} - BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) @@ -118,7 +113,7 @@ void LoadingWindow_Win32::SetIcon( const RageSurface *pIcon ) SetClassLong( hwnd, GCL_HICON, (LONG) m_hIcon ); } -void LoadingWindow_Win32::SetSplash( const RString sPath ) +void LoadingWindow_Win32::SetSplash( const RageSurface *pSplash ) { if( g_hBitmap != NULL ) { @@ -126,7 +121,7 @@ void LoadingWindow_Win32::SetSplash( const RString sPath ) g_hBitmap = NULL; } - g_hBitmap = LoadWin32Surface( sPath, hwnd ); + g_hBitmap = LoadWin32Surface( pSplash, hwnd ); if( g_hBitmap != NULL ) { SendDlgItemMessage( diff --git a/src/arch/LoadingWindow/LoadingWindow_Win32.h b/src/arch/LoadingWindow/LoadingWindow_Win32.h index f2131f1bf7..bce72a4de4 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Win32.h +++ b/src/arch/LoadingWindow/LoadingWindow_Win32.h @@ -16,7 +16,7 @@ public: void Paint(); void SetText( RString sText ); void SetIcon( const RageSurface *pIcon ); - void SetSplash( const RString sPath ); + void SetSplash( const RageSurface *pSplash ); void SetProgress( const int progress ); void SetTotalWork( const int totalWork ); void SetIndeterminate( bool indeterminate );