summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2BalloonWnd.cpp
blob: 192855952d255cdc193781e0dded147e2f4430ec (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#include "StdAfx.h"
#include "GlobalFunc.h"
#include "T2BalloonWnd.h"
#include "../T2TowerDoc.h"
#include "../T2TowerMainView.h"

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

#line 16
IMPLEMENT_DYNCREATE(T2BalloonWnd, CFrameWnd);

T2BalloonWnd::T2BalloonWnd() {
    mVisible = false;
}

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

BEGIN_MESSAGE_MAP(T2BalloonWnd, CFrameWnd)
    ON_WM_ERASEBKGND()
    ON_WM_LBUTTONDOWN()
    ON_WM_RBUTTONDOWN()
    ON_WM_MOUSEMOVE()
    ON_WM_TIMER()
    ON_WM_DESTROY()
END_MESSAGE_MAP()

#pragma var_order(rect4, rect5, rect1, save, rect7, rgn4, rect2, rect3, pDC)
void T2BalloonWnd::Show(int inX, int inY, const CString& inText, BOOL inIsPause) {
    mIsPause = inIsPause;

    mFont.CreatePointFont(100, "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E");

    mWndClass = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH));

    CRect rect1(0, 0, 50, 50);
    Create(mWndClass, inText, WS_POPUP, rect1, AfxGetMainWnd(), NULL, WS_EX_TOPMOST);

    CRect rect2;
    GetClientRect(rect2);
    ClientToScreen(rect2);

    CRect rect3;
    rect3.top = rect2.top - rect1.top;
    rect3.left = rect2.left - rect1.left;
    rect3.bottom = rect1.bottom - rect2.bottom;
    rect3.right = rect1.right - rect2.right;

    CDC *pDC = GetDC();
    int save = pDC->SaveDC();
    pDC->SelectObject(mFont);

    mRect1.SetRectEmpty();
    // 123456789012345
    pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54", &mRect1, DT_SINGLELINE | DT_CALCRECT);
    pDC->DrawText(inText, &mRect1, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);

    mRect1.NormalizeRect();
    mRect1.OffsetRect(-mRect1.left, -mRect1.top);

    mRect2.SetRect(10, 10, 10, 10);
    mRect1.OffsetRect(mRect2.left, mRect2.top);

    CRect rect4;
    GetDesktopWindow()->GetClientRect(rect4);

    CRect rect5;
    rect5 = mRect1;
    rect5 += mRect2;
    rect5.InflateRect(0, 0, 0, 16);
    rect5.NormalizeRect();
    rect5.OffsetRect(-rect5.left, -rect5.top);
    rect5.OffsetRect(inX, inY - rect5.Height());
    mDirection = 1;

    if (rect1.SubtractRect(rect5, rect4)) {
        rect5 = mRect1;
        rect5 += mRect2;
        rect5.InflateRect(0, 0, 0, 16);
        rect5.NormalizeRect();
        rect5.OffsetRect(-rect5.left, -rect5.top);
        rect5.OffsetRect(inX - rect5.Width(), inY - rect5.Height());
        mDirection = 0;

        if (rect1.SubtractRect(rect5, rect4)) {
            rect5 = mRect1;
            rect5 += mRect2;
            rect5.InflateRect(0, 0, 0, 16);
            rect5.NormalizeRect();
            rect5.OffsetRect(-rect5.left, -rect5.top);
            rect5.OffsetRect(inX, inY);
            mDirection = 3;

            if (rect1.SubtractRect(rect5, rect4)) {
                rect5 = mRect1;
                rect5 += mRect2;
                rect5.InflateRect(0, 0, 0, 16);
                rect5.NormalizeRect();
                rect5.OffsetRect(-rect5.left, -rect5.top);
                rect5.OffsetRect(inX - rect5.Width(), inY);
                mDirection = 2;
            }
        }
    }

    rect5 += rect3;
    SetWindowPos(NULL, rect5.left, rect5.top, rect5.Width(), rect5.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
    rect5 -= rect3;

    rect5.OffsetRect(-rect5.left, -rect5.top);

    CRect rect7(1, 1, 1, 1);
    rect5 -= rect7;

    if (mDirection == 1) {
        mRgn.CreateRectRgn(0, 0, 1, 1);

        CRgn baseRegion;
        baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20);

        CRgn arrowRegion;
        POINT arrowPoints[3];
        arrowPoints[0].x = rect5.left + 10;
        arrowPoints[0].y = rect5.bottom - 18;
        arrowPoints[1].x = rect5.left;
        arrowPoints[1].y = rect5.bottom;
        arrowPoints[2].x = rect5.left + 21;
        arrowPoints[2].y = rect5.bottom - 18;
        arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE);
        mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR);
    } else if (mDirection == 0) {
        mRgn.CreateRectRgn(0, 0, 1, 1);

        CRgn baseRegion;
        baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20);

        CRgn arrowRegion;
        POINT arrowPoints[3];
        arrowPoints[0].x = rect5.right - 10;
        arrowPoints[0].y = rect5.bottom - 18;
        arrowPoints[1].x = rect5.right;
        arrowPoints[1].y = rect5.bottom;
        arrowPoints[2].x = rect5.right - 21;
        arrowPoints[2].y = rect5.bottom - 18;
        arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE);
        mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR);
    } else if (mDirection == 3) {
        mRect1.OffsetRect(0, 16);
        mRgn.CreateRectRgn(0, 0, 1, 1);

        CRgn baseRegion;
        baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20);

        CRgn arrowRegion;
        POINT arrowPoints[3];
        arrowPoints[0].x = rect5.left + 10;
        arrowPoints[0].y = rect5.top + 18;
        arrowPoints[1].x = rect5.left;
        arrowPoints[1].y = rect5.top;
        arrowPoints[2].x = rect5.left + 21;
        arrowPoints[2].y = rect5.top + 18;
        arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE);
        mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR);
    } else if (mDirection == 2) {
        mRect1.OffsetRect(0, 16);
        mRgn.CreateRectRgn(0, 0, 1, 1);

        CRgn baseRegion;
        baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20);

        CRgn arrowRegion;
        POINT arrowPoints[3];
        arrowPoints[0].x = rect5.right - 10;
        arrowPoints[0].y = rect5.top + 18;
        arrowPoints[1].x = rect5.right;
        arrowPoints[1].y = rect5.top;
        arrowPoints[2].x = rect5.right - 21;
        arrowPoints[2].y = rect5.top + 18;
        arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE);
        mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR);
    } else {
        mRgn.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom, 20, 20);
    }

    CRgn rgn4;
    rgn4.CreateRectRgn(0, 0, 1, 1);
    rgn4.CopyRgn(&mRgn);
    rgn4.OffsetRgn(rect3.left, rect3.top);
    ::SetWindowRgn(m_hWnd, rgn4, true);

    rgn4.Detach();
    pDC->RestoreDC(save);
    ReleaseDC(pDC);

    ShowWindow(SW_SHOWNA);
    SetCapture();

    mVisible = true;
    GetCursorPos(&mStartCursorPos);

    if (mIsPause)
        GetCurrentT2TowerDoc()->towerDoc_vf290(true);

    SetTimer(1, 1500, NULL);
}

