Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Toolbars #1217

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
429 changes: 225 additions & 204 deletions src/mpc-hc/AppSettings.cpp

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/mpc-hc/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "../filters/renderer/VideoRenderers/RenderersSettings.h"
#include "SettingsDefines.h"
#include "Shaders.h"
#include "MPCToolbarLayout.h"

#include <afxadv.h>
#include <afxsock.h>
Expand Down Expand Up @@ -265,6 +266,7 @@ struct AutoChangeFullscreenMode {
};

struct wmcmd_base : public ACCEL {
const char* cmdidStr;
BYTE mouse;
BYTE mouseFS;
BYTE mouseVirt;
Expand Down Expand Up @@ -297,18 +299,18 @@ struct wmcmd_base : public ACCEL {
};

wmcmd_base()
: ACCEL( {
0, 0, 0
})
: cmdidStr("")
, ACCEL{ 0, 0, 0 }
, mouse(NONE)
, mouseFS(NONE)
, mouseVirt(0)
, mouseFSVirt(0)
, dwname(0)
, appcmd(0) {}

constexpr wmcmd_base(WORD _cmd, WORD _key, BYTE _fVirt, DWORD _dwname, UINT _appcmd = 0, BYTE _mouse = NONE, BYTE _mouseFS = NONE, BYTE _mouseVirt = 0, BYTE _mouseFSVirt = 0)
: ACCEL{ _fVirt, _key, _cmd }
constexpr wmcmd_base(const char *_cmdidStr, WORD _cmd, WORD _key, BYTE _fVirt, DWORD _dwname, UINT _appcmd = 0, BYTE _mouse = NONE, BYTE _mouseFS = NONE, BYTE _mouseVirt = 0, BYTE _mouseFSVirt = 0)
: cmdidStr(_cmdidStr)
, ACCEL{ _fVirt, _key, _cmd }
, mouse(_mouse)
, mouseFS(_mouseFS)
, mouseVirt(_mouseVirt)
Expand Down Expand Up @@ -542,6 +544,8 @@ class CAppSettings
// cmdline params
UINT64 nCLSwitches;
CAtlList<CString> slFiles, slDubs, slSubs, slFilters;
static std::map<CStringA, DWORD> CommandStrToID;
static std::map<DWORD, const wmcmd_base*> CommandIDToWMCMD;

// Initial position (used by command line flags)
REFERENCE_TIME rtShift;
Expand Down Expand Up @@ -867,6 +871,7 @@ class CAppSettings

bool bEnableLogging;
bool bUseLegacyToolbar;
MPCToolbarLayout toolBarLayout;

bool IsD3DFullscreen() const;
CString SelectedAudioRenderer() const;
Expand Down
17 changes: 17 additions & 0 deletions src/mpc-hc/ImageGrayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,20 @@ bool ImageGrayer::UpdateColor(const CImage& imgSource, CImage& imgDest, bool dis

return true;
}

void ImageGrayer::PreMultiplyAlpha(CImage& imgSource) {
BYTE* bits = static_cast<BYTE*>(imgSource.GetBits());
for (int y = 0; y < imgSource.GetHeight(); y++, bits += imgSource.GetPitch()) {
RGBQUAD* p = reinterpret_cast<RGBQUAD*>(bits);
for (int x = 0; x < imgSource.GetWidth(); x++) {
HLS hls(p[x]);

RGBQUAD rgb = hls.toRGBQUAD();

p[x].rgbRed = static_cast<BYTE>(round((float)p[x].rgbRed * p[x].rgbReserved / 255.0f));
p[x].rgbBlue = static_cast<BYTE>(round((float)p[x].rgbBlue * p[x].rgbReserved / 255.0f));
p[x].rgbGreen = static_cast<BYTE>(round((float)p[x].rgbGreen * p[x].rgbReserved / 255.0f));
}
}
}

1 change: 1 addition & 0 deletions src/mpc-hc/ImageGrayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ namespace ImageGrayer

bool Gray(const CImage& imgSource, CImage& imgDest, float brightness = 1.0f);
bool UpdateColor(const CImage& imgSource, CImage& imgDest, bool disabled, mpcColorStyle colorStyle);
void PreMultiplyAlpha(CImage& imgSource);
}
62 changes: 62 additions & 0 deletions src/mpc-hc/MPCToolbarLayout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "stdafx.h"
#include "MPCToolbarLayout.h"
#include "RegexUtil.h"
#include "AppSettings.h"


