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

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/mpc-hc/PlayerToolBar.cpp')
-rw-r--r--src/mpc-hc/PlayerToolBar.cpp99
1 files changed, 71 insertions, 28 deletions
diff --git a/src/mpc-hc/PlayerToolBar.cpp b/src/mpc-hc/PlayerToolBar.cpp
index af75f9499..ac408e253 100644
--- a/src/mpc-hc/PlayerToolBar.cpp
+++ b/src/mpc-hc/PlayerToolBar.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2015 see Authors.txt
+ * (C) 2006-2016 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -21,13 +21,15 @@
#include "stdafx.h"
#include "mplayerc.h"
-#include <math.h>
+#include <cmath>
#include <atlbase.h>
#include <afxpriv.h>
#include "MPCPngImage.h"
#include "PlayerToolBar.h"
#include "MainFrm.h"
#include "PathUtils.h"
+#include "SVGImage.h"
+#include "ImageGrayer.h"
// CPlayerToolBar
@@ -35,17 +37,19 @@ IMPLEMENT_DYNAMIC(CPlayerToolBar, CToolBar)
CPlayerToolBar::CPlayerToolBar(CMainFrame* pMainFrame)
: m_pMainFrame(pMainFrame)
, m_nButtonHeight(16)
- , m_pButtonsImages(nullptr)
, m_volumeMinSizeInc(0)
{
+ GetEventd().Connect(m_eventc, {
+ MpcEvent::DPI_CHANGED,
+ MpcEvent::DEFAULT_TOOLBAR_SIZE_CHANGED,
+ }, std::bind(&CPlayerToolBar::EventCallback, this, std::placeholders::_1));
}
CPlayerToolBar::~CPlayerToolBar()
{
- SAFE_DELETE(m_pButtonsImages);
}
-bool CPlayerToolBar::LoadExternalToolBar(CImage* image)
+bool CPlayerToolBar::LoadExternalToolBar(CImage& image)
{
// Paths and extensions to try (by order of preference)
std::vector<CString> paths({ PathUtils::GetProgramPath() });
@@ -55,10 +59,17 @@ bool CPlayerToolBar::LoadExternalToolBar(CImage* image)
}
const std::vector<CString> extensions({ _T("png"), _T("bmp") });
+ // TODO: Find a better solution?
+ float dpiScaling = (float)std::min(m_pMainFrame->m_dpi.ScaleFactorX(), m_pMainFrame->m_dpi.ScaleFactorY());
+
// Try loading the external toolbar
for (const auto& path : paths) {
+ if (SUCCEEDED(SVGImage::Load(PathUtils::CombinePaths(path, _T("toolbar.svg")), image, dpiScaling))) {
+ return true;
+ }
+
for (const auto& ext : extensions) {
- if (SUCCEEDED(image->Load(PathUtils::CombinePaths(path, _T("toolbar.") + ext)))) {
+ if (SUCCEEDED(image.Load(PathUtils::CombinePaths(path, _T("toolbar.") + ext)))) {
return true;
}
}
@@ -67,6 +78,47 @@ bool CPlayerToolBar::LoadExternalToolBar(CImage* image)
return false;
}
+void CPlayerToolBar::LoadToolbarImage()
+{
+ // We are currently not aware of any cases where the scale factors are different
+ float dpiScaling = (float)std::min(m_pMainFrame->m_dpi.ScaleFactorX(), m_pMainFrame->m_dpi.ScaleFactorY());
+ float defaultToolbarScaling = AfxGetAppSettings().nDefaultToolbarSize / 16.0f;
+
+ CImage image;
+ if (LoadExternalToolBar(image) || (!AfxGetAppSettings().bUseLegacyToolbar && SUCCEEDED(SVGImage::Load(IDF_SVG_TOOLBAR, image, dpiScaling * defaultToolbarScaling)))) {
+ CBitmap* bmp = CBitmap::FromHandle(image);
+ int width = image.GetWidth();
+ int height = image.GetHeight();
+ int bpp = image.GetBPP();
+ if (width == height * 15) {
+ // the manual specifies that sizeButton should be sizeImage inflated by (7, 6)
+ SetSizes(CSize(height + 7, height + 6), CSize(height, height));
+
+ m_pButtonsImages.reset(DEBUG_NEW CImageList());
+ if (bpp == 32) {
+ m_pButtonsImages->Create(height, height, ILC_COLOR32 | ILC_MASK, 1, 0);
+ m_pButtonsImages->Add(bmp, nullptr); // alpha is the mask
+
+ CImage imageDisabled;
+ if (ImageGrayer::Gray(image, imageDisabled)) {
+ m_pDisabledButtonsImages.reset(DEBUG_NEW CImageList());
+ m_pDisabledButtonsImages->Create(height, height, ILC_COLOR32 | ILC_MASK, 1, 0);
+ m_pDisabledButtonsImages->Add(CBitmap::FromHandle(imageDisabled), nullptr); // alpha is the mask
+ } else {
+ m_pDisabledButtonsImages = nullptr;
+ }
+ } else {
+ m_pButtonsImages->Create(height, height, ILC_COLOR24 | ILC_MASK, 1, 0);
+ m_pButtonsImages->Add(bmp, RGB(255, 0, 255));
+ }
+ m_nButtonHeight = height;
+ GetToolBarCtrl().SetImageList(m_pButtonsImages.get());
+ GetToolBarCtrl().SetDisabledImageList(m_pDisabledButtonsImages.get());
+ }
+ image.Destroy();
+ }
+}
+
BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
{
VERIFY(__super::CreateEx(pParentWnd,
@@ -109,29 +161,8 @@ BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
m_volctrl.SetRange(0, 100);
m_nButtonHeight = 16; // reset m_nButtonHeight
- CImage image;
- if (LoadExternalToolBar(&image)) {
- CBitmap* bmp = CBitmap::FromHandle(image);
- int width = image.GetWidth();
- int height = image.GetHeight();
- int bpp = image.GetBPP();
- if (width == height * 15) {
- // the manual specifies that sizeButton should be sizeImage inflated by (7, 6)
- SetSizes(CSize(height + 7, height + 6), CSize(height, height));
- m_pButtonsImages = DEBUG_NEW CImageList();
- if (bpp == 32) {
- m_pButtonsImages->Create(height, height, ILC_COLOR32 | ILC_MASK, 1, 0);
- m_pButtonsImages->Add(bmp, nullptr); // alpha is the mask
- } else {
- m_pButtonsImages->Create(height, height, ILC_COLOR24 | ILC_MASK, 1, 0);
- m_pButtonsImages->Add(bmp, RGB(255, 0, 255));
- }
- m_nButtonHeight = height;
- GetToolBarCtrl().SetImageList(m_pButtonsImages);
- }
- image.Destroy();
- }
+ LoadToolbarImage();
return TRUE;
}
@@ -211,6 +242,18 @@ void CPlayerToolBar::SetVolume(int volume)
m_volctrl.SetPosInternal(volume);
}
+void CPlayerToolBar::EventCallback(MpcEvent ev)
+{
+ switch (ev) {
+ case MpcEvent::DPI_CHANGED:
+ case MpcEvent::DEFAULT_TOOLBAR_SIZE_CHANGED:
+ LoadToolbarImage();
+ break;
+ default:
+ UNREACHABLE_CODE();
+ }
+}
+
BEGIN_MESSAGE_MAP(CPlayerToolBar, CToolBar)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
ON_WM_SIZE()