summaryrefslogtreecommitdiff
path: root/src/T2GraphWindow.cpp
blob: b1a8d143c63ca1f38f268199692fe3826a005410 (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
142
143
144
145
146
#include "GlobalFunc.h"
#include "T2GraphWindow.h"
#include "T2HUnknown.h"
#include "T2TowerDoc.h"
#include "T2WorldDef.h"

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

#line 16
IMPLEMENT_DYNCREATE(T2GraphWindow, CFrameWnd)

T2GraphWindow::T2GraphWindow() {
    mDocument = NULL;
}

T2GraphWindow::~T2GraphWindow() {
}

BEGIN_MESSAGE_MAP(T2GraphWindow, CFrameWnd)
    ON_WM_ERASEBKGND()
    ON_WM_HSCROLL()
    ON_WM_SIZE()
    ON_WM_QUERYNEWPALETTE()
END_MESSAGE_MAP()

BOOL T2GraphWindow::OnEraseBkgnd(CDC *pDC) {
#pragma var_order(pen4, rect2, brush, i, pen2, save, pen3, font, newSave, newDC, x, y, pen1, clientRect, position, bitmap)
    if (!mDocument || !mDocument->mWorldDef)
        return CFrameWnd::OnQueryNewPalette();

    int save = pDC->SaveDC();
    pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false);
    pDC->RealizePalette();

    CDC newDC;
    newDC.CreateCompatibleDC(pDC);
    int newSave = newDC.SaveDC();
    newDC.SelectPalette(mDocument->mWorldDef->GetPalette(), false);
    newDC.RealizePalette();

    CRect clientRect;
    GetClientRect(clientRect);

    HBITMAP bitmap = Create256DIBitmap(newDC.m_hDC, clientRect.Width(), clientRect.Height());
    SelectObject(newDC.m_hDC, bitmap);

    CBrush brush;

    brush.CreateSysColorBrush(COLOR_BTNFACE);
    newDC.FillRect(clientRect, &brush);
    brush.DeleteObject();

    brush.CreateSolidBrush(PALETTERGB(255, 255, 255));

    CRect rect2 = clientRect;
    rect2.top += 16;
    rect2.left += 1;
    rect2.right -= 1;
    rect2.bottom -= 1;
    newDC.FillRect(rect2, &brush);

    CPen pen1;
    pen1.CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNHIGHLIGHT));

    CPen pen2;
    pen2.CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));

    CPen pen3;
    pen3.CreatePen(PS_SOLID, 0, PALETTERGB(0, 0, 0));

    newDC.SelectObject(pen2);
    newDC.MoveTo(0, 16);
    newDC.LineTo(clientRect.right, 16);

    newDC.SelectObject(pen3);
    newDC.MoveTo(0, 17);
    newDC.LineTo(clientRect.right, 17);

    CFont font;
    font.CreateFont(-12, 0, 0, 0, FW_NORMAL, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E");
    newDC.SelectObject(font);
    newDC.SetBkMode(TRANSPARENT);

    newDC.Draw3dRect(10, 4, 28, 9, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT));
    newDC.TextOut(39, 2, "\x8E\x91\x8B\xE0");

    newDC.Draw3dRect(80, 4, 28, 9, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT));
    newDC.TextOut(109, 2, "\x90\x6C\x8C\xFB");

    CPen pen4;
    pen4.CreatePen(PS_SOLID, 0, PALETTERGB(255, 0, 0));
    newDC.SelectObject(pen4);

    int position = mDocument->_170->GetFirst();
    int x = mDocument->_170->GetLength() - 1;
    int y;
    int i = 0;
    while (position >= 0) {
        y = clientRect.bottom - 4 - (mDocument->_170->GetNext(position) / 1000);
        if (i == 0)
            newDC.MoveTo(x, y);
        else
            newDC.LineTo(x, y);
        x--;
        i++;
    }

    pDC->BitBlt(0, 0, clientRect.Width(), clientRect.Height(), &newDC, 0, 0, SRCCOPY);

    newDC.RestoreDC(newSave);
    newDC.DeleteDC();
    DeleteObject(bitmap);

    pDC->RestoreDC(save);

    return true;
}

void T2GraphWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
}

void T2GraphWindow::OnSize(UINT nType, int cx, int cy) {
    CFrameWnd::OnSize(nType, cx, cy);
}

BOOL T2GraphWindow::OnQueryNewPalette() {
    if (!mDocument || !mDocument->mWorldDef)
        return CFrameWnd::OnQueryNewPalette();

    CDC *pDC = GetDC();
    pDC->SaveDC();
    pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false);
    pDC->RealizePalette();
    pDC->RestoreDC(-1);
    ReleaseDC(pDC);

    return true;
}

void T2GraphWindow::SetDocument(T2TowerDoc *inDoc) {
    mDocument = inDoc;
}