Removed NativeTransparency option (now always enabled)

This commit is contained in:
Birunthan Mohanathas 2012-04-17 09:32:10 +03:00
parent 174a612c49
commit 8332f8465e
3 changed files with 55 additions and 130 deletions

View File

@ -115,7 +115,6 @@ CMeterWindow::CMeterWindow(const std::wstring& config, const std::wstring& iniFi
m_WindowStartHidden(false), m_WindowStartHidden(false),
m_SavePosition(false), // Must be false m_SavePosition(false), // Must be false
m_SnapEdges(true), m_SnapEdges(true),
m_NativeTransparency(true),
m_AlphaValue(255), m_AlphaValue(255),
m_FadeDuration(250), m_FadeDuration(250),
m_WindowZPosition(ZPOSITION_NORMAL), m_WindowZPosition(ZPOSITION_NORMAL),
@ -1794,7 +1793,6 @@ void CMeterWindow::ReadConfig()
m_WindowStartHidden = false; m_WindowStartHidden = false;
m_SavePosition = true; m_SavePosition = true;
m_SnapEdges = true; m_SnapEdges = true;
m_NativeTransparency = true;
m_ClickThrough = false; m_ClickThrough = false;
m_KeepOnScreen = true; m_KeepOnScreen = true;
m_AutoSelectScreen = false; m_AutoSelectScreen = false;
@ -1835,7 +1833,6 @@ void CMeterWindow::ReadConfig()
m_WindowStartHidden = 0!=parser.ReadInt(section, L"StartHidden", m_WindowStartHidden); m_WindowStartHidden = 0!=parser.ReadInt(section, L"StartHidden", m_WindowStartHidden);
m_SavePosition = 0!=parser.ReadInt(section, L"SavePosition", m_SavePosition); m_SavePosition = 0!=parser.ReadInt(section, L"SavePosition", m_SavePosition);
m_SnapEdges = 0!=parser.ReadInt(section, L"SnapEdges", m_SnapEdges); m_SnapEdges = 0!=parser.ReadInt(section, L"SnapEdges", m_SnapEdges);
m_NativeTransparency = 0!=parser.ReadInt(section, L"NativeTransparency", m_NativeTransparency);
m_ClickThrough = 0!=parser.ReadInt(section, L"ClickThrough", m_ClickThrough); m_ClickThrough = 0!=parser.ReadInt(section, L"ClickThrough", m_ClickThrough);
m_KeepOnScreen = 0!=parser.ReadInt(section, L"KeepOnScreen", m_KeepOnScreen); m_KeepOnScreen = 0!=parser.ReadInt(section, L"KeepOnScreen", m_KeepOnScreen);
m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", m_AutoSelectScreen); m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", m_AutoSelectScreen);
@ -2442,17 +2439,6 @@ bool CMeterWindow::ResizeWindow(bool reset)
m_WindowH = m_Background->GetHeight(); m_WindowH = m_Background->GetHeight();
//Calculate the window position from the config parameters //Calculate the window position from the config parameters
WindowToScreen(); WindowToScreen();
if (!m_NativeTransparency)
{
// Graph the desktop and place the background on top of it
Bitmap* desktop = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
Graphics graphics(desktop);
Rect r(0, 0, m_WindowW, m_WindowH);
graphics.DrawImage(m_Background, r, 0, 0, m_WindowW, m_WindowH, UnitPixel);
delete m_Background;
m_Background = desktop;
}
} }
delete tintedBackground; delete tintedBackground;
@ -2466,36 +2452,9 @@ bool CMeterWindow::ResizeWindow(bool reset)
SetWindowSizeVariables(m_WindowW, m_WindowH); SetWindowSizeVariables(m_WindowW, m_WindowH);
if (!m_NativeTransparency)
{
// If Background is not set, take a copy from the desktop
if (m_Background == NULL && m_BackgroundMode == BGMODE_COPY)
{
m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
}
}
return true; return true;
} }
/*
** Grabs a part of the desktop
*/
Bitmap* CMeterWindow::GrabDesktop(int x, int y, int w, int h)
{
HDC desktopDC = GetDC(0);
HDC dc = CreateCompatibleDC(desktopDC);
HBITMAP desktopBM = CreateCompatibleBitmap(desktopDC, w, h);
HBITMAP oldBM = (HBITMAP)SelectObject(dc, desktopBM);
BitBlt(dc, 0, 0, w, h, desktopDC, x, y, SRCCOPY);
SelectObject(dc, oldBM);
DeleteDC(dc);
ReleaseDC(0, desktopDC);
Bitmap* background = new Bitmap(desktopBM, NULL);
DeleteObject(desktopBM);
return background;
}
/* /*
** Creates the back buffer bitmap. ** Creates the back buffer bitmap.
** **
@ -2552,7 +2511,7 @@ void CMeterWindow::CreateRegion(bool clear)
} }
} }
SetWindowRgn(m_Window, region, !m_NativeTransparency); SetWindowRgn(m_Window, region, FALSE);
} }
} }
@ -2668,11 +2627,6 @@ void CMeterWindow::Redraw()
} }
UpdateTransparency(m_TransparencyValue, false); UpdateTransparency(m_TransparencyValue, false);
if (!m_NativeTransparency)
{
InvalidateRect(m_Window, NULL, FALSE);
}
} }
/* /*
@ -2857,43 +2811,33 @@ void CMeterWindow::Update(bool nodraw)
*/ */
void CMeterWindow::UpdateTransparency(int alpha, bool reset) void CMeterWindow::UpdateTransparency(int alpha, bool reset)
{ {
if (m_NativeTransparency) if (reset)
{ {
if (reset) AddWindowExStyle(WS_EX_LAYERED);
{
AddWindowExStyle(WS_EX_LAYERED);
}
BLENDFUNCTION blendPixelFunction = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
POINT ptWindowScreenPosition = {m_ScreenX, m_ScreenY};
POINT ptSrc = {0, 0};
SIZE szWindow = {m_DIBSectionBufferW, m_DIBSectionBufferH};
HDC dcScreen = GetDC(0);
HDC dcMemory = CreateCompatibleDC(dcScreen);
SelectObject(dcMemory, m_DIBSectionBuffer);
BOOL ret = UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
if (!ret)
{
// Retry after resetting WS_EX_LAYERED flag
RemoveWindowExStyle(WS_EX_LAYERED);
AddWindowExStyle(WS_EX_LAYERED);
UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
}
ReleaseDC(0, dcScreen);
DeleteDC(dcMemory);
m_TransparencyValue = alpha;
} }
else
BLENDFUNCTION blendPixelFunction = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
POINT ptWindowScreenPosition = {m_ScreenX, m_ScreenY};
POINT ptSrc = {0, 0};
SIZE szWindow = {m_DIBSectionBufferW, m_DIBSectionBufferH};
HDC dcScreen = GetDC(0);
HDC dcMemory = CreateCompatibleDC(dcScreen);
SelectObject(dcMemory, m_DIBSectionBuffer);
BOOL ret = UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
if (!ret)
{ {
if (reset) // Retry after resetting WS_EX_LAYERED flag
{ RemoveWindowExStyle(WS_EX_LAYERED);
RemoveWindowExStyle(WS_EX_LAYERED); AddWindowExStyle(WS_EX_LAYERED);
} UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
} }
ReleaseDC(0, dcScreen);
DeleteDC(dcMemory);
m_TransparencyValue = alpha;
} }
/* /*
@ -3037,7 +2981,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CMeterWindow::FadeWindow(int from, int to) void CMeterWindow::FadeWindow(int from, int to)
{ {
if (!m_NativeTransparency || m_FadeDuration == 0) if (m_FadeDuration == 0)
{ {
if (to == 0) if (to == 0)
{ {
@ -3321,7 +3265,7 @@ LRESULT CMeterWindow::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (m_WindowHide) switch (m_WindowHide)
{ {
case HIDEMODE_HIDE: case HIDEMODE_HIDE:
if (!m_NativeTransparency || m_TransparencyValue == m_AlphaValue) if (m_TransparencyValue == m_AlphaValue)
{ {
FadeWindow(m_AlphaValue, 0); FadeWindow(m_AlphaValue, 0);
} }
@ -4675,26 +4619,18 @@ LRESULT CMeterWindow::OnDelayedRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam)
*/ */
LRESULT CMeterWindow::OnDelayedMove(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnDelayedMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
if (m_NativeTransparency) m_Parser.ResetMonitorVariables(this);
// Move the window to correct position
ResizeWindow(true);
if (m_KeepOnScreen)
{ {
m_Parser.ResetMonitorVariables(this); MapCoordsToScreen(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
// Move the window to correct position
ResizeWindow(true);
if (m_KeepOnScreen)
{
MapCoordsToScreen(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
}
SetWindowPos(m_Window, NULL, m_ScreenX, m_ScreenY, m_WindowW, m_WindowH, SWP_NOZORDER | SWP_NOACTIVATE);
}
else
{
// With copy transparency we'll do a full refresh
PostMessage(m_Window, WM_METERWINDOW_DELAYED_REFRESH, (WPARAM)NULL, (LPARAM)NULL);
} }
SetWindowPos(m_Window, NULL, m_ScreenX, m_ScreenY, m_WindowW, m_WindowH, SWP_NOZORDER | SWP_NOACTIVATE);
return 0; return 0;
} }

View File

@ -224,7 +224,6 @@ public:
int GetXScreen() { return m_WindowXScreen; } int GetXScreen() { return m_WindowXScreen; }
int GetYScreen() { return m_WindowYScreen; } int GetYScreen() { return m_WindowYScreen; }
bool GetNativeTransparency() { return m_NativeTransparency; }
bool GetClickThrough() { return m_ClickThrough; } bool GetClickThrough() { return m_ClickThrough; }
bool GetKeepOnScreen() { return m_KeepOnScreen; } bool GetKeepOnScreen() { return m_KeepOnScreen; }
bool GetAutoSelectScreen() { return m_AutoSelectScreen; } bool GetAutoSelectScreen() { return m_AutoSelectScreen; }
@ -305,7 +304,6 @@ private:
void CreateRegion(bool clear); void CreateRegion(bool clear);
void GetSkinFolders(const std::wstring& folder); void GetSkinFolders(const std::wstring& folder);
Gdiplus::Bitmap* GrabDesktop(int x, int y, int w, int h);
void SnapToWindow(CMeterWindow* window, LPWINDOWPOS wp); void SnapToWindow(CMeterWindow* window, LPWINDOWPOS wp);
void MapCoordsToScreen(int& x, int& y, int w, int h); void MapCoordsToScreen(int& x, int& y, int w, int h);
void WindowToScreen(); void WindowToScreen();
@ -410,7 +408,6 @@ private:
bool m_WindowStartHidden; // If true, the window is hidden at startup bool m_WindowStartHidden; // If true, the window is hidden at startup
bool m_SavePosition; // If true, the window's position is saved bool m_SavePosition; // If true, the window's position is saved
bool m_SnapEdges; // If true, the window snaps to the edges of the screen when moved bool m_SnapEdges; // If true, the window snaps to the edges of the screen when moved
bool m_NativeTransparency; // If true, use the W2k/XP native transparency
int m_AlphaValue; // The 'from' transparency value 0 - 255 int m_AlphaValue; // The 'from' transparency value 0 - 255
int m_FadeDuration; // Time it takes to fade the window int m_FadeDuration; // Time it takes to fade the window
ZPOSITION m_WindowZPosition; // Window's Z-position ZPOSITION m_WindowZPosition; // Window's Z-position

View File

@ -2836,38 +2836,30 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con
} }
// Tick the transparency // Tick the transparency
if (!meterWindow->GetNativeTransparency()) HMENU alphaMenu = GetSubMenu(settingsMenu, 1);
if (alphaMenu)
{ {
EnableMenuItem(settingsMenu, 1, MF_BYPOSITION | MF_GRAYED); // "Transparency" menu int value = (int)(10 - meterWindow->GetAlphaValue() / 25.5);
EnableMenuItem(settingsMenu, IDM_SKIN_CLICKTHROUGH, MF_BYCOMMAND | MF_GRAYED); value = min(9, value);
} value = max(0, value);
else CheckMenuItem(alphaMenu, value, MF_BYPOSITION | MF_CHECKED);
{
HMENU alphaMenu = GetSubMenu(settingsMenu, 1); switch (meterWindow->GetWindowHide())
if (alphaMenu)
{ {
int value = (int)(10 - meterWindow->GetAlphaValue() / 25.5); case HIDEMODE_FADEIN:
value = min(9, value); CheckMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_CHECKED);
value = max(0, value); EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED);
CheckMenuItem(alphaMenu, value, MF_BYPOSITION | MF_CHECKED); break;
switch (meterWindow->GetWindowHide()) case HIDEMODE_FADEOUT:
{ CheckMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_CHECKED);
case HIDEMODE_FADEIN: EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED);
CheckMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_CHECKED); break;
EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED);
break;
case HIDEMODE_FADEOUT: case HIDEMODE_HIDE:
CheckMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_CHECKED); EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED);
break; break;
case HIDEMODE_HIDE:
EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(alphaMenu, IDM_SKIN_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED);
break;
}
} }
} }