#include "CT2App.h" #include "GlobalFunc.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" #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 = 0; _F0 = 0; mSoundPlayer = NULL; mDirectSound = NULL; mToolWindow = NULL; mMsgWindow = NULL; mCtrlPalette = NULL; ((CT2App *) AfxGetApp())->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_OL) { DeinitSound(); } #endif } void T2MainWindow::DeinitSound() { if (mDirectSound) { #ifdef _WIN32 mDirectSound->Release(); #endif mDirectSound = NULL; } } /*virtual*/ BOOL T2MainWindow::PreCreateWindow(CREATESTRUCT& cs) { cs.style |= WS_TABSTOP | WS_GROUP | WS_VSCROLL; return CFrameWnd::PreCreateWindow(cs); } afx_msg int T2MainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { #line 123 // mDbgStepRun = DEBUG_NEW DbgStepRun; // mDbgIPS = DEBUG_NEW DbgIPS; if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; InitSound(); #line 130 mSoundPlayer = DEBUG_NEW T2SoundPlayer(this, mDirectSound); SetWindowRgn(CreateRectRgn(100, 100, 100, 100), true); return 0; } afx_msg void T2MainWindow::OnDestroy() { gT2App->mMainWindow = NULL; // ffCalledFromDestroy(); CFrameWnd::OnDestroy(); // 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); mWndClassA = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); RECT rect; SetRect(&rect, 100, 100, 300, 300); mToolWindow = ((CT2App *) AfxGetApp())->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. } void T2MainWindow::Teardown() { delete mToolWindow; delete mMsgWindow; delete mCtrlPalette; 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 *theTowerDoc = (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() { T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); x4144FA(); CRect rect; GetWindowRect(rect); int width = rect.Width(); int height = rect.Height(); if (width && height && theTowerDoc && theView && theTowerDoc->mWorldDef) { theView->tmv_vf138(theTowerDoc->mWorldDef->mInitPos, 0x102); _F0 = 1; theView->ShowWindow(SW_SHOW); } } void T2MainWindow::x4144FA() { T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theTowerDoc && theView && theTowerDoc->mWorldDef) { RECT clientRect; GetClientRect(&clientRect); RECT unitRect; SetRect(&unitRect, 0, 0, theTowerDoc->mWorldDef->GetWidth(), theTowerDoc->mWorldDef->GetHeight()); UT2Coordinate::UnitToQD(unitRect, theTowerDoc->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 *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); if (theTowerDoc) { 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(theTowerDoc->mZoomLevel); break; case SB_LINEUP: scrollPos -= UT2Coordinate::UnitVSize(theTowerDoc->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, scrollPos - origScrollPos, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { theView->tmv_vf130(scrollPos); theView->tmv_vf120(); } } } afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); if (theTowerDoc) { 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(theTowerDoc->mZoomLevel); break; case SB_LINELEFT: scrollPos -= UT2Coordinate::UnitHSize(theTowerDoc->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.top = activeClientRect.top; ScrollWindow(scrollPos - origScrollPos, 0, myClientRect, myClientRect); UpdateWindow(); T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); if (theView) { theView->tmv_vf134(scrollPos); theView->tmv_vf120(); } } } afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); if (!theTowerDoc || !theTowerDoc->mWorldDef || !theTowerDoc->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_DEFAULT_PRECIS, 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"); 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 && theTowerDoc && theView) { 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; 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; 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 = theTowerDoc->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 = (theTowerDoc->towerDoc_vf108() == 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; if (number > 1 && (number % 5 == 0)) show = true; if (number == 1) show = true; if (number < 1 && ((number - 1) % 5 == 0)) show = true; if (show) { if (number >= 1) wsprintf(str, "%d", number); else wsprintf(str, "B%d", 1 - number); int textLen = strlen(str); textPos.x = 2; textPos.y = ((anotherRect.top + anotherRect.bottom) / 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); } } } 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 *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); if (theTowerDoc && theTowerDoc->mWorldDef) { CDC *pDC = GetDC(); pDC->SaveDC(); pDC->SelectPalette(theTowerDoc->mWorldDef->GetPalette(), false); pDC->RealizePalette(); pDC->RestoreDC(-1); ReleaseDC(pDC); InvalidateRect(NULL); T2TowerMainView *theTowerMainView = theTowerDoc->GetTowerMainView(); if (theTowerMainView) theTowerMainView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); DWORD processID; GetWindowThreadProcessId(this, &processID); CWnd *window = GetDesktopWindow()->GetWindow(GW_CHILD); while (window) { DWORD checkProcessID; GetWindowThreadProcessId(window, &checkProcessID); if (processID == checkProcessID) window->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); window = window->GetWindow(GW_HWNDNEXT); } } } afx_msg void T2MainWindow::OnCmdDebugEvent() { // TODO: DbgEventList } afx_msg void T2MainWindow::OnUpdateCmdDebugEvent(CCmdUI *pCmdUI) { pCmdUI->Enable(); } afx_msg void T2MainWindow::OnClose() { T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); if (theTowerDoc->towerDoc_vf1A4()) return; CFrameWnd::OnClose(); } afx_msg void T2MainWindow::OnCmdDebugMode() { HMENU oldMenu = GetMenu(this); HMENU newMenu = LoadMenu(AfxGetInstanceHandle(), 130); m_hMenuDefault = newMenu; SetMenu(this, newMenu); DestroyMenu(oldMenu); }