From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/T2Dialog.cpp | 331 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 src/T2DLL/T2Dialog.cpp (limited to 'src/T2DLL/T2Dialog.cpp') diff --git a/src/T2DLL/T2Dialog.cpp b/src/T2DLL/T2Dialog.cpp new file mode 100644 index 0000000..c00b5d7 --- /dev/null +++ b/src/T2DLL/T2Dialog.cpp @@ -0,0 +1,331 @@ +#include "CTokenizer.h" +#include "T2Dialog.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" + +IMPLEMENT_DYNAMIC(T2Dialog, CWnd) + +T2Dialog::T2Dialog() { + mInModalLoop = false; + mUserCon = 0; + mDeleteOnClose = false; + mFontName = "�l�r �o�S�V�b�N"; + + for (int i = 0; i < 10; i++) + mFontNums[i] = 0; +} + +/*virtual*/ T2Dialog::~T2Dialog() { + for (int i = 0; i < 10; i++) { + if (mFonts[i]) + delete mFonts[i]; + } +} + +void T2Dialog::Realize(void* a, T2DLGTEMPLATE* tmpl, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette, int b, CWnd* parentWnd, UINT nID, int d) { + mEC = a; + mTowerDoc = towerDoc; + mF4 = d; + mTemplate = *tmpl; + mImageObj = imageObj; + + if (towerDoc && mTowerDoc->mWorldDef) + mPalette = mTowerDoc->mWorldDef->GetPalette(); + else if (palette) + mPalette = palette; + else + mPalette = NULL; + + if (!parentWnd) + parentWnd = AfxGetMainWnd(); + + for (int i = 0; i < 10; i++) + mFonts[i] = NULL; + mFontCount = 0; + mCurrentFont = -1; + + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = 100; + rect.bottom = 100; + + CString wndClass = AfxRegisterWndClass( + CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS, + LoadCursor(NULL, IDC_ARROW), + (HBRUSH) GetStockObject(WHITE_BRUSH), + NULL); + + CreateEx( + b ? WS_EX_TOOLWINDOW : 0, + wndClass, + "", + b ? (WS_POPUP | WS_CAPTION) : WS_CHILD, + rect, + parentWnd, + nID + ); +} + +BEGIN_MESSAGE_MAP(T2Dialog, CWnd) + ON_WM_CREATE() + ON_WM_DESTROY() + ON_WM_QUERYNEWPALETTE() + ON_WM_ERASEBKGND() + ON_WM_LBUTTONDBLCLK() + ON_WM_LBUTTONDOWN() + ON_WM_LBUTTONUP() + ON_WM_ACTIVATEAPP() +END_MESSAGE_MAP() + +int T2Dialog::OnCreate(CREATESTRUCT* cs) { + if (CWnd::OnCreate(cs) == -1) + return -1; + + HRSRC rsrc = FindResource(mTemplate.moduleHandle, MAKEINTATOM(mTemplate.resID), "T2DLG"); + if (!rsrc) { + MessageBox("�_�C�A���O������܂���B"); + return 0; + } + +#line 90 + _ASSERT(rsrc); + + HGLOBAL hglobal = LoadResource(mTemplate.moduleHandle, rsrc); +#line 92 + _ASSERT(hglobal); + + void *resData = LockResource(hglobal); +#line 94 + _ASSERT(resData); + + DWORD resSize = SizeofResource(mTemplate.moduleHandle, rsrc); + char *buffer = (char *) malloc(resSize + 1); + memcpy(buffer, resData, resSize); + buffer[resSize] = 0; + + DoOnCreate(buffer); + free(buffer); + + OnT2Create(); + + if (mTowerDoc && !(GetWindowLong(m_hWnd, GWL_STYLE) & WS_CHILD)) { + if (mModal != 0) + mTowerDoc->towerDoc_vf1A0(1); + if (mModal == 1) + mTowerDoc->towerDoc_vf290(1); + } + + if (mF4 && !(cs->style & WS_CHILD)) + ShowWindow(SW_SHOW); + + return 0; +} + +T2Dialog::T2DialogDef::T2DialogDef() + : width(100) + , height(100) + , modal(1) + , title(NULL) + , center(true) + , flags(0x50000000) // is this a style? +{ +} + +/*virtual*/ T2Dialog::T2DialogDef::~T2DialogDef() { +} + +/*virtual*/ void T2Dialog::AfterBurner(T2DialogDef& def) { + mModal = def.modal; + SetWindowText(def.title); + + CRect windowRect, clientRect, desktopRect; + GetWindowRect(windowRect); + GetClientRect(clientRect); + GetDesktopWindow()->GetClientRect(desktopRect); + + def.width += (windowRect.Width() - clientRect.Width()); + def.height += (windowRect.Height() - clientRect.Height()); + + int cx = def.center ? (mTemplate.pt.x - def.width / 2) : mTemplate.pt.x; + if (cx < desktopRect.left) + cx = desktopRect.left; + if (cx + def.width >= desktopRect.right) + cx = desktopRect.right - def.width; + + int cy = def.center ? (mTemplate.pt.y - def.height / 2) : mTemplate.pt.y; + if (cy < desktopRect.top) + cy = desktopRect.top; + if (cy + def.height >= desktopRect.bottom) + cy = desktopRect.bottom - def.height; + + SetWindowPos(NULL, cx, cy, def.width, def.height, SWP_NOZORDER); +} + +/*virtual*/ void T2Dialog::DoOnCreate(char* data) { + T2DialogDef def; + CreateDlgItemLoop(def, data); + AfterBurner(def); +} + +void T2Dialog::CreateDlgItemLoop(T2DialogDef& def, char* data) { + CTokenizer tokenizer(data); + + while (tokenizer.NextWord()) { + if (tokenizer.Current()[0] == '#') + tokenizer.NextString("\r\n"); + else + CreateDlgItem(tokenizer, def); + } +} + +/*virtual*/ void T2Dialog::CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def) { + // TODO: this requires like 500 other classes lmfao +} + +void T2Dialog::OnDestroy() { + OnT2Destroy(); + CWnd::OnDestroy(); + + if (mTowerDoc && !(GetWindowLong(m_hWnd, GWL_STYLE) & WS_CHILD)) { + if (mModal != 0) + mTowerDoc->towerDoc_vf1A0(0); + if (mModal == 1) + mTowerDoc->towerDoc_vf290(0); + } +} + +int T2Dialog::OnQueryNewPalette() { + return CWnd::OnQueryNewPalette(); +} + +int T2Dialog::OnEraseBkgnd(CDC* dc) { + int result = true; + + if (!OnT2PreEraseBkgnd(dc)) { + int savedDC = dc->SaveDC(); + + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + CBrush brush; + brush.CreateStockObject(LTGRAY_BRUSH); + + CRect rect1; + GetClientRect(rect1); + dc->FillRect(rect1, &brush); + + CPen pen1; + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + + CPen pen2; + pen2.CreateStockObject(GRAY_BRUSH); // wait... that's not a pen + + CRect rect2; + GetClientRect(rect2); + + dc->SelectObject(pen1); + dc->MoveTo(rect2.right - 1, rect2.top); + dc->LineTo(rect2.left, rect2.top); + dc->LineTo(rect2.left, rect2.bottom); + + dc->SelectObject(pen2); + dc->MoveTo(rect2.right - 1, rect2.top + 1); + dc->LineTo(rect2.right - 1, rect2.bottom - 1); + dc->LineTo(rect2.left, rect2.bottom - 1); + + dc->RestoreDC(savedDC); + + result = OnT2EraseBkgnd(dc); + } + + return result; +} + +/*virtual*/ int T2Dialog::OnCommand(UINT cmd, long data) { + int result = true; + + WORD hi = HIWORD(cmd); + WORD lo = LOWORD(cmd); + + if ((lo == 1 || lo == 2) && (hi == 0)) { + if (lo == 1) + OnT2OK(); + else + OnT2Cancel(); + DoClose(lo); + } else { + result = OnT2DialogCommand(cmd, data); + } + + return result; +} + +int T2Dialog::DoModal() { + mInModalLoop = true; + int result = RunModalLoop(MLF_NOIDLEMSG); + if (mInModalLoop) + DestroyWindow(); + return result; +} + +void T2Dialog::DoClose(int nResult) { + if (mInModalLoop) + EndModalLoop(nResult); + else + DestroyWindow(); +} + +/*virtual*/ int T2Dialog::PreTranslateMessage(MSG* msg) { + return CWnd::PreTranslateMessage(msg); +} + +/*virtual*/ int T2Dialog::PreCreateWindow(CREATESTRUCT&) { + return 1; +} + +void T2Dialog::MakeRadioGroup(int, int, int) { + // TODO - depends on vfCC of something +} + +void T2Dialog::MakeTabPanel(int baseID1, int baseID2, int count, int currentIndex) { + for (unsigned short i = 1; i <= count; i++) { + unsigned short id2 = baseID2 + i; + unsigned short id1 = baseID1 + i; + GetDlgItem(id2)->EnableWindow(i != currentIndex); + if (baseID1 != 0) + GetDlgItem(id1)->ShowWindow((i != currentIndex) ? SW_HIDE : SW_SHOW); + } +} + +void T2Dialog::OnLButtonDblClk(UINT nFlags, CPoint pt) { + OnT2DlgLButtonDblClk(nFlags, pt); +} + +void T2Dialog::OnLButtonDown(UINT nFlags, CPoint pt) { + OnT2DlgLButtonDown(nFlags, pt); +} + +void T2Dialog::OnLButtonUp(UINT nFlags, CPoint pt) { + OnT2DlgLButtonUp(nFlags, pt); +} + +/*virtual*/ void T2Dialog::PostNcDestroy() { + if (mDeleteOnClose) + delete this; + else + CWnd::PostNcDestroy(); +} + +HFONT T2Dialog::GetFont() { + HFONT font = NULL; + + if (mCurrentFont >= 0) + font = *mFonts[mCurrentFont]; + + return font; +} + +void T2Dialog::OnActivateApp(BOOL bActive, HTASK hTask) { + CWnd::OnActivateApp(bActive, hTask); +} -- cgit v1.2.3