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:
1 parent
7eebd3bd6c
commit
326e162d16
2 files changed
+36
-17
No files matched your search
@@ -452,7 +452,7 @@ namespace {
|
|||||||
const int kStatusInfoMinWidth = 170;
|
const int kStatusInfoMinWidth = 170;
|
||||||
const int kStatusInfoHeight = 24;
|
const int kStatusInfoHeight = 24;
|
||||||
const int kStatusInfoPadX = 16; // 文本左右留白
|
const int kStatusInfoPadX = 16; // 文本左右留白
|
||||||
// 宽度按 16px 取整:FPS / KB/s 每秒都在变,位数进位会让窗口每秒抖动一两个像素
|
// 宽度按 16px 取整,避免质量名变化时窗口左右微挪
|
||||||
const int kStatusInfoWidthStep = 16;
|
const int kStatusInfoWidthStep = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,15 +497,20 @@ BOOL CStatusInfoWnd::Create(CWnd* pParent)
|
|||||||
|
|
||||||
int CStatusInfoWnd::MeasureWidth()
|
int CStatusInfoWnd::MeasureWidth()
|
||||||
{
|
{
|
||||||
if (m_strInfo.IsEmpty())
|
|
||||||
return kStatusInfoMinWidth;
|
|
||||||
|
|
||||||
CClientDC dc(this);
|
CClientDC dc(this);
|
||||||
CFont* pOldFont = dc.SelectObject(&m_infoFont);
|
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);
|
dc.SelectObject(pOldFont);
|
||||||
|
|
||||||
int w = sz.cx + kStatusInfoPadX * 2;
|
int w = cx + kStatusInfoPadX * 2;
|
||||||
if (w < kStatusInfoMinWidth)
|
if (w < kStatusInfoMinWidth)
|
||||||
w = kStatusInfoMinWidth;
|
w = kStatusInfoMinWidth;
|
||||||
w = (w + kStatusInfoWidthStep - 1) / kStatusInfoWidthStep * kStatusInfoWidthStep;
|
w = (w + kStatusInfoWidthStep - 1) / kStatusInfoWidthStep * kStatusInfoWidthStep;
|
||||||
@@ -538,6 +543,8 @@ void CStatusInfoWnd::UpdateInfo(double fps, double kbps, const CString& quality)
|
|||||||
else
|
else
|
||||||
m_strInfo.Format(_T("%.0f FPS | %.0f KB/s | %s"), fps, kbps, quality.GetString());
|
m_strInfo.Format(_T("%.0f FPS | %.0f KB/s | %s"), fps, kbps, quality.GetString());
|
||||||
|
|
||||||
|
m_strQuality = quality;
|
||||||
|
|
||||||
// 文本变了宽度就可能变(切档原因的四种文案长度不同),隐藏时也算,
|
// 文本变了宽度就可能变(切档原因的四种文案长度不同),隐藏时也算,
|
||||||
// 免得下次 Show 出来先窄一帧再撑开。
|
// 免得下次 Show 出来先窄一帧再撑开。
|
||||||
ResizeToFit();
|
ResizeToFit();
|
||||||
@@ -698,16 +705,27 @@ void CStatusInfoWnd::OnPaint()
|
|||||||
CPaintDC dc(this);
|
CPaintDC dc(this);
|
||||||
CRect rc;
|
CRect rc;
|
||||||
GetClientRect(&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);
|
||||||
|
|
||||||
// 文字
|
memDC.FillSolidRect(rc, RGB(40, 40, 40));
|
||||||
dc.SetBkMode(TRANSPARENT);
|
memDC.SetBkMode(TRANSPARENT);
|
||||||
dc.SetTextColor(RGB(220, 220, 220));
|
memDC.SetTextColor(RGB(220, 220, 220));
|
||||||
CFont* pOldFont = dc.SelectObject(&m_infoFont);
|
CFont* pOldFont = memDC.SelectObject(&m_infoFont);
|
||||||
dc.DrawText(m_strInfo, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
memDC.DrawText(m_strInfo, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||||
dc.SelectObject(pOldFont);
|
memDC.SelectObject(pOldFont);
|
||||||
|
|
||||||
|
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memDC, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
|
memDC.SelectObject(pOldBmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CStatusInfoWnd::OnEraseBkgnd(CDC* pDC)
|
BOOL CStatusInfoWnd::OnEraseBkgnd(CDC* pDC)
|
||||||
|
|||||||
@@ -181,14 +181,15 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CString m_strInfo;
|
CString m_strInfo;
|
||||||
|
CString m_strQuality; // 最近一次的质量名,测宽时按最宽数字占位用它拼样本
|
||||||
int m_nOpacityLevel;
|
int m_nOpacityLevel;
|
||||||
bool m_bVisible;
|
bool m_bVisible;
|
||||||
|
|
||||||
// 宽度按文本自适应。原来写死 170,档位名后面跟出「(链路改善)」这类切档原因时
|
// 宽度按质量名自适应。原来写死 170,档位名后面跟出「(链路改善)」这类切档原因时
|
||||||
// 会被截断;170 现在只是下限。
|
// 会被截断;170 只是下限。FPS / 速率的位数变化不再影响宽度,避免每秒 resize。
|
||||||
int m_nWidth = 170;
|
int m_nWidth = 170;
|
||||||
CFont m_infoFont; // 绘制与测量共用,Create 里建一次
|
CFont m_infoFont; // 绘制与测量共用,Create 里建一次
|
||||||
int MeasureWidth(); // 当前文本的窗口宽度(不小于下限,按 16px 取整)
|
int MeasureWidth(); // 按最宽占位算窗口宽度(不小于下限,按 16px 取整)
|
||||||
void ResizeToFit(); // 宽度有变化时改窗口大小,保持中心不动
|
void ResizeToFit(); // 宽度有变化时改窗口大小,保持中心不动
|
||||||
|
|
||||||
// 拖动支持
|
// 拖动支持
|
||||||
|
|||||||
Reference in new issue
Block a user