From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/T2DlgItemPeopleView.cpp | 195 +++++++++++++++++++++++++++++++++++--- 1 file changed, 180 insertions(+), 15 deletions(-) (limited to 'src/T2DLL/T2DlgItemPeopleView.cpp') diff --git a/src/T2DLL/T2DlgItemPeopleView.cpp b/src/T2DLL/T2DlgItemPeopleView.cpp index ff64ccc..d0689a5 100644 --- a/src/T2DLL/T2DlgItemPeopleView.cpp +++ b/src/T2DLL/T2DlgItemPeopleView.cpp @@ -1,49 +1,214 @@ +#include "LArray.h" +#include "T2BitImage.h" +#include "T2DlgItemHScr.h" #include "T2DlgItemPeopleView.h" +#include "T2InfoDialog.h" +#include "T2People.h" +#include "T2PeopleLinkIterator.h" +#include "UT2Coordinate.h" -T2DlgItemPeopleView::T2DlgItemPeopleView(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemPeopleView::T2DlgItemPeopleView(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ +#line 20 + mArray = DEBUG_NEW LArray(sizeof(T2People *)); + mImage = NULL; } /*virtual*/ T2DlgItemPeopleView::~T2DlgItemPeopleView() { + delete mArray; + if (mImage) + delete mImage; } -/*virtual*/ int T2DlgItemPeopleView::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemPeopleView::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + mParent = inParentWnd; + return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID); } -/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) { + T2DlgItem::OnT2DlgItemCreate(inCreateStruct); + + CRect rect; + GetClientRect(&rect); + if (rect.Height() >= (36 - (UT2Coordinate::CalcRoofThick(0) + UT2Coordinate::CalcFloorThick(0)) + 16)) { + CRect scrollerRect = rect; + scrollerRect.top = scrollerRect.bottom - 16; + +#line 47 + T2DlgItemHScr *theScroller = DEBUG_NEW T2DlgItemHScr(mTowerDoc, mImageObj, mPalette); + theScroller->Create("", WS_VISIBLE | WS_CHILD, scrollerRect, this, 100); + } + + return 0; } -/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemPeopleView::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2DlgItemHScr *theScr = (T2DlgItemHScr *) GetDlgItem(100); + int theScrollPos = theScr ? theScr->GetValue() : 0; + + CRect rect; + GetClientRect(rect); + if (theScr) + rect.bottom -= 15; + + int saved = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen thePen; + thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + pDC->SelectObject(thePen); + pDC->SelectObject(CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH))); + pDC->Rectangle(rect); + + rect.DeflateRect(1, 1); + pDC->IntersectClipRect(rect); + + if (mImage) { + CRect rect2(0, UT2Coordinate::CalcRoofThick(0), mImage->mBitmap.header.biWidth, mImage->mBitmap.header.biHeight - UT2Coordinate::CalcFloorThick(0)); + StretchDIBits(pDC->m_hDC, rect.left - theScrollPos, rect.top, mFullWidth, mFullHeight, rect2.left, rect2.bottom + 1, rect2.Width(), -rect2.Height(), mImage->mData, (const BITMAPINFO *) &mImage->mBitmap, DIB_PAL_COLORS, SRCCOPY); + } + + pDC->RestoreDC(saved); + return true; } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + if (mArray) { + T2DlgItemHScr *scroll = (T2DlgItemHScr *) GetDlgItem(100); + int theScrollValue = scroll ? scroll->GetValue() : 0; + + int theClickH = ((inPt.x + theScrollValue - 1) * (36 - (UT2Coordinate::CalcFloorThick(0) + UT2Coordinate::CalcRoofThick(0)))) / mFullHeight; + int h = 0; + + LArrayIterator iterator(*mArray); + T2People *thePeople; + + while (iterator.Next(&thePeople)) { + h += thePeople->GetWidth() * 8; + if (theClickH < h) { + mParent->EnableWindow(false); + + T2InfoDialog *theInfoDialog = thePeople->ShowInfoDialog(mTowerDoc); + theInfoDialog->DoModal(); + FinishAdd(); + + Invalidate(); + mParent->EnableWindow(true); + break; + } + } + } + + SetMouseCursor(183); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonDown(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonUp(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemMouseMove(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) { + if (inFlags & MK_LBUTTON) + SetMouseCursor(183); + else + SetMouseCursor(193); } -void T2DlgItemPeopleView::SetMouseCursor(unsigned int) { +void T2DlgItemPeopleView::SetMouseCursor(UINT inCursor) { + CWinApp *theApp = AfxGetApp(); + HCURSOR cursor = theApp->LoadCursor(inCursor); + if (cursor) + SetCursor(cursor); } -/*virtual*/ int T2DlgItemPeopleView::OnCommand(unsigned int, long) { +/*virtual*/ BOOL T2DlgItemPeopleView::OnCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL result = false; + + if (LOWORD(inWParam) == 100) { + InvalidateRect(NULL); + result = true; + } + + return result; } -void T2DlgItemPeopleView::SetPeople(T2People*) { +void T2DlgItemPeopleView::SetPeople(T2People* inPeople) { + if (inPeople) { + StartAdd(); + + T2PeopleLinkIterator iterator(inPeople); + T2People *thePeople; + + while (iterator.Next(&thePeople)) + AddOne(thePeople); + + FinishAdd(); + } } void T2DlgItemPeopleView::StartAdd() { -} + if (mArray && mArray->GetCount() > 0) + mArray->RemoveItemsAt(mArray->GetCount(), 1); -void T2DlgItemPeopleView::FinishAdd() { + delete mImage; + mImage = NULL; } -void T2DlgItemPeopleView::AddOne(T2People*) { +void T2DlgItemPeopleView::FinishAdd() { + if (mArray) { +#pragma var_order(imageRect, rect, width, theScroller, iterator2, thePeople, h, iterator1) + delete mImage; + mImage = NULL; + + T2DlgItemHScr *theScroller = (T2DlgItemHScr *) GetDlgItem(100); + T2People *thePeople; + + int width = 0; + LArrayIterator iterator1(*mArray); + while (iterator1.Next(&thePeople)) + width += thePeople->GetWidth() * 8; + + CRect rect; + GetClientRect(rect); + if (theScroller) + rect.bottom -= 15; + + rect.DeflateRect(1, 1); + mFullHeight = rect.Height(); + mFullWidth = (width * mFullHeight) / (36 - (UT2Coordinate::CalcFloorThick(0) + UT2Coordinate::CalcRoofThick(0))); + + CRect imageRect(0, 0, width, 36); +#line 214 + mImage = DEBUG_NEW T2BitImage(imageRect); + mImage->Clear(0); + + int h = 0; + LArrayIterator iterator2(*mArray); + while (iterator2.Next(&thePeople)) { + int w = thePeople->GetWidth() * 8; + CRect drawRect(0, 0, w, 36); + drawRect.OffsetRect(h, 0); + thePeople->Draw(mImage, drawRect); + h += w; + } + + if (theScroller) { + theScroller->SetPage(rect.Width()); + theScroller->SetRange(mFullWidth); + } + } +} + +void T2DlgItemPeopleView::AddOne(T2People* inPeople) { + if (inPeople) + mArray->Add(&inPeople); } -- cgit v1.2.3