summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2SilhouettePane.cpp
blob: 64d0b05073be2cd5dddad2098c5ef4691b0433c3 (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
#include "T2BitImage.h"
#include "T2People.h"
#include "T2SilhouettePane.h"
#include "UT2Coordinate.h"
#include <MINMAX.H>

T2SilhouettePane::T2SilhouettePane(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette)
    : T2DlgItem(towerDoc, imageObj, palette)
{
    mPeople = NULL;
    mHasCustomColor = false;
    mA0 = 0;
    mSilhouetteType = 0;
    m8C = 0;
    m90 = 0;
}

/*virtual*/ T2SilhouettePane::~T2SilhouettePane() {
}

/*virtual*/ void T2SilhouettePane::DrawSelf(CDC* dc) {
    CRect clientRect;
    GetClientRect(clientRect);

    if (mPeople && !clientRect.IsRectEmpty()) {
#pragma var_order(ratio, image, origColor, rect3, imageRect, rect4)
        dc->FillRect(clientRect, CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH)));

        clientRect.DeflateRect(2, 2);

        int origColor = mPeople->mColor;
        if (mHasCustomColor)
            mPeople->mColor = mCustomColor;

        CRect imageRect(0, 0, mPeople->GetWidth() * 8, 36);
        T2BitImage *image = new T2BitImage(imageRect);
        image->Clear(0);
        mPeople->Draw(image, imageRect);

        CRect rect3 = imageRect;
        rect3.top += UT2Coordinate::CalcRoofThick(0);
        rect3.bottom -= UT2Coordinate::CalcFloorThick(0);

        float ratio = min(float(clientRect.Width()) / float(rect3.Width()), float(clientRect.Height()) / float(rect3.Height()));
        if (ratio < 1.0)
            ratio = 1.0f;

        CRect rect4(0, 0, rect3.Width() * ratio, rect3.Height() * ratio);
        rect4.OffsetRect(
            clientRect.left + (clientRect.Width() - rect4.Width()) / 2,
            clientRect.top + (clientRect.Height() - rect4.Height()) / 2
        );

        StretchDIBits(
            dc->m_hDC,
            rect4.left, rect4.top,
            rect4.Width(), rect4.Height(),
            rect3.left, rect3.bottom + 1,
            rect3.Width(), -rect3.Height(),
            image->mData, (BITMAPINFO *) &image->mBitmap,
            DIB_PAL_COLORS, SRCCOPY);

        delete image;

        mPeople->mColor = origColor;
    }
}

/*virtual*/ BOOL T2SilhouettePane::OnT2DlgItemEraseBkgnd(CDC* dc) {
    int save = dc->SaveDC();
    dc->SelectPalette(mPalette, false);
    dc->RealizePalette();

    if (!mPeople)
        return false;

    DrawSelf(dc);
    dc->RestoreDC(save);

    return true;
}

/*virtual*/ BOOL T2SilhouettePane::OnCreate(CREATESTRUCT* cs) {
    return T2DlgItem::OnCreate(cs);
}

void T2SilhouettePane::SetPeople(T2People* people) {
    mPeople = people;
    InvalidateRect(NULL);
}