mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Adjusted GenerateBadgeIcon()
This commit is contained in:
parent
2caed8f826
commit
e637d78303
@ -1647,17 +1647,17 @@ void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState,
|
|||||||
static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
||||||
{
|
{
|
||||||
HDC hdc = NULL, hdcMem = NULL;
|
HDC hdc = NULL, hdcMem = NULL;
|
||||||
HBITMAP hBitmap = NULL, hOldBitmap = NULL;
|
HBITMAP hBitmap = NULL;
|
||||||
HBITMAP hBitmapMask = NULL;
|
HBITMAP hBitmapMask = NULL;
|
||||||
ICONINFO iconInfo;
|
ICONINFO iconInfo;
|
||||||
HICON hIcon = NULL;
|
HICON hIcon = NULL;
|
||||||
HFONT hFont = NULL, hOldFont = NULL;
|
HFONT hFont = NULL;
|
||||||
int width = 16, height = 16;
|
int width = 16, height = 16;
|
||||||
int fontSize = 16;
|
int fontSize = 16, weight = FW_REGULAR;
|
||||||
RECT contentRect;
|
RECT contentRect = { 0, 0, width, height };
|
||||||
char countStr[4];
|
char countStr[4];
|
||||||
|
|
||||||
//Convert count to string (is guaranteed to be at max 2 digits)
|
//Convert count to string (is guaranteed to be at max 3 digits)
|
||||||
memset(countStr, 0, 4 * sizeof(char));
|
memset(countStr, 0, 4 * sizeof(char));
|
||||||
sprintf(countStr, "%d", count);
|
sprintf(countStr, "%d", count);
|
||||||
WCHAR* countWStr = _glfwCreateWideStringFromUTF8Win32(countStr);
|
WCHAR* countWStr = _glfwCreateWideStringFromUTF8Win32(countStr);
|
||||||
@ -1669,39 +1669,35 @@ static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
|||||||
hBitmap = CreateCompatibleBitmap(hdc, width, height);
|
hBitmap = CreateCompatibleBitmap(hdc, width, height);
|
||||||
hBitmapMask = CreateCompatibleBitmap(hdc, width, height);
|
hBitmapMask = CreateCompatibleBitmap(hdc, width, height);
|
||||||
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
||||||
hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap);
|
SelectObject(hdcMem, hBitmap);
|
||||||
|
|
||||||
//PatBlt(hdcMem, 0, 0, 16, 16, BLACKNESS);
|
//PatBlt(hdcMem, 0, 0, 16, 16, BLACKNESS);
|
||||||
SelectObject(hdcMem, CreateSolidBrush(RGB(0x26, 0x25, 0x2D)));
|
SelectObject(hdcMem, CreateSolidBrush(RGB(0x26, 0x25, 0x2D)));
|
||||||
Ellipse(hdcMem, 0, 0, width - 1, height - 1); //15x15 gives a more fancy ellipse
|
Ellipse(hdcMem, 0, 0, width + 1, height + 1); //17x17 gives a more fancy ellipse
|
||||||
SelectObject(hdcMem, CreateSolidBrush(RGB(255, 255, 255)));
|
|
||||||
|
|
||||||
SetTextColor(hdcMem, RGB(255, 255, 255)); //Use white text color
|
|
||||||
SetBkMode(hdcMem, TRANSPARENT); //Make font background transparent
|
|
||||||
|
|
||||||
//TODO Transparency (cull outside of circle)
|
//TODO Transparency (cull outside of circle)
|
||||||
|
|
||||||
//Adjust font size depending on digits to display
|
//Adjust font size depending on digits to display
|
||||||
if (count > 99)
|
if (count > 99)
|
||||||
fontSize = 12;
|
{
|
||||||
|
fontSize = 10;
|
||||||
|
weight = FW_LIGHT;
|
||||||
|
}
|
||||||
else if (count > 9)
|
else if (count > 9)
|
||||||
fontSize = 14;
|
fontSize = 14;
|
||||||
|
|
||||||
//Create and set font
|
//Create and set font
|
||||||
hFont = CreateFont(fontSize, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, 0,
|
hFont = CreateFont(fontSize, 0, 0, 0, weight, FALSE, FALSE, FALSE, 0,
|
||||||
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
|
||||||
DEFAULT_PITCH | FF_DONTCARE, TEXT("Segeo UI"));
|
DEFAULT_PITCH | FF_DONTCARE, TEXT("Segeo UI"));
|
||||||
hOldFont = (HFONT)SelectObject(hdcMem, hFont);
|
SelectObject(hdcMem, hFont);
|
||||||
|
|
||||||
//Draw numbers (center aligned)
|
//Draw numbers (center aligned)
|
||||||
contentRect.top = 0; contentRect.left = 0; contentRect.right = width; contentRect.bottom = height;
|
SetTextColor(hdcMem, RGB(255, 255, 255)); //Use white text color
|
||||||
DrawText(hdcMem, countWStr, -1, &contentRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
SetBkMode(hdcMem, TRANSPARENT); //Make font background transparent
|
||||||
|
SetTextAlign(hdcMem, TA_LEFT | TA_TOP | TA_NOUPDATECP);
|
||||||
|
|
||||||
//Re-apply old settings
|
DrawText(hdcMem, countWStr, lstrlen(countWStr), &contentRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||||
SelectObject(hdc, hOldFont);
|
|
||||||
hOldFont = NULL;
|
|
||||||
SelectObject(hdc, hOldBitmap);
|
|
||||||
hOldBitmap = NULL;
|
|
||||||
|
|
||||||
//Generate icon from bitmap
|
//Generate icon from bitmap
|
||||||
iconInfo.fIcon = TRUE;
|
iconInfo.fIcon = TRUE;
|
||||||
@ -1709,7 +1705,6 @@ static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
|||||||
iconInfo.yHotspot = 0;
|
iconInfo.yHotspot = 0;
|
||||||
iconInfo.hbmMask = hBitmapMask;
|
iconInfo.hbmMask = hBitmapMask;
|
||||||
iconInfo.hbmColor = hBitmap;
|
iconInfo.hbmColor = hBitmap;
|
||||||
|
|
||||||
hIcon = CreateIconIndirect(&iconInfo);
|
hIcon = CreateIconIndirect(&iconInfo);
|
||||||
|
|
||||||
//Cleanup
|
//Cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user