From ac144a0522b54d4d659e1abf410b97949ff1ed87 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sun, 5 Feb 2017 09:15:08 +0100 Subject: [PATCH] Remove hwnd and related ddraw stuff --- blupi.cpp | 56 +----------- button.cpp | 3 +- button.h | 3 +- decor.cpp | 4 +- decor.h | 3 +- event.cpp | 15 ++- event.h | 3 +- jauge.cpp | 3 +- jauge.h | 3 +- menu.cpp | 3 +- menu.h | 3 +- movie.cpp | 35 +++---- movie.h | 12 +-- pixmap.cpp | 261 ++++++++++------------------------------------------- pixmap.h | 7 +- 15 files changed, 89 insertions(+), 325 deletions(-) diff --git a/blupi.cpp b/blupi.cpp index a592d74..0c275a3 100644 --- a/blupi.cpp +++ b/blupi.cpp @@ -34,7 +34,6 @@ // Variables globales -HWND g_hWnd; // handle à la fenêtre SDL_Window *g_window; SDL_Renderer *g_renderer; CEvent* g_pEvent = NULL; @@ -416,10 +415,10 @@ bool InitFail(char *msg, bool bDirectX) else strcpy(buffer, "Error ("); strcat(buffer, msg); strcat(buffer, ")"); - MessageBox(g_hWnd, buffer, TITLE, MB_OK); + + SDL_ShowSimpleMessageBox (SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR, "Error", buffer, g_window); FinishObjects(); - DestroyWindow(g_hWnd); return false; } @@ -427,7 +426,6 @@ bool InitFail(char *msg, bool bDirectX) static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) { - WNDCLASS wc; POINT totalDim, iconDim; RECT rcRect; bool bOK; @@ -444,21 +442,6 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) // Create a window. if ( g_bFullScreen ) { - g_hWnd = CreateWindowEx - ( - WS_EX_TOPMOST, - NAME, - TITLE, - WS_POPUP, - 0, 0, - GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN), - NULL, - NULL, - hInstance, - NULL - ); - g_window = SDL_CreateWindow ( NAME, 0, 0, @@ -469,31 +452,6 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) } else { - int sx, sy; - RECT WindowRect; - - sx = GetSystemMetrics(SM_CXSCREEN); - sy = GetSystemMetrics(SM_CYSCREEN); - - SetRect(&WindowRect, (sx-LXIMAGE)/2, (sy-LYIMAGE)/2, - (sx+LXIMAGE)/2, (sy+LYIMAGE)/2); - AdjustWindowRect(&WindowRect, WS_POPUPWINDOW|WS_CAPTION, true); - WindowRect.top += GetSystemMetrics(SM_CYCAPTION); - - g_hWnd = CreateWindow - ( - NAME, - TITLE, - WS_POPUPWINDOW|WS_CAPTION|WS_VISIBLE, - (sx-LXIMAGE)/2, (sy-LYIMAGE)/2, - WindowRect.right - WindowRect.left, - WindowRect.bottom - WindowRect.top, - HWND_DESKTOP, - NULL, - hInstance, - NULL - ); - g_window = SDL_CreateWindow (NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LXIMAGE, LYIMAGE, 0); } @@ -511,10 +469,6 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) return false; } - ShowWindow(g_hWnd, nCmdShow); - UpdateWindow(g_hWnd); - SetFocus(g_hWnd); - if ( !bOK ) // config.def pas correct ? { return InitFail("Game not correctly installed", false); @@ -526,7 +480,7 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) totalDim.x = LXIMAGE; totalDim.y = LYIMAGE; - if ( !g_pPixmap->Create(g_hWnd, totalDim, g_bFullScreen, g_mouseType) ) + if ( !g_pPixmap->Create(totalDim, g_bFullScreen, g_mouseType) ) return InitFail("Create pixmap", true); OutputDebug("Image: init\n"); @@ -677,14 +631,14 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) g_pDecor = new CDecor; if ( g_pDecor == NULL ) return InitFail("New decor", false); - g_pDecor->Create(g_hWnd, g_pSound, g_pPixmap); + g_pDecor->Create(g_pSound, g_pPixmap); g_pDecor->MapInitColors(); // Crée le gestionnaire d'événements. g_pEvent = new CEvent; if ( g_pEvent == NULL ) return InitFail("New event", false); - g_pEvent->Create(g_hWnd, g_pPixmap, g_pDecor, g_pSound, g_pMovie); + g_pEvent->Create(g_pPixmap, g_pDecor, g_pSound, g_pMovie); g_pEvent->SetFullScreen(g_bFullScreen); g_pEvent->SetMouseType(g_mouseType); #if _INTRO diff --git a/button.cpp b/button.cpp index 839de65..cfda18f 100644 --- a/button.cpp +++ b/button.cpp @@ -41,7 +41,7 @@ CButton::~CButton() // Crée un nouveau bouton. -bool CButton::Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, +bool CButton::Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int type, bool bMinimizeRedraw, int *pMenu, int nbMenu, int *pToolTips, int nbToolTips, @@ -60,7 +60,6 @@ bool CButton::Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, iconDim.x = ttypes[type*2+0]; iconDim.y = ttypes[type*2+1]; - m_hWnd = hWnd; m_pPixmap = pPixmap; m_pSound = pSound; m_type = type; diff --git a/button.h b/button.h index 4689019..f8bf44b 100644 --- a/button.h +++ b/button.h @@ -10,7 +10,7 @@ public: CButton(); ~CButton(); - bool Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, + bool Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int type, bool bMinimizeRedraw, int *pMenu, int nbMenu, int *pTooltips, int nbToolTips, @@ -42,7 +42,6 @@ protected: bool MouseUp(POINT pos); protected: - HWND m_hWnd; CPixmap* m_pPixmap; CDecor* m_pDecor; CSound* m_pSound; diff --git a/decor.cpp b/decor.cpp index af6df61..83d7471 100644 --- a/decor.cpp +++ b/decor.cpp @@ -99,7 +99,6 @@ POINT GetVector(int direct) CDecor::CDecor() { - m_hWnd = NULL; m_pSound = NULL; m_pUndoDecor = NULL; @@ -149,9 +148,8 @@ CDecor::~CDecor() // Initialisation générale. -void CDecor::Create(HWND hWnd, CSound *pSound, CPixmap *pPixmap) +void CDecor::Create(CSound *pSound, CPixmap *pPixmap) { - m_hWnd = hWnd; m_pSound = pSound; m_pPixmap = pPixmap; m_bOutline = false; diff --git a/decor.h b/decor.h index 44c86e9..983b6b5 100644 --- a/decor.h +++ b/decor.h @@ -363,7 +363,7 @@ public: POINT ConvPosToCel(POINT pos, bool bMap=false); POINT ConvPosToCel2(POINT pos); - void Create(HWND hWnd, CSound *pSound, CPixmap *pPixmap); + void Create(CSound *pSound, CPixmap *pPixmap); void Init(int channel, int icon); void InitAfterBuild(); void ResetHili(); @@ -439,7 +439,6 @@ protected: int GetSeeIcon(char *pBits, int index); protected: - HWND m_hWnd; CSound* m_pSound; CPixmap* m_pPixmap; Cellule* m_pUndoDecor; diff --git a/event.cpp b/event.cpp index 82f4000..6dd71c7 100644 --- a/event.cpp +++ b/event.cpp @@ -1538,12 +1538,11 @@ void CEvent::SetMouseType(int mouseType) // Crée le gestionnaire d'événements. -void CEvent::Create(HWND hWnd, CPixmap *pPixmap, CDecor *pDecor, +void CEvent::Create(CPixmap *pPixmap, CDecor *pDecor, CSound *pSound, CMovie *pMovie) { POINT pos; - m_hWnd = hWnd; m_pPixmap = pPixmap; m_pDecor = pDecor; m_pSound = pSound; @@ -1553,10 +1552,10 @@ void CEvent::Create(HWND hWnd, CPixmap *pPixmap, CDecor *pDecor, pos.x = 10; pos.y = 158; - m_jauges[0].Create(m_hWnd, m_pPixmap, m_pSound, pos, 1, true); + m_jauges[0].Create(m_pPixmap, m_pSound, pos, 1, true); pos.y += DIMJAUGEY+2; - m_jauges[1].Create(m_hWnd, m_pPixmap, m_pSound, pos, 3, true); + m_jauges[1].Create(m_pPixmap, m_pSound, pos, 3, true); } @@ -1720,7 +1719,7 @@ bool CEvent::CreateButtons() } } - m_buttons[i].Create(m_hWnd, m_pPixmap, m_pSound, pos, + m_buttons[i].Create(m_pPixmap, m_pSound, pos, table[m_index].buttons[i].type, bMinimizeRedraw, table[m_index].buttons[i].iconMenu+1, @@ -3506,7 +3505,7 @@ bool CEvent::PlayUp(POINT pos, Uint16 mod) { m_menuCel = m_pDecor->ConvPosToCel(pos); m_menuPos = pos; - m_menu.Create(m_hWnd, m_pPixmap, m_pSound, + m_menu.Create(m_pPixmap, m_pSound, pos, m_menuNb, m_menuButtons, m_menuErrors, m_menuPerso); m_bMenu = true; @@ -4031,7 +4030,7 @@ bool CEvent::StartMovie(char *pFilename) strcpy(filename+strlen(filename)-4, ".blp"); // remplace .avi par .blp m_pSound->Cache(SOUND_MOVIE, filename); - if ( !m_pMovie->Play(m_hWnd, rect, pFilename) ) return false; + if ( !m_pMovie->Play(rect, pFilename) ) return false; m_bRunMovie = true; m_pSound->Play(SOUND_MOVIE, 0, 0); return true; @@ -4041,7 +4040,7 @@ bool CEvent::StartMovie(char *pFilename) void CEvent::StopMovie() { - m_pMovie->Stop(m_hWnd); + m_pMovie->Stop(); m_pPixmap->RestorePalette(); m_pSound->Flush(SOUND_MOVIE); // m_pSound->RestartMusic(); diff --git a/event.h b/event.h index 34e2bf1..17d4e6d 100644 --- a/event.h +++ b/event.h @@ -59,7 +59,7 @@ public: ~CEvent(); POINT GetMousePos(); - void Create(HWND hWnd, CPixmap *pPixmap, CDecor *pDecor, CSound *pSound, CMovie *pMovie); + void Create(CPixmap *pPixmap, CDecor *pDecor, CSound *pSound, CMovie *pMovie); void SetFullScreen(bool bFullScreen); void SetMouseType(int mouseType); int GetWorld(); @@ -156,7 +156,6 @@ protected: bool m_bAccessBuild; bool m_bFullScreen; int m_mouseType; - HWND m_hWnd; CPixmap* m_pPixmap; CDecor* m_pDecor; CSound* m_pSound; diff --git a/jauge.cpp b/jauge.cpp index bf934c9..a919cf2 100644 --- a/jauge.cpp +++ b/jauge.cpp @@ -34,10 +34,9 @@ CJauge::~CJauge() // Crée un nouveau bouton. -bool CJauge::Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, +bool CJauge::Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int type, bool bMinimizeRedraw) { - m_hWnd = hWnd; m_pPixmap = pPixmap; m_pSound = pSound; m_type = type; diff --git a/jauge.h b/jauge.h index fbfd34b..0c38882 100644 --- a/jauge.h +++ b/jauge.h @@ -14,7 +14,7 @@ public: CJauge(); ~CJauge(); - bool Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, + bool Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int type, bool bMinimizeRedraw); void Draw(); void Redraw(); @@ -29,7 +29,6 @@ public: void SetRedraw(); protected: - HWND m_hWnd; CPixmap* m_pPixmap; CDecor* m_pDecor; CSound* m_pSound; diff --git a/menu.cpp b/menu.cpp index 8e9da76..dd107df 100644 --- a/menu.cpp +++ b/menu.cpp @@ -92,14 +92,13 @@ CMenu::~CMenu() // Crée un nouveau bouton. -bool CMenu::Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, +bool CMenu::Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int nb, int *pButtons, int *pErrors, int perso) { pos.x -= DIMBUTTONX/2; pos.y -= DIMBUTTONY/2; - m_hWnd = hWnd; m_pPixmap = pPixmap; m_pSound = pSound; m_nbButtons = nb; diff --git a/menu.h b/menu.h index 9ba6918..46c3149 100644 --- a/menu.h +++ b/menu.h @@ -12,7 +12,7 @@ public: CMenu(); ~CMenu(); - bool Create(HWND hWnd, CPixmap *pPixmap, CSound *pSound, + bool Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int nb, int *pButtons, int *pErrors, int perso); void Update(int nb, int *pButtons, int *pErrors); @@ -33,7 +33,6 @@ protected: bool MouseUp(POINT pos); protected: - HWND m_hWnd; CPixmap* m_pPixmap; CDecor* m_pDecor; CSound* m_pSound; diff --git a/movie.cpp b/movie.cpp index c170460..4541dc3 100644 --- a/movie.cpp +++ b/movie.cpp @@ -62,7 +62,7 @@ void CMovie::termAVI() // Sets the movie rectange to be // centered within the app's window. -void CMovie::positionMovie(HWND hWnd, RECT rect) +void CMovie::positionMovie(RECT rect) { // reposition the playback (child) window MoveWindow(m_hwndMovie, @@ -73,7 +73,7 @@ void CMovie::positionMovie(HWND hWnd, RECT rect) // Close the movie and anything associated with it. | // This function clears the and flags | -void CMovie::fileCloseMovie(HWND hWnd) +void CMovie::fileCloseMovie() { MCI_GENERIC_PARMS mciGeneric; @@ -82,10 +82,6 @@ void CMovie::fileCloseMovie(HWND hWnd) m_fPlaying = false; // can't be playing any longer m_fMovieOpen = false; // no more movies open - - // cause a total repaint to occur - InvalidateRect(hWnd, NULL, true); - UpdateWindow(hWnd); } @@ -95,7 +91,7 @@ void CMovie::fileCloseMovie(HWND hWnd) // the movie paused when opened. // Sets on success. -bool CMovie::fileOpenMovie(HWND hWnd, RECT rect, char *pFilename) +bool CMovie::fileOpenMovie(RECT rect, char *pFilename) { MCI_DGV_OPEN_PARMS mciOpen; MCI_DGV_WINDOW_PARMS mciWindow; @@ -113,7 +109,7 @@ bool CMovie::fileOpenMovie(HWND hWnd, RECT rect, char *pFilename) } // we got a filename, now close any old movie and open the new one. */ - if ( m_fMovieOpen ) fileCloseMovie(hWnd); + if ( m_fMovieOpen ) fileCloseMovie(); // we have a .AVI movie to open, use MCI // set up the open parameters @@ -123,7 +119,7 @@ bool CMovie::fileOpenMovie(HWND hWnd, RECT rect, char *pFilename) mciOpen.lpstrElementName = string; mciOpen.lpstrAlias = NULL; mciOpen.dwStyle = WS_CHILD; - mciOpen.hWndParent = hWnd; + mciOpen.hWndParent = nullptr; // try to open the file if ( mciSendCommand(0, MCI_OPEN, @@ -151,12 +147,7 @@ bool CMovie::fileOpenMovie(HWND hWnd, RECT rect, char *pFilename) m_hwndMovie = (HWND)mciStatus.dwReturn; // now get the movie centered - positionMovie(hWnd, rect); - - // cause an update to occur - InvalidateRect(hWnd, NULL, false); - UpdateWindow(hWnd); - + positionMovie(rect); return true; } else @@ -172,7 +163,7 @@ bool CMovie::fileOpenMovie(HWND hWnd, RECT rect, char *pFilename) // of the flag. | // This function sets the flag appropriately when done| -void CMovie::playMovie(HWND hWnd, int nDirection) +void CMovie::playMovie(int nDirection) { m_fPlaying = !m_fPlaying; // swap the play flag @@ -186,7 +177,7 @@ void CMovie::playMovie(HWND hWnd, int nDirection) MCI_DGV_PLAY_PARMS mciPlay; // init to play all - mciPlay.dwCallback = MAKELONG(hWnd,0); + mciPlay.dwCallback = MAKELONG(nullptr,0); mciPlay.dwFrom = mciPlay.dwTo = 0; dwFlags = MCI_NOTIFY; if ( nDirection == IDM_RPLAY ) @@ -280,19 +271,19 @@ bool CMovie::IsExist(char *pFilename) // Montre un film avi. -bool CMovie::Play(HWND hWnd, RECT rect, char *pFilename) +bool CMovie::Play(RECT rect, char *pFilename) { if ( !m_bEnable ) return false; - if ( !fileOpenMovie(hWnd, rect, pFilename) ) return false; - playMovie(hWnd, IDM_PLAY); + if ( !fileOpenMovie(rect, pFilename) ) return false; + playMovie(IDM_PLAY); return true; } // Stoppe le film avi. -void CMovie::Stop(HWND hWnd) +void CMovie::Stop() { if ( !m_bEnable ) return; - fileCloseMovie(hWnd); + fileCloseMovie(); } diff --git a/movie.h b/movie.h index 5172707..cc7fda7 100644 --- a/movie.h +++ b/movie.h @@ -12,14 +12,14 @@ public: bool Create(); bool GetEnable(); bool IsExist(char *pFilename); - bool Play(HWND hWnd, RECT rect, char *pFilename); - void Stop(HWND hWnd); + bool Play(RECT rect, char *pFilename); + void Stop(); protected: - void playMovie(HWND hWnd, int nDirection); - bool fileOpenMovie(HWND hWnd, RECT rect, char *pFilename); - void fileCloseMovie(HWND hWnd); - void positionMovie(HWND hWnd, RECT rect); + void playMovie(int nDirection); + bool fileOpenMovie(RECT rect, char *pFilename); + void fileCloseMovie(); + void positionMovie(RECT rect); void termAVI(); bool initAVI(); diff --git a/pixmap.cpp b/pixmap.cpp index edc6462..0b2cd2b 100644 --- a/pixmap.cpp +++ b/pixmap.cpp @@ -43,7 +43,7 @@ CPixmap::CPixmap() for ( i=0 ; iRelease(); - m_lpDDSurface[i]= NULL; + SDL_DestroyTexture (m_lpSDLTexture[i]); + m_lpSDLTexture[i] = NULL; } } @@ -116,13 +116,11 @@ void CPixmap::SetDebug(bool bDebug) // Crée l'objet DirectDraw principal. // Retourne false en cas d'erreur. -bool CPixmap::Create(HWND hwnd, POINT dim, +bool CPixmap::Create(POINT dim, bool bFullScreen, int mouseType) { - DDSURFACEDESC ddsd; HRESULT ddrval; - m_hWnd = hwnd; m_bFullScreen = bFullScreen; m_mouseType = mouseType; m_dim = dim; @@ -140,15 +138,6 @@ bool CPixmap::Create(HWND hwnd, POINT dim, return false; } - // Get exclusive mode. - if ( m_bFullScreen ) - { - ddrval = m_lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN); - } - else - { - ddrval = m_lpDD->SetCooperativeLevel(hwnd, DDSCL_NORMAL); - } if ( ddrval != DD_OK ) { OutputDebug("Fatal error: SetCooperativeLevel\n"); @@ -166,54 +155,6 @@ bool CPixmap::Create(HWND hwnd, POINT dim, } } - // Create the primary surface with 1 back buffer. - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ddrval = m_lpDD->CreateSurface(&ddsd, &m_lpDDSPrimary, NULL); - if ( ddrval != DD_OK ) - { - TraceErrorDD(ddrval, "pixmap", 0); - OutputDebug("Fatal error: CreateSurface\n"); - return false; - } - - // Create the back buffer. - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH; -//? ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY; - ddsd.dwWidth = dim.x; - ddsd.dwHeight = dim.y; - - ddrval = m_lpDD->CreateSurface(&ddsd, &m_lpDDSBack, NULL); - if ( ddrval != DD_OK ) - { - TraceErrorDD(ddrval, "pixmap", 0); - OutputDebug("Fatal error: CreateBackSurface\n"); - return false; - } - - // Create the mouse buffer. - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH; -//? ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY; - ddsd.dwWidth = DIMBLUPIX; - ddsd.dwHeight = DIMBLUPIY; - - ddrval = m_lpDD->CreateSurface(&ddsd, &m_lpDDSMouse, NULL); - if ( ddrval != DD_OK ) - { - TraceErrorDD(ddrval, "pixmap", 0); - OutputDebug("Fatal error: CreateMouseSurface\n"); - return false; - } - // Create a DirectDrawClipper object. The object enables clipping to the // window boundaries in the IDirectDrawSurface::Blt function for the // primary surface. @@ -227,21 +168,13 @@ bool CPixmap::Create(HWND hwnd, POINT dim, return false; } - ddrval = m_lpClipper->SetHWnd(0, hwnd); + ddrval = m_lpClipper->SetHWnd(0, nullptr); if ( ddrval != DD_OK ) { TraceErrorDD(ddrval, "pixmap", 0); OutputDebug("Can't set clipper window handle\n"); return false; } - - ddrval = m_lpDDSPrimary->SetClipper(m_lpClipper); - if ( ddrval != DD_OK ) - { - TraceErrorDD(ddrval, "pixmap", 0); - OutputDebug("Can't attach clipper to primary surface\n"); - return false; - } } return true; @@ -305,7 +238,6 @@ void CPixmap::Fill(RECT rect, COLORREF color) HRESULT CPixmap::RestoreAll() { if ( m_bDebug ) OutputDebug("CPixmap::RestoreAll\n"); - int i; HRESULT ddrval; if ( m_lpDDSPrimary && m_lpDDSPrimary->IsLost() ) @@ -326,17 +258,6 @@ HRESULT CPixmap::RestoreAll() // if( ddrval != DD_OK ) return ddrval; } - for ( i=0 ; iIsLost() ) - { - ddrval = m_lpDDSurface[i]->Restore(); - if( ddrval == DD_OK ) - { - DDReLoadBitmap(m_lpDDSurface[i], m_filename[i]); - } - } - } return DD_OK; } @@ -392,18 +313,9 @@ HRESULT CPixmap::BltFast(int chDst, int channel, dstRect.y = dst.y; //SDL_BlitSurface (m_lpSDLSurface[channel], &srcRect, m_lpSDLBack, &dstRect); SDL_RenderCopy (g_renderer, m_lpSDLTexture[channel], &srcRect, &dstRect); - if (channel != CHMAP) - ddrval = m_lpDDSBack->BltFast(dst.x, dst.y, - m_lpDDSurface[channel], - &rcRect, dwTrans); - } else { - if (channel != CHMAP) - ddrval = m_lpDDSurface[chDst]->BltFast(dst.x, dst.y, - m_lpDDSurface[channel], - &rcRect, dwTrans); SDL_Rect srcRect, dstRect; srcRect.x = rcRect.left; srcRect.y = rcRect.top; @@ -437,20 +349,15 @@ HRESULT CPixmap::BltFast(int chDst, int channel, // Effectue un appel BltFast. // Les modes sont 0=transparent, 1=opaque. -HRESULT CPixmap::BltFast(LPDIRECTDRAWSURFACE lpDD, SDL_Texture *lpSDL, +HRESULT CPixmap::BltFast(SDL_Texture *lpSDL, int channel, POINT dst, RECT rcRect, int mode) { DWORD dwTrans; - HRESULT ddrval; + HRESULT ddrval = DD_OK; if ( mode == 0 ) dwTrans = DDBLTFAST_SRCCOLORKEY; else dwTrans = DDBLTFAST_NOCOLORKEY; - while( true ) - { - ddrval = lpDD->BltFast(dst.x, dst.y, - m_lpDDSurface[channel], - &rcRect, dwTrans); SDL_Rect srcRect, dstRect; srcRect.x = rcRect.left; srcRect.y = rcRect.top; @@ -463,16 +370,6 @@ HRESULT CPixmap::BltFast(LPDIRECTDRAWSURFACE lpDD, SDL_Texture *lpSDL, SDL_SetRenderTarget (g_renderer, lpSDL); SDL_RenderCopy (g_renderer, m_lpSDLTexture[channel], &srcRect, &dstRect); SDL_SetRenderTarget (g_renderer, nullptr); - if ( ddrval == DD_OK ) break; - - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - if ( ddrval != DD_OK ) break; - } - - if ( ddrval != DDERR_WASSTILLDRAWING ) break; - } return ddrval; } @@ -589,11 +486,6 @@ bool CPixmap::Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] != NULL ) - { - Flush(channel); - } - // Create and set the palette. if ( bUsePalette ) { @@ -619,8 +511,6 @@ bool CPixmap::Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, } } - // Create the offscreen surface, by loading our bitmap. - m_lpDDSurface[channel] = DDLoadBitmap(m_lpDD, pFilename, 0, 0); std::string file = pFilename; if (_access ((file + ".bmp").c_str (), 0 /* F_OK */) != -1) file += ".bmp"; @@ -635,8 +525,18 @@ bool CPixmap::Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, int access, w, h; SDL_QueryTexture (texture, &format, &access, &w, &h); - m_lpSDLTexture[channel] = SDL_CreateTexture (g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, w, h); - SDL_SetTextureBlendMode (m_lpSDLTexture[channel], SDL_BLENDMODE_BLEND); + if (!m_lpSDLTexture[channel]) + { + m_lpSDLTexture[channel] = SDL_CreateTexture (g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, w, h); + SDL_SetTextureBlendMode (m_lpSDLTexture[channel], SDL_BLENDMODE_BLEND); + } + else + { + SDL_SetRenderTarget (g_renderer, m_lpSDLTexture[channel]); + SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 0); + SDL_RenderClear (g_renderer); + SDL_SetRenderTarget (g_renderer, nullptr); + } SDL_SetRenderTarget (g_renderer, m_lpSDLTexture[channel]); SDL_RenderCopy (g_renderer, texture, nullptr, nullptr); @@ -654,16 +554,6 @@ bool CPixmap::Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, if (channel != CHBLUPI) SDL_FreeSurface (surface); - if ( m_lpDDSurface[channel] == NULL ) - { - OutputDebug("Fatal error: DDLoadBitmap\n"); - return false; - } - - // Set the color key to white - if ( m_bDebug ) OutputDebug("DDSetColorKey\n"); - DDSetColorKey(m_lpDDSurface[channel], RGB(255,255,255)); // blanc - strcpy(m_filename[channel], pFilename); m_totalDim[channel] = totalDim; @@ -692,12 +582,10 @@ bool CPixmap::Cache(int channel, SDL_Surface *surface, POINT totalDim) { if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] != NULL ) - { - Flush(channel); - } - // Create the offscreen surface, by loading our bitmap. + if (m_lpSDLTexture[channel]) + SDL_DestroyTexture (m_lpSDLTexture[channel]); + m_lpSDLTexture[channel] = SDL_CreateTextureFromSurface (g_renderer, surface); if (m_lpSDLTexture[channel] == NULL ) @@ -715,25 +603,13 @@ bool CPixmap::Cache(int channel, SDL_Surface *surface, POINT totalDim) return true; } -// Purge une image. - -void CPixmap::Flush(int channel) -{ - if ( channel < 0 || channel >= MAXIMAGE ) return; - if ( m_lpDDSurface[channel] == NULL ) return; - - m_lpDDSurface[channel]->Release(); - m_lpDDSurface[channel]= NULL; -} - // Définition de la couleur transparente. void CPixmap::SetTransparent(int channel, COLORREF color) { if ( channel < 0 || channel >= MAXIMAGE ) return; - if ( m_lpDDSurface[channel] == NULL ) return; + if (m_lpSDLTexture[channel] == NULL ) return; - DDSetColorKey(m_lpDDSurface[channel], color); m_colorSurface[2*channel+0] = color; m_colorSurface[2*channel+1] = color; } @@ -743,9 +619,8 @@ void CPixmap::SetTransparent(int channel, COLORREF color) void CPixmap::SetTransparent2(int channel, COLORREF color1, COLORREF color2) { if ( channel < 0 || channel >= MAXIMAGE ) return; - if ( m_lpDDSurface[channel] == NULL ) return; + if (m_lpSDLTexture[channel] == NULL ) return; - DDSetColorKey2(m_lpDDSurface[channel], color1, color2); m_colorSurface[2*channel+0] = color1; m_colorSurface[2*channel+1] = color2; } @@ -772,10 +647,9 @@ bool CPixmap::IsIconPixel(int channel, int rank, POINT pos) { int nbx, nby; COLORREF rgb; - HDC hDC; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -785,17 +659,21 @@ bool CPixmap::IsIconPixel(int channel, int rank, POINT pos) if ( rank < 0 || rank >= nbx*nby ) return false; - pos.x += (rank%nbx)*m_iconDim[channel].x; - pos.y += (rank/nbx)*m_iconDim[channel].y; + pos.x += (rank % nbx) * m_iconDim[channel].x; + pos.y += (rank / nbx) * m_iconDim[channel].y; - if ( m_lpDDSurface[channel]->GetDC(&hDC) != DD_OK ) return false; - rgb = GetPixel(hDC, pos.x, pos.y); - m_lpDDSurface[channel]->ReleaseDC(hDC); + SDL_Rect rect; + rect.x = pos.x; + rect.y = pos.y; + rect.w = 1; + rect.h = 1; + Uint32 pixel = 0; - if ( rgb == m_colorSurface[2*channel+0] || - rgb == m_colorSurface[2*channel+1] ) return false; + SDL_SetRenderTarget (g_renderer, m_lpSDLTexture[channel]); + SDL_RenderReadPixels (g_renderer, &rect, 0, &pixel, 4); + SDL_SetRenderTarget (g_renderer, nullptr); - return true; + return !!pixel; } @@ -811,7 +689,7 @@ bool CPixmap::DrawIcon(int chDst, int channel, int rank, POINT pos, COLORREF oldColor1, oldColor2; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( channel != CHMAP && m_lpDDSurface[channel] == NULL ) return false; + if ( channel != CHMAP && m_lpSDLTexture[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -855,7 +733,7 @@ bool CPixmap::DrawIconDemi(int chDst, int channel, int rank, POINT pos, COLORREF oldColor1, oldColor2; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -895,7 +773,7 @@ bool CPixmap::DrawIconPart(int chDst, int channel, int rank, POINT pos, COLORREF oldColor1, oldColor2; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -933,7 +811,7 @@ bool CPixmap::DrawPart(int chDst, int channel, POINT dest, RECT rect, COLORREF oldColor1, oldColor2; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; oldColor1 = m_colorSurface[2*channel+0]; oldColor2 = m_colorSurface[2*channel+1]; @@ -954,7 +832,7 @@ bool CPixmap::DrawImage(int chDst, int channel, RECT rect, int mode) HRESULT ddrval; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; dst.x = rect.left; dst.y = rect.top; @@ -983,7 +861,7 @@ bool CPixmap::BuildIconMask(int channelMask, int rankMask, HRESULT ddrval; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if (m_lpSDLTexture[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -1000,7 +878,7 @@ bool CPixmap::BuildIconMask(int channelMask, int rankMask, rect.bottom = rect.top + m_iconDim[channel].y; posDst.x = (rankDst%nbx)*m_iconDim[channel].x; posDst.y = (rankDst/nbx)*m_iconDim[channel].y; - ddrval = BltFast(m_lpDDSurface[channel], m_lpSDLTexture[channel], channel, posDst, rect, 1); + ddrval = BltFast(m_lpSDLTexture[channel], channel, posDst, rect, 1); if ( ddrval != DD_OK ) return false; if ( m_iconDim[channelMask].x == 0 || @@ -1015,7 +893,7 @@ bool CPixmap::BuildIconMask(int channelMask, int rankMask, rect.top = (rankMask/nbx)*m_iconDim[channelMask].y; rect.right = rect.left + m_iconDim[channelMask].x; rect.bottom = rect.top + m_iconDim[channelMask].y; - ddrval = BltFast(m_lpDDSurface[channel], m_lpSDLTexture[channel], channelMask, posDst, rect, 0); + ddrval = BltFast(m_lpSDLTexture[channel], channelMask, posDst, rect, 0); if ( ddrval != DD_OK ) return false; return true; @@ -1027,61 +905,16 @@ bool CPixmap::BuildIconMask(int channelMask, int rankMask, bool CPixmap::Display() { - HRESULT ddrval; - RECT DestRect, MapRect; + RECT MapRect; m_bBackDisplayed = true; - // Get screen coordinates of client window for blit - GetClientRect(m_hWnd, &DestRect); - ClientToScreen(m_hWnd, (LPPOINT)&DestRect); - ClientToScreen(m_hWnd, (LPPOINT)&DestRect+1); - MapRect.left = 0; MapRect.top = 0; MapRect.right = m_dim.x; MapRect.bottom = m_dim.y; - // do the blit from back surface - ddrval = m_lpDDSPrimary->Blt - ( - &DestRect, // destination rect - m_lpDDSBack, - &MapRect, // source rect - DDBLT_WAIT, - &m_DDbltfx - ); - /*SDL_Rect srcRect, dstRect; - srcRect.x = MapRect.left; - srcRect.y = MapRect.top; - srcRect.w = MapRect.right - MapRect.left; - srcRect.h = MapRect.bottom - MapRect.top; - dstRect.x = DestRect.left; - dstRect.y = DestRect.top; - dstRect.w = DestRect.right - DestRect.left; - dstRect.h = DestRect.bottom - DestRect.top; - SDL_BlitSurface (m_lpSDLPrimary, &srcRect, m_lpSDLBack, &dstRect);*/ - - /* - * Copies the bmp surface to the window surface - */ - /*SDL_BlitSurface (m_lpSDLBack, - NULL, - m_lpSDLPrimary, - NULL);*/ - - /* - * Now updating the window - */ - //SDL_UpdateWindowSurface (g_window); - SDL_RenderPresent (g_renderer); - - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - } - if ( ddrval != DD_OK ) return false; return true; } diff --git a/pixmap.h b/pixmap.h index ed15047..e3b4b48 100644 --- a/pixmap.h +++ b/pixmap.h @@ -18,7 +18,7 @@ public: void SetDebug(bool bDebug); - bool Create(HWND hwnd, POINT dim, bool bFullScreen, int mouseType); + bool Create(POINT dim, bool bFullScreen, int mouseType); bool Flush(); bool Restore(); bool InitSysPalette(); @@ -31,7 +31,6 @@ public: bool Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, bool bUsePalette); bool Cache(int channel, char *pFilename, POINT totalDim, bool bUsePalette); bool Cache(int channel, SDL_Surface *surface, POINT totalDim); - void Flush(int channel); void SetTransparent(int channel, COLORREF color); void SetTransparent2(int channel, COLORREF color1, COLORREF color2); void SetClipping(RECT clip); @@ -58,7 +57,7 @@ public: protected: HRESULT RestoreAll(); HRESULT BltFast(int chDst, int channel, POINT dst, RECT rcRect, int mode); - HRESULT BltFast(LPDIRECTDRAWSURFACE lpDD, SDL_Texture *lpSDL, + HRESULT BltFast(SDL_Texture *lpSDL, int channel, POINT dst, RECT rcRect, int mode); RECT MouseRectSprite(); @@ -70,7 +69,6 @@ protected: int m_mouseType; bool m_bDebug; bool m_bPalette; - HWND m_hWnd; POINT m_dim; // dimensions totales RECT m_clipRect; // rectangle de clipping @@ -87,7 +85,6 @@ protected: SDL_Cursor * m_lpSDLCursors[MAXCURSORS]; SDL_Surface * m_lpSDLBlupi; LPDIRECTDRAWPALETTE m_lpDDPal; // the primary surface palette - LPDIRECTDRAWSURFACE m_lpDDSurface[MAXIMAGE]; // offscreen surfaces SDL_Surface * m_lpSDLSurface[MAXIMAGE]; SDL_Texture * m_lpSDLTexture[MAXIMAGE]; LPDIRECTDRAWCLIPPER m_lpClipper;