summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemButtonBase.cpp
blob: bb2fc146b03403249ff3b463a996c763a056715b (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
#include "T2DlgItemButtonBase.h"

T2DlgItemButtonBase::T2DlgItemButtonBase(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2DlgItem(inDoc, inImageObj, inPalette)
    , mIsClicked(false)
{
}

/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonDown(UINT, CPoint) {
    SetCapture();
    mIsClicked = true;
    m74 = true;
    SetPattern(100);
    Invalidate();
}

/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonUp(UINT, CPoint) {
    if (mIsClicked) {
        ReleaseCapture();
        mIsClicked = false;

        if (m74) {
            m74 = false;
            SetPattern(0);
            Invalidate();
            Notify(GetDlgCtrlID(), 0, NULL);
        }
    }
}

/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemMouseMove(UINT, CPoint inPt) {
    if (mIsClicked) {
        CRect rect;
        GetClientRect(rect);
        BOOL inRect = rect.PtInRect(inPt);
        if (inRect != m74) {
            m74 = inRect;
            SetPattern(m74 ? 100 : 0);
            Invalidate();
        }
    }
}

/*virtual*/ void T2DlgItemButtonBase::DrawButtonBase(CDC* pDC, const RECT& inRect, BOOL flag) {
    if (IsWindowEnabled() && flag) {
#pragma var_order(brush, penB, save, penA)
        int save = pDC->SaveDC();
        pDC->SelectPalette(mPalette, false);
        pDC->RealizePalette();

        CPen penA;
        penA.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
        CBrush brush;
        brush.CreateSolidBrush(PALETTERGB(179, 179, 179));

        pDC->SelectObject(penA);
        pDC->SelectObject(brush);
        pDC->Rectangle(&inRect);

        CPen penB;
        penB.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133));
        pDC->SelectObject(penB);
        pDC->MoveTo(inRect.right - 2, inRect.top + 1);
        pDC->LineTo(inRect.left + 1, inRect.top + 1);
        pDC->LineTo(inRect.left + 1, inRect.bottom - 1);

        pDC->RestoreDC(save);
    } else {
#pragma var_order(brush, penB, penC, save, penA)
        int save = pDC->SaveDC();
        pDC->SelectPalette(mPalette, false);
        pDC->RealizePalette();

        CPen penA;
        penA.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
        CBrush brush;
        brush.CreateSolidBrush(PALETTERGB(204, 204, 204));

        pDC->SelectObject(penA);
        pDC->SelectObject(brush);
        pDC->Rectangle(&inRect);

        CPen penB;
        penB.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255));
        CPen penC;
        penC.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133));

        pDC->SelectObject(penB);
        pDC->MoveTo(inRect.right - 2, inRect.top + 1);
        pDC->LineTo(inRect.left + 1, inRect.top + 1);
        pDC->LineTo(inRect.left + 1, inRect.bottom - 1);

        pDC->SelectObject(penC);
        pDC->MoveTo(inRect.right - 2, inRect.top + 2);
        pDC->LineTo(inRect.right - 2, inRect.bottom - 2);
        pDC->LineTo(inRect.left + 1, inRect.bottom - 2);

        pDC->RestoreDC(save);
    }
}