#pragma var_order(brush, text, save, clientRect)
afx_msg BOOL T2BalloonWnd::OnEraseBkgnd(CDC* pDC) {
    int save = pDC->SaveDC();

    CRect clientRect;
    GetClientRect(clientRect);
    pDC->FillSolidRect(clientRect, RGB(255, 255, 255));

    CBrush brush;
    brush.CreateStockObject(BLACK_BRUSH);
    pDC->FrameRgn(&mRgn, &brush, 1, 1);

    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SelectObject(mFont);

    CString text;
    GetWindowText(text);
    pDC->DrawText(text, &mRect1, DT_WORDBREAK | DT_NOPREFIX);

    pDC->RestoreDC(save);

    return true;
}

afx_msg void T2BalloonWnd::OnLButtonDown(UINT nFlags, CPoint point) {
    ClientToScreen(&point);
    ShowWindow(SW_HIDE);
    ReleaseCapture();
    mVisible = false;
    DestroyWindow();

    CWnd *belowWindow = WindowFromPoint(point);
    if (belowWindow->m_hWnd == ((CFrameWnd *) AfxGetMainWnd())->GetActiveView()->m_hWnd) {
        belowWindow->ScreenToClient(&point);
        belowWindow->SendMessage(WM_LBUTTONDOWN, nFlags, MAKELONG(point.x, point.y));
    }
}

afx_msg void T2BalloonWnd::OnRButtonDown(UINT nFlags, CPoint point) {
    ClientToScreen(&point);
    ShowWindow(SW_HIDE);
    ReleaseCapture();
    mVisible = false;
    DestroyWindow();

    CWnd *belowWindow = WindowFromPoint(point);
    if (belowWindow->m_hWnd == ((CFrameWnd *) AfxGetMainWnd())->GetActiveView()->m_hWnd) {
        belowWindow->ScreenToClient(&point);
        belowWindow->SendMessage(WM_RBUTTONDOWN, nFlags, MAKELONG(point.x, point.y));
    }
}

afx_msg void T2BalloonWnd::OnMouseMove(UINT nFlags, CPoint point) {
    POINT cursor;
    GetCursorPos(&cursor);

    if (abs(mStartCursorPos.x - cursor.x) > 3 || abs(mStartCursorPos.y - cursor.y) > 3) {
        ShowWindow(SW_HIDE);
        ReleaseCapture();
        mVisible = false;
        DestroyWindow();
    }
}

afx_msg void T2BalloonWnd::OnTimer(UINT nIDEvent) {
    if (nIDEvent == 1) {
        ShowWindow(SW_HIDE);
        ReleaseCapture();
        mVisible = false;
        DestroyWindow();
    }
}

afx_msg void T2BalloonWnd::OnDestroy() {
    CFrameWnd::OnDestroy();

    if (mIsPause)
        GetCurrentT2TowerDoc()->towerDoc_vf294();

    KillTimer(1);
}