summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemPeopleView.cpp
blob: e3435d50b1c06105cd862ae7b5386010a672e614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#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);
}