mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 06:14:35 +00:00
Added alt text to _glfwSetWindowTaskbarBadgeWin32()
This commit is contained in:
parent
e637d78303
commit
5ca07929a8
@ -1644,24 +1644,18 @@ void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState,
|
|||||||
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar progress state");
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar progress state");
|
||||||
}
|
}
|
||||||
|
|
||||||
static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
static HICON GenerateBadgeIcon(HWND hWnd, WCHAR* text)
|
||||||
{
|
{
|
||||||
HDC hdc = NULL, hdcMem = NULL;
|
HDC hdc = NULL, hdcMem = NULL;
|
||||||
HBITMAP hBitmap = NULL;
|
HBITMAP hBitmap = NULL, hBitmapMask = NULL;
|
||||||
HBITMAP hBitmapMask = NULL;
|
|
||||||
ICONINFO iconInfo;
|
ICONINFO iconInfo;
|
||||||
HICON hIcon = NULL;
|
HICON hIcon = NULL;
|
||||||
HFONT hFont = NULL;
|
HFONT hFont = NULL;
|
||||||
int width = 16, height = 16;
|
int width = 16, height = 16;
|
||||||
int fontSize = 16, weight = FW_REGULAR;
|
int fontSize = 16, weight = FW_REGULAR;
|
||||||
RECT contentRect = { 0, 0, width, height };
|
RECT contentRect = { 0, 0, width, height };
|
||||||
char countStr[4];
|
|
||||||
|
|
||||||
//Convert count to string (is guaranteed to be at max 3 digits)
|
if (!text)
|
||||||
memset(countStr, 0, 4 * sizeof(char));
|
|
||||||
sprintf(countStr, "%d", count);
|
|
||||||
WCHAR* countWStr = _glfwCreateWideStringFromUTF8Win32(countStr);
|
|
||||||
if (!countWStr)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hdc = GetDC(hWnd);
|
hdc = GetDC(hWnd);
|
||||||
@ -1671,19 +1665,18 @@ static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
|||||||
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
||||||
SelectObject(hdcMem, hBitmap);
|
SelectObject(hdcMem, hBitmap);
|
||||||
|
|
||||||
//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); //17x17 gives a more fancy ellipse
|
Ellipse(hdcMem, 0, 0, width + 1, height + 1); //17x17 gives a more fancy ellipse
|
||||||
|
|
||||||
//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 (lstrlen(text) > 2)
|
||||||
{
|
{
|
||||||
fontSize = 10;
|
fontSize = 10;
|
||||||
weight = FW_LIGHT;
|
weight = FW_LIGHT;
|
||||||
}
|
}
|
||||||
else if (count > 9)
|
else if (lstrlen(text) > 1)
|
||||||
fontSize = 14;
|
fontSize = 14;
|
||||||
|
|
||||||
//Create and set font
|
//Create and set font
|
||||||
@ -1692,12 +1685,12 @@ static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
|||||||
DEFAULT_PITCH | FF_DONTCARE, TEXT("Segeo UI"));
|
DEFAULT_PITCH | FF_DONTCARE, TEXT("Segeo UI"));
|
||||||
SelectObject(hdcMem, hFont);
|
SelectObject(hdcMem, hFont);
|
||||||
|
|
||||||
//Draw numbers (center aligned)
|
//Draw text (center aligned)
|
||||||
SetTextColor(hdcMem, RGB(255, 255, 255)); //Use white text color
|
SetTextColor(hdcMem, RGB(255, 255, 255)); //Use white text color
|
||||||
SetBkMode(hdcMem, TRANSPARENT); //Make font background transparent
|
SetBkMode(hdcMem, TRANSPARENT); //Make font background transparent
|
||||||
SetTextAlign(hdcMem, TA_LEFT | TA_TOP | TA_NOUPDATECP);
|
SetTextAlign(hdcMem, TA_LEFT | TA_TOP | TA_NOUPDATECP);
|
||||||
|
|
||||||
DrawText(hdcMem, countWStr, lstrlen(countWStr), &contentRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
DrawText(hdcMem, text, lstrlen(text), &contentRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||||
|
|
||||||
//Generate icon from bitmap
|
//Generate icon from bitmap
|
||||||
iconInfo.fIcon = TRUE;
|
iconInfo.fIcon = TRUE;
|
||||||
@ -1713,8 +1706,6 @@ static HICON GenerateBadgeIcon(HWND hWnd, int count)
|
|||||||
DeleteObject(hBitmapMask);
|
DeleteObject(hBitmapMask);
|
||||||
DeleteObject(hFont);
|
DeleteObject(hFont);
|
||||||
|
|
||||||
_glfw_free(countWStr);
|
|
||||||
|
|
||||||
return hIcon;
|
return hIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1722,6 +1713,8 @@ void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count)
|
|||||||
{
|
{
|
||||||
HRESULT res = S_OK;
|
HRESULT res = S_OK;
|
||||||
HICON icon = NULL;
|
HICON icon = NULL;
|
||||||
|
char countStr[4];
|
||||||
|
WCHAR* countWStr = NULL;
|
||||||
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
@ -1736,22 +1729,38 @@ void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!window->win32.taskbarList)
|
if (!window->win32.taskbarList)
|
||||||
|
{
|
||||||
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar badge count");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
count = min(count, 999);
|
count = min(count, 999);
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
icon = GenerateBadgeIcon(window->win32.handle, count);
|
//Convert count to string (its guaranteed to be at max 3 digits)
|
||||||
if (!icon)
|
memset(countStr, 0, 4 * sizeof(char));
|
||||||
|
sprintf(countStr, "%d", count);
|
||||||
|
countWStr = _glfwCreateWideStringFromUTF8Win32(countStr);
|
||||||
|
if (!countWStr)
|
||||||
{
|
{
|
||||||
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar badge count");
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar badge count");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
icon = GenerateBadgeIcon(window->win32.handle, countWStr);
|
||||||
|
if (!icon)
|
||||||
|
{
|
||||||
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar badge count");
|
||||||
|
_glfw_free(countWStr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should probably set the alt text too. Integer as text is better than nothing. Use the same string for the icon and alt text in the string version.
|
res = window->win32.taskbarList->lpVtbl->SetOverlayIcon(window->win32.taskbarList, window->win32.handle, icon, countWStr ? countWStr : TEXT(""));
|
||||||
res = window->win32.taskbarList->lpVtbl->SetOverlayIcon(window->win32.taskbarList, window->win32.handle, icon, TEXT(""));
|
|
||||||
|
if (countWStr)
|
||||||
|
_glfw_free(countWStr);
|
||||||
|
|
||||||
if(icon)
|
if(icon)
|
||||||
DestroyIcon(icon);
|
DestroyIcon(icon);
|
||||||
|
Loading…
Reference in New Issue
Block a user