mirror of
https://github.com/moparisthebest/FireTray
synced 2024-11-17 22:35:02 -05:00
iron out text icon creation
This commit is contained in:
parent
c52b9da609
commit
347eb1e720
@ -517,6 +517,7 @@ firetray.PrefListener = new PrefListener(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mail_notification_type':
|
case 'mail_notification_type':
|
||||||
|
case 'icon_text_color':
|
||||||
firetray.Messaging.updateIcon();
|
firetray.Messaging.updateIcon();
|
||||||
break;
|
break;
|
||||||
case 'new_mail_icon_names':
|
case 'new_mail_icon_names':
|
||||||
|
@ -104,6 +104,15 @@ function gdi32_defines(lib) {
|
|||||||
this.THAI_CHARSET = 222;
|
this.THAI_CHARSET = 222;
|
||||||
this.EASTEUROPE_CHARSET = 238;
|
this.EASTEUROPE_CHARSET = 238;
|
||||||
this.RUSSIAN_CHARSET = 204;
|
this.RUSSIAN_CHARSET = 204;
|
||||||
|
this.DEFAULT_QUALITY = 0;
|
||||||
|
this.DRAFT_QUALITY = 1;
|
||||||
|
this.PROOF_QUALITY = 2;
|
||||||
|
this.NONANTIALIASED_QUALITY = 3;
|
||||||
|
this.ANTIALIASED_QUALITY = 4;
|
||||||
|
this.CLEARTYPE_QUALITY = 5;
|
||||||
|
this.CLEARTYPE_NATURAL_QUALITY = 6;
|
||||||
|
|
||||||
|
lib.lazy_bind("GetTextFaceW", ctypes.int, win32.HDC, ctypes.int, win32.LPTSTR);
|
||||||
lib.lazy_bind("SetTextColor", win32.COLORREF, win32.HDC, win32.COLORREF);
|
lib.lazy_bind("SetTextColor", win32.COLORREF, win32.HDC, win32.COLORREF);
|
||||||
lib.lazy_bind("SetBkMode", ctypes.int, win32.HDC, ctypes.int);
|
lib.lazy_bind("SetBkMode", ctypes.int, win32.HDC, ctypes.int);
|
||||||
this.TRANSPARENT = 1;
|
this.TRANSPARENT = 1;
|
||||||
|
@ -285,29 +285,37 @@ firetray.StatusIcon = {
|
|||||||
|
|
||||||
// http://forums.codeguru.com/showthread.php?379565-Windows-SDK-GDI-How-do-I-choose-a-font-size-to-exactly-fit-a-string-in-a
|
// http://forums.codeguru.com/showthread.php?379565-Windows-SDK-GDI-How-do-I-choose-a-font-size-to-exactly-fit-a-string-in-a
|
||||||
|
|
||||||
let nHeight = 32, fnWeight = gdi32.FW_BOLD;
|
let fnHeight = firetray.js.floatToInt(height);
|
||||||
let hFont = gdi32.CreateFontW(nHeight, 0, 0, 0, fnWeight, 0, 0, 0,
|
let hFont = gdi32.CreateFontW(fnHeight, 0, 0, 0, gdi32.FW_MEDIUM, 0, 0, 0,
|
||||||
gdi32.ANSI_CHARSET, 0, 0, 0, gdi32.FF_SWISS, "Sans"); // get font
|
gdi32.ANSI_CHARSET, 0, 0, 0, gdi32.FF_SWISS, "Sans"); // get font
|
||||||
hFont = ctypes.cast(gdi32.SelectObject(hdcMem, hFont), win32.HFONT); // replace font in bitmap by hFont
|
ctypes.cast(gdi32.SelectObject(hdcMem, hFont), win32.HFONT); // replace font in bitmap by hFont
|
||||||
gdi32.SetTextColor(hdcMem, win32.COLORREF(this.cssColorToCOLORREF(color)));
|
let faceName = ctypes.jschar.array()(32);
|
||||||
gdi32.SetBkMode(hdcMem, gdi32.TRANSPARENT); // VERY IMPORTANT
|
gdi32.GetTextFaceW(hdcMem, 32, faceName);
|
||||||
// gdi32.SetTextAlign(hdcMem, gdi32.GetTextAlign(hdcMem) & (~gdi32.TA_CENTER));
|
log.debug(" font="+faceName);
|
||||||
// gdi32.SetTextAlign(hdcMem, gdi32.TA_CENTER);
|
|
||||||
log.debug(" ___ALIGN=(winLastError="+ctypes.winLastError+") "+gdi32.GetTextAlign(hdcMem));
|
|
||||||
|
|
||||||
let size = new gdi32.SIZE();
|
let size = new gdi32.SIZE();
|
||||||
// GetTextExtentPoint32 is known as more reliable than DrawText(DT_CALCRECT)
|
gdi32.GetTextExtentPoint32W(hdcMem, text, text.length, size.address()); // more reliable than DrawText(DT_CALCRECT)
|
||||||
|
|
||||||
|
while (size.cx > width - 6 || size.cy > height - 4) {
|
||||||
|
fnHeight -= 1;
|
||||||
|
hFont = gdi32.CreateFontW(fnHeight, 0, 0, 0, gdi32.FW_SEMIBOLD, 0, 0, 0,
|
||||||
|
gdi32.ANSI_CHARSET, 0, 0, gdi32.PROOF_QUALITY,
|
||||||
|
gdi32.FF_SWISS, "Arial");
|
||||||
|
ctypes.cast(gdi32.SelectObject(hdcMem, hFont), win32.HFONT);
|
||||||
|
|
||||||
|
gdi32.GetTextExtentPoint32W(hdcMem, text, text.length, size.address()); // more reliable than DrawText(DT_CALCRECT)
|
||||||
|
log.debug(" fnHeight="+fnHeight+" width="+size.cx);
|
||||||
|
}
|
||||||
gdi32.GetTextExtentPoint32W(hdcMem, text, text.length, size.address());
|
gdi32.GetTextExtentPoint32W(hdcMem, text, text.length, size.address());
|
||||||
let nWidth = size.cx;
|
|
||||||
log.debug(" WIDTH="+nWidth);
|
|
||||||
|
|
||||||
// let rect = new win32.RECT();
|
gdi32.SetTextColor(hdcMem, win32.COLORREF(this.cssColorToCOLORREF(color)));
|
||||||
// let height = user32.DrawTextW(hdcMem, text, text.length, rect.address(), user32.DT_SINGLELINE | user32.DT_CENTER | user32.DT_VCENTER | user32.DT_CALCRECT);
|
gdi32.SetBkMode(hdcMem, gdi32.TRANSPARENT); // VERY IMPORTANT
|
||||||
// log.debug(" HEIGHT="+height+", rect="+rect);
|
gdi32.SetTextAlign(hdcMem, gdi32.TA_TOP|gdi32.TA_CENTER);
|
||||||
|
log.debug(" ___ALIGN=(winLastError="+ctypes.winLastError+") "+gdi32.GetTextAlign(hdcMem));
|
||||||
|
|
||||||
let nXStart = firetray.js.floatToInt((width - nWidth)/2),
|
let nXStart = firetray.js.floatToInt((width - size.cx)/2),
|
||||||
nYStart = firetray.js.floatToInt((height - nHeight)/2);
|
nYStart = firetray.js.floatToInt((height - size.cy)/2);
|
||||||
gdi32.TextOutW(hdcMem, nXStart, nYStart, text, text.length); // ref point for alignment
|
gdi32.TextOutW(hdcMem, width/2, nYStart+2, text, text.length); // ref point for alignment
|
||||||
|
|
||||||
gdi32.SelectObject(hdcMem, hBitmapOrig);
|
gdi32.SelectObject(hdcMem, hBitmapOrig);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user