#include "StdAfx.h" #include "LArray.h" #include "T2BitImage.h" #include "T2DlgItemHScr.h" #include "T2DlgItemPeopleView.h" #include "T2InfoDialog.h" #include "T2People.h" #include "T2PeopleLinkIterator.h" #include "UT2Coordinate.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif T2DlgItemPeopleView::T2DlgItemPeopleView(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItem(inDoc, inImageObj, inPalette) { #line 20 mArray = new LArray(sizeof(T2People *)); mImage = NULL; } /*virtual*/ T2DlgItemPeopleView::~T2DlgItemPeopleView() { delete mArray; if (mImage) delete mImage; } /*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(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 = new T2DlgItemHScr(mTowerDoc, mImageObj, mPalette); theScroller->Create("", WS_VISIBLE | WS_CHILD, scrollerRect, this, 100); } return 0; } /*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(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(UINT inFlags, CPoint inPt) { SetMouseCursor(193); } /*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonDown(UINT inFlags, CPoint inPt) { SetMouseCursor(193); } /*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonUp(UINT inFlags, CPoint inPt) { SetMouseCursor(193); } /*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) { if (inFlags & MK_LBUTTON) SetMouseCursor(183); else SetMouseCursor(193); } void T2DlgItemPeopleView::SetMouseCursor(UINT inCursor) { CWinApp *theApp = AfxGetApp(); HCURSOR cursor = theApp->LoadCursor(inCursor); if (cursor) SetCursor(cursor); } /*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* 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); delete mImage; mImage = NULL; } 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 = 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); }