Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PlayerInfoBar.cpp « mpc-hc « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 250d7a7275fddca225cb89a6946698f7422687a6 (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
/*
 * (C) 2003-2006 Gabest
 * (C) 2006-2015 see Authors.txt
 *
 * This file is part of MPC-HC.
 *
 * MPC-HC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-HC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "stdafx.h"
#include "mplayerc.h"
#include "PlayerInfoBar.h"
#include "MainFrm.h"


// CPlayerInfoBar

IMPLEMENT_DYNAMIC(CPlayerInfoBar, CDialogBar)
CPlayerInfoBar::CPlayerInfoBar(CMainFrame* pMainFrame)
    : m_pMainFrame(pMainFrame)
{
    GetEventd().Connect(m_eventc, {
        MpcEvent::DPI_CHANGED,
    }, std::bind(&CPlayerInfoBar::EventCallback, this, std::placeholders::_1));
}

CPlayerInfoBar::~CPlayerInfoBar()
{
}

bool CPlayerInfoBar::SetLine(CString label, CString info)
{
    info.Trim();
    if (info.IsEmpty()) {
        return RemoveLine(label);
    }

    for (size_t idx = 0; idx < m_label.GetCount(); idx++) {
        CString tmp;
        m_label[idx]->GetWindowText(tmp);
        if (label == tmp) {
            m_info[idx]->GetWindowText(tmp);
            if (info != tmp) {
                m_info[idx]->SetWindowText(info);
                m_tooltip.UpdateTipText(info, m_info[idx]);
            }
            return false;
        }
    }

    CAutoPtr<CStatusLabel> l(DEBUG_NEW CStatusLabel(m_pMainFrame->m_dpi, true, false));
    l->Create(label, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | SS_OWNERDRAW, CRect(0, 0, 0, 0), this);
    m_label.Add(l);

    CAutoPtr<CStatusLabel> i(DEBUG_NEW CStatusLabel(m_pMainFrame->m_dpi, false, true));
    i->Create(info, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | SS_OWNERDRAW | SS_NOTIFY, CRect(0, 0, 0, 0), this);
    m_tooltip.AddTool(i, info);
    m_info.Add(i);

    Relayout();

    return true;
}

void CPlayerInfoBar::GetLine(CString label, CString& info)
{
    info.Empty();

    for (size_t idx = 0; idx < m_label.GetCount(); idx++) {
        CString tmp;
        m_label[idx]->GetWindowText(tmp);
        if (label == tmp) {
            m_info[idx]->GetWindowText(tmp);
            info = tmp;
            return;
        }
    }
}

bool CPlayerInfoBar::RemoveLine(CString label)
{
    for (size_t i = 0; i < m_label.GetCount(); i++) {
        CString tmp;
        m_label[i]->GetWindowText(tmp);
        if (label == tmp) {
            m_tooltip.DelTool(m_info[i]);
            m_label.RemoveAt(i);
            m_info.RemoveAt(i);
            Relayout();
            return true;
        }
    }
    return false;
}

void CPlayerInfoBar::RemoveAllLines()
{
    m_label.RemoveAll();
    m_info.RemoveAll();

    // invalidate and redraw bypassing message queue
    Invalidate();
    UpdateWindow();
}

BOOL CPlayerInfoBar::Create(CWnd* pParentWnd)
{
    BOOL res = CDialogBar::Create(pParentWnd, IDD_PLAYERINFOBAR, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM, IDD_PLAYERINFOBAR);

    m_tooltip.Create(this, TTS_NOPREFIX);
    m_tooltip.Activate(TRUE);
    m_tooltip.SetMaxTipWidth(m_pMainFrame->m_dpi.ScaleX(500));
    m_tooltip.SetDelayTime(TTDT_AUTOPOP, 10000);

    return res;
}

BOOL CPlayerInfoBar::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CDialogBar::PreCreateWindow(cs)) {
        return FALSE;
    }

    m_dwStyle &= ~CBRS_BORDER_TOP;
    m_dwStyle &= ~CBRS_BORDER_BOTTOM;

    return TRUE;
}

CSize CPlayerInfoBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
    CRect r;
    GetParent()->GetClientRect(&r);
    r.bottom = r.top + (LONG)m_label.GetCount() * m_pMainFrame->m_dpi.ScaleY(17) +
               (m_label.GetCount() ? m_pMainFrame->m_dpi.ScaleY(2) * 2 : 0);
    return r.Size();
}

void CPlayerInfoBar::EventCallback(MpcEvent ev)
{
    switch (ev) {
        case MpcEvent::DPI_CHANGED:
            for (size_t i = 0; i < m_label.GetCount(); i++) {
                m_label[i]->ScaleFont(m_pMainFrame->m_dpi);
            }
            for (size_t i = 0; i < m_info.GetCount(); i++) {
                m_info[i]->ScaleFont(m_pMainFrame->m_dpi);
            }
            break;

        default:
            ASSERT(FALSE);
    }
}

void CPlayerInfoBar::Relayout()
{
    CRect r;
    GetParent()->GetClientRect(&r);

    int w = m_pMainFrame->m_dpi.ScaleX(100);
    const int h = m_pMainFrame->m_dpi.ScaleY(17);
    int y = m_pMainFrame->m_dpi.ScaleY(2);

    for (size_t i = 0; i < m_label.GetCount(); i++) {
        CDC* pDC = m_label[i]->GetDC();
        CString str;
        m_label[i]->GetWindowText(str);
        w = std::max<int>(w, pDC->GetTextExtent(str).cx);
        m_label[i]->ReleaseDC(pDC);
    }

    const int sep = m_pMainFrame->m_dpi.ScaleX(10);
    for (size_t i = 0; i < m_label.GetCount(); i++, y += h) {
        m_label[i]->MoveWindow(1, y, w - sep, h);
        m_info[i]->MoveWindow(w + sep, y, r.Width() - w - sep - 1, h);
    }
}

BEGIN_MESSAGE_MAP(CPlayerInfoBar, CDialogBar)
    ON_WM_ERASEBKGND()
    ON_WM_SIZE()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// CPlayerInfoBar message handlers

BOOL CPlayerInfoBar::PreTranslateMessage(MSG* pMsg)
{
    if (IsWindow(m_tooltip)) {
        m_tooltip.RelayEvent(pMsg);
    }

    return __super::PreTranslateMessage(pMsg);
}

BOOL CPlayerInfoBar::OnEraseBkgnd(CDC* pDC)
{
    for (CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow()) {
        CRect r;
        pChild->GetClientRect(&r);
        pChild->MapWindowPoints(this, &r);
        pDC->ExcludeClipRect(&r);
    }

    CRect r;
    GetClientRect(&r);

    CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());

    if (pFrame->m_pLastBar != this || pFrame->m_fFullScreen) {
        r.InflateRect(0, 0, 0, 1);
    }

    if (pFrame->m_fFullScreen) {
        r.InflateRect(1, 0, 1, 0);
    }

    pDC->Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));

    r.DeflateRect(1, 1);

    pDC->FillSolidRect(&r, 0);

    return TRUE;
}

void CPlayerInfoBar::OnSize(UINT nType, int cx, int cy)
{
    CDialogBar::OnSize(nType, cx, cy);

    Relayout();

    Invalidate();
}

void CPlayerInfoBar::OnLButtonDown(UINT nFlags, CPoint point)
{
    CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
    if (!pFrame->m_fFullScreen) {
        MapWindowPoints(pFrame, &point, 1);
        pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
    }
}