summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemArrows.cpp
blob: f70651f6dfee03f5e38de0596311fde7f3eaa79c (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
#include "StdAfx.h"
#include "T2BitImage.h"
#include "T2DlgItemArrows.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

T2DlgItemArrows::T2DlgItemArrows(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2DlgItem(inDoc, inImageObj, inPalette)
    , mMinimum(0)
    , mMaximum(0)
    , mIsClicked(false)
{
}

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

/*virtual*/ BOOL T2DlgItemArrows::Create(const char* windowName, DWORD style, const RECT& inRect, CWnd* parentWnd, UINT nId) {
    CRect rect = inRect;
    CRect theImageArea;
    T2BitImage *theImage = GetObjectImage(theImageArea, "DLGITEM:Arrows");
    if (theImage) {
        rect.right = rect.left + theImageArea.Width();
        rect.bottom = rect.top + theImageArea.Height();
    }
    return T2DlgItem::Create(windowName, style, rect, parentWnd, nId);
}

/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) {
    CRect rect;
    GetClientRect(rect);

    CRect imageRect;
    if (GetObjectImage(imageRect, "DLGITEM:Arrows")) {
        CRect upRect = imageRect;
        upRect.bottom = upRect.top + (upRect.Height() / 2);
        upRect.OffsetRect(-upRect.left + rect.left, -upRect.top + rect.top);

        CRect dnRect = upRect;
        dnRect.OffsetRect(-dnRect.left + rect.left, -dnRect.top + rect.top + upRect.Height() + 1);

        if (upRect.PtInRect(inPt)) {
            SetPattern(100);
            mMouseRect = upRect;
        } else if (dnRect.PtInRect(inPt)) {
            SetPattern(101);
            mMouseRect = dnRect;
        }
    }

    if (GetPattern() != 0) {
        SetCapture();
        m74 = true;
        mIsClicked = true;
        InvalidateRect(mMouseRect);

        SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1));
        Notify(GetDlgCtrlID(), 0, NULL);
        mTimerID = SetTimer(999, 100, NULL);
    }
}

/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt) {
    if (mIsClicked) {
        if (mTimerID)
            KillTimer(mTimerID);

        SetPattern(0);
        ReleaseCapture();
        mIsClicked = false;

        if (m74) {
            m74 = false;
            InvalidateRect(mMouseRect);
        }
    }
}

/*virtual*/ void T2DlgItemArrows::OnT2DlgItemMouseMove(UINT nFlags, CPoint pt) {
    if (mIsClicked) {
        BOOL inRect = mMouseRect.PtInRect(pt);
        if (inRect != m74) {
            m74 = inRect;
            InvalidateRect(mMouseRect);
        }
    }
}

/*virtual*/ BOOL T2DlgItemArrows::OnT2DlgItemEraseBkgnd(CDC* pDC) {
    CRect theFrameRect;
    GetClientRect(theFrameRect);

    int save = pDC->SaveDC();
    pDC->SelectPalette(mPalette, false);
    pDC->RealizePalette();

    CRect theImageArea;
    T2BitImage *theImage = GetObjectImage(theImageArea, "DLGITEM:Arrows", !m74 ? 0 : GetPattern());

    if (theImage) {
        CRect drawRect = theImageArea;
        drawRect.OffsetRect(-drawRect.left + theFrameRect.left, -drawRect.top + theFrameRect.top);
        theImage->CopyImage(pDC, theImageArea, drawRect, 0, NULL);
    }

    pDC->RestoreDC(save);

    return true;
}

/*virtual*/ void T2DlgItemArrows::OnT2Timer(UINT id) {
    if (id == mTimerID && m74) {
        SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1));
        Notify(GetDlgCtrlID(), 0, NULL);
    }
}

/*virtual*/ void T2DlgItemArrows::SetMinValue(int inValue) {
    mMinimum = inValue;
    if (mValue < inValue)
        SetValue(inValue);
}

/*virtual*/ void T2DlgItemArrows::SetMaxValue(int inValue) {
    mMaximum = inValue;
    if (mValue > inValue)
        SetValue(inValue);
}

/*virtual*/ void T2DlgItemArrows::SetValue(int inValue) {
    if (inValue < mMinimum)
        inValue = mMinimum;
    else if (inValue > mMaximum)
        inValue = mMaximum;

    T2DlgItem::SetValue(inValue);
}