Fix(server): keep the full-screen status overlay steady

The window is now measured against a widest-case numeric placeholder
plus the current quality name, so changing FPS/bandwidth digits and
KB/MB unit switches no longer call SetWindowPos; only a quality label
change does. The frame is painted into a memory DC and blitted in one
go, so the layered window never shows the intermediate background-only
frame that made the bar blink once per second.
This commit is contained in:
yuanyuanxiang committed 2026-11-20 14:31:22 +01:00
1 parent 7eebd3bd6c
commit 326e162d16
2 files changed
+36 -17

No files matched your search

+32 -14
View File
@@ -452,7 +452,7 @@ namespace {
const int kStatusInfoMinWidth = 170;
const int kStatusInfoHeight = 24;
const int kStatusInfoPadX = 16; // 文本左右留白
// 宽度按 16px 取整:FPS / KB/s 每秒都在变,位数进位会让窗口每秒抖动一两个像素
// 宽度按 16px 取整,避免质量名变化时窗口左右微挪
const int kStatusInfoWidthStep = 16;
}
@@ -497,15 +497,20 @@ BOOL CStatusInfoWnd::Create(CWnd* pParent)
int CStatusInfoWnd::MeasureWidth()
{
if (m_strInfo.IsEmpty())
return kStatusInfoMinWidth;
CClientDC dc(this);
CFont* pOldFont = dc.SelectObject(&m_infoFont);
CSize sz = dc.GetTextExtent(m_strInfo);
// 用最宽的数字占位测宽,而不是实际文本:FPS / 速率每秒都在变,按实际文本
// 量宽会让窗口在位数进位、KB/MB 单位切换时每秒 resize 一次,分层窗口 resize
// 会闪。这样宽度只随质量名变化。
CString kbSample, mbSample;
kbSample.Format(_T("888 FPS | 8888 KB/s | %s"), m_strQuality.GetString());
mbSample.Format(_T("888 FPS | 888.8 MB/s | %s"), m_strQuality.GetString());
int cx = max(dc.GetTextExtent(kbSample).cx, dc.GetTextExtent(mbSample).cx);
dc.SelectObject(pOldFont);
int w = sz.cx + kStatusInfoPadX * 2;
int w = cx + kStatusInfoPadX * 2;
if (w < kStatusInfoMinWidth)
w = kStatusInfoMinWidth;
w = (w + kStatusInfoWidthStep - 1) / kStatusInfoWidthStep * kStatusInfoWidthStep;
@@ -538,6 +543,8 @@ void CStatusInfoWnd::UpdateInfo(double fps, double kbps, const CString& quality)
else
m_strInfo.Format(_T("%.0f FPS | %.0f KB/s | %s"), fps, kbps, quality.GetString());
m_strQuality = quality;
// 文本变了宽度就可能变(切档原因的四种文案长度不同),隐藏时也算,
// 免得下次 Show 出来先窄一帧再撑开。
ResizeToFit();
@@ -698,16 +705,27 @@ void CStatusInfoWnd::OnPaint()
CPaintDC dc(this);
CRect rc;
GetClientRect(&rc);
if (rc.IsRectEmpty())
return;
// 背景
dc.FillSolidRect(rc, RGB(40, 40, 40));
// 分层窗口上分两步画(先擦背景再写字),合成器可能采到中间的纯色帧,
// 每秒刷新一次就表现为闪。整帧画进内存 DC,一次 BitBlt 上屏。
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
CBitmap* pOldBmp = memDC.SelectObject(&bmp);
// 文字
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(220, 220, 220));
CFont* pOldFont = dc.SelectObject(&m_infoFont);
dc.DrawText(m_strInfo, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dc.SelectObject(pOldFont);
memDC.FillSolidRect(rc, RGB(40, 40, 40));
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(RGB(220, 220, 220));
CFont* pOldFont = memDC.SelectObject(&m_infoFont);
memDC.DrawText(m_strInfo, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.SelectObject(pOldFont);
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBmp);
}
BOOL CStatusInfoWnd::OnEraseBkgnd(CDC* pDC)