mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Fixed cursor flicker issue with some applications
Removed support for background transparency with RGB(255,0,255)
This commit is contained in:
parent
8332f8465e
commit
f48d892526
@ -45,134 +45,6 @@ UINT GetUniqueID()
|
|||||||
return id++;
|
return id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRGN BitmapToRegion(HBITMAP hbm, COLORREF clrTransp, COLORREF clrTolerance)
|
|
||||||
{
|
|
||||||
HRGN hRgn = NULL;
|
|
||||||
|
|
||||||
if (hbm)
|
|
||||||
{
|
|
||||||
// create a dc for the 32 bit dib
|
|
||||||
HDC hdcMem = CreateCompatibleDC(NULL);
|
|
||||||
if (hdcMem)
|
|
||||||
{
|
|
||||||
// get the size
|
|
||||||
BITMAP bm;
|
|
||||||
GetObject(hbm, sizeof(BITMAP), &bm);
|
|
||||||
|
|
||||||
BITMAPINFOHEADER bmpInfo32;
|
|
||||||
bmpInfo32.biSize = sizeof(BITMAPINFOHEADER);
|
|
||||||
bmpInfo32.biWidth = bm.bmWidth;
|
|
||||||
bmpInfo32.biHeight = bm.bmHeight;
|
|
||||||
bmpInfo32.biPlanes = 1;
|
|
||||||
bmpInfo32.biBitCount = 32;
|
|
||||||
bmpInfo32.biCompression = BI_RGB;
|
|
||||||
bmpInfo32.biSizeImage = 0;
|
|
||||||
bmpInfo32.biXPelsPerMeter = 0;
|
|
||||||
bmpInfo32.biYPelsPerMeter = 0;
|
|
||||||
bmpInfo32.biClrUsed = 0;
|
|
||||||
bmpInfo32.biClrImportant = 0;
|
|
||||||
|
|
||||||
VOID* pbits32;
|
|
||||||
HBITMAP hbm32 = CreateDIBSection(hdcMem, (BITMAPINFO *) & bmpInfo32, DIB_RGB_COLORS, &pbits32, NULL, 0);
|
|
||||||
if (hbm32)
|
|
||||||
{
|
|
||||||
HBITMAP hbmOld32 = (HBITMAP)SelectObject(hdcMem, hbm32);
|
|
||||||
|
|
||||||
// Create a DC just to copy the bitmap into the memory D
|
|
||||||
HDC hdcTmp = CreateCompatibleDC(hdcMem);
|
|
||||||
if (hdcTmp)
|
|
||||||
{
|
|
||||||
// Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits
|
|
||||||
BITMAP bm32;
|
|
||||||
GetObject(hbm32, sizeof(bm32), &bm32);
|
|
||||||
while (bm32.bmWidthBytes % 4)
|
|
||||||
++bm32.bmWidthBytes;
|
|
||||||
|
|
||||||
// Copy the bitmap into the memory D
|
|
||||||
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcTmp, hbm);
|
|
||||||
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcTmp, 0, 0, SRCCOPY);
|
|
||||||
|
|
||||||
// get the limits for the colors
|
|
||||||
BYTE clrHiR = ( 0xff - GetRValue( clrTolerance ) > GetRValue( clrTransp ) ) ? GetRValue( clrTransp ) + GetRValue( clrTolerance ) : 0xff;
|
|
||||||
BYTE clrHiG = ( 0xff - GetGValue( clrTolerance ) > GetGValue( clrTransp ) ) ? GetGValue( clrTransp ) + GetGValue( clrTolerance ) : 0xff;
|
|
||||||
BYTE clrHiB = ( 0xff - GetBValue( clrTolerance ) > GetBValue( clrTransp ) ) ? GetBValue( clrTransp ) + GetBValue( clrTolerance ) : 0xff;
|
|
||||||
BYTE clrLoR = ( GetRValue( clrTolerance ) < GetRValue( clrTransp ) ) ? GetRValue( clrTransp ) - GetRValue( clrTolerance ) : 0x00;
|
|
||||||
BYTE clrLoG = ( GetGValue( clrTolerance ) < GetGValue( clrTransp ) ) ? GetGValue( clrTransp ) - GetGValue( clrTolerance ) : 0x00;
|
|
||||||
BYTE clrLoB = ( GetBValue( clrTolerance ) < GetBValue( clrTransp ) ) ? GetBValue( clrTransp ) - GetBValue( clrTolerance ) : 0x00;
|
|
||||||
|
|
||||||
// Allocate initial RGNDATA buffer
|
|
||||||
#define ALLOC_UNIT 100
|
|
||||||
DWORD maxRects = ALLOC_UNIT;
|
|
||||||
HANDLE hRgnData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
|
|
||||||
RGNDATA* pRgnData = (RGNDATA*)GlobalLock(hRgnData);
|
|
||||||
pRgnData->rdh.dwSize = sizeof(RGNDATAHEADER);
|
|
||||||
pRgnData->rdh.iType = RDH_RECTANGLES;
|
|
||||||
pRgnData->rdh.nCount = pRgnData->rdh.nRgnSize = 0;
|
|
||||||
SetRect(&pRgnData->rdh.rcBound, 0, 0, bm.bmWidth, bm.bmHeight);
|
|
||||||
|
|
||||||
// Scan each bitmap row from bottom to top (the bitmap is inverted vertically
|
|
||||||
BYTE* p32 = (BYTE*)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes;
|
|
||||||
for (int y = 0; y < bm.bmHeight; ++y)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < bm.bmWidth; ++x)
|
|
||||||
{
|
|
||||||
int x0 = x;
|
|
||||||
|
|
||||||
// loop through all non transparent pixels
|
|
||||||
while (x < bm.bmWidth)
|
|
||||||
{
|
|
||||||
BYTE* p = p32 + 4 * x;
|
|
||||||
// if the pixel is transparent, then break
|
|
||||||
if (*p >= clrLoB && *p <= clrHiB)
|
|
||||||
{
|
|
||||||
++p;
|
|
||||||
if (*p >= clrLoG && *p <= clrHiG)
|
|
||||||
{
|
|
||||||
++p;
|
|
||||||
if (*p >= clrLoR && *p <= clrHiR)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if found one or more non-transparent pixels in a row, add them to the rgn...
|
|
||||||
if (x > x0)
|
|
||||||
{
|
|
||||||
if (pRgnData->rdh.nCount >= maxRects)
|
|
||||||
{
|
|
||||||
// Reallocate RGNDATA buffer
|
|
||||||
GlobalUnlock(hRgnData);
|
|
||||||
maxRects += ALLOC_UNIT;
|
|
||||||
hRgnData = GlobalReAlloc(hRgnData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE);
|
|
||||||
pRgnData = (RGNDATA*)GlobalLock(hRgnData);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetRect(((RECT*)pRgnData->Buffer) + pRgnData->rdh.nCount, x0, y, x, y + 1);
|
|
||||||
++pRgnData->rdh.nCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p32 -= bm32.bmWidthBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the region with the collected rectangles
|
|
||||||
hRgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pRgnData);
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
GlobalUnlock(hRgnData);
|
|
||||||
GlobalFree(hRgnData);
|
|
||||||
SelectObject(hdcTmp, hbmOld);
|
|
||||||
DeleteDC(hdcTmp);
|
|
||||||
}
|
|
||||||
SelectObject(hdcMem, hbmOld32);
|
|
||||||
DeleteObject(hbm32);
|
|
||||||
}
|
|
||||||
DeleteDC(hdcMem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hRgn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin)
|
void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin)
|
||||||
{
|
{
|
||||||
// The stub implementation (some of this code is taken from lsapi.cpp)
|
// The stub implementation (some of this code is taken from lsapi.cpp)
|
||||||
|
@ -40,8 +40,6 @@ UINT GetUniqueID();
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
UINT TypeID() { static UINT id = GetUniqueID(); return id; }
|
UINT TypeID() { static UINT id = GetUniqueID(); return id; }
|
||||||
|
|
||||||
HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance);
|
|
||||||
|
|
||||||
std::string ConvertToAscii(LPCTSTR str);
|
std::string ConvertToAscii(LPCTSTR str);
|
||||||
std::wstring ConvertToWide(LPCSTR str);
|
std::wstring ConvertToWide(LPCSTR str);
|
||||||
std::string ConvertToUTF8(LPCWSTR str);
|
std::string ConvertToUTF8(LPCWSTR str);
|
||||||
|
@ -409,7 +409,6 @@ void CMeterWindow::Refresh(bool init, bool all)
|
|||||||
m_Hidden = m_WindowStartHidden;
|
m_Hidden = m_WindowStartHidden;
|
||||||
|
|
||||||
// Set the window region
|
// Set the window region
|
||||||
CreateRegion(true); // Clear the region
|
|
||||||
UpdateTransparency(m_AlphaValue, true); // Add/Remove layered flag
|
UpdateTransparency(m_AlphaValue, true); // Add/Remove layered flag
|
||||||
Update(false);
|
Update(false);
|
||||||
|
|
||||||
@ -2482,39 +2481,6 @@ void CMeterWindow::CreateDoubleBuffer(int cx, int cy)
|
|||||||
m_DIBSectionBufferH = cy;
|
m_DIBSectionBufferH = cy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
** Creates/Clears a window region
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
void CMeterWindow::CreateRegion(bool clear)
|
|
||||||
{
|
|
||||||
if (clear)
|
|
||||||
{
|
|
||||||
SetWindowRgn(m_Window, NULL, TRUE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HRGN region = NULL;
|
|
||||||
|
|
||||||
// Set window region if needed
|
|
||||||
if (!m_BackgroundName.empty())
|
|
||||||
{
|
|
||||||
if (m_WindowW != 0 && m_WindowH != 0)
|
|
||||||
{
|
|
||||||
HBITMAP background = NULL;
|
|
||||||
m_DoubleBuffer->GetHBITMAP(Color(255,0,255), &background);
|
|
||||||
if (background)
|
|
||||||
{
|
|
||||||
region = BitmapToRegion(background, RGB(255,0,255), 0x101010);
|
|
||||||
DeleteObject(background);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SetWindowRgn(m_Window, region, FALSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Redraws the meters and paints the window
|
** Redraws the meters and paints the window
|
||||||
**
|
**
|
||||||
@ -2622,7 +2588,6 @@ void CMeterWindow::Redraw()
|
|||||||
|
|
||||||
if (m_ResetRegion || !m_BackgroundName.empty())
|
if (m_ResetRegion || !m_BackgroundName.empty())
|
||||||
{
|
{
|
||||||
CreateRegion(false);
|
|
||||||
m_ResetRegion = false;
|
m_ResetRegion = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,6 @@ private:
|
|||||||
|
|
||||||
bool HitTest(int x, int y);
|
bool HitTest(int x, int y);
|
||||||
|
|
||||||
void CreateRegion(bool clear);
|
|
||||||
void GetSkinFolders(const std::wstring& folder);
|
void GetSkinFolders(const std::wstring& folder);
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user