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

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

T2DlgItemIButton::T2DlgItemIButton(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2DlgItemButtonBase(inDoc, inImageObj, inPalette)
{
}

/*virtual*/ BOOL T2DlgItemIButton::OnT2DlgItemEraseBkgnd(CDC* pDC) {
#pragma var_order(imageRect, rect30, clientRect, newDC, image, save3, save2, text, save, rect74, brush, bitmap, hbitmap)
    CRect clientRect;
    GetClientRect(clientRect);

    int save = pDC->SaveDC();
    pDC->SelectPalette(mPalette, false);
    pDC->RealizePalette();
    DrawButtonBase(pDC, clientRect, GetPattern() == 100);

    CString text;
    GetWindowText(text);

    CRect imageRect;
    T2BitImage *image = GetObjectImage(imageRect, text);

    CRect rect30;
    rect30.left = (clientRect.Width() - imageRect.Width()) / 2;
    rect30.top = (clientRect.Height() - imageRect.Height()) / 2;
    rect30.right = rect30.left + imageRect.Width();
    rect30.bottom = rect30.top + imageRect.Height();

    int save2 = pDC->SaveDC();
    CRect rect74 = imageRect;
    OffsetRect(&rect74, -rect74.left, -rect74.top);

    CDC newDC;
    newDC.CreateCompatibleDC(pDC);

    int save3 = newDC.SaveDC();
    newDC.SelectPalette(mPalette, false);
    newDC.RealizePalette();

    HBITMAP hbitmap = Create256DIBitmap(newDC.m_hDC, rect74.right, rect74.bottom);
    SelectObject(newDC.m_hDC, hbitmap);

    CBitmap bitmap;
    CBrush brush;
    image->CopyImage(&newDC, imageRect, rect74);

    if (!IsWindowEnabled()) {
        bitmap.LoadBitmap(170);
        brush.CreatePatternBrush(&bitmap);
        pDC->SelectObject(brush);
        pDC->BitBlt(rect30.left, rect30.top, rect30.Width(), rect30.Height(), &newDC, 0, 0, /*DPSDxax*/ 0xCA0749);
    } else {
        if (GetPattern() == 100)
            rect30.OffsetRect(1, 1);
        pDC->BitBlt(rect30.left, rect30.top, rect30.Width(), rect30.Height(), &newDC, 0, 0, SRCCOPY);
    }

    newDC.RestoreDC(save3);
    newDC.DeleteDC();
    DeleteObject(hbitmap);

    pDC->RestoreDC(save2);
    pDC->RestoreDC(save);

    return true;
}