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

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

T2DlgItemText::T2DlgItemText(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2DlgItem(inDoc, inImageObj, inPalette)
    , mHasTextColor(false)
{
}

void T2DlgItemText::SetTextColor(COLORREF inColor) {
    mTextColor = inColor;
    mHasTextColor = true;
}

/*virtual*/ void T2DlgItemText::GetDescriptor(CString& outStr) const {
    GetContentText(outStr);
}

/*virtual*/ void T2DlgItemText::SetDescriptor(const CString& inStr) {
    CString str(GetJustification());
    str += inStr;
    SetWindowText(str);

    CRect clientRect;
    GetClientRect(clientRect);
    MapWindowPoints(GetParent(), clientRect);
    GetParent()->InvalidateRect(clientRect);
}

/*virtual*/ BOOL T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC* pDC) {
    CRect rect;
    GetClientRect(rect);

    int theSave = pDC->SaveDC();

    pDC->SelectPalette(mPalette, false);
    pDC->RealizePalette();
    pDC->SetTextColor(mHasTextColor ? mTextColor : PALETTEINDEX(255));
    pDC->SetBkMode(TRANSPARENT);
    pDC->SelectObject(mFont);

    CString str;
    GetContentText(str);

    char just = GetJustification();
    UINT format = DT_WORDBREAK | DT_NOPREFIX;

    if (isupper(just)) {
        format |= DT_VCENTER;
        just = tolower(just);
    }

    switch (just) {
        case 'c': format |= DT_CENTER; break;
        case 'l': format |= DT_LEFT; break;
        case 'r': format |= DT_RIGHT; break;
    }

    pDC->DrawText(str, rect, format);

    pDC->RestoreDC(theSave);

    return true;
}

char T2DlgItemText::GetJustification() const {
    char result = 'l';

    CString text;
    GetWindowText(text);
    if (text.GetLength() > 0)
        result = text[0];

    return result;
}

void T2DlgItemText::GetContentText(CString& outStr) const {
    GetWindowText(outStr);

    if (outStr.GetLength() > 0)
        outStr = outStr.Mid(1);
}

void T2DlgItemText::InfoDialogMessage(CString& inStr, long inTime) {
    if (inTime != -1) {
        GetDescriptor(mPreviousString);
        mTimerID = SetTimer(1000, inTime, NULL);
    } else {
        mPreviousString.Empty();
        mTimerID = 0;
    }
    SetDescriptor(inStr);
}

/*virtual*/ void T2DlgItemText::OnT2Timer(UINT id) {
    if (id == mTimerID && mPreviousString.GetLength() > 0) {
        SetDescriptor(mPreviousString);
        mPreviousString.Empty();
        KillTimer(mTimerID);
    }
}