Files
itgmania212121/stepmania/src/arch/LoadingWindow/LoadingWindow_Win32.cpp
T

141 lines
4.0 KiB
C++
Raw Normal View History

2003-02-16 04:02:21 +00:00
#include "../../global.h"
#include "../../RageUtil.h"
#include "LoadingWindow_Win32.h"
2004-03-04 01:35:42 +00:00
#include "RageFileManager.h"
#include "resource.h"
#include <windows.h>
2004-04-05 08:38:19 +00:00
#include "SDL_utils.h"
2004-04-05 08:38:19 +00:00
static HBITMAP g_hBitmap = NULL;
2003-09-05 08:22:06 +00:00
2004-04-05 08:38:19 +00:00
/* Load a file into a GDI surface. */
HBITMAP LoadWin32Surface( CString fn )
{
SDL_Surface *s = SDL_LoadImage( fn );
if( s == NULL )
return NULL;
ConvertSDLSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 );
HBITMAP bitmap = CreateCompatibleBitmap( GetDC(NULL), s->w, s->h );
ASSERT( bitmap );
HDC BitmapDC = CreateCompatibleDC( GetDC(NULL) );
SelectObject( BitmapDC, bitmap );
/* This is silly, but simple. We only do this once, on a small image. */
for( int y = 0; y < s->h; ++y )
{
unsigned const char *line = ((unsigned char *) s->pixels) + (y * s->pitch);
for( int x = 0; x < s->w; ++x )
{
unsigned const char *data = line + (x*s->format->BytesPerPixel);
SetPixelV( BitmapDC, x, y, RGB( data[3], data[2], data[1] ) );
}
}
SelectObject( BitmapDC, NULL );
DeleteObject( BitmapDC );
SDL_FreeSurface( s );
return bitmap;
}
2003-09-05 08:22:06 +00:00
BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
2003-09-05 08:22:06 +00:00
switch( msg )
{
case WM_INITDIALOG:
2004-04-05 08:38:19 +00:00
g_hBitmap = LoadWin32Surface( "Data/splash.png" );
if( g_hBitmap == NULL )
g_hBitmap = LoadWin32Surface( "Data/splash.bmp" );
2003-09-13 19:09:01 +00:00
SendMessage(
GetDlgItem(hWnd,IDC_SPLASH),
STM_SETIMAGE,
(WPARAM) IMAGE_BITMAP,
(LPARAM) (HANDLE) g_hBitmap );
2003-09-05 08:22:06 +00:00
break;
2003-09-13 19:09:01 +00:00
2003-09-05 08:22:06 +00:00
case WM_DESTROY:
DeleteObject( g_hBitmap );
g_hBitmap = NULL;
break;
}
return FALSE;
}
LoadingWindow_Win32::LoadingWindow_Win32()
{
2002-12-16 02:08:58 +00:00
hwnd = CreateDialog(handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, WndProc);
2003-12-30 02:00:16 +00:00
for( unsigned i = 0; i < 3; ++i )
text[i] = "XXX"; /* always set on first call */
SetText("Initializing hardware...");
Paint();
}
LoadingWindow_Win32::~LoadingWindow_Win32()
{
if(hwnd)
DestroyWindow( hwnd );
}
void LoadingWindow_Win32::Paint()
{
SendMessage( hwnd, WM_PAINT, 0, 0 );
/* Process all queued messages since the last paint. This allows the window to
* come back if it loses focus during load. */
MSG msg;
while( PeekMessage( &msg, hwnd, 0, 0, PM_NOREMOVE ) ) {
GetMessage(&msg, hwnd, 0, 0 );
DispatchMessage( &msg );
}
}
void LoadingWindow_Win32::SetText(CString str)
{
CStringArray asMessageLines;
split( str, "\n", asMessageLines, false );
2003-12-30 02:00:16 +00:00
while( asMessageLines.size() < 3 )
asMessageLines.push_back( "" );
const int msgs[] = { IDC_STATIC_MESSAGE1, IDC_STATIC_MESSAGE2, IDC_STATIC_MESSAGE3 };
for( unsigned i = 0; i < 3; ++i )
{
if( text[i] == asMessageLines[i] )
continue;
text[i] = asMessageLines[i];
2003-12-30 02:00:16 +00:00
SendDlgItemMessage( hwnd, msgs[i], WM_SETTEXT, 0,
(LPARAM)asMessageLines[i].c_str());
}
}
/*
2004-05-15 22:16:39 +00:00
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/