[loading window] Now the loading window has it's own thread. As such, the paint method is no longer needed.

This commit is contained in:
Henrik Andersson
2011-06-04 02:12:08 +02:00
parent 227863965c
commit 86cc2818e0
5 changed files with 46 additions and 19 deletions
-2
View File
@@ -266,7 +266,6 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
ld->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s",
Basename(sGroupDirName).c_str(),
Basename(sSongDirName).c_str()));
ld->Paint();
}
Song* pNewSong = new Song;
if( !pNewSong->LoadFromSongDir( sSongDirName ) )
@@ -755,7 +754,6 @@ void SongManager::InitCoursesFromDisk( LoadingWindow *ld )
ld->SetText( LOADING_COURSES.GetValue()+ssprintf("\n%s\n%s",
Basename(*sCourseGroup).c_str(),
Basename(*sCoursePath).c_str()));
ld->Paint();
}
Course* pCourse = new Course;
-1
View File
@@ -11,7 +11,6 @@ public:
virtual RString Init() { return RString(); }
virtual ~LoadingWindow() { }
virtual void Paint() { }
virtual void SetText( RString str ) = 0;
virtual void SetIcon( const RageSurface *pIcon ) { }
virtual void SetProgress( const int progress ) { m_progress=progress; }
+38 -9
View File
@@ -80,8 +80,18 @@ static HBITMAP LoadWin32Surface( RString sFile, HWND hWnd )
return ret;
}
BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
INT_PTR CALLBACK LoadingWindow_Win32::DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
LoadingWindow_Win32 *self;
if(msg==WM_INITDIALOG) {
self=(LoadingWindow_Win32 *)lParam;
SetWindowLong(hWnd,DWL_USER,(LONG)self);
} else {
self=(LoadingWindow_Win32 *)GetWindowLong(hWnd,DWL_USER);
}
switch( msg )
{
case WM_INITDIALOG:
@@ -99,12 +109,21 @@ BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam,
(WPARAM) IMAGE_BITMAP,
(LPARAM) (HANDLE) g_hBitmap );
SetWindowTextA( hWnd, PRODUCT_ID );
{
HWND progressCtrl=GetDlgItem( hWnd, IDC_PROGRESS );
SetWindowLong(progressCtrl,GWL_STYLE, PBS_MARQUEE | GetWindowLong(progressCtrl,GWL_STYLE));
SendMessage(progressCtrl,PBM_SETMARQUEE,1,0);
}
break;
case WM_DESTROY:
DeleteObject( g_hBitmap );
g_hBitmap = NULL;
break;
case WM_ENTERIDLE:
SetEvent(self->guiReadyEvent);
}
return FALSE;
@@ -128,33 +147,43 @@ LoadingWindow_Win32::LoadingWindow_Win32()
InitCommonControlsEx(&cceData);
m_hIcon = NULL;
hwnd = CreateDialog( handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, WndProc );
guiReadyEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
CreateThread(NULL, NULL, MessagePump, (void *)this, 0, NULL);
WaitForSingleObject(guiReadyEvent,0);
for( unsigned i = 0; i < 3; ++i )
text[i] = "ABC"; /* always set on first call */
SetText( "" );
Paint();
}
LoadingWindow_Win32::~LoadingWindow_Win32()
{
if(guiReadyEvent)
CloseHandle(guiReadyEvent);
if( hwnd )
DestroyWindow( hwnd );
if( m_hIcon != NULL )
DestroyIcon( m_hIcon );
}
void LoadingWindow_Win32::Paint()
DWORD WINAPI LoadingWindow_Win32::MessagePump(LPVOID thisAsVoidPtr)
{
SendMessage( hwnd, WM_PAINT, 0, 0 );
LoadingWindow_Win32 *self=(LoadingWindow_Win32 *)thisAsVoidPtr;
/* Process all queued messages since the last paint. This allows the window to
* come back if it loses focus during load. */
self->hwnd = CreateDialogParam( self->handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, DlgProc, (LPARAM)thisAsVoidPtr);
// Run the message loop in a separate thread to keep the gui responsive during the loading
MSG msg;
while( PeekMessage( &msg, hwnd, 0, 0, PM_NOREMOVE ) )
while( GetMessage(&msg, self->hwnd, 0, 0 ) )
{
GetMessage(&msg, hwnd, 0, 0 );
if(IsDialogMessage(self->hwnd,&msg)) continue;
DispatchMessage( &msg );
}
return msg.wParam;
}
void LoadingWindow_Win32::SetText( RString sText )
+5 -2
View File
@@ -14,7 +14,6 @@ public:
~LoadingWindow_Win32();
void SetText( RString sText );
void Paint();
void SetIcon( const RageSurface *pIcon );
void SetProgress( const int progress );
void SetTotalWork( const int totalWork );
@@ -24,8 +23,12 @@ private:
HWND hwnd;
RString text[3];
HICON m_hIcon;
HANDLE pumpThread;
HANDLE guiReadyEvent;
static BOOL CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
static DWORD WINAPI MessagePump(LPVOID thisAsVoidPtr);
static INT_PTR CALLBACK DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
};
#define USE_LOADING_WINDOW_WIN32
+3 -5
View File
@@ -7,10 +7,7 @@
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define _WIN32_WINNT 0x0501
#include "winres.h"
#include "CommCtrl.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
@@ -45,15 +42,16 @@ BEGIN
END
IDD_LOADING_DIALOG DIALOGEX 0, 0, 317, 94
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
STYLE DS_SETFONT | DS_CENTER | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Stepmania"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CTEXT "line1",IDC_STATIC_MESSAGE1,0,67,310,10,SS_NOPREFIX | SS_CENTERIMAGE
CTEXT "line2",IDC_STATIC_MESSAGE2,0,76,310,10,SS_NOPREFIX | SS_CENTERIMAGE
CTEXT "line3",IDC_STATIC_MESSAGE3,0,84,310,10,SS_NOPREFIX | SS_CENTERIMAGE
CONTROL "",IDC_SPLASH,"Static",SS_BITMAP,0,0,310,25
CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_MARQUEE,7,51,298,14
CONTROL "",IDC_PROGRESS,"msctls_progress32",0x0,7,51,298,14
END
IDD_DISASM_CRASH DIALOGEX 0, 0, 332, 114