diff --git a/blupi.cpp b/blupi.cpp index 374c30b..17a07a1 100644 --- a/blupi.cpp +++ b/blupi.cpp @@ -177,7 +177,6 @@ void UpdateFrame(void) POINT posMouse; int i, term, speed; - g_pPixmap->MouseBackClear(); // enlève la souris dans "back" posMouse = g_pEvent->GetLastMousePos(); phase = g_pEvent->GetPhase(); @@ -277,8 +276,6 @@ void UpdateFrame(void) if ( term == 1 ) g_pEvent->ChangePhase(WM_PHASE_LOST); // perdu if ( term == 2 ) g_pEvent->ChangePhase(WM_PHASE_WINMOVIE); // gagné } - - g_pPixmap->MouseBackDraw(); // remet la souris dans "back" } @@ -360,22 +357,13 @@ static void FinishObjects(void) } } - -LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK WindowProc2 (HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam, + const SDL_Event *event) { static HINSTANCE hInstance; POINT mousePos, totalDim, iconDim; -#if 0 - if ( message != WM_TIMER ) - { - char s[100]; - sprintf(s, "message=%d,%d\n", message, wParam); - OutputDebug(s); - } -#endif - // La touche F10 envoie un autre message pour activer // le menu dans les applications Windows standard ! if ( message == WM_SYSKEYDOWN && wParam == VK_F10 ) @@ -388,7 +376,7 @@ LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, } if ( g_pEvent != NULL && - g_pEvent->TreatEvent(message, wParam, lParam) ) return 0; + g_pEvent->TreatEvent(event) ) return 0; switch( message ) { @@ -547,6 +535,11 @@ LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, return DefWindowProc(hWnd, message, wParam, lParam); } +LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + return WindowProc2 (hWnd, message, wParam, lParam, nullptr); +} // Erreur dans DoInit. @@ -668,8 +661,6 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) UpdateWindow(g_hWnd); SetFocus(g_hWnd); - ChangeSprite(SPRITE_WAIT); // met le sablier maison - if ( !bOK ) // config.def pas correct ? { return InitFail("Game not correctly installed", false); @@ -812,6 +803,7 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow) // Load all cursors g_pPixmap->LoadCursors (); + g_pPixmap->ChangeSprite (SPRITE_WAIT); // met le sablier maison // Crée le gestionnaire de son. g_pSound = new CSound; @@ -866,7 +858,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, SetTimer(g_hWnd, 1, g_timerInterval, NULL); - while ( true ) + while (SDL_TRUE) { if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { @@ -880,8 +872,18 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, else { // make sure we go to sleep if we have nothing else to do - if ( !g_bActive ) WaitMessage(); + if (!g_bActive) + WaitMessage (); + else + Sleep (1); } + + SDL_Event event; + while (SDL_PollEvent (&event)) + { + WindowProc2 (nullptr, 0, 0, 0, &event); + } + } out: diff --git a/button.cpp b/button.cpp index 347dffa..839de65 100644 --- a/button.cpp +++ b/button.cpp @@ -10,7 +10,7 @@ #include "decor.h" #include "button.h" #include "misc.h" - +#include "event.h" ///////////////////////////////////////////////////////////////////////////// @@ -241,27 +241,39 @@ void CButton::SetHide(bool bHide) // Traitement d'un événement. -bool CButton::TreatEvent(UINT message, WPARAM wParam, LPARAM lParam) +bool CButton::TreatEvent(const SDL_Event &event) { POINT pos; if ( m_bHide || !m_bEnable ) return false; - pos = ConvLongToPos(lParam); + //pos = ConvLongToPos(lParam); - switch( message ) + switch (event.type) { - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: + case SDL_MOUSEBUTTONDOWN: + if ( event.button.button != SDL_BUTTON_LEFT + && event.button.button != SDL_BUTTON_RIGHT) + break; + + pos.x = event.button.x; + pos.y = event.button.y; if ( MouseDown(pos) ) return true; break; - case WM_MOUSEMOVE: + case SDL_MOUSEMOTION: + pos.x = event.motion.x; + pos.y = event.motion.y; if ( MouseMove(pos) ) return true; break; - case WM_LBUTTONUP: - case WM_RBUTTONUP: + case SDL_MOUSEBUTTONUP: + if ( event.button.button != SDL_BUTTON_LEFT + && event.button.button != SDL_BUTTON_RIGHT) + break; + + pos.x = event.button.x; + pos.y = event.button.y; if ( MouseUp(pos) ) return false; // (*) break; } @@ -350,7 +362,7 @@ bool CButton::MouseDown(POINT pos) m_mouseState = 1; m_bMouseDown = true; m_bRedraw = true; - PostMessage(m_hWnd, WM_UPDATE, 0, 0); + CEvent::PushUserEvent (WM_UPDATE); m_pSound->PlayImage(SOUND_CLICK, pos); return true; @@ -394,7 +406,7 @@ bool CButton::MouseMove(POINT pos) iMenu != m_selMenu ) { m_bRedraw = true; - PostMessage(m_hWnd, WM_UPDATE, 0, 0); + CEvent::PushUserEvent (WM_UPDATE); } return m_bMouseDown; @@ -416,7 +428,7 @@ bool CButton::MouseUp(POINT pos) if ( m_message != -1 ) { - PostMessage(m_hWnd, m_message, 0, 0); + CEvent::PushUserEvent (m_message); } return true; diff --git a/button.h b/button.h index 223e76c..4689019 100644 --- a/button.h +++ b/button.h @@ -30,7 +30,7 @@ public: bool GetHide(); void SetHide(bool bHide); - bool TreatEvent(UINT message, WPARAM wParam, LPARAM lParam); + bool TreatEvent(const SDL_Event &event); bool MouseOnButton(POINT pos); int GetToolTips(POINT pos); diff --git a/decor.h b/decor.h index bca6fc5..49ba9d9 100644 --- a/decor.h +++ b/decor.h @@ -341,9 +341,9 @@ public: int StatisticGetFire(); void StatisticDraw(); void GenerateStatictic(); - bool StatisticDown(POINT pos, int fwKeys); - bool StatisticMove(POINT pos, int fwKeys); - bool StatisticUp(POINT pos, int fwKeys); + bool StatisticDown(POINT pos); + bool StatisticMove(POINT pos); + bool StatisticUp(POINT pos); int StatisticDetect(POINT pos); // Chemin.cpp diff --git a/decstat.cpp b/decstat.cpp index 562300b..de2edb3 100644 --- a/decstat.cpp +++ b/decstat.cpp @@ -802,7 +802,7 @@ void CDecor::GenerateStatictic() // Bouton pressé dans les statistiques. -bool CDecor::StatisticDown(POINT pos, int fwKeys) +bool CDecor::StatisticDown(POINT pos) { int hili, rank, x, y, show, icon; POINT cel; @@ -991,7 +991,7 @@ bool CDecor::StatisticDown(POINT pos, int fwKeys) // Souris déplacée dans les statistiques. -bool CDecor::StatisticMove(POINT pos, int fwKeys) +bool CDecor::StatisticMove(POINT pos) { int rank; @@ -1008,7 +1008,7 @@ bool CDecor::StatisticMove(POINT pos, int fwKeys) // Bouton relâché dans les statistiques. -bool CDecor::StatisticUp(POINT pos, int fwKeys) +bool CDecor::StatisticUp(POINT pos) { return false; } diff --git a/event.cpp b/event.cpp index 83b56ac..9cbb2c5 100644 --- a/event.cpp +++ b/event.cpp @@ -51,15 +51,15 @@ DescInfo; static char cheat_code[9][20] = { - "VISION", // 0 - "POWER", // 1 - "LONESOME", // 2 - "ALLMISSIONS", // 3 - "QUICK", // 4 - "HELPME", // 5 - "INVINCIBLE", // 6 - "SUPERBLUPI", // 7 - "CONSTRUIRE", // 8 (CPOTUSVJSF) + "vision", // 0 + "power", // 1 + "lonesome", // 2 + "allmissions", // 3 + "quick", // 4 + "helpme", // 5 + "invincible", // 6 + "superblupi", // 7 + "construire", // 8 (CPOTUSVJSF) }; @@ -1454,11 +1454,10 @@ CEvent::CEvent() m_bAccessBuild = false; m_bRunMovie = false; m_bBuildModify = false; - m_bMousePress = false; m_bMouseDown = false; m_oldMousePos.x = 0; m_oldMousePos.y = 0; - m_mouseSprite = 0; + m_mouseSprite = SPRITE_ARROW; m_bFillMouse = false; m_bWaitMouse = false; m_bHideMouse = false; @@ -1480,7 +1479,7 @@ CEvent::CEvent() m_bDemoPlay = false; m_pDemoBuffer = NULL; m_demoTime = 0; - m_bCtrlDown = false; + m_keymod = 0; for ( i=0 ; iSetMousePosSprite(pos, m_mouseSprite, m_bDemoPlay); - ChangeSprite(m_mouseSprite); + m_pPixmap->ChangeSprite(m_mouseSprite); } // Met ou enlève le sablier de la souris. @@ -2512,7 +2513,7 @@ void CEvent::WaitMouse(bool bWait) m_mouseSprite = MousePosToSprite(GetMousePos()); } m_pPixmap->SetMouseSprite(m_mouseSprite, m_bDemoPlay); - ChangeSprite(m_mouseSprite); + m_pPixmap->ChangeSprite(m_mouseSprite); } // Cache ou montre la souris. @@ -2530,18 +2531,16 @@ void CEvent::HideMouse(bool bHide) m_mouseSprite = MousePosToSprite(GetMousePos()); } m_pPixmap->SetMouseSprite(m_mouseSprite, m_bDemoPlay); - ChangeSprite(m_mouseSprite); + m_pPixmap->ChangeSprite(m_mouseSprite); } // Traite les événements pour tous les boutons. -bool CEvent::EventButtons(UINT message, WPARAM wParam, LPARAM lParam) +bool CEvent::EventButtons(const SDL_Event &event, POINT pos) { - POINT pos, test; + POINT test; int i, lg, oldx, sound, res; - pos = ConvLongToPos(lParam); - // Cherche le tool tips à utiliser pour la souris. m_textToolTips[0] = 0; oldx = m_posToolTips.x; @@ -2606,15 +2605,17 @@ bool CEvent::EventButtons(UINT message, WPARAM wParam, LPARAM lParam) { m_bHiliInfoButton = true; - if ( message == WM_LBUTTONDOWN || - message == WM_RBUTTONDOWN ) + if (event.type == SDL_MOUSEBUTTONDOWN + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { if ( m_pDecor->GetInfoMode() ) sound = SOUND_CLOSE; else sound = SOUND_OPEN; m_pSound->PlayImage(sound, pos); } - if ( message == WM_LBUTTONUP || - message == WM_RBUTTONUP ) + if (event.type == SDL_MOUSEBUTTONUP + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { // Montre ou cache les infos tout en haut. m_pDecor->SetInfoMode(!m_pDecor->GetInfoMode()); @@ -2630,13 +2631,15 @@ bool CEvent::EventButtons(UINT message, WPARAM wParam, LPARAM lParam) { m_bHiliHelpButton = true; - if ( message == WM_LBUTTONDOWN || - message == WM_RBUTTONDOWN ) + if (event.type == SDL_MOUSEBUTTONDOWN + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { m_pSound->PlayImage(SOUND_CLICK, pos); } - if ( message == WM_LBUTTONUP || - message == WM_RBUTTONUP ) + if (event.type == SDL_MOUSEBUTTONUP + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { // Inverse le mode aide dans les infos. m_bInfoHelp = !m_bInfoHelp; @@ -2655,13 +2658,15 @@ bool CEvent::EventButtons(UINT message, WPARAM wParam, LPARAM lParam) if ( m_phase == WM_PHASE_BUILD ) { - if ( message == WM_LBUTTONDOWN || - message == WM_RBUTTONDOWN ) + if (event.type == SDL_MOUSEBUTTONDOWN + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { m_pDecor->HideTooltips(true); // plus de tooltips pour décor } - if ( message == WM_LBUTTONUP || - message == WM_RBUTTONUP ) + if (event.type == SDL_MOUSEBUTTONUP + && ( event.button.button == SDL_BUTTON_LEFT + || event.button.button == SDL_BUTTON_RIGHT)) { m_pDecor->HideTooltips(false); } @@ -2671,13 +2676,13 @@ bool CEvent::EventButtons(UINT message, WPARAM wParam, LPARAM lParam) i = 0; while ( table[m_index].buttons[i].message != 0 ) { - if ( m_buttons[i].TreatEvent(message, wParam, lParam) ) return true; + if ( m_buttons[i].TreatEvent(event) ) return true; i ++; } if ( m_phase == WM_PHASE_PLAY ) { - if ( m_menu.TreatEvent(message, wParam, lParam) ) return true; + if ( m_menu.TreatEvent(event) ) return true; } return false; @@ -2785,7 +2790,7 @@ bool CEvent::ChangePhase(UINT phase) m_textToolTips[0] = 0; m_posToolTips.x = -1; m_bPause = false; - m_bCtrlDown = false; + m_keymod = 0; m_bMouseDown = false; m_debugPos.x = 0; m_debugPos.y = 0; @@ -3252,9 +3257,6 @@ void CEvent::DecorAutoShift(POINT pos) max = 4-m_scrollSpeed; // max <- 3..1 -//? if ( m_bMousePress && -//? (m_phase == WM_PHASE_PLAY || -//? m_phase == WM_PHASE_BUILD) ) if ( m_phase == WM_PHASE_PLAY || m_phase == WM_PHASE_BUILD ) { @@ -3366,7 +3368,7 @@ bool CEvent::IsShift() // Modifie le décor lorsque le bouton de la souris est pressé. -bool CEvent::PlayDown(POINT pos, int fwKeys) +bool CEvent::PlayDown(POINT pos, const SDL_Event &event) { bool bDecor = false; bool bMap = false; @@ -3386,7 +3388,7 @@ bool CEvent::PlayDown(POINT pos, int fwKeys) return true; } - m_pDecor->StatisticDown(pos, fwKeys); + m_pDecor->StatisticDown(pos); if ( pos.x >= POSMAPX && pos.x <= POSMAPX+DIMMAPX && pos.y >= POSMAPY && pos.y <= POSMAPY+DIMMAPY ) @@ -3403,7 +3405,7 @@ bool CEvent::PlayDown(POINT pos, int fwKeys) if ( !bDecor && !bMap ) return false; cel = m_pDecor->ConvPosToCel(pos, true); - if ( fwKeys&MK_RBUTTON ) + if (event.button.button == SDL_BUTTON_RIGHT) { if ( bMap ) { @@ -3430,7 +3432,7 @@ bool CEvent::PlayDown(POINT pos, int fwKeys) { m_bHili = true; m_bMouseDown = true; - m_pDecor->BlupiHiliDown(pos, !!(fwKeys & MK_SHIFT)); + m_pDecor->BlupiHiliDown(pos, !!(m_keymod & KMOD_SHIFT)); } else { @@ -3443,7 +3445,7 @@ bool CEvent::PlayDown(POINT pos, int fwKeys) // Modifie le décor lorsque la souris est déplacée. -bool CEvent::PlayMove(POINT pos, int fwKeys) +bool CEvent::PlayMove(POINT pos, Uint16 mod) { if ( m_bMenu ) { @@ -3456,13 +3458,13 @@ bool CEvent::PlayMove(POINT pos, int fwKeys) return true; } - m_pDecor->StatisticMove(pos, fwKeys); + m_pDecor->StatisticMove(pos); if ( m_bMouseDown ) // bouton souris pressé ? { if ( m_bHili ) { - m_pDecor->BlupiHiliMove(pos, !!(fwKeys & MK_SHIFT)); + m_pDecor->BlupiHiliMove(pos, !!(mod & KMOD_SHIFT)); } else { @@ -3479,7 +3481,7 @@ bool CEvent::PlayMove(POINT pos, int fwKeys) // Modifie le décor lorsque le bouton de la souris est relâché. -bool CEvent::PlayUp(POINT pos, int fwKeys) +bool CEvent::PlayUp(POINT pos, Uint16 mod) { static int table_sound_boing[3] = { @@ -3488,13 +3490,13 @@ bool CEvent::PlayUp(POINT pos, int fwKeys) SOUND_BOING3, }; - m_pDecor->StatisticUp(pos, fwKeys); + m_pDecor->StatisticUp(pos); if ( m_bMouseDown ) // bouton souris pressé ? { if ( m_bHili ) { - m_pDecor->BlupiHiliUp(pos, !!(fwKeys & MK_SHIFT)); + m_pDecor->BlupiHiliUp(pos, !!(mod & KMOD_SHIFT)); } else { @@ -3802,7 +3804,7 @@ static int tableHome[] = // Modifie le décor lorsque le bouton de la souris est pressé. -bool CEvent::BuildDown(POINT pos, int fwKeys, bool bMix) +bool CEvent::BuildDown(POINT pos, Uint16 mod, bool bMix) { POINT cel; int menu, channel, icon; @@ -3833,7 +3835,7 @@ bool CEvent::BuildDown(POINT pos, int fwKeys, bool bMix) } } - if ( fwKeys & MK_CONTROL ) // touche Ctrl enfoncée ? + if (mod & KMOD_CTRL) // touche Ctrl enfoncée ? { WaitMouse(true); m_pDecor->ArrangeFill(cel, CHFLOOR, tableFloor[menu*10+m_lastFloor[menu]], true); @@ -3867,7 +3869,7 @@ bool CEvent::BuildDown(POINT pos, int fwKeys, bool bMix) } } - if ( fwKeys & MK_CONTROL ) // touche Ctrl enfoncée ? + if (mod & KMOD_CTRL) // touche Ctrl enfoncée ? { WaitMouse(true); m_pDecor->ArrangeFill(cel, CHOBJECT, tableObject[menu*10+m_lastObject[menu]], false); @@ -3898,7 +3900,7 @@ bool CEvent::BuildDown(POINT pos, int fwKeys, bool bMix) } } - if ( fwKeys & MK_CONTROL ) // touche Ctrl enfoncée ? + if (mod & KMOD_CTRL) // touche Ctrl enfoncée ? { WaitMouse(true); m_pDecor->ArrangeFill(cel, CHOBJECT, tableHome[menu*10+m_lastHome[menu]], false); @@ -3982,11 +3984,11 @@ bool CEvent::BuildDown(POINT pos, int fwKeys, bool bMix) // Modifie le décor lorsque la souris est déplacée. -bool CEvent::BuildMove(POINT pos, int fwKeys) +bool CEvent::BuildMove(POINT pos, Uint16 mod, const SDL_Event &event) { - if ( fwKeys & MK_LBUTTON ) // bouton souris pressé ? + if (event.motion.state & SDL_BUTTON (SDL_BUTTON_LEFT)) // bouton souris pressé ? { - BuildDown(pos, fwKeys, false); + BuildDown(pos, mod, false); } if ( GetState(WM_DECOR4) == 1 ) // pose d'un blupi @@ -4003,7 +4005,7 @@ bool CEvent::BuildMove(POINT pos, int fwKeys) // Modifie le décor lorsque le bouton de la souris est relâché. -bool CEvent::BuildUp(POINT pos, int fwKeys) +bool CEvent::BuildUp(POINT pos) { return true; } @@ -4519,7 +4521,7 @@ void CEvent::DemoStep() SetCursorPos(pos.x, pos.y); } - TreatEventBase(message, wParam, lParam); + TreatEventBase(nullptr); // XXX: use SDL_Event if ( m_demoIndex >= m_demoEnd ) { @@ -4584,55 +4586,50 @@ POINT CEvent::GetLastMousePos() // Traitement d'un événement. -bool CEvent::TreatEvent(UINT message, WPARAM wParam, LPARAM lParam) +bool CEvent::TreatEvent(const SDL_Event *event) { if ( m_bDemoPlay ) // démo en lecture ? { - if ( message == WM_KEYDOWN || // l'utilisateur clique ? - message == WM_KEYUP || -// message == WM_LBUTTONDOWN || -// message == WM_RBUTTONDOWN || - message == WM_LBUTTONUP || - message == WM_RBUTTONUP ) + if (event->type == SDL_KEYDOWN || + event->type == SDL_KEYUP || + event->type == SDL_MOUSEBUTTONUP) // is the user clicking? { - DemoPlayStop(); + DemoPlayStop (); return true; } - if ( message == WM_MOUSEMOVE ) // l'utilisateur bouge ? - { + + if (event->type == SDL_MOUSEMOTION) // is the user moving? return true; - } } - return TreatEventBase(message, wParam, lParam); + return TreatEventBase(event); } // Traitement d'un événement. -bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) +bool CEvent::TreatEventBase(const SDL_Event *event) { POINT pos; - int fwKeys; int i, sound; char c; bool bEnable; - pos = ConvLongToPos(lParam); - fwKeys = static_cast (wParam); + //DemoRecEvent(message, wParam, lParam); XXX: use SDL_Event - DemoRecEvent(message, wParam, lParam); + if (!event) + return false; - switch( message ) + switch (event->type) { - case WM_KEYDOWN: - if ( wParam >= 'A' && wParam <= 'Z' ) + case SDL_KEYDOWN: + if ( event->key.keysym.sym >= SDLK_a && event->key.keysym.sym <= SDLK_z ) { if ( m_posCheat == 0 ) // première lettre ? { m_rankCheat = -1; for ( i=0 ; i<9 ; i++ ) { - if ( (char)wParam == cheat_code[i][0] ) + if ( (char) event->key.keysym.sym == cheat_code[i][0] ) { m_rankCheat = i; break; @@ -4643,7 +4640,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) { c = cheat_code[m_rankCheat][m_posCheat]; if ( m_posCheat != 0 && m_rankCheat == 8 ) c++; // CONSTRUIRE ? - if ( (char)wParam == c ) + if ( (char) event->key.keysym.sym == c ) { m_posCheat ++; if ( cheat_code[m_rankCheat][m_posCheat] == 0 ) @@ -4746,15 +4743,17 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) if ( m_phase == WM_PHASE_BYE ) { - PostMessage(m_hWnd, WM_CLOSE, 0, 0); + SDL_Event ev; + ev.type = SDL_QUIT; + SDL_PushEvent (&ev); } - switch( wParam ) + switch (event->key.keysym.sym) { - case VK_END: + case SDLK_END: DemoRecStop(); return true; - case VK_ESCAPE: + case SDLK_ESCAPE: if ( m_bRunMovie ) { StopMovie(); @@ -4799,11 +4798,13 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } if ( m_phase == WM_PHASE_BYE ) { - PostMessage(m_hWnd, WM_CLOSE, 0, 0); + SDL_Event ev; + ev.type = SDL_QUIT; + SDL_PushEvent (&ev); break; } return true; - case VK_RETURN: + case SDLK_RETURN: if ( m_phase == WM_PHASE_PLAY || m_phase == WM_PHASE_READ || m_phase == WM_PHASE_WRITE || @@ -4837,27 +4838,27 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) return true; } return true; - case VK_LEFT: + case SDLK_LEFT: //? DecorShift(-4,4); DecorShift(-2,2); return true; - case VK_RIGHT: + case SDLK_RIGHT: //? DecorShift(4,-4); DecorShift(2,-2); return true; - case VK_UP: + case SDLK_UP: //? DecorShift(-6,-6); DecorShift(-3,-3); return true; - case VK_DOWN: + case SDLK_DOWN: //? DecorShift(6,6); DecorShift(3,3); return true; - case VK_HOME: + case SDLK_HOME: pos = m_pDecor->GetHome(); m_pDecor->SetCoin(pos); return true; - case VK_SPACE: + case SDLK_SPACE: if ( m_bRunMovie ) { StopMovie(); @@ -4866,7 +4867,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } m_pDecor->FlipOutline(); return true; - case VK_PAUSE: + case SDLK_PAUSE: m_bPause = !m_bPause; if ( m_phase == WM_PHASE_PLAY ) { @@ -4880,8 +4881,16 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } } return true; - case VK_CONTROL: - m_bCtrlDown = true; + + case SDLK_LSHIFT: + case SDLK_RSHIFT: + m_keymod |= KMOD_SHIFT; + break; + + case SDLK_LCTRL: + case SDLK_RCTRL: + m_keymod |= KMOD_CTRL; + OutputDebugString ("CTRL: DOWN"); if ( m_phase == WM_PHASE_BUILD ) { m_bFillMouse = true; @@ -4892,7 +4901,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) m_bFillMouse = false; } return true; - case VK_F1: + case SDLK_F1: if ( m_phase == WM_PHASE_PLAY ) { // Montre ou cache les infos tout en haut. @@ -4904,116 +4913,130 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) m_pDecor->SetInfoMode(!m_pDecor->GetInfoMode()); } return true; - case VK_F9: + case SDLK_F8: if ( m_phase == WM_PHASE_PLAY ) { - m_pDecor->MemoPos(0, m_bCtrlDown); + m_pDecor->MemoPos(0, !!(m_keymod & KMOD_CTRL)); } return true; - case VK_F10: + case SDLK_F10: if ( m_phase == WM_PHASE_PLAY ) { - m_pDecor->MemoPos(1, m_bCtrlDown); + m_pDecor->MemoPos(1, !!(m_keymod & KMOD_CTRL)); } return true; - case VK_F11: + case SDLK_F11: if ( m_phase == WM_PHASE_PLAY ) { - m_pDecor->MemoPos(2, m_bCtrlDown); + m_pDecor->MemoPos(2, !!(m_keymod & KMOD_CTRL)); } return true; - case VK_F12: + case SDLK_F12: if ( m_phase == WM_PHASE_PLAY ) { - m_pDecor->MemoPos(3, m_bCtrlDown); + m_pDecor->MemoPos(3, !!(m_keymod & KMOD_CTRL)); } return true; } break; - case WM_KEYUP: - switch( wParam ) + case SDL_KEYUP: + switch (event->key.keysym.sym) { - case VK_CONTROL: - m_bCtrlDown = false; + case SDLK_LSHIFT: + case SDLK_RSHIFT: + m_keymod &= ~KMOD_SHIFT; + break; + + case SDLK_LCTRL: + case SDLK_RCTRL: + m_keymod &= ~KMOD_CTRL; + OutputDebugString ("CTRL: UP"); m_bFillMouse = false; MouseSprite(GetMousePos()); return true; } break; - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - m_bMousePress = true; + case SDL_MOUSEBUTTONDOWN: + if ( event->button.button != SDL_BUTTON_LEFT + && event->button.button != SDL_BUTTON_RIGHT) + break; + + pos.x = event->button.x; + pos.y = event->button.y; + MouseSprite(pos); //? DecorAutoShift(pos); - if ( EventButtons(message, wParam, lParam) ) return true; + if ( EventButtons(*event, pos) ) return true; if ( m_phase == WM_PHASE_BUILD ) { - if ( BuildDown(pos, fwKeys) ) return true; + if ( BuildDown(pos, m_keymod) ) return true; } if ( m_phase == WM_PHASE_PLAY ) { - if ( PlayDown(pos, fwKeys) ) return true; + if ( PlayDown(pos, *event) ) return true; } break; - case WM_MOUSEMOVE: - if ( m_mouseType == MOUSETYPEWINPOS && - (pos.x != m_oldMousePos.x || - pos.y != m_oldMousePos.y ) ) - { - m_oldMousePos = pos; - ClientToScreen(m_hWnd, &m_oldMousePos); - SetCursorPos(m_oldMousePos.x, m_oldMousePos.y); // (*) - } + case SDL_MOUSEMOTION: + pos.x = event->motion.x; + pos.y = event->motion.y; + m_oldMousePos = pos; MouseSprite(pos); - if ( EventButtons(message, wParam, lParam) ) return true; + if ( EventButtons(*event, pos) ) return true; if ( m_phase == WM_PHASE_BUILD ) { - if ( BuildMove(pos, fwKeys) ) return true; + if ( BuildMove(pos, m_keymod, *event) ) return true; } if ( m_phase == WM_PHASE_PLAY ) { - if ( PlayMove(pos, fwKeys) ) return true; + if ( PlayMove(pos, m_keymod) ) return true; } break; - case WM_NCMOUSEMOVE: + case SDL_MOUSEBUTTONUP: + if ( event->button.button != SDL_BUTTON_LEFT + && event->button.button != SDL_BUTTON_RIGHT) break; - case WM_LBUTTONUP: - case WM_RBUTTONUP: - m_bMousePress = false; - if ( EventButtons(message, wParam, lParam) ) return true; + pos.x = event->button.x; + pos.y = event->button.y; + + if ( EventButtons(*event, pos) ) return true; if ( m_phase == WM_PHASE_BUILD ) { - if ( BuildUp(pos, fwKeys) ) return true; + if ( BuildUp(pos) ) return true; } if ( m_phase == WM_PHASE_PLAY ) { - if ( PlayUp(pos, fwKeys) ) return true; + if ( PlayUp(pos, m_keymod) ) return true; } if ( m_phase == WM_PHASE_BYE ) { - PostMessage(m_hWnd, WM_CLOSE, 0, 0); + SDL_Event ev; + ev.type = SDL_QUIT; + SDL_PushEvent (&ev); } break; - case WM_PHASE_DEMO: + case SDL_USEREVENT: + switch (event->user.code) + { + case WM_PHASE_DEMO: m_demoNumber = 0; DemoPlayStart(); break; - case WM_PHASE_SCHOOL: + case WM_PHASE_SCHOOL: m_bSchool = true; m_bPrivate = false; if ( ChangePhase(WM_PHASE_INFO) ) return true; break; - case WM_PHASE_MISSION: + case WM_PHASE_MISSION: m_bSchool = false; m_bPrivate = false; if ( m_mission == 0 ) // première mission ? @@ -5026,45 +5049,45 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } break; - case WM_PHASE_PRIVATE: + case WM_PHASE_PRIVATE: m_bSchool = false; m_bPrivate = true; if ( ChangePhase(WM_PHASE_INFO) ) return true; break; - case WM_PHASE_INTRO1: - case WM_PHASE_INTRO2: - case WM_PHASE_INIT: - case WM_PHASE_HISTORY0: - case WM_PHASE_HISTORY1: - case WM_PHASE_INFO: - case WM_PHASE_PLAY: - case WM_PHASE_READ: - case WM_PHASE_WRITE: - case WM_PHASE_WRITEp: - case WM_PHASE_BUILD: - case WM_PHASE_BUTTON: - case WM_PHASE_TERM: - case WM_PHASE_STOP: - case WM_PHASE_HELP: - case WM_PHASE_MUSIC: - case WM_PHASE_REGION: - case WM_PHASE_SETUP: - case WM_PHASE_SETUPp: - case WM_PHASE_PLAYMOVIE: - case WM_PHASE_H0MOVIE: - case WM_PHASE_H1MOVIE: - case WM_PHASE_H2MOVIE: - case WM_PHASE_WINMOVIE: - case WM_PHASE_BYE: - if ( ChangePhase(message) ) return true; + case WM_PHASE_INTRO1: + case WM_PHASE_INTRO2: + case WM_PHASE_INIT: + case WM_PHASE_HISTORY0: + case WM_PHASE_HISTORY1: + case WM_PHASE_INFO: + case WM_PHASE_PLAY: + case WM_PHASE_READ: + case WM_PHASE_WRITE: + case WM_PHASE_WRITEp: + case WM_PHASE_BUILD: + case WM_PHASE_BUTTON: + case WM_PHASE_TERM: + case WM_PHASE_STOP: + case WM_PHASE_HELP: + case WM_PHASE_MUSIC: + case WM_PHASE_REGION: + case WM_PHASE_SETUP: + case WM_PHASE_SETUPp: + case WM_PHASE_PLAYMOVIE: + case WM_PHASE_H0MOVIE: + case WM_PHASE_H1MOVIE: + case WM_PHASE_H2MOVIE: + case WM_PHASE_WINMOVIE: + case WM_PHASE_BYE: + if ( ChangePhase(event->user.code) ) return true; break; - case WM_PHASE_UNDO: + case WM_PHASE_UNDO: m_pDecor->UndoBack(); // revient en arrière break; - case WM_PREV: + case WM_PREV: m_pDecor->SetInvincible(false); m_pDecor->SetSuper(false); if ( m_bPrivate ) @@ -5093,7 +5116,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } break; - case WM_NEXT: + case WM_NEXT: m_pDecor->SetInvincible(false); m_pDecor->SetSuper(false); if ( m_bPrivate ) @@ -5126,7 +5149,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } break; - case WM_DECOR1: + case WM_DECOR1: SetState(WM_DECOR1, 1); SetState(WM_DECOR2, 0); SetState(WM_DECOR3, 0); @@ -5134,7 +5157,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) SetState(WM_DECOR5, 0); break; - case WM_DECOR2: + case WM_DECOR2: SetState(WM_DECOR1, 0); SetState(WM_DECOR2, 1); SetState(WM_DECOR3, 0); @@ -5142,7 +5165,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) SetState(WM_DECOR5, 0); break; - case WM_DECOR3: + case WM_DECOR3: SetState(WM_DECOR1, 0); SetState(WM_DECOR2, 0); SetState(WM_DECOR3, 1); @@ -5150,7 +5173,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) SetState(WM_DECOR5, 0); break; - case WM_DECOR4: + case WM_DECOR4: SetState(WM_DECOR1, 0); SetState(WM_DECOR2, 0); SetState(WM_DECOR3, 0); @@ -5158,7 +5181,7 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) SetState(WM_DECOR5, 0); break; - case WM_DECOR5: + case WM_DECOR5: SetState(WM_DECOR1, 0); SetState(WM_DECOR2, 0); SetState(WM_DECOR3, 0); @@ -5166,85 +5189,85 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) SetState(WM_DECOR5, 1); break; - case WM_PHASE_SKILL1: + case WM_PHASE_SKILL1: m_pDecor->SetSkill(0); SetState(WM_PHASE_SKILL1, true); SetState(WM_PHASE_SKILL2, false); break; - case WM_PHASE_SKILL2: + case WM_PHASE_SKILL2: m_pDecor->SetSkill(1); SetState(WM_PHASE_SKILL1, false); SetState(WM_PHASE_SKILL2, true); break; - case WM_BUTTON0: - case WM_BUTTON1: - case WM_BUTTON2: - case WM_BUTTON3: - case WM_BUTTON4: - case WM_BUTTON5: - case WM_BUTTON6: - case WM_BUTTON7: - case WM_BUTTON8: - case WM_BUTTON9: - case WM_BUTTON10: - case WM_BUTTON11: - case WM_BUTTON12: - case WM_BUTTON13: - case WM_BUTTON14: - case WM_BUTTON15: - case WM_BUTTON16: - case WM_BUTTON17: - case WM_BUTTON18: - case WM_BUTTON19: - case WM_BUTTON20: - case WM_BUTTON21: - case WM_BUTTON22: - case WM_BUTTON23: - case WM_BUTTON24: - case WM_BUTTON25: - case WM_BUTTON26: - case WM_BUTTON27: - case WM_BUTTON28: - case WM_BUTTON29: - case WM_BUTTON30: - case WM_BUTTON31: - case WM_BUTTON32: - case WM_BUTTON33: - case WM_BUTTON34: - case WM_BUTTON35: - case WM_BUTTON36: - case WM_BUTTON37: - case WM_BUTTON38: - case WM_BUTTON39: - ChangeButtons(message); + case WM_BUTTON0: + case WM_BUTTON1: + case WM_BUTTON2: + case WM_BUTTON3: + case WM_BUTTON4: + case WM_BUTTON5: + case WM_BUTTON6: + case WM_BUTTON7: + case WM_BUTTON8: + case WM_BUTTON9: + case WM_BUTTON10: + case WM_BUTTON11: + case WM_BUTTON12: + case WM_BUTTON13: + case WM_BUTTON14: + case WM_BUTTON15: + case WM_BUTTON16: + case WM_BUTTON17: + case WM_BUTTON18: + case WM_BUTTON19: + case WM_BUTTON20: + case WM_BUTTON21: + case WM_BUTTON22: + case WM_BUTTON23: + case WM_BUTTON24: + case WM_BUTTON25: + case WM_BUTTON26: + case WM_BUTTON27: + case WM_BUTTON28: + case WM_BUTTON29: + case WM_BUTTON30: + case WM_BUTTON31: + case WM_BUTTON32: + case WM_BUTTON33: + case WM_BUTTON34: + case WM_BUTTON35: + case WM_BUTTON36: + case WM_BUTTON37: + case WM_BUTTON38: + case WM_BUTTON39: + ChangeButtons(event->user.code); break; - case WM_READ0: - case WM_READ1: - case WM_READ2: - case WM_READ3: - case WM_READ4: - case WM_READ5: - case WM_READ6: - case WM_READ7: - case WM_READ8: - case WM_READ9: - Read(message); + case WM_READ0: + case WM_READ1: + case WM_READ2: + case WM_READ3: + case WM_READ4: + case WM_READ5: + case WM_READ6: + case WM_READ7: + case WM_READ8: + case WM_READ9: + Read(event->user.code); ChangePhase(WM_PHASE_PLAY); // joue break; - case WM_WRITE0: - case WM_WRITE1: - case WM_WRITE2: - case WM_WRITE3: - case WM_WRITE4: - case WM_WRITE5: - case WM_WRITE6: - case WM_WRITE7: - case WM_WRITE8: - case WM_WRITE9: - Write(message); + case WM_WRITE0: + case WM_WRITE1: + case WM_WRITE2: + case WM_WRITE3: + case WM_WRITE4: + case WM_WRITE5: + case WM_WRITE6: + case WM_WRITE7: + case WM_WRITE8: + case WM_WRITE9: + Write(event->user.code); if ( m_phase == WM_PHASE_WRITEp ) { ChangePhase(WM_PHASE_PLAY); // joue @@ -5255,11 +5278,12 @@ bool CEvent::TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam) } break; - case WM_MOVIE: + case WM_MOVIE: StartMovie("movie\\essai.avi"); ChangePhase(WM_PHASE_INIT); break; } + } return false; } @@ -5319,3 +5343,16 @@ void CEvent::IntroStep() } } +void CEvent::PushUserEvent (int code) +{ + SDL_Event event; + + event.type = SDL_USEREVENT; + event.user.code = code; + event.user.data1 = nullptr; + event.user.data2 = nullptr; + + SDL_PushEvent (&event); + +} + diff --git a/event.h b/event.h index 81900b8..1f5d133 100644 --- a/event.h +++ b/event.h @@ -2,6 +2,11 @@ #pragma once +#include "jauge.h" +#include "menu.h" + +class CMovie; + ///////////////////////////////////////////////////////////////////////////// typedef struct @@ -77,13 +82,13 @@ public: void SetMenu(int button, int menu); bool DrawButtons(); - int MousePosToSprite(POINT pos); + MouseSprites MousePosToSprite(POINT pos); void MouseSprite(POINT pos); void WaitMouse(bool bWait); void HideMouse(bool bHide); POINT GetLastMousePos(); - bool TreatEvent(UINT message, WPARAM wParam, LPARAM lParam); - bool TreatEventBase(UINT message, WPARAM wParam, LPARAM lParam); + bool TreatEvent(const SDL_Event *event); + bool TreatEventBase(const SDL_Event *event); void DecorAutoShift(POINT pos); @@ -91,8 +96,6 @@ public: void StopMovie(); bool IsMovie(); - bool FlipObject(); - void Read(int message); void Write(int message); @@ -106,24 +109,27 @@ public: void IntroStep(); +public: + static void PushUserEvent (int code); + protected: void DrawTextCenter(int res, int x, int y, int font=0); bool CreateButtons(); - bool EventButtons(UINT message, WPARAM wParam, LPARAM lParam); + bool EventButtons(const SDL_Event &event, POINT pos); bool MouseOnButton(POINT pos); int SearchPhase(UINT phase); void DecorShift(int dx, int dy); - bool PlayDown(POINT pos, int fwKeys); - bool PlayMove(POINT pos, int fwKeys); - bool PlayUp(POINT pos, int fwKeys); + bool PlayDown(POINT pos, const SDL_Event &event); + bool PlayMove(POINT pos, Uint16 mod); + bool PlayUp(POINT pos, Uint16 mod); void ChangeButtons(int message); void BuildFloor(POINT cel, int insIcon); void BuildWater(POINT cel, int insIcon); - bool BuildDown(POINT pos, int fwKeys, bool bMix=true); - bool BuildMove(POINT pos, int fwKeys); - bool BuildUp(POINT pos, int fwKeys); + bool BuildDown(POINT pos, Uint16 mod, bool bMix=true); + bool BuildMove(POINT pos, Uint16 mod, const SDL_Event &event); + bool BuildUp(POINT pos); void PrivateLibelle(); bool ReadLibelle(int world, bool bSchool, bool bHelp); @@ -172,14 +178,13 @@ protected: int m_menuPerso; POINT m_menuCel; POINT m_oldMousePos; - bool m_bMousePress; bool m_bMouseDown; bool m_bHili; int m_fileWorld[10]; int m_fileTime[10]; POINT m_posToolTips; char m_textToolTips[50]; - int m_mouseSprite; + MouseSprites m_mouseSprite; bool m_bFillMouse; bool m_bWaitMouse; bool m_bHideMouse; @@ -211,7 +216,7 @@ protected: size_t m_demoIndex; size_t m_demoEnd; int m_demoNumber; - bool m_bCtrlDown; + Uint16 m_keymod; POINT m_debugPos; int m_introTime; }; diff --git a/menu.cpp b/menu.cpp index 128987d..a793105 100644 --- a/menu.cpp +++ b/menu.cpp @@ -13,6 +13,7 @@ #include "menu.h" #include "text.h" #include "misc.h" +#include "event.h" ///////////////////////////////////////////////////////////////////////////// @@ -346,27 +347,39 @@ bool CMenu::IsExist() // Traitement d'un événement. -bool CMenu::TreatEvent(UINT message, WPARAM wParam, LPARAM lParam) +bool CMenu::TreatEvent(const SDL_Event &event) { POINT pos; if ( m_nbButtons == 0 ) return false; - pos = ConvLongToPos(lParam); + //pos = ConvLongToPos(lParam); - switch( message ) - { - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: + switch (event.type) + { + case SDL_MOUSEBUTTONDOWN: + if ( event.button.button != SDL_BUTTON_LEFT + && event.button.button != SDL_BUTTON_RIGHT) + break; + + pos.x = event.button.x; + pos.y = event.button.y; if ( MouseDown(pos) ) return true; break; - case WM_MOUSEMOVE: + case SDL_MOUSEMOTION: + pos.x = event.motion.x; + pos.y = event.motion.y; if ( MouseMove(pos) ) return true; break; - case WM_LBUTTONUP: - case WM_RBUTTONUP: + case SDL_MOUSEBUTTONUP: + if ( event.button.button != SDL_BUTTON_LEFT + && event.button.button != SDL_BUTTON_RIGHT) + break; + + pos.x = event.button.x; + pos.y = event.button.y; if ( MouseUp(pos) ) return true; break; } @@ -431,7 +444,7 @@ void CMenu::Message() { if ( m_selRank != -1 ) { - PostMessage(m_hWnd, WM_BUTTON0+m_selRank, 0, 0); + CEvent::PushUserEvent (WM_BUTTON0 + m_selRank); } } diff --git a/menu.h b/menu.h index 7a060ff..2fb32ad 100644 --- a/menu.h +++ b/menu.h @@ -22,7 +22,7 @@ public: bool IsExist(); void Message(); - bool TreatEvent(UINT message, WPARAM wParam, LPARAM lParam); + bool TreatEvent(const SDL_Event &event); protected: int Detect(POINT pos); diff --git a/misc.cpp b/misc.cpp index 7d3611e..016b61f 100644 --- a/misc.cpp +++ b/misc.cpp @@ -12,7 +12,6 @@ // Variables globales HINSTANCE g_hInstance; -int g_lastSprite = 0; extern bool g_bFullScreen; // false si mode de test extern int g_mouseType; extern char g_CDPath[MAX_PATH]; @@ -44,34 +43,6 @@ void LoadString(UINT nID, char *pBuffer, int lgBuffer) LoadString(g_hInstance, nID, pBuffer, lgBuffer); } -// Change le lutin de la souris. - -void ChangeSprite(int sprite) -{ - HCURSOR hCursor = nullptr; - - if ( g_mouseType == MOUSETYPEGRA ) return; - if ( g_lastSprite == sprite ) return; - - if ( sprite == SPRITE_ARROW ) hCursor = LoadCursor(g_hInstance, "IDC_ARROW"); - if ( sprite == SPRITE_POINTER ) hCursor = LoadCursor(g_hInstance, "IDC_POINTER"); - if ( sprite == SPRITE_MAP ) hCursor = LoadCursor(g_hInstance, "IDC_MAP"); - if ( sprite == SPRITE_ARROWU ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWU"); - if ( sprite == SPRITE_ARROWD ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWD"); - if ( sprite == SPRITE_ARROWL ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWL"); - if ( sprite == SPRITE_ARROWR ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWR"); - if ( sprite == SPRITE_ARROWUL ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWUL"); - if ( sprite == SPRITE_ARROWUR ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWUR"); - if ( sprite == SPRITE_ARROWDL ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWDL"); - if ( sprite == SPRITE_ARROWDR ) hCursor = LoadCursor(g_hInstance, "IDC_ARROWDR"); - if ( sprite == SPRITE_WAIT ) hCursor = LoadCursor(g_hInstance, "IDC_WAIT"); - if ( sprite == SPRITE_EMPTY ) hCursor = LoadCursor(g_hInstance, "IDC_EMPTY"); - if ( sprite == SPRITE_FILL ) hCursor = LoadCursor(g_hInstance, "IDC_FILL"); - - g_lastSprite = sprite; -} - - // Conversion de la position de la souris. POINT ConvLongToPos(LPARAM lParam) diff --git a/misc.h b/misc.h index 7f74b1f..83451f0 100644 --- a/misc.h +++ b/misc.h @@ -6,7 +6,6 @@ extern void InitHInstance(HINSTANCE hInstance); extern void OutputDebug(char *pMessage); extern void LoadString(UINT nID, char *pBuffer, int lgBuffer); -extern void ChangeSprite(int sprite); extern POINT ConvLongToPos(LPARAM lParam); diff --git a/pixmap.cpp b/pixmap.cpp index ec2fdff..e95a1ac 100644 --- a/pixmap.cpp +++ b/pixmap.cpp @@ -32,7 +32,6 @@ CPixmap::CPixmap() m_bPalette = true; m_mouseSprite = SPRITE_WAIT; - MouseHotSpot(); m_mousePos.x = LXIMAGE/2; m_mousePos.y = LYIMAGE/2; m_mouseBackPos = m_mousePos; @@ -53,7 +52,9 @@ CPixmap::CPixmap() // initialize special effects structure ZeroMemory(&m_DDbltfx, sizeof(m_DDbltfx)); - m_DDbltfx.dwSize = sizeof(m_DDbltfx); + m_DDbltfx.dwSize = sizeof(m_DDbltfx); + + m_lpCurrentCursor = nullptr; } // Destructeur. @@ -966,7 +967,6 @@ bool CPixmap::DrawImage(int chDst, int channel, RECT rect, int mode) if ( channel == CHBACK ) { - MouseBackSave(); // sauve ce qui sera sous la souris m_bBackDisplayed = false; } @@ -1098,12 +1098,6 @@ void CPixmap::SetMousePosSprite(POINT pos, int sprite, bool bDemoPlay) m_mousePos = pos; m_mouseSprite = sprite; - MouseHotSpot(); - - if ( !bDemoPlay ) - { - MouseUpdate(); - } } // Positionne la souris. @@ -1114,11 +1108,6 @@ void CPixmap::SetMousePos(POINT pos, bool bDemoPlay) m_mousePos.y == pos.y ) return; m_mousePos = pos; - - if ( !bDemoPlay ) - { - MouseUpdate(); - } } // Change le lutin de la souris. @@ -1128,12 +1117,6 @@ void CPixmap::SetMouseSprite(int sprite, bool bDemoPlay) if ( m_mouseSprite == sprite ) return; m_mouseSprite = sprite; - MouseHotSpot(); - - if ( !bDemoPlay ) - { - MouseUpdate(); - } SDL_SetCursor (m_lpSDLCursors[sprite - 1]); } @@ -1145,90 +1128,6 @@ void CPixmap::MouseShow(bool bShow) SDL_ShowCursor (bShow); } -// Met à jour le dessin de la souris. - -void CPixmap::MouseUpdate() -{ - RECT oldRect, newRect, rcRect; - - if ( m_lpDDSurface[CHBLUPI] == NULL ) return; - if ( m_mouseType != MOUSETYPEGRA ) return; - if ( m_mouseSprite == SPRITE_EMPTY ) return; - - oldRect.left = m_mouseBackPos.x; - oldRect.top = m_mouseBackPos.y; - oldRect.right = m_mouseBackPos.x + DIMBLUPIX; - oldRect.bottom = m_mouseBackPos.y + DIMBLUPIY; - - newRect.left = m_mousePos.x - m_mouseHotSpot.x; - newRect.top = m_mousePos.y - m_mouseHotSpot.y; - newRect.right = newRect.left + DIMBLUPIX; - newRect.bottom = newRect.top + DIMBLUPIY; - - MouseBackRestore(); // enlève la souris dans m_lpDDSBack - MouseBackDraw(); // dessine la souris dans m_lpDDSBack - - if ( m_bBackDisplayed ) - { - if ( IntersectRect(&rcRect, &oldRect, &newRect) ) - { - UnionRect(&rcRect, &oldRect, &newRect); - MouseQuickDraw(rcRect); - } - else - { - MouseQuickDraw(oldRect); - MouseQuickDraw(newRect); - } - } -} - -// Dessine rapidement la souris dans l'écran. -// Il s'agit en fait de dessiner un petit morceau rectangulaire -// de m_lpDDSBack dans l'écran. - -bool CPixmap::MouseQuickDraw(RECT rect) -{ - HRESULT ddrval; - RECT DestRect; - - if ( rect.left < 0 ) rect.left = 0; - if ( rect.right > LXIMAGE ) rect.right = LXIMAGE; - if ( rect.top < 0 ) rect.top = 0; - if ( rect.bottom > LYIMAGE ) rect.bottom = LYIMAGE; - - // Get screen coordinates of client window for blit - DestRect = rect; - ClientToScreen(m_hWnd, (LPPOINT)&DestRect); - ClientToScreen(m_hWnd, (LPPOINT)&DestRect+1); - - // do the blit from back surface - ddrval = m_lpDDSPrimary->Blt - ( - &DestRect, // destination rect - m_lpDDSBack, - &rect, // source rect - DDBLT_WAIT, - &m_DDbltfx - ); - SDL_Rect srcRect, dstRect; - srcRect.x =rect.left; - srcRect.y =rect.top; - srcRect.w =rect.right - rect.left; - srcRect.h =rect.bottom - rect.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); - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - } - if ( ddrval != DD_OK ) return false; - return true; -} - // Invalide la copie sous la souris. void CPixmap::MouseInvalidate() @@ -1236,223 +1135,6 @@ void CPixmap::MouseInvalidate() m_bMouseBack = false; } -// Enlève la souris dans m_lpDDSBack. - -void CPixmap::MouseBackClear() -{ - if ( m_mouseType != MOUSETYPEGRA ) return; - MouseBackRestore(); // enlève la souris dans m_lpDDSBack -} - -// Dessine la souris dans m_lpDDSBack. - -void CPixmap::MouseBackDraw() -{ - POINT dst; - RECT rcRect; - - if ( m_lpDDSurface[CHBLUPI] == NULL ) return; - if ( m_mouseType != MOUSETYPEGRA ) return; - if ( m_mouseSprite == SPRITE_EMPTY ) return; - - MouseBackSave(); // sauve ce qui sera sous la souris - - dst.x = m_mousePos.x - m_mouseHotSpot.x; - dst.y = m_mousePos.y - m_mouseHotSpot.y; - rcRect = MouseRectSprite(); - - if ( dst.x < 0 ) - { - rcRect.left -= dst.x; - dst.x = 0; - } - if ( dst.x+DIMBLUPIX > LXIMAGE ) - { - rcRect.right -= (dst.x+DIMBLUPIX)-LXIMAGE; - } - if ( dst.y < 0 ) - { - rcRect.top -= dst.y; - dst.y = 0; - } - if ( dst.y+DIMBLUPIY > LYIMAGE ) - { - rcRect.bottom -= (dst.y+DIMBLUPIY)-LYIMAGE; - } - - // Dessine le lutin dans m_lpDDSBack. - BltFast(m_lpDDSBack, nullptr, CHBLUPI, dst, rcRect, 0); -} - -// Sauve le fond sous la souris. -// m_lpDDSMouse <- m_lpDDSBack - -void CPixmap::MouseBackSave() -{ - HRESULT ddrval; - POINT dst; - RECT rcRect; - - if ( m_lpDDSurface[CHBLUPI] == NULL ) return; - if ( m_mouseType != MOUSETYPEGRA ) return; - if ( m_mouseSprite == SPRITE_EMPTY ) return; - - m_mouseBackPos.x = m_mousePos.x - m_mouseHotSpot.x; - m_mouseBackPos.y = m_mousePos.y - m_mouseHotSpot.y; - m_bMouseBack = true; - - dst.x = 0; - dst.y = 0; - - rcRect.left = m_mouseBackPos.x; - rcRect.top = m_mouseBackPos.y; - rcRect.right = m_mouseBackPos.x + DIMBLUPIX; - rcRect.bottom = m_mouseBackPos.y + DIMBLUPIY; - - if ( rcRect.left < 0 ) - { - dst.x -= rcRect.left; - rcRect.left = 0; - } - if ( rcRect.right > LXIMAGE ) - { - rcRect.right = LXIMAGE; - } - if ( rcRect.top < 0 ) - { - dst.y -= rcRect.top; - rcRect.top = 0; - } - if ( rcRect.bottom > LYIMAGE ) - { - rcRect.bottom = LYIMAGE; - } - - while( true ) - { - ddrval = m_lpDDSMouse->BltFast(dst.x, dst.y, - m_lpDDSBack, - &rcRect, DDBLTFAST_NOCOLORKEY); - SDL_Rect srcRect, dstRect; - srcRect.x = rcRect.left; - srcRect.y = rcRect.top; - srcRect.w = rcRect.right - rcRect.left; - srcRect.h = rcRect.bottom - rcRect.top; - dstRect = srcRect; - dstRect.x = dst.x; - dstRect.y = dst.y; - if ( ddrval == DD_OK ) break; - - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - if ( ddrval != DD_OK ) break; - } - - if ( ddrval != DDERR_WASSTILLDRAWING ) break; - } -} - -// Restitue le fond sous la souris. -// m_lpDDSBack <- m_lpDDSMouse - -void CPixmap::MouseBackRestore() -{ - HRESULT ddrval; - POINT dst; - RECT rcRect; - - if ( m_lpDDSurface[CHBLUPI] == NULL ) return; - if ( !m_bMouseBack ) return; - - dst.x = m_mouseBackPos.x; - dst.y = m_mouseBackPos.y; - - rcRect.left = 0; - rcRect.top = 0; - rcRect.right = DIMBLUPIX; - rcRect.bottom = DIMBLUPIY; - - if ( dst.x < 0 ) - { - rcRect.left -= dst.x; - dst.x = 0; - } - if ( dst.x+DIMBLUPIX > LXIMAGE ) - { - rcRect.right -= (dst.x+DIMBLUPIX)-LXIMAGE; - } - if ( dst.y < 0 ) - { - rcRect.top -= dst.y; - dst.y = 0; - } - if ( dst.y+DIMBLUPIY > LYIMAGE ) - { - rcRect.bottom -= (dst.y+DIMBLUPIY)-LYIMAGE; - } - - while( true ) - { - ddrval = m_lpDDSBack->BltFast(dst.x, dst.y, - m_lpDDSMouse, - &rcRect, DDBLTFAST_NOCOLORKEY); - SDL_Rect srcRect, dstRect; - srcRect.x = rcRect.left; - srcRect.y = rcRect.top; - srcRect.w = rcRect.right - rcRect.left; - srcRect.h = rcRect.bottom - rcRect.top; - dstRect = srcRect; - dstRect.x = dst.x; - dstRect.y = dst.y; - if ( ddrval == DD_OK ) break; - - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - if ( ddrval != DD_OK ) break; - } - - if ( ddrval != DDERR_WASSTILLDRAWING ) break; - } -} - -// Affiche le contenu de m_lpDDSMouse dans le -// coin sup/gauche. - -void CPixmap::MouseBackDebug() -{ - HRESULT ddrval; - RECT DestRect, MapRect; - - // 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 = DIMBLUPIX; - MapRect.bottom = DIMBLUPIY; - - DestRect.right = DestRect.left + DIMBLUPIX; - DestRect.bottom = DestRect.top + DIMBLUPIY; - - // do the blit from back surface - ddrval = m_lpDDSPrimary->Blt - ( - &DestRect, // destination rect - m_lpDDSMouse, - &MapRect, // source rect - DDBLT_WAIT, - &m_DDbltfx - ); - if ( ddrval == DDERR_SURFACELOST ) - { - ddrval = RestoreAll(); - } -} - // Retourne le rectangle correspondant au sprite // de la souris dans CHBLUPI. @@ -1486,45 +1168,6 @@ RECT CPixmap::MouseRectSprite() return rcRect; } -// Initialise le hot spot selon le sprite en cours. - -void CPixmap::MouseHotSpot() -{ - int rank; - - static int table_mouse_hotspot[MAXCURSORS * 2] = - { - 30, 30, // SPRITE_ARROW - 20, 15, // SPRITE_POINTER - 31, 26, // SPRITE_MAP - 25, 14, // SPRITE_ARROWU - 24, 35, // SPRITE_ARROWD - 15, 24, // SPRITE_ARROWL - 35, 24, // SPRITE_ARROWR - 18, 16, // SPRITE_ARROWUL - 32, 18, // SPRITE_ARROWUR - 17, 30, // SPRITE_ARROWDL - 32, 32, // SPRITE_ARROWDR - 30, 30, // SPRITE_WAIT - 30, 30, // SPRITE_EMPTY - 21, 51, // SPRITE_FILL - }; - - if ( m_mouseSprite >= SPRITE_ARROW && - m_mouseSprite <= SPRITE_FILL ) - { - rank = m_mouseSprite - SPRITE_ARROW; // rank <- 0..n - - m_mouseHotSpot.x = table_mouse_hotspot[rank*2+0]; - m_mouseHotSpot.y = table_mouse_hotspot[rank*2+1]; - } - else - { - m_mouseHotSpot.x = 0; - m_mouseHotSpot.y = 0; - } -} - SDL_Point CPixmap::GetCursorHotSpot (int sprite) { static const int hotspots[MAXCURSORS * 2] = @@ -1646,4 +1289,13 @@ void CPixmap::LoadCursors () // FIXME: change cursor first value to 0 m_lpSDLCursors[sprite - 1] = SDL_CreateColorCursor (surface, hotspot.x, hotspot.y); } +} + +void CPixmap::ChangeSprite (MouseSprites sprite) +{ + if (m_lpCurrentCursor == m_lpSDLCursors[sprite - 1]) + return; + + SDL_SetCursor (m_lpSDLCursors[sprite - 1]); + m_lpCurrentCursor = m_lpSDLCursors[sprite - 1]; } \ No newline at end of file diff --git a/pixmap.h b/pixmap.h index d925507..00b2a31 100644 --- a/pixmap.h +++ b/pixmap.h @@ -55,9 +55,8 @@ public: void SetMouseSprite(int sprite, bool bDemoPlay); void MouseShow(bool bShow); void MouseInvalidate(); - void MouseBackClear(); - void MouseBackDraw(); void LoadCursors (); + void ChangeSprite (MouseSprites sprite); protected: HRESULT RestoreAll(); @@ -65,13 +64,7 @@ protected: HRESULT BltFast(LPDIRECTDRAWSURFACE lpDD, SDL_Texture *lpSDL, int channel, POINT dst, RECT rcRect, int mode); - void MouseUpdate(); - bool MouseQuickDraw(RECT rect); - void MouseBackSave(); - void MouseBackRestore(); - void MouseBackDebug(); RECT MouseRectSprite(); - void MouseHotSpot(); SDL_Point GetCursorHotSpot (int sprite); SDL_Rect GetCursorRect (int sprite); @@ -86,7 +79,6 @@ protected: POINT m_mousePos; int m_mouseSprite; - POINT m_mouseHotSpot; POINT m_mouseBackPos; bool m_bMouseBack; bool m_bBackDisplayed; @@ -97,6 +89,7 @@ protected: LPDIRECTDRAWSURFACE m_lpDDSBack; // DirectDraw back surface SDL_Surface * m_lpSDLBack; LPDIRECTDRAWSURFACE m_lpDDSMouse; // DirectDraw back surface + SDL_Cursor * m_lpCurrentCursor; SDL_Cursor * m_lpSDLCursors[MAXCURSORS]; SDL_Surface * m_lpSDLBlupi; LPDIRECTDRAWPALETTE m_lpDDPal; // the primary surface palette