diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-07-05 19:04:06 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-07-05 19:04:06 +0100 |
commit | 5e61c1280c15ab9969b94cd360cafd4a11b2dd30 (patch) | |
tree | 1fdb60d771c4351b5aa5dcf1a43376c0558625a4 /src/T2MainWindow.cpp | |
parent | c2efba6907fab934a04959b9bb644cf7141cc955 (diff) | |
download | t2win-5e61c1280c15ab9969b94cd360cafd4a11b2dd30.tar.gz t2win-5e61c1280c15ab9969b94cd360cafd4a11b2dd30.zip |
matched T2.exe
Diffstat (limited to '')
-rw-r--r-- | src/T2MainWindow.cpp | 224 |
1 files changed, 130 insertions, 94 deletions
diff --git a/src/T2MainWindow.cpp b/src/T2MainWindow.cpp index 2874e91..096859a 100644 --- a/src/T2MainWindow.cpp +++ b/src/T2MainWindow.cpp @@ -1,4 +1,8 @@ -#include "CT2App.h" +#include "DbgEventList.h" +#include "DbgIPS.h" +#include "DbgStepRun.h" +#include "T2.h" +#include "T2CtrlPalette.h" #include "T2DLL.h" #include "T2MainWindow.h" #include "T2MsgWindow.h" @@ -9,6 +13,12 @@ #include "T2WorldDef.h" #include "UT2Coordinate.h" +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + #line 22 IMPLEMENT_DYNCREATE(T2MainWindow, CFrameWnd) @@ -28,7 +38,7 @@ BEGIN_MESSAGE_MAP(T2MainWindow, CFrameWnd) END_MESSAGE_MAP() T2MainWindow::T2MainWindow() { - _EC = 0; + _EC = true; _F0 = 0; mSoundPlayer = NULL; mDirectSound = NULL; @@ -36,7 +46,7 @@ T2MainWindow::T2MainWindow() { mMsgWindow = NULL; mCtrlPalette = NULL; - ((CT2App *) AfxGetApp())->mMainWindow = this; + T2_APP->mMainWindow = this; } /*virtual*/ T2MainWindow::~T2MainWindow() { @@ -70,14 +80,14 @@ void T2MainWindow::InitSound() { return; } - DSBUFFERDESC bufferDesc; - memset(&bufferDesc, 0, sizeof(DSBUFFERDESC)); - bufferDesc.dwSize = sizeof(DSBUFFERDESC); - bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + DSBUFFERDESC bufferdesc; + memset(&bufferdesc, 0, sizeof(DSBUFFERDESC)); + bufferdesc.dwSize = sizeof(DSBUFFERDESC); + bufferdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; LPDIRECTSOUNDBUFFER buffer = NULL; - if (mDirectSound->CreateSoundBuffer(&bufferDesc, &buffer, NULL) != S_OL) { + if (mDirectSound->CreateSoundBuffer(&bufferdesc, &buffer, NULL) != S_OK) { DeinitSound(); } #endif @@ -93,61 +103,81 @@ void T2MainWindow::DeinitSound() { } /*virtual*/ BOOL T2MainWindow::PreCreateWindow(CREATESTRUCT& cs) { - cs.style |= WS_TABSTOP | WS_GROUP | WS_VSCROLL; + cs.style |= WS_HSCROLL | WS_VSCROLL | WS_CLIPCHILDREN; return CFrameWnd::PreCreateWindow(cs); } afx_msg int T2MainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { #line 123 - // mDbgStepRun = DEBUG_NEW DbgStepRun; - // mDbgIPS = DEBUG_NEW DbgIPS; + mDbgStepRun = new DbgStepRun(this); + mDbgIPS = new DbgIPS(this); if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; InitSound(); #line 130 - mSoundPlayer = DEBUG_NEW T2SoundPlayer(this, mDirectSound); + mSoundPlayer = new T2SoundPlayer(this, mDirectSound); - SetWindowRgn(CreateRectRgn(100, 100, 100, 100), true); + HRGN rgn = CreateRectRgn(100, 100, 100, 100); + SetWindowRgn(rgn, true); return 0; } afx_msg void T2MainWindow::OnDestroy() { gT2App->mMainWindow = NULL; - // ffCalledFromDestroy(); + ffDestroy(); CFrameWnd::OnDestroy(); - // mDbgStepRun->DestroyWindow(); - // delete mDbgStepRun; - // mDbgIPS->DestroyWindow(); - // delete mDbgIPS; + mDbgStepRun->DestroyWindow(); + delete mDbgStepRun; + mDbgIPS->DestroyWindow(); + delete mDbgIPS; } void T2MainWindow::Setup() { RECT windowRect; GetWindowRect(&windowRect); - SetWindowRgn(CreateRectRgn(0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top), true); + + int mainWindowWidth = windowRect.right - windowRect.left; + int mainWindowHeight = windowRect.bottom - windowRect.top; + HRGN rgn = CreateRectRgn(0, 0, mainWindowWidth, mainWindowHeight); + SetWindowRgn(NULL, true); mWndClassA = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); RECT rect; SetRect(&rect, 100, 100, 300, 300); - mToolWindow = ((CT2App *) AfxGetApp())->mToolWindow; + mToolWindow = T2_APP->mToolWindow; mToolWindow->Create(mWndClassA, "Tools", WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE | WS_POPUP, rect, this, NULL, WS_EX_TOOLWINDOW); mWndClassB = AfxRegisterWndClass(0, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); SetRect(&rect, 0, 0, 520, 50); - // ... - // more stuff here. +#line 194 + mMsgWindow = new T2MsgWindow; + mMsgWindow->Create(mWndClassB, "Information", WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE | WS_POPUP, rect, this, NULL, WS_EX_TOOLWINDOW); + + SetRect(&rect, 500, 100, 600, 150); +#line 198 + mCtrlPalette = new T2CtrlPalette; + mCtrlPalette->Create(mWndClassB, "Control", WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE | WS_POPUP, rect, this, NULL, WS_EX_TOOLWINDOW); + + mWndClassC = AfxRegisterWndClass(0, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + GetDesktopWindow()->GetClientRect(&rect); + rect.top = rect.bottom - 200; + rect.left = rect.right - 300; } void T2MainWindow::Teardown() { - delete mToolWindow; - delete mMsgWindow; - delete mCtrlPalette; + if (mToolWindow) + mToolWindow->DestroyWindow(); + if (mMsgWindow) + mMsgWindow->DestroyWindow(); + if (mCtrlPalette) + mCtrlPalette->DestroyWindow(); mToolWindow = NULL; mMsgWindow = NULL; @@ -164,7 +194,7 @@ void T2MainWindow::Teardown() { afx_msg void T2MainWindow::OnSize(UINT nType, int cx, int cy) { T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (!_EC) { CFrameWnd::OnSize(nType, cx, cy); @@ -183,34 +213,35 @@ afx_msg void T2MainWindow::OnSize(UINT nType, int cx, int cy) { } void T2MainWindow::x414445() { + int width, height; T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); x4144FA(); - CRect rect; - GetWindowRect(rect); - int width = rect.Width(); - int height = rect.Height(); + CRect mainWindowRect; + GetWindowRect(mainWindowRect); + width = mainWindowRect.Width(); + height = mainWindowRect.Height(); - if (width && height && theTowerDoc && theView && theTowerDoc->mWorldDef) { - theView->tmv_vf138(theTowerDoc->mWorldDef->mInitPos, 0x102); + if (width && height && theDocument && theView && theDocument->mWorldDef) { + theView->tmv_vf138(theDocument->mWorldDef->mInitPos, kScroll2 | kScrollOpt2); _F0 = 1; theView->ShowWindow(SW_SHOW); } } void T2MainWindow::x4144FA() { - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); - if (theTowerDoc && theView && theTowerDoc->mWorldDef) { + if (theDocument && theView && theDocument->mWorldDef) { RECT clientRect; - GetClientRect(&clientRect); + theView->GetClientRect(&clientRect); RECT unitRect; - SetRect(&unitRect, 0, 0, theTowerDoc->mWorldDef->GetWidth(), theTowerDoc->mWorldDef->GetHeight()); - UT2Coordinate::UnitToQD(unitRect, theTowerDoc->mZoomLevel, true); + SetRect(&unitRect, 0, 0, theDocument->mWorldDef->GetWidth(), theDocument->mWorldDef->GetHeight()); + UT2Coordinate::UnitToQD(unitRect, theDocument->mZoomLevel, true); SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); @@ -230,9 +261,10 @@ void T2MainWindow::x4144FA() { } afx_msg void T2MainWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); - if (theTowerDoc) { + if (theDocument) { +#pragma var_order(scrollLimit, activeClientRect, activeView, myClientRect, clientRect, origScrollPos, scrollPos, theView) RECT clientRect; GetClientRect(&clientRect); @@ -245,10 +277,10 @@ afx_msg void T2MainWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrol scrollPos = scrollLimit; break; case SB_LINEDOWN: - scrollPos += UT2Coordinate::UnitVSize(theTowerDoc->mZoomLevel); + scrollPos += UT2Coordinate::UnitVSize(theDocument->mZoomLevel); break; case SB_LINEUP: - scrollPos -= UT2Coordinate::UnitVSize(theTowerDoc->mZoomLevel); + scrollPos -= UT2Coordinate::UnitVSize(theDocument->mZoomLevel); break; case SB_PAGEDOWN: scrollPos += clientRect.bottom / 2; @@ -283,21 +315,22 @@ afx_msg void T2MainWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrol myClientRect.top = activeClientRect.top; - ScrollWindow(0, scrollPos - origScrollPos, myClientRect, myClientRect); + ScrollWindow(0, origScrollPos - scrollPos, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { - theView->tmv_vf130(scrollPos); + theView->SetScrollV(scrollPos); theView->tmv_vf120(); } } } afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); - if (theTowerDoc) { + if (theDocument) { +#pragma var_order(scrollLimit, activeClientRect, activeView, myClientRect, clientRect, origScrollPos, scrollPos, theView) RECT clientRect; GetClientRect(&clientRect); @@ -310,10 +343,10 @@ afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrol scrollPos = scrollLimit; break; case SB_LINERIGHT: - scrollPos += UT2Coordinate::UnitHSize(theTowerDoc->mZoomLevel); + scrollPos += UT2Coordinate::UnitHSize(theDocument->mZoomLevel); break; case SB_LINELEFT: - scrollPos -= UT2Coordinate::UnitHSize(theTowerDoc->mZoomLevel); + scrollPos -= UT2Coordinate::UnitHSize(theDocument->mZoomLevel); break; case SB_PAGERIGHT: scrollPos += clientRect.right / 2; @@ -346,23 +379,24 @@ afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrol activeView->GetClientRect(activeClientRect); activeView->MapWindowPoints(this, activeClientRect); - myClientRect.top = activeClientRect.top; + myClientRect.left = activeClientRect.left; - ScrollWindow(scrollPos - origScrollPos, 0, myClientRect, myClientRect); + ScrollWindow(origScrollPos - scrollPos, 0, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { - theView->tmv_vf134(scrollPos); + theView->SetScrollH(scrollPos); theView->tmv_vf120(); } } } afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); +#pragma var_order(shadowPen, bigFont, theView, brush, save, highlightPen, theDocument, clientRect, smallFont) + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); - if (!theTowerDoc || !theTowerDoc->mWorldDef || !theTowerDoc->Get22C()) { + if (!theDocument || !theDocument->mWorldDef || !theDocument->Get22C()) { CRect clientRect; GetClientRect(clientRect); @@ -384,10 +418,10 @@ afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { CPen highlightPen(PS_SOLID, 0, GetSysColor(COLOR_BTNHIGHLIGHT)); CFont bigFont; - bigFont.CreateFont(-14, 0, 900, 900, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + bigFont.CreateFont(-14, 0, 900, 900, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_LH_ANGLES | CLIP_TT_ALWAYS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); CFont smallFont; - smallFont.CreateFont(-14, 0, 0, 0, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + smallFont.CreateFont(-14, 0, 0, 0, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_LH_ANGLES | CLIP_TT_ALWAYS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); pDC->SelectObject(shadowPen); pDC->MoveTo(clientRect.right, 0); @@ -398,16 +432,17 @@ afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { CView *theView = GetActiveView(); - if (_F0 && theTowerDoc && theView) { + if (_F0 && theDocument && theView) { +#pragma var_order(scrollInfoV, hRange, height, scrollInfoH, viewRect, str, textPos, x, y, i, textLen, anotherRect, showAllNumbers, vRange, theTowerMainView) CRect viewRect; theView->GetClientRect(viewRect); theView->MapWindowPoints(this, viewRect); T2TowerMainView *theTowerMainView = (T2TowerMainView *) theView; - viewRect.left += theTowerMainView->m84; - viewRect.right += theTowerMainView->m84; - viewRect.top += theTowerMainView->m88; - viewRect.bottom += theTowerMainView->m88; + viewRect.left += theTowerMainView->mImageOrigin.x; + viewRect.right += theTowerMainView->mImageOrigin.x; + viewRect.top += theTowerMainView->mImageOrigin.y; + viewRect.bottom += theTowerMainView->mImageOrigin.y; pDC->SelectObject(shadowPen); pDC->MoveTo(viewRect.left - 1, 0); @@ -433,6 +468,7 @@ afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { int y; char str[4]; POINT textPos; + int textLen; for (i = 0; i < 10; i++) { x = viewRect.left + (hRange * i) / 10; @@ -476,7 +512,7 @@ afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { pDC->SetWindowOrg(0, scrollInfoV.nPos); int vRange = scrollInfoV.nMax - scrollInfoV.nMin; - int height = theTowerDoc->mWorldDef->GetHeight(); + int height = theDocument->mWorldDef->GetHeight(); pDC->SelectObject(bigFont); @@ -493,41 +529,40 @@ afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { pDC->LineTo(16, y); } - BOOL showAllNumbers = (theTowerDoc->towerDoc_vf108() == 0); + BOOL showAllNumbers = (theDocument->GetZoomLevel() == 0); for (i = 0; i <= height; i++) { y = viewRect.top + (vRange * i) / height; anotherRect.SetRect(0, y, 14, viewRect.top + (vRange * (i + 1)) / height); - int number = theTowerDoc->mWorldDef->mGroundLine - i; - BOOL show = showAllNumbers; + int number = theDocument->mWorldDef->mGroundLine - i; + BOOL isShow = showAllNumbers; if (number > 1 && (number % 5 == 0)) - show = true; + isShow = true; if (number == 1) - show = true; + isShow = true; if (number < 1 && ((number - 1) % 5 == 0)) - show = true; + isShow = true; - if (show) { + if (isShow) { if (number >= 1) wsprintf(str, "%d", number); else - wsprintf(str, "B%d", 1 - number); - - int textLen = strlen(str); + wsprintf(str, "B%d", -number + 1); + textLen = strlen(str); textPos.x = 2; - textPos.y = ((anotherRect.top + anotherRect.bottom) / 2) - (pDC->GetTextExtent(str, 2).cx / 2); + textPos.y = ((anotherRect.top + anotherRect.bottom) / 2) + (pDC->GetTextExtent(str, textLen).cx / 2); pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT)); - pDC->TextOut(textPos.x + 1, textPos.y + 1, str, 2); + pDC->TextOut(textPos.x + 1, textPos.y + 1, str, textLen); pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW)); - pDC->TextOut(textPos.x - 1, textPos.y - 1, str, 2); + pDC->TextOut(textPos.x - 1, textPos.y - 1, str, textLen); pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); - pDC->TextOut(textPos.x, textPos.y, str, 2); + pDC->TextOut(textPos.x, textPos.y, str, textLen); } } } @@ -543,40 +578,41 @@ afx_msg void T2MainWindow::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimi afx_msg void T2MainWindow::OnActivateApp(BOOL bActive, HTASK hTask) { CWnd::OnActivateApp(bActive, hTask); - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); - if (theTowerDoc && theTowerDoc->mWorldDef) { + if (theDocument && theDocument->mWorldDef) { CDC *pDC = GetDC(); pDC->SaveDC(); - pDC->SelectPalette(theTowerDoc->mWorldDef->GetPalette(), false); + pDC->SelectPalette(theDocument->mWorldDef->GetPalette(), false); pDC->RealizePalette(); pDC->RestoreDC(-1); ReleaseDC(pDC); InvalidateRect(NULL); - T2TowerMainView *theTowerMainView = theTowerDoc->GetTowerMainView(); + T2TowerMainView *theTowerMainView = theDocument->GetMainView(); if (theTowerMainView) theTowerMainView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); - DWORD processID; - GetWindowThreadProcessId(this, &processID); + DWORD thisProcessId; + GetWindowThreadProcessId(*this, &thisProcessId); - CWnd *window = GetDesktopWindow()->GetWindow(GW_CHILD); - while (window) { - DWORD checkProcessID; - GetWindowThreadProcessId(window, &checkProcessID); + CWnd *wnd = GetDesktopWindow()->GetWindow(GW_CHILD); + while (wnd) { + DWORD checkProcessId; + GetWindowThreadProcessId(*wnd, &checkProcessId); - if (processID == checkProcessID) - window->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); + if (thisProcessId == checkProcessId) + wnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); - window = window->GetWindow(GW_HWNDNEXT); + wnd = wnd->GetWindow(GW_HWNDNEXT); } } } afx_msg void T2MainWindow::OnCmdDebugEvent() { - // TODO: DbgEventList + DbgEventList dlg(NULL); + dlg.DoModal(); } afx_msg void T2MainWindow::OnUpdateCmdDebugEvent(CCmdUI *pCmdUI) { @@ -584,18 +620,18 @@ afx_msg void T2MainWindow::OnUpdateCmdDebugEvent(CCmdUI *pCmdUI) { } afx_msg void T2MainWindow::OnClose() { - T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); - if (theTowerDoc->towerDoc_vf1A4()) + if (theDocument->towerDoc_vf1A4()) return; CFrameWnd::OnClose(); } afx_msg void T2MainWindow::OnCmdDebugMode() { - HMENU oldMenu = GetMenu(this); - HMENU newMenu = LoadMenu(AfxGetInstanceHandle(), 130); + HMENU oldMenu = ::GetMenu(*this); + HMENU newMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCE(130)); m_hMenuDefault = newMenu; - SetMenu(this, newMenu); + ::SetMenu(*this, newMenu); DestroyMenu(oldMenu); } |