#include "StdAfx.h" #include "GlobalFunc.h" #include "T2FloorInfo.h" #include "T2FloorNumberTable.h" #include "T2Mover.h" #include "T2MoverModuleTable.h" #include "../T2TowerDoc.h" T2FloorNumberTable::T2FloorNumberTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItemImageTable(inDoc, inImageObj, inPalette) , mMover(NULL) , mMoverModuleTable(NULL) { SetRect(&mRect, 0, 0, 0, 0); _10C = 0; _110 = 0; } /*virtual*/ T2FloorNumberTable::~T2FloorNumberTable() { } /*virtual*/ BOOL T2FloorNumberTable::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID); } void T2FloorNumberTable::SetMover(T2Mover* inMover) { mMover = inMover; InsertRows(mMover->GetLength(), 0, NULL); } void T2FloorNumberTable::SetMoverModuleTable(T2MoverModuleTable* inTable) { mMoverModuleTable = inTable; } int T2FloorNumberTable::GetVScrValue() { if (mMoverModuleTable) return mMoverModuleTable->GetVScrValue(); else return 0; } void T2FloorNumberTable::ClickCell(const TableCellT& inCell, POINT inPt) { if (mMover) { StflNotification info; info.floorNumber = mRows - inCell.row; info.theTable = this; BroadcastMessage('stfl', &info); } } void T2FloorNumberTable::RefreshCell(int inFloor) { TableCellT theCell; theCell.row = mRows - inFloor; theCell.col = 1; RECT cellRect; if (FetchLocalCellFrame(theCell, cellRect)) InvalidateRect(&cellRect); } /*virtual*/ void T2FloorNumberTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { if (mMover) { RECT cellRect; if (FetchLocalCellFrame(inCell, cellRect)) { RECT theDrawArea = mRect; OffsetRect(&theDrawArea, cellRect.left, cellRect.top); T2FloorInfo *theFloorInfo = GetCurrentT2TowerDoc()->GetFloorInfo(); RECT moverArea; mMover->GetEquipArea(moverArea); int floor = mRows - inCell.row; int floorNum = theFloorInfo->UnitToFloor(moverArea.top + inCell.row); char buffer[256]; sprintf(buffer, "%d", floorNum); int saveDC = pDC->SaveDC(); CBrush baseBrush; baseBrush.CreateSolidBrush(RGB(255, 255, 255)); pDC->SelectObject(baseBrush); pDC->SelectStockObject(BLACK_PEN); pDC->Rectangle(&moverArea); pDC->MoveTo(cellRect.left, cellRect.bottom - 1); pDC->LineTo(cellRect.right - 1, cellRect.bottom - 1); InflateRect(&theDrawArea, 1, 1); pDC->DrawText(buffer, strlen(buffer), &theDrawArea, DT_CENTER | DT_VCENTER | DT_SINGLELINE); if (!mMover->IsStopPosition(floor)) { pDC->SetTextColor(_110); pDC->MoveTo(theDrawArea.left, theDrawArea.top); pDC->LineTo(theDrawArea.right - 1, theDrawArea.bottom - 1); pDC->MoveTo(theDrawArea.left, theDrawArea.bottom - 1); pDC->LineTo(theDrawArea.right - 1, theDrawArea.top); } pDC->RestoreDC(saveDC); } } } /*virtual*/ BOOL T2FloorNumberTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { RECT theTableRect, cellFrame; GetClientRect(&theTableRect); unsigned int height, width; GetTableSize(height, width); int position = GetVScrValue() * mRowHeight; for (unsigned int x = 1; x <= width; x++) { for (unsigned int y = 1; y <= height; y++) { TableCellT cell; cell.row = y; cell.col = x; if (FetchLocalCellFrame(cell, cellFrame)) { OffsetRect(&cellFrame, 0, -position); BOOL isVisible = IntersectRect(&cellFrame, &cellFrame, &theTableRect); if (isVisible) DrawCellSelf(pDC, cell, false); } } } InvalidateRect(&cellFrame); return true; } /*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { POINT pt = inPt; ClientToView(&pt, 1); TableCellT cell; FetchCellHitBy(pt, cell); ClickCell(cell, inPt); } /*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { } /*virtual*/ void T2FloorNumberTable::OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) { }