#include "DbgEventList.h" #include "DbgIPS.h" #include "DbgStepRun.h" #include "T2.h" #include "T2CtrlPalette.h" #include "T2DLL.h" #include "T2MainWindow.h" #include "T2MsgWindow.h" #include "T2SoundPlayer.h" #include "T2ToolWindow.h" #include "T2TowerDoc.h" #include "T2TowerMainView.h" #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) BEGIN_MESSAGE_MAP(T2MainWindow, CFrameWnd) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_CLOSE() ON_WM_SIZE() ON_WM_VSCROLL() ON_WM_HSCROLL() ON_WM_ERASEBKGND() ON_WM_ACTIVATE() ON_WM_ACTIVATEAPP() ON_COMMAND(0x8018, OnCmdDebugEvent) ON_UPDATE_COMMAND_UI(0x8018, OnUpdateCmdDebugEvent) ON_COMMAND(0x8023, OnCmdDebugMode) END_MESSAGE_MAP() T2MainWindow::T2MainWindow() { _EC = true; _F0 = 0; mSoundPlayer = NULL; mDirectSound = NULL; mToolWindow = NULL; mMsgWindow = NULL; mCtrlPalette = NULL; T2_APP->mMainWindow = this; } /*virtual*/ T2MainWindow::~T2MainWindow() { if (mSoundPlayer) { delete mSoundPlayer; Sounds = NULL; } DeinitSound(); } void T2MainWindow::InitSound() { mDirectSound = NULL; if (DirectSoundCreate(NULL, &mDirectSound, NULL) != S_OK) { DeinitSound(); return; } #ifdef _WIN32 DSCAPS caps; memset(&caps, 0, sizeof(DSCAPS)); caps.dwSize = sizeof(DSCAPS); HRESULT result = mDirectSound->GetCaps(&caps); #line 80 _ASSERT(result == S_OK); if (mDirectSound->SetCooperativeLevel(GetSafeHwnd(), DSSCL_NORMAL) != S_OK) { DeinitSound(); return; } 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_OK) { DeinitSound(); } #endif } void T2MainWindow::DeinitSound() { if (mDirectSound) { #ifdef _WIN32 mDirectSound->Release(); #endif mDirectSound = NULL; } } /*virtual*/ BOOL T2MainWindow::PreCreateWindow(CREATESTRUCT& cs) { cs.style |= WS_HSCROLL | WS_VSCROLL | WS_CLIPCHILDREN; return CFrameWnd::PreCreateWindow(cs); } afx_msg int T2MainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { #line 123 mDbgStepRun = new DbgStepRun(this); mDbgIPS = new DbgIPS(this); if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; InitSound(); #line 130 mSoundPlayer = new T2SoundPlayer(this, mDirectSound); HRGN rgn = CreateRectRgn(100, 100, 100, 100); SetWindowRgn(rgn, true); return 0; } afx_msg void T2MainWindow::OnDestroy() { gT2App->mMainWindow = NULL; ffDestroy(); CFrameWnd::OnDestroy(); mDbgStepRun->DestroyWindow(); delete mDbgStepRun; mDbgIPS->DestroyWindow(); delete mDbgIPS; } void T2MainWindow::Setup() { RECT windowRect; GetWindowRect(&windowRect); 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 = 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); #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() { if (mToolWindow) mToolWindow->DestroyWindow(); if (mMsgWindow) mMsgWindow->DestroyWindow(); if (mCtrlPalette) mCtrlPalette->DestroyWindow(); mToolWindow = NULL; mMsgWindow = NULL; mCtrlPalette = NULL; } /*virtual*/ void T2MainWindow::AssertValid() const { CFrameWnd::AssertValid(); } /*virtual*/ void T2MainWindow::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } afx_msg void T2MainWindow::OnSize(UINT nType, int cx, int cy) { T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (!_EC) { CFrameWnd::OnSize(nType, cx, cy); } else if (theView) { CRect rect; GetClientRect(rect); rect.top += 16; rect.left += 16; theView->SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER); } x4144FA(); if (theView) theView->tmv_vf144(); } void T2MainWindow::x414445() { int width, height; T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); x4144FA(); CRect mainWindowRect; GetWindowRect(mainWindowRect); width = mainWindowRect.Width(); height = mainWindowRect.Height(); 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 *theDocument = (T2TowerDoc *) GetActiveDocument(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theDocument && theView && theDocument->mWorldDef) { RECT clientRect; theView->GetClientRect(&clientRect); RECT unitRect; SetRect(&unitRect, 0, 0, theDocument->mWorldDef->GetWidth(), theDocument->mWorldDef->GetHeight()); UT2Coordinate::UnitToQD(unitRect, theDocument->mZoomLevel, true); SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); info.fMask = SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL; info.nMin = 0; info.nMax = unitRect.bottom; info.nPage = clientRect.bottom; SetScrollInfo(SB_VERT, &info); info.nMax = unitRect.right; info.nPage = clientRect.right; SetScrollInfo(SB_HORZ, &info); InvalidateRect(NULL); } } afx_msg void T2MainWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (theDocument) { #pragma var_order(scrollLimit, activeClientRect, activeView, myClientRect, clientRect, origScrollPos, scrollPos, theView) RECT clientRect; GetClientRect(&clientRect); int scrollLimit = GetScrollLimit(SB_VERT); int origScrollPos = GetScrollPos(SB_VERT); int scrollPos = origScrollPos; switch (nSBCode) { case SB_BOTTOM: scrollPos = scrollLimit; break; case SB_LINEDOWN: scrollPos += UT2Coordinate::UnitVSize(theDocument->mZoomLevel); break; case SB_LINEUP: scrollPos -= UT2Coordinate::UnitVSize(theDocument->mZoomLevel); break; case SB_PAGEDOWN: scrollPos += clientRect.bottom / 2; break; case SB_PAGEUP: scrollPos -= clientRect.bottom / 2; break; case SB_THUMBTRACK: scrollPos = nPos; break; case SB_TOP: scrollPos = 0; break; } if (scrollPos < 0) scrollPos = 0; else if (scrollPos > scrollLimit) scrollPos = scrollLimit; SetScrollPos(SB_VERT, scrollPos); CRect myClientRect; GetClientRect(myClientRect); myClientRect.left = 1; CView *activeView = GetActiveView(); CRect activeClientRect; activeView->GetClientRect(activeClientRect); activeView->MapWindowPoints(this, activeClientRect); myClientRect.top = activeClientRect.top; ScrollWindow(0, origScrollPos - scrollPos, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { theView->SetScrollV(scrollPos); theView->tmv_vf120(); } } } afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (theDocument) { #pragma var_order(scrollLimit, activeClientRect, activeView, myClientRect, clientRect, origScrollPos, scrollPos, theView) RECT clientRect; GetClientRect(&clientRect); int scrollLimit = GetScrollLimit(SB_HORZ); int origScrollPos = GetScrollPos(SB_HORZ); int scrollPos = origScrollPos; switch (nSBCode) { case SB_RIGHT: scrollPos = scrollLimit; break; case SB_LINERIGHT: scrollPos += UT2Coordinate::UnitHSize(theDocument->mZoomLevel); break; case SB_LINELEFT: scrollPos -= UT2Coordinate::UnitHSize(theDocument->mZoomLevel); break; case SB_PAGERIGHT: scrollPos += clientRect.right / 2; break; case SB_PAGELEFT: scrollPos -= clientRect.right / 2; break; case SB_THUMBTRACK: scrollPos = nPos; break; case SB_LEFT: scrollPos = 0; break; } if (scrollPos < 0) scrollPos = 0; else if (scrollPos > scrollLimit) scrollPos = scrollLimit; SetScrollPos(SB_HORZ, scrollPos); CRect myClientRect; GetClientRect(myClientRect); myClientRect.top = 1; CView *activeView = GetActiveView(); CRect activeClientRect; activeView->GetClientRect(activeClientRect); activeView->MapWindowPoints(this, activeClientRect); myClientRect.left = activeClientRect.left; ScrollWindow(origScrollPos - scrollPos, 0, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { theView->SetScrollH(scrollPos); theView->tmv_vf120(); } } } afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { #pragma var_order(shadowPen, bigFont, theView, brush, save, highlightPen, theDocument, clientRect, smallFont) T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (!theDocument || !theDocument->mWorldDef || !theDocument->Get22C()) { CRect clientRect; GetClientRect(clientRect); CBrush brush(GetSysColor(COLOR_BTNFACE)); pDC->FillRect(clientRect, &brush); return true; } int save = pDC->SaveDC(); CRect clientRect; GetClientRect(clientRect); CBrush brush(GetSysColor(COLOR_BTNFACE)); pDC->FillRect(clientRect, &brush); CPen shadowPen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); 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_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_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); pDC->LineTo(0, 0); pDC->LineTo(0, clientRect.bottom); pDC->SetBkMode(TRANSPARENT); CView *theView = GetActiveView(); 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->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); pDC->LineTo(viewRect.left - 1, viewRect.top - 1); pDC->LineTo(-1, viewRect.top - 1); pDC->ExcludeClipRect(0, 0, viewRect.left, viewRect.top); SCROLLINFO scrollInfoH; SCROLLINFO scrollInfoV; GetScrollInfo(SB_HORZ, &scrollInfoH); GetScrollInfo(SB_VERT, &scrollInfoV); pDC->SetWindowOrg(scrollInfoH.nPos, 0); CRect anotherRect; int hRange = scrollInfoH.nMax - scrollInfoH.nMin; pDC->SelectObject(smallFont); int i; int x; int y; char str[4]; POINT textPos; int textLen; for (i = 0; i < 10; i++) { x = viewRect.left + (hRange * i) / 10; anotherRect.SetRect(x, 1, viewRect.left + (hRange * (i + 1)) / 10, 16); pDC->SelectObject(shadowPen); pDC->MoveTo(x - 1, 1); pDC->LineTo(x - 1, 16); pDC->SelectObject(highlightPen); pDC->MoveTo(x, 1); pDC->LineTo(x, 16); str[0] = "\x82\x60"[0]; str[1] = "\x82\x60"[1] + i; str[2] = 0; textPos.y = 2; textPos.x = ((anotherRect.left + anotherRect.right) / 2) - (pDC->GetTextExtent(str, 2).cx / 2); pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT)); pDC->TextOut(textPos.x + 1, textPos.y + 1, str, 2); pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW)); pDC->TextOut(textPos.x - 1, textPos.y - 1, str, 2); pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); pDC->TextOut(textPos.x, textPos.y, str, 2); } x = viewRect.left + hRange; anotherRect.SetRect(x, 1, viewRect.left + (hRange * 11) / 10, 16); pDC->SelectObject(shadowPen); pDC->MoveTo(x - 1, 1); pDC->LineTo(x - 1, 16); pDC->SelectObject(highlightPen); pDC->MoveTo(x, 1); pDC->LineTo(x, 16); pDC->SetWindowOrg(0, scrollInfoV.nPos); int vRange = scrollInfoV.nMax - scrollInfoV.nMin; int height = theDocument->mWorldDef->GetHeight(); pDC->SelectObject(bigFont); for (i = 0; i <= height; i++) { y = viewRect.top + (vRange * i) / height; anotherRect.SetRect(0, y, 14, viewRect.top + (vRange * (i + 1)) / height); pDC->SelectObject(shadowPen); pDC->MoveTo(1, y - 1); pDC->LineTo(16, y - 1); pDC->SelectObject(highlightPen); pDC->MoveTo(1, y); pDC->LineTo(16, y); } 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 = theDocument->mWorldDef->mGroundLine - i; BOOL isShow = showAllNumbers; if (number > 1 && (number % 5 == 0)) isShow = true; if (number == 1) isShow = true; if (number < 1 && ((number - 1) % 5 == 0)) isShow = true; if (isShow) { if (number >= 1) wsprintf(str, "%d", number); else wsprintf(str, "B%d", -number + 1); textLen = strlen(str); textPos.x = 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, textLen); pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW)); pDC->TextOut(textPos.x - 1, textPos.y - 1, str, textLen); pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); pDC->TextOut(textPos.x, textPos.y, str, textLen); } } } pDC->RestoreDC(save); return false; } afx_msg void T2MainWindow::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) { CFrameWnd::OnActivate(nState, pWndOther, bMinimized); } afx_msg void T2MainWindow::OnActivateApp(BOOL bActive, HTASK hTask) { CWnd::OnActivateApp(bActive, hTask); T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (theDocument && theDocument->mWorldDef) { CDC *pDC = GetDC(); pDC->SaveDC(); pDC->SelectPalette(theDocument->mWorldDef->GetPalette(), false); pDC->RealizePalette(); pDC->RestoreDC(-1); ReleaseDC(pDC); InvalidateRect(NULL); T2TowerMainView *theTowerMainView = theDocument->GetMainView(); if (theTowerMainView) theTowerMainView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); DWORD thisProcessId; GetWindowThreadProcessId(*this, &thisProcessId); CWnd *wnd = GetDesktopWindow()->GetWindow(GW_CHILD); while (wnd) { DWORD checkProcessId; GetWindowThreadProcessId(*wnd, &checkProcessId); if (thisProcessId == checkProcessId) wnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); wnd = wnd->GetWindow(GW_HWNDNEXT); } } } afx_msg void T2MainWindow::OnCmdDebugEvent() { DbgEventList dlg(NULL); dlg.DoModal(); } afx_msg void T2MainWindow::OnUpdateCmdDebugEvent(CCmdUI *pCmdUI) { pCmdUI->Enable(); } afx_msg void T2MainWindow::OnClose() { T2TowerDoc *theDocument = (T2TowerDoc *) GetActiveDocument(); if (theDocument->towerDoc_vf1A4()) return; CFrameWnd::OnClose(); } afx_msg void T2MainWindow::OnCmdDebugMode() { HMENU oldMenu = ::GetMenu(*this); HMENU newMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCE(130)); m_hMenuDefault = newMenu; ::SetMenu(*this, newMenu); DestroyMenu(oldMenu); }