MPCToolbarLayout& operator <<= (MPCToolbarLayout& tbLayout, const CStringW& strLayout) {
RegexUtil::wregexResults results;
std::wregex tbPattern(LR"(<\|([^<>\|]*)\|([0-9-]*)\|>)");
tbLayout.buttons.clear();
tbLayout.SVGIndex.clear();
RegexUtil::wstringMatch(tbPattern, (const wchar_t*)strLayout, results);
if (results.size() > 0) {
for (RegexUtil::wregexResult tbElement: results) {
if (tbElement.size() == 2) {
int index = -1;
if (StrToInt32(tbElement[1].c_str(), index)) {
int id = -1;
if (tbElement[0] == L"BUTTONSEP") {
id = ID_BUTTONSEP;
} else if (tbElement[0] == L"DUMMYSEPARATOR") {
id = ID_DUMMYSEPARATOR;
} else if (CAppSettings::CommandStrToID.count(tbElement[0].c_str()) > 0) {
id = CAppSettings::CommandStrToID[tbElement[0].c_str()];
}
if (-1 != id) {
tbLayout.buttons.push_back(id);
tbLayout.SVGIndex.push_back(index);
}
}
}
}
}

return tbLayout;
}

CStringW& operator <<= (CStringW& strLayout, const MPCToolbarLayout& tbLayout) {
if (tbLayout.buttons.size() > 0 && tbLayout.SVGIndex.size() == tbLayout.buttons.size()) {
strLayout = L"";
for (std::vector<int>::size_type i = 0; i < tbLayout.buttons.size(); ++i) {
int button = tbLayout.buttons[i];
if (CAppSettings::CommandIDToWMCMD.count(button) || button==ID_BUTTONSEP || button==ID_DUMMYSEPARATOR) {
CStringW t;
int idx = tbLayout.SVGIndex[i];
if (button == ID_BUTTONSEP) {
t.Format(L"<|BUTTONSEP|%d|>", idx);
} else if (button == ID_DUMMYSEPARATOR) {
t.Format(L"<|DUMMYSEPARATOR|%d|>", idx);
} else {
const char* cmdStr = CAppSettings::CommandIDToWMCMD[button]->cmdidStr;
t.Format(L"<|%hs|%d|>", cmdStr, idx);
}
strLayout += t;
}
}
} else {
strLayout = MPCToolbarLayout::defaultLayout;
}

return strLayout;
}
10 changes: 10 additions & 0 deletions src/mpc-hc/MPCToolbarLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

class MPCToolbarLayout {
public:
std::vector<int> buttons;
std::vector<int> SVGIndex;
static constexpr wchar_t *defaultLayout = L"<|PLAY_PLAY|-1|><|PLAY_PAUSE|-1|><|PLAY_STOP|-1|><|BUTTONSEP|-1|><|NAVIGATE_SKIPBACK|-1|><|PLAY_DECRATE|-1|><|PLAY_INCRATE|-1|><|NAVIGATE_SKIPFORWARD|-1|><|BUTTONSEP|-1|><|PLAY_FRAMESTEP|-1|><|BUTTONSEP|-1|><|DUMMYSEPARATOR|-1|><|VOLUME_MUTE|-1|>";
friend CStringW& operator <<= (CStringW& strLayout, const MPCToolbarLayout& tbLayout);
friend MPCToolbarLayout& operator <<= (MPCToolbarLayout& tbLayout, const CStringW& strLayout);
};
Loading