Snapshot before repaint phase 2
This commit is contained in:
+38
@@ -1,6 +1,7 @@
|
||||
#include "Control.h"
|
||||
#include "SxLog.h"
|
||||
#include<assert.h>
|
||||
#include "Window.h"
|
||||
|
||||
StellarX::ControlText& StellarX::ControlText::operator=(const ControlText& text)
|
||||
{
|
||||
@@ -123,6 +124,13 @@ void Control::restoreStyle()
|
||||
|
||||
void Control::requestRepaint(Control* parent)
|
||||
{
|
||||
if (shouldDeferManagedRepaint())
|
||||
{
|
||||
if (auto* host = getHostWindow())
|
||||
host->requestManagedRepaint();
|
||||
return;
|
||||
}
|
||||
|
||||
// 说明:
|
||||
// - 常规路径:子控件调用 requestRepaint(this->parent),然后 parent 负责局部重绘(Canvas/TabControl override)
|
||||
// - 兜底路径:如果某个“容器控件”没 override requestRepaint,就会出现 parent==this 的递归风险
|
||||
@@ -147,6 +155,13 @@ void Control::requestRepaint(Control* parent)
|
||||
|
||||
void Control::onRequestRepaintAsRoot()
|
||||
{
|
||||
if (shouldDeferManagedRepaint())
|
||||
{
|
||||
if (auto* host = getHostWindow())
|
||||
host->requestManagedRepaint();
|
||||
return;
|
||||
}
|
||||
|
||||
SX_LOG_TRACE("Dirty")
|
||||
<< SX_T("触发根重绘:id=", "onRequestRepaintAsRoot: id=") << id
|
||||
<< SX_T("(从根节点开始重画)", " (root repaint)");
|
||||
@@ -157,6 +172,29 @@ void Control::onRequestRepaintAsRoot()
|
||||
draw(); // 只有“无父”时才允许立即画,不会被谁覆盖
|
||||
}
|
||||
|
||||
bool Control::shouldDeferManagedRepaint() const
|
||||
{
|
||||
Window* host = getHostWindow();
|
||||
return host && host->isManagedDispatchActive();
|
||||
}
|
||||
|
||||
Window* Control::getHostWindow() const
|
||||
{
|
||||
if (hostWindow)
|
||||
return hostWindow;
|
||||
return parent ? parent->getHostWindow() : nullptr;
|
||||
}
|
||||
|
||||
RECT Control::getBoundsRect() const
|
||||
{
|
||||
RECT rc{};
|
||||
rc.left = x;
|
||||
rc.top = y;
|
||||
rc.right = x + width;
|
||||
rc.bottom = y + height;
|
||||
return rc;
|
||||
}
|
||||
|
||||
void Control::saveBackground(int x, int y, int w, int h)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user