Mercurial > mm7
changeset 1655:a7eebb6ee7a2
Window Resize (change arguments to MM7_Initialize)
author | Nomad |
---|---|
date | Wed, 18 Sep 2013 11:13:38 +0200 |
parents | d11b5669f089 |
children | 55bdb9b043e3 51c63e03e856 620b6ba3e6b8 |
files | NPC.cpp NPC.h Render.cpp Render.h UI/UIHouses.cpp UI/UiGame.cpp mm7_2.cpp mm7_data.cpp mm7_data.h |
diffstat | 9 files changed, 67 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/NPC.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/NPC.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -503,10 +503,10 @@ switch (decode_step) { case 1: - pNPCGreetings[i].pGreeting[0] = RemoveQuotes(test_string); + pNPCGreetings[i].pGreetings[0] = RemoveQuotes(test_string); break; case 2: - pNPCGreetings[i].pGreeting[1] = RemoveQuotes(test_string); + pNPCGreetings[i].pGreetings[1] = RemoveQuotes(test_string); break; } }
--- a/NPC.h Wed Sep 18 11:05:06 2013 +0600 +++ b/NPC.h Wed Sep 18 11:13:38 2013 +0200 @@ -132,8 +132,15 @@ #pragma pack(push, 1) struct NPCGreeting { - char *pGreeting[2]; //at first meet - //char *pGreeting2; // at latest meets + union + { + struct + { + char *pGreeting1; //at first meet + char *pGreeting2; // at latest meets + }; + char *pGreetings[2]; + }; }; #pragma pack(pop)
--- a/Render.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/Render.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -2094,10 +2094,14 @@ hd_water_current_frame = 0; } -bool Render::Initialize(bool bWindowed, uint32_t uDefaultDevice, bool bColoredLights, uint32_t uDetailLevel, bool bTinting) +bool Render::Initialize(bool bWindowed, int windowed_width, int windowed_height, uint32_t uDefaultDevice, + bool bColoredLights, uint32_t uDetailLevel, bool bTinting) { bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0); + bStartInWindow = bWindowed; + windowed_mode_width = windowed_width; + windowed_mode_height = windowed_height; uDesiredDirect3DDevice = uDefaultDevice;//ReadWindowsRegistryInt("D3D Device", 1); @@ -2177,30 +2181,21 @@ //----- (0049ED18) -------------------------------------------------------- void Render::PresentBlackScreen() { - LONG w; // edx@3 IDirectDrawSurface *v2; // eax@3 DDBLTFX v3; // [sp+4h] [bp-74h]@5 RECT x; // [sp+68h] [bp-10h]@3 memset(&v3, 0, sizeof(DDBLTFX)); + GetWindowRect(hWnd, &x); if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion >= 5) { - x.left = uWindowX; - x.right = uWindowX + uWindowHeight; - x.top = uWindowY; - w = uWindowY + uWindowWidth; v2 = (IDirectDrawSurface *)this->pBackBuffer4; } else { - x.left = uWindowX; - x.right = uWindowX + uWindowHeight; - x.top = uWindowY; - w = uWindowY + uWindowWidth; v2 = (IDirectDrawSurface *)this->pBackBuffer2; } - x.bottom = w; v3.dwFillColor = 0; v3.dwSize = 100; v2->Blt(&x, 0, 0, DDBLT_COLORFILL, &v3); @@ -8361,13 +8356,6 @@ } if ( pRenderer->bWindowMode ) { - if ( GetWindowRect(hWnd, &Rect) ) - { - WriteWindowsRegistryInt("window X", Rect.left); - WriteWindowsRegistryInt("window Y", Rect.top); - uWindowX = Rect.left; - uWindowY = Rect.top; - } SetMenu(hWnd, 0); SetWindowLongA(hWnd, -20, 0); SetWindowLongA(hWnd, -16, 0x10000000u); @@ -8379,7 +8367,6 @@ { ClipCursor(0); pRenderer->SwitchToWindow(hWnd); - SetWindowLongA(hWnd, -16, uWindowStyle); } if ( pRenderer->pRenderD3D ) { @@ -8434,14 +8421,14 @@ pMouse->SetCurrentCursorBitmap(); if ( pRenderer->bWindowMode ) { - InvalidateRect(0, 0, 0); - MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0); + //MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0); + CenterWindowAndAdjustSize(hWnd, windowed_mode_width, windowed_mode_height); ShowWindow(hWnd, SW_SHOWNORMAL); } pMouse->bActive = 1; if ( pVideoPlayer->AnyMovieLoaded() ) pVideoPlayer->SelectMovieType(); - if ( BYTE1(dword_6BE364_game_settings_1) & 8 ) + if (dword_6BE364_game_settings_1 & 0x0800 ) BYTE1(dword_6BE364_game_settings_1) &= 0xF7u; else pEventTimer->Resume();
--- a/Render.h Wed Sep 18 11:05:06 2013 +0600 +++ b/Render.h Wed Sep 18 11:13:38 2013 +0200 @@ -269,7 +269,7 @@ static Render *Create() {return new Render;} - bool Initialize(bool bWindowed, uint32_t uDefaultDevice, + bool Initialize(bool bWindowed, int window_width, int window_height, uint32_t uDefaultDevice, bool bColoredLights, uint32_t uDetailLevel, bool bTinting); @@ -457,6 +457,10 @@ unsigned int uCurrentlyLockedSurfacePitch; unsigned __int16 *pCurrentlyLockedSurfaceDataPtr; unsigned __int16 *pCurrentlyLockedSoftSurface; + + + int windowed_mode_width; + int windowed_mode_height; }; #pragma pack(pop)
--- a/UI/UIHouses.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/UI/UIHouses.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -3420,7 +3420,7 @@ { house_window.uFrameWidth = game_viewport_width; house_window.uFrameZ = 452; - pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreeting[((pNPC->uFlags & 3) == 2)]; + pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreetings[((pNPC->uFlags & 3) == 2)]; //pInString = (char *)*(&pNPCStats->field_17884 + ((pNPC->uFlags & 3) == 2) + 2 * pNPC->greet); pRenderer->GetLeather(8, 352 - (pFontArrus->CalcTextHeight(pInString, &house_window, 13, 0) + 7), pIcons_LOD->GetTexture(uTextureID_Leather), pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight
--- a/UI/UiGame.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/UI/UiGame.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -434,9 +434,9 @@ if (pNPC->greet) { if ((pNPC->uFlags & 3) == 2) - pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreeting[1]; + pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreeting2; else - pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreeting[0]; + pInString = pNPCStats->pNPCGreetings[pNPC->greet].pGreeting1; } } else if (pGreetType == 2)//HiredNPC_greet
--- a/mm7_2.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/mm7_2.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -4277,8 +4277,35 @@ } } + + +void CenterWindowAndAdjustSize(HWND hwnd, int client_width, int client_height) +{ + RECT rcWindow; + GetWindowRect(hWnd, &rcWindow); + + RECT rcClient; + GetClientRect(hWnd, &rcClient); + + int window_borders_width = (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left), + window_borders_height = (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top); + int window_total_width = client_width + window_borders_width, + window_total_height = client_height + window_borders_height; + + MoveWindow(hWnd, (GetSystemMetrics(SM_CXSCREEN) - window_total_width) / 2, + (GetSystemMetrics(SM_CYSCREEN) - window_total_height) / 2, + window_total_width, + window_total_height, 0); +/* + auto hDesktopDC = GetDC(nullptr); + uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES); + uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES); + ReleaseDC(nullptr, hDesktopDC); +*/ +} + //----- (004651F4) -------------------------------------------------------- -bool MM7_Initialize() +bool MM7_Initialize(int game_width, int game_height) { wchar_t pCurrentDir[1024]; _wgetcwd(pCurrentDir, 1024); @@ -4318,29 +4345,10 @@ return false; } - auto hDesktopDC = GetDC(nullptr); - uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES); - uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES); - ReleaseDC(nullptr, hDesktopDC); - - uint uTotalWinWidth = 2 * GetSystemMetrics(SM_CXFRAME) + 640; - uint uTotalWinHeight = GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYFRAME) + 480; - - uint uWinCenteredPosX = (uDesktopWidth - uTotalWinWidth) / 2; - uint uWinCenteredPosY = (uDesktopHeight - uTotalWinHeight) / 2; - - uWindowX = ReadWindowsRegistryInt("window X", uWinCenteredPosX); - uWindowX = uDesktopWidth / 2 - 640 / 2; - WriteWindowsRegistryInt("window X", uWindowX); - - uWindowY = ReadWindowsRegistryInt("window Y", uWinCenteredPosY); - uWindowY = uDesktopHeight / 2 - 480 / 2; - WriteWindowsRegistryInt("window Y", uWindowY); - hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and MagicŪ VII", - uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER, - uWindowX, uWindowY, - 640, 480, + WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER, + 0, 0, + 1, 1, nullptr, nullptr, wcxw.hInstance, @@ -4485,7 +4493,10 @@ } } } + SetMenu(hWnd, menu); + CenterWindowAndAdjustSize(hWnd, game_width, game_height); + ShowWindow(hWnd, SW_SHOWNORMAL); SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); @@ -4503,7 +4514,7 @@ uint uLevelOfDetail = ReadWindowsRegistryInt("Detail Level", 1); uint bTinting = ReadWindowsRegistryInt("Tinting", 1) != 0; - if (!pRenderer->Initialize(bWindowMode, uDefaultDevice, bColoredLights, uLevelOfDetail, bTinting)) + if (!pRenderer->Initialize(bWindowMode, game_width, game_height, uDefaultDevice, bColoredLights, uLevelOfDetail, bTinting)) { Log::Warning(L"Render failed to initialize"); return false; @@ -4532,18 +4543,7 @@ GameUI_StatusBar_UpdateTimedString(1); pGame = Game::Create(); pMouse = pGame->pMouseInstance; - - - RECT rcWindow; - GetWindowRect(hWnd, &rcWindow); - - RECT rcClient; - GetClientRect(hWnd, &rcClient); - uWindowWidth = rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640; - uWindowHeight = rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480; - MoveWindow(hWnd, uWindowX, uWindowY, - rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640, - rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0); + pIcons_LOD = new LODFile_IconsBitmaps; if (!pIcons_LOD->Load("data\\icons.lod", "icons")) @@ -4858,7 +4858,6 @@ break; } - ShowWindow(hWnd, SW_SHOWNORMAL); return true; } @@ -5065,7 +5064,7 @@ assert(sizeof(MonsterInfo) == 0x58); assert(sizeof(MonsterStats) == 0x5BA0); assert(sizeof(RenderD3D) == 0x148); - assert(sizeof(Render) == 0x129844); +// assert(sizeof(Render) == 0x129844); assert(sizeof(Player) == 0x1B3C); assert(sizeof(Party_stru0) == 0x678); assert(sizeof(Party) == 0x16238); @@ -5153,7 +5152,7 @@ uCPUSpeed = 2048; // about 2GHz - if (!MM7_Initialize()) + if (!MM7_Initialize(640, 480)) { Log::Warning(L"MM init: failed"); pGame->Deinitialize();
--- a/mm7_data.cpp Wed Sep 18 11:05:06 2013 +0600 +++ b/mm7_data.cpp Wed Sep 18 11:13:38 2013 +0200 @@ -1198,11 +1198,6 @@ float fTurnSpeedMultiplier = 1.0f; // weak float flt_6BE150_look_up_down_dangle = 1.0f; // weak HWND hWnd; // idb -int uWindowWidth; // idb -int uWindowHeight; // idb -int uWindowX; // idb -int uWindowY; // idb -LONG uWindowStyle; // idb int dword_6BE340; // weak char pCurrentMapName[32]; // idb unsigned int uLevelMapStatsID;
--- a/mm7_data.h Wed Sep 18 11:05:06 2013 +0600 +++ b/mm7_data.h Wed Sep 18 11:13:38 2013 +0200 @@ -847,11 +847,6 @@ //extern HINSTANCE hInstance; // idb //extern char *pCmdLine; extern HWND hWnd; // idb -extern int uWindowWidth; // idb -extern int uWindowHeight; // idb -extern int uWindowX; // idb -extern int uWindowY; // idb -extern LONG uWindowStyle; // idb extern int dword_6BE340; // weak extern char pCurrentMapName[32]; // idb extern unsigned int uLevelMapStatsID; @@ -1369,6 +1364,7 @@ } //inline void __fastcall j_memset32(int a2, void *a1, unsigned int a3) {memset32(a1, a2, a3);} +void CenterWindowAndAdjustSize(HWND hwnd, int client_width, int client_height); #define ErrD3D(hr) do {extern void ErrHR(HRESULT, const char *, const char *, const char *, int); ErrHR(hr, "Direct3D", __FUNCTION__, __FILE__, __LINE__);} while(0)