diff options
Diffstat (limited to 'engines/tony/window.cpp')
-rw-r--r-- | engines/tony/window.cpp | 538 |
1 files changed, 10 insertions, 528 deletions
diff --git a/engines/tony/window.cpp b/engines/tony/window.cpp index ae8d3612c3..c05af6b5e0 100644 --- a/engines/tony/window.cpp +++ b/engines/tony/window.cpp @@ -45,6 +45,8 @@ * * **************************************************************************/ +#include "common/scummsys.h" +#include "util.h" #include "tony/window.h" #include "tony/game.h" #include "tony/tony.h" @@ -61,7 +63,7 @@ static uint16 m_wPrecalcTable[0x10000]; \****************************************************************************/ RMWindow::RMWindow() { - m_Primary = NULL; m_Back = NULL; + } RMWindow::~RMWindow() { @@ -69,188 +71,9 @@ RMWindow::~RMWindow() { RMText::Unload(); } -#ifdef REFACTOR_ME -LRESULT CALLBACK GlobalWindowProc(HWND hWnd, uint32 msg, uint16 wParam, int32 lParam) { - if ((HWND)theGame.m_wnd == NULL) - return DefWindowProc(hWnd, msg, wParam, lParam); - - switch (msg) { - case WM_CREATE: - return 0; - - case WM_CLOSE: - PostQuitMessage(0); - return 0; - - default: - return theGame.m_wnd.WindowProc(msg, wParam, lParam); - } -} -#endif - -#ifdef REFACTOR_ME -LRESULT RMWindow::WindowProc(uint32 msg, uint16 wParam, int32 lParam) { - switch (msg) { - case WM_ACTIVATE: - if (LOWORD(wParam)!=WA_INACTIVE) - theGame.Pause(false); - else - theGame.Pause(true); - return 0; - - case WM_ENTERMENULOOP: - case WM_ENTERSIZEMOVE: - if (!m_bFullscreen) - theGame.Pause(true); - return 0; - - case WM_EXITMENULOOP: - case WM_EXITSIZEMOVE: - if (!m_bFullscreen) - theGame.Pause(false); - return 0; -/* - case WM_KEYDOWN: - switch (wParam) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (GetAsyncKeyState(VK_CONTROL)&0x8000) - theGame.SaveState(wParam-'0'); - else if (GetAsyncKeyState(VK_SHIFT)&0x8000) - theGame.LoadState(wParam-'0'); - return 0; - } - return 0; -*/ - - case WM_PAINT: -// Repaint(); - ValidateRect(m_hWnd, NULL); - return 0; - - case WM_COMMAND: - switch LOWORD(wParam) { -/* - case ID_OPTIONS: - theGame.OptionScreen(); - break; -*/ - - case ID_FULLSCREEN: - theGame.SwitchFullscreen(!m_bFullscreen); - break; -/* - case ID_ENABLEINPUT: - theGame.GetEngine()->EnableInput(); - break; -*/ - case ID_SCREENSHOT: - m_bGrabScreenshot = true; -// m_bGrabMovie = !m_bGrabMovie; - break; - - case ID_MOVIE: -// m_bGrabMovie = !m_bGrabMovie; - break; -/* - case ID_BLACKWHITE: - m_bBlackWhite = !m_bBlackWhite; - break; -*/ - default: - return DefWindowProc(m_hWnd, msg, wParam, lParam); - } - return 0; - - case WM_SYSKEYDOWN: - if (m_bFullscreen) - return 0; - else - return DefWindowProc(m_hWnd ,msg, wParam, lParam); - - default: - if (m_hWnd != NULL) // Fix del bug visto da BoundsChecker - return DefWindowProc(m_hWnd, msg, wParam, lParam); - return 0; - } -} -#endif - -/* -HANDLE hWaitFlip; -bool bExitThread; - -void DoFlipThread(LPDIRECTDRAWSURFACE lpDDSPrimary) { - bExitThread=false; - while (1) { - WaitForSingleObject(hWaitFlip,INFINITE); - if (bExitThread) _endthread(); - lpDDSPrimary->Flip(NULL,DDFLIP_WAIT); - } -} -*/ - -void RMWindow::InitDirectDraw(void) { -#ifdef REFACTOR_ME - DDInit(); - - ShowCursor(false); - ShowWindow(m_hWnd, SW_SHOW); - UpdateWindow(m_hWnd); -#endif -} - -void RMWindow::Init(/*HINSTANCE hInst*/) { -#ifdef REFACTOR_ME - WNDCLASS wc; - - // Registra la classe di finestra - wc.style = CS_HREDRAW|CS_VREDRAW; - wc.lpfnWndProc = GlobalWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInst; - wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON1)); - wc.hCursor = LoadCursor(NULL,IDC_ARROW); - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = "RMClass"; - RegisterClass(&wc); - - m_hWnd = CreateWindow( - "RMClass", - "Tony Tough and the night of Roasted Moths", - WS_OVERLAPPEDWINDOW & (~WS_THICKFRAME) & (~WS_BORDER) & (~WS_MAXIMIZEBOX), - 50, 50, - RM_SX + GetSystemMetrics(SM_CXDLGFRAME) * 2, - RM_SY + GetSystemMetrics(SM_CYDLGFRAME) * 2 + GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION), - NULL, - NULL, - hInst, - NULL - ); - - if (m_hWnd == NULL) { - int err = GetLastError(); - RMString str; - - str.Format("error: %u",err); - MessageBox(NULL,str,"sux",MB_OK); - - assert(0); - } - - // Inizializza la finestra directdraw - //DDInit(); +void RMWindow::Init() { + initGraphics(RM_SX, RM_SY, false); // Inizializza i conteggi degli FPS fps = lastfcount = fcount = lastsecond = 0; @@ -258,361 +81,20 @@ void RMWindow::Init(/*HINSTANCE hInst*/) { m_bGrabScreenshot = false; m_bGrabThumbnail = false; m_bGrabMovie = false; - - //hWaitFlip = CreateEvent(NULL,false,false, NULL); -#endif } void RMWindow::Close(void) { - DDClose(); -#ifdef REFACTOR_ME - DestroyWindow(m_hWnd); -#endif } void RMWindow::GrabThumbnail(uint16 *thumbmem) { - m_bGrabThumbnail = true; - m_wThumbBuf = thumbmem; -} - -float RGB_to_HSL(float r,float g, float b, float *h, float *s, float *l) { - float v; - float m; - float vm; - float r2, g2, b2; - - if (r > g) v = r; else v = g; - if (v > b) v = v; else v = b; - if (r < b) m = r; else m = b; - if (m < b) m = m; else m = b; - - if ((*l = (m + v) / 2.0f) <= 0.0f) return *l; - if ((*s = vm = v - m) > 0.0f) { - *s /= (*l <= 0.5f) ? (v + m) : (2.0f - v - m) ; - } else - return *l; - - r2 = (v - r) / vm; - g2 = (v - g) / vm; - b2 = (v - b) / vm; - - if (r == v) - *h = (g == m ? 5.0f + b2 : 1.0f - g2); - else if (g == v) - *h = (b == m ? 1.0f + r2 : 3.0f - b2); - else - *h = (r == m ? 3.0f + g2 : 5.0f - r2); - - *h /= 6; - - return *l; -} - -#define ITOF(val) (float)((float)(val) / 31.0f) -#define FTOI(val) (int)(((float)(val) * 31.0f + 0.5f)) - -void RMWindow::CreateBWPrecalcTable(void) { -#define CLAMP(var, min, max) var = (var < min ? min : (var > max ? max : var)); - - int i; - int r, g, b; - int min, max; - int shiftR, shiftG, shiftB; - - // Calcola i valori di shift in base alle maschere - for (shiftR = 15; (mskRed & (1 << shiftR)) == 0; shiftR--) - ; - for (shiftG = 15; (mskGreen & (1 << shiftG)) == 0; shiftG--) - ; - for (shiftB = 15; (mskBlue & (1 << shiftB)) == 0; shiftB--) - ; - - shiftR -= 4; - shiftG -= 4; - shiftB -= 4; - - // @@@ CLAMP inutile (in teoria) - CLAMP(shiftR, 0, 15); - CLAMP(shiftG, 0, 15); - CLAMP(shiftB, 0, 15); - - for (i = 0; i < 0x10000; i++) { - r=(i >> shiftR) & 0x1F; - g=(i >> shiftG) & 0x1F; - b=(i >> shiftB) & 0x1F; - -#if 1 - if (r < g) min=r; else min = g; - if (b < min) min = b; - if (r > g) max = r; else max = g; - if (b > max) max = b; - min = (min + max) / 2; -#else - // Nuova formula B&W. L'immagine è più fedele all'originale, ma l'effetto è peggiore - float fr, fg, fb; - - fr = (float)r / 63.0f; - fg = (float)g / 63.0f; - fb = (float)b / 63.0f; - - min = (int)((fr*0.11f + fg*0.69f + fb*0.33f)*63.f); -#endif - - /* - RGB_to_HSL(ITOF(r), ITOF(g), ITOF(b), &h, &s, &l); - min = FTOI(l); - */ - - r = min + 8 - 8; - g = min + 5 - 8; - b = min + 0 - 8; - - CLAMP(r, 0, 31); - CLAMP(g, 0, 31); - CLAMP(b, 0, 31); - - m_wPrecalcTable[i] = (b << shiftB) | (g << shiftG) | (r << shiftR); - } -} - - -void RMWindow::DDClose(void) { -#ifdef REFACTOR_ME - DDRELEASE(m_Back); - DDRELEASE(m_Primary); - DDRELEASE(m_MainClipper); - DDRELEASE(m_BackClipper); - DDRELEASE(m_DD); -#endif -} - -void RMWindow::DDInit(void) { -#ifdef REFACTOR_ME - HRESULT err; - - // Crea DirectDraw - err = DirectDrawCreate(NULL, &m_DD, NULL); - assert(err == DD_OK); - - // Crea il clipper - err = DirectDrawCreateClipper(0, &m_MainClipper, NULL); - err=DirectDrawCreateClipper(0, &m_BackClipper, NULL); - - // Lo associa alla finestra - m_MainClipper->SetHWnd(0, m_hWnd); - - // Setta la cooperazione a normal - m_DD->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL); - -#ifdef STARTFULLSCREEN - // Di default in fullscreen - m_bFullscreen=false; // Fa finta, per obbligarlo a cambiare - m_Primary=m_Back=NULL; - SwitchFullscreen(true); -#else - // Di default in finestra - m_bFullscreen = true; // Fa finta, per obbligarlo a cambiare - m_Primary = m_Back = NULL; - SwitchFullscreen(false); -#endif - -/* - if (!ISMODE1() && !ISMODE2() && !ISMODE3() && !ISMODE4()) { - RMString str; - str.Format("Graphic mode not supported: %04x %04x %04x",mskRed,mskGreen,mskBlue); - MessageBox(m_hWnd,str,"Debug",MB_OK); - } -*/ -#endif + warning("TODO: RMWindow::GrabThumbnail"); } - -void RMWindow::SwitchFullscreen(bool bFull) { -#ifdef REFACTOR_ME - HRESULT err; - DDSURFACEDESC ddsd; - DDSCAPS ddscaps; - DDBLTFX ddbltfx; - Common::Rect rcWin; - - // Se non c'e' niente da fare, esci - if (bFull == m_bFullscreen) - return; - - // Termina il thread di flipping - //bExitThread = true; - - // Rilascia le superfici create in precedenza (se ce n'erano) - DDRELEASE(m_Back); - DDRELEASE(m_Primary); - - // Legge le coordinate della finestra - if (m_bFullscreen) { - rcWin.left = 50; - rcWin.top = 50; - } else { - GetWindowRect(m_hWnd, &rcWin); - } - - if (bFull) { - // Setta la risoluzione - m_DD->SetCooperativeLevel(m_hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); - m_DD->SetDisplayMode(RM_SX, RM_SY, 16); - - // A tutto schermo, possiamo creare una catena di flipping - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; - ddsd.dwBackBufferCount = 1; - if ((err=m_DD->CreateSurface(&ddsd, &m_Primary, NULL)) != DD_OK) { - //wsprintf(errbuf,"Error creating primary surface2 (%lx)",err); - //MessageBox(hWnd,errbuf,"grSwitchFullscreen()",MB_OK); - assert(0); - } - - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - if ((err=m_Primary->GetAttachedSurface(&ddscaps, &m_Back)) != DD_OK) { - //wsprintf(errbuf,"Error getting attached surface2 (%lx)",err); - //MessageBox(hWnd,errbuf,"grSwitchFullscreen()",MB_OK); - assert(0); - } - - // Pulisce i buffer - ddbltfx.dwSize = sizeof(ddbltfx); - ddbltfx.dwFillColor = 0; - m_Back->Blt(NULL, NULL, NULL,DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); - - ddbltfx.dwSize=sizeof(ddbltfx); - ddbltfx.dwFillColor = 0; - m_Primary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); - - // Inizializza il thread - //_beginthread((void (*)(void*))DoFlipThread,10240,(void*)m_Primary); - } else { - // In windowed, non possiamo fare flipping (purtroppo) - m_DD->RestoreDisplayMode(); - m_DD->SetCooperativeLevel(m_hWnd,DDSCL_NORMAL); - - ZeroMemory(&ddsd,sizeof(ddsd)); - ddsd.dwSize=sizeof(ddsd); - ddsd.dwFlags=DDSD_CAPS; - ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE; - if ((err=m_DD->CreateSurface(&ddsd,&m_Primary, NULL)) != DD_OK) { - //wsprintf(errbuf,"Error creating primary surface (%lx)",err); - //MessageBox(hWnd,errbuf,"ChangeResolution()",MB_OK); - assert(0); - } - - ZeroMemory(&ddsd,sizeof(ddsd)); - ddsd.dwSize=sizeof(ddsd); - ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT; - ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN; // se puo', in video memory - ddsd.dwWidth=RM_SX; - ddsd.dwHeight=RM_SY; - if ((err=m_DD->CreateSurface(&ddsd,&m_Back, NULL)) != DD_OK) { - //wsprintf(errbuf,"Error creating backbuffer surface (%lx)",err); - //MessageBox(hWnd,errbuf,"ChangeResolution()",MB_OK); - assert(0); - } - - // Pulizia per favore - ddbltfx.dwSize = sizeof(ddbltfx); - ddbltfx.dwFillColor = 0; - m_Back->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); - } - - // Posiziona e ridimensiona la finestra - if (bFull) { - SetWindowPos(m_hWnd, HWND_TOP, 0, 0, RM_SX, RM_SY, 0); - - // Disabilita il clipper (non necessario) - m_Primary->SetClipper(NULL); - } else { - SetWindowPos(m_hWnd, HWND_TOP, rcWin.left, rcWin.top, RM_SX + GetSystemMetrics(SM_CXDLGFRAME) * 2, - RM_SY + GetSystemMetrics(SM_CYDLGFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION), 0); - - m_Primary->SetClipper(m_MainClipper); - //m_Primary->SetClipper(NULL); - } - - // Si ricorda il nuovo stato - m_bFullscreen = bFull; - InvalidateRect(m_hWnd, NULL, false); - - // Legge il nuovo pixel format - UpdatePixelFormat(); -#endif -} - -void RMWindow::UpdatePixelFormat(void) { -#ifdef REFACTOR_ME - DDPIXELFORMAT ddpf; - - // Si fa ridare il nuovo pixel format - ddpf.dwSize = sizeof(ddpf); - m_Primary->GetPixelFormat(&ddpf); - - // Copia le componenti dei colori - mskRed = ddpf.dwRBitMask; - mskGreen = ddpf.dwGBitMask; - mskBlue = ddpf.dwBBitMask; - - // Ricalcola la tabella per l'effetto b&w - CreateBWPrecalcTable(); -#endif -} - - +/** + * Repaint the screen + */ void RMWindow::Repaint(void) { -#ifdef REFACTOR_ME - Common::Rect rcWin; - HRESULT err; - - if (m_Primary==NULL) - return; - - // Se siamo a tutto schermo, basta un flip - if (m_bFullscreen) { - m_DD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); - - // Flippa flappa - while (1) { - //err=m_Primary->Flip(NULL,DDFLIP_WAIT); - err = m_Primary->BltFast(0, 0, m_Back, NULL, DDBLTFAST_WAIT); - - if (err==DD_OK) - break; - else if (err == DDERR_SURFACELOST) { - //MessageBox(NULL,"Primary lost!","RMWindow::Repaint()",MB_OK); - m_Primary->Restore(); - return; - } - } - } - // Altrimenti bisogna andare di blit - else { - // Si calcola il rettangolo effettivamente visibile - GetWindowRect(m_hWnd, &rcWin); - OffsetRect(&rcWin, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYCAPTION)); - - // Aggiusta le dimensioni del rettangolo - rcWin.right = rcWin.left + RM_SX; - rcWin.bottom = rcWin.top + RM_SY; - - // Blit del back nel primary - while (1) { - err = m_Primary->Blt(&rcWin, m_Back, NULL,DDBLT_WAIT, NULL); - if (err == DD_OK) - break; - else if (err == DDERR_SURFACELOST) { - //MessageBox(NULL,"Primary lost!","RMWindow::Repaint()",MB_OK); - m_Primary->Restore(); - return; - } - } - } -#endif + g_system->updateScreen(); } |