Custom draw noise gate's volume preview progress bar (avoid theme animations)

master
HomeWorld 2013-05-29 03:17:43 +03:00
parent e1d95c559f
commit 0e9889967a
2 changed files with 58 additions and 2 deletions

View File

@ -299,6 +299,60 @@ INT_PTR NoiseGateSettings::ProcMessage(UINT message, WPARAM wParam, LPARAM lPara
return FALSE;
}
LRESULT CALLBACK NoiseGateSettings::PBSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch(uMsg)
{
case WM_ERASEBKGND:
return TRUE;
case WM_PAINT:
{
RECT clRect, eclRect;
PAINTSTRUCT ps;
int orientation, position;
PBRANGE pbRange;
HBRUSH hGold = CreateSolidBrush(0x37AFD4);
orientation = (GetWindowLongPtr(hWnd, GWL_STYLE) & PBS_VERTICAL) ? 1:0; //0 = horizontal, 1 = vertical
position = (int)SendMessage(hWnd, PBM_GETPOS, 0, 0);
SendMessage(hWnd, PBM_GETRANGE, TRUE, (LPARAM)&pbRange);
GetClientRect(hWnd, &clRect);
memcpy(&eclRect, &clRect, sizeof(RECT));
HDC hDC = BeginPaint(hWnd, &ps);
if(orientation)
{
clRect.top = clRect.bottom - int(float(clRect.bottom - clRect.top) * float(position - pbRange.iLow) / (float)(pbRange.iHigh - pbRange.iLow));
eclRect.bottom = clRect.top;
FillRect(hDC, &eclRect, (HBRUSH)COLOR_WINDOW);
FillRect(hDC, &clRect, hGold);
}
else
{
clRect.right = clRect.left + int(float(clRect.right - clRect.left) * float(position - pbRange.iLow) / (float)(pbRange.iHigh - pbRange.iLow));
eclRect.left = clRect.right;
FillRect(hDC, &eclRect, (HBRUSH)COLOR_WINDOW);
FillRect(hDC, &clRect, hGold);
}
DeleteObject(hGold);
EndPaint(hWnd, &ps);
return TRUE;
}
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
void NoiseGateSettings::MsgInitDialog()
{
HWND ctrlHwnd;
@ -313,9 +367,10 @@ void NoiseGateSettings::MsgInitDialog()
RefreshConfig();
// Volume preview
// FIXME: Don't use a progress bar as the default Windows style smoothly interpolates between
// values making if difficult to see the real sound level.
// Custom drawn progress bar
ctrlHwnd = GetDlgItem(hwnd, IDC_CURVOL);
SetWindowSubclass(ctrlHwnd, PBSubclassProc, 0, 0);
SendMessage(ctrlHwnd, PBM_SETRANGE32, 0, CURVOL_RESOLUTION); // Bottom = 0, top = CURVOL_RESOLUTION
RepaintVolume(); // Repaint immediately
SetTimer(hwnd, REPAINT_TIMER_ID, 16, NULL); // Repaint every 16ms (~60fps)

View File

@ -108,6 +108,7 @@ public:
virtual void CancelSettings();
virtual bool HasDefaults() const;
virtual void SetDefaults();
static LRESULT CALLBACK PBSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
};
//============================================================================