feat: add a new awesome feature

This commit is contained in:
2025-11-30 19:05:58 +08:00
parent f05962954f
commit 46febdb973
21 changed files with 318 additions and 101 deletions
+1 -1
View File
@@ -224,7 +224,7 @@ void Button::draw()
//设置按钮填充模式
setfillstyle((int)buttonFillMode, (int)buttonFillIma, buttonFileIMAGE);
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
saveBackground(this->x, this->y, this->width, this->height);
saveBackground(this->x, this->y, (this->width + bordWith), (this->height + bordHeight));
// 恢复背景(清除旧内容)
restBackground();
//根据按钮形状绘制
+29 -3
View File
@@ -12,6 +12,28 @@ Canvas::Canvas(int x, int y, int width, int height)
this->id = "Canvas";
}
void Canvas::setX(int x)
{
this->x = x;
for (auto& c : controls)
{
c->onWindowResize();
c->setX(c->getLocalX() + this->x);
}
dirty = true;
}
void Canvas::setY(int y)
{
this->y = y;
for (auto& c : controls)
{
c->onWindowResize();
c->setY(c->getLocalY() + this->y);
}
dirty = true;
}
void Canvas::clearAllControls()
{
controls.clear();
@@ -36,21 +58,22 @@ void Canvas::draw()
// 在绘制画布之前,先恢复并更新背景快照:
// 1. 如果已有快照,则先回贴旧快照以清除之前的内容。
// 2. 当坐标或尺寸变化,或缓存图像无效时,丢弃旧快照并重新抓取新的背景。
int margin = canvaslinewidth > 1 ? canvaslinewidth : 1;
if (hasSnap)
{
// 恢复旧快照,清除上一次绘制
restBackground();
// 如果位置或尺寸变了,或没有有效缓存,则重新抓取
if (!saveBkImage || saveBkX != this->x || saveBkY != this->y || saveWidth != this->width || saveHeight != this->height)
if (!saveBkImage || saveBkX != this->x - margin || saveBkY != this->y - margin || saveWidth != this->width + margin * 2 || saveHeight != this->height + margin * 2)
{
discardBackground();
saveBackground(this->x, this->y, this->width, this->height);
saveBackground(this->x - margin, this->y - margin, this->width + margin * 2, this->height + margin * 2);
}
}
else
{
// 首次绘制或没有快照时直接抓取背景
saveBackground(this->x, this->y, this->width, this->height);
saveBackground(this->x- margin, this->y- margin, this->width + margin*2, this->height + margin*2);
}
// 再次恢复最新快照,确保绘制区域干净
restBackground();
@@ -98,6 +121,7 @@ bool Canvas::handleEvent(const ExMessage& msg)
void Canvas::addControl(std::unique_ptr<Control> control)
{
//坐标转化
control->setX(control->getLocalX() + this->x);
control->setY(control->getLocalY() + this->y);
@@ -363,3 +387,5 @@ void Canvas::requestRepaint(Control* parent)
+2 -1
View File
@@ -58,7 +58,7 @@ void Control::setLayoutMode(StellarX::LayoutMode layoutMode_)
{
this->layoutMode = layoutMode_;
}
void Control::steAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2)
void Control::setAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2)
{
this->anchor_1 = anchor_1;
this->anchor_2 = anchor_2;
@@ -144,6 +144,7 @@ void Control::discardBackground()
{
if (saveBkImage)
{
restBackground();
delete saveBkImage;
saveBkImage = nullptr;
}
+2 -33
View File
@@ -40,13 +40,7 @@ void Dialog::draw()
Canvas::setLinewidth(BorderWidth);
Canvas::setCanvasBkColor(this->backgroundColor);
Canvas::setShape(StellarX::ControlShape::ROUND_RECTANGLE);
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
saveBackground(this->x, this->y, this->width, this->height);
//设置所有控件为脏状态
/*for(auto& c :this->controls)
c->setDirty(true);*/
restBackground();
Canvas::draw();
//绘制消息文本
@@ -269,6 +263,7 @@ void Dialog::setInitialization(bool init)
{
initDialogSize();
saveBackground((x - BorderWidth), (y - BorderWidth), (width + 2 * BorderWidth), (height + 2 * BorderWidth));
this->dirty = true;
}
}
@@ -621,32 +616,6 @@ void Dialog::initDialogSize()
initCloseButton(); // 初始化关闭按钮
}
void Dialog::saveBackground(int x, int y, int w, int h)
{
if (w <= 0 || h <= 0) return;
saveBkX = x; saveBkY = y; saveWidth = w; saveHeight = h;
if (saveBkImage)
{
//尺寸变了才重建,避免反复 new/delete
if (saveBkImage->getwidth() != w || saveBkImage->getheight() != h)
{
delete saveBkImage; saveBkImage = nullptr;
}
}
if (!saveBkImage) saveBkImage = new IMAGE(w + BorderWidth*2, h + BorderWidth*2);
SetWorkingImage(nullptr); // ★抓屏幕
getimage(saveBkImage, x - BorderWidth, y - BorderWidth, w + BorderWidth*2, h+ BorderWidth*2);
hasSnap = true;
}
void Dialog::restBackground()
{
if (!hasSnap || !saveBkImage) return;
// 直接回贴屏幕(与抓取一致)
SetWorkingImage(nullptr);
putimage(saveBkX - BorderWidth, saveBkY - BorderWidth,saveBkImage);
}
void Dialog::addControl(std::unique_ptr<Control> control)
{
control->setParent(this);
+47 -19
View File
@@ -162,28 +162,56 @@ TabControl::~TabControl()
{
}
void TabControl::setX(int x)
{
this->x = x;
initTabBar();
initTabPage();
dirty = true;
for (auto& c : controls)
{
c.first->onWindowResize();
c.second->onWindowResize();
}
}
void TabControl::setY(int y)
{
this->y = y;
initTabBar();
initTabPage();
dirty = true;
for (auto& c : controls)
{
c.first->onWindowResize();
c.second->onWindowResize();
}
}
void TabControl::draw()
{
if (!dirty || !show)return;
// 在绘制 TabControl 之前,先恢复并更新背景快照:
if (hasSnap)
{
// 先回贴旧快照,清除之前的绘制
restBackground();
// 如位置或尺寸变化,丢弃旧快照并重新抓取
if (!saveBkImage || saveBkX != this->x || saveBkY != this->y || saveWidth != this->width || saveHeight != this->height)
{
discardBackground();
saveBackground(this->x, this->y, this->width, this->height);
}
}
else
{
// 首次绘制时抓取背景
saveBackground(this->x, this->y, this->width, this->height);
}
// 再次恢复最新背景,保证绘制区域干净
restBackground();
// // 在绘制 TabControl 之前,先恢复并更新背景快照:
//int margin = canvaslinewidth > 1 ? canvaslinewidth : 1;
//if (hasSnap)
//{
// // 恢复旧快照,清除上一次绘制
// restBackground();
// // 如果位置或尺寸变了,或没有有效缓存,则重新抓取
// if (!saveBkImage || saveBkX != this->x - margin || saveBkY != this->y - margin || saveWidth != this->width + margin * 2 || saveHeight != this->height + margin * 2)
// {
// discardBackground();
// saveBackground(this->x - margin, this->y - margin, this->width + margin * 2, this->height + margin * 2);
// }
//}
//else
//{
// // 首次绘制或没有快照时直接抓取背景
// saveBackground(this->x - margin, this->y - margin, this->width + margin * 2, this->height + margin * 2);
//}
// // 再次恢复最新背景,保证绘制区域干净
// restBackground();
// 绘制画布背景和基本形状及其子画布控件
Canvas::draw();
for (auto& c : controls)
+15
View File
@@ -250,6 +250,20 @@ void Table::drawButton()
}
void Table::setX(int x)
{
this->x = x;
isNeedButtonAndPageNum = true;
dirty = true;
}
void Table::setY(int y)
{
this->y = y;
isNeedButtonAndPageNum = true;
dirty = true;
}
void Table::setWidth(int width)
{
// 调整列宽以匹配新的表格总宽度。不修改 localWidth,避免累计误差。
@@ -285,6 +299,7 @@ void Table::setWidth(int width)
void Table::setHeight(int height)
{
//高度不变
}
Table::Table(int x, int y)
+19 -17
View File
@@ -243,7 +243,10 @@ void Window::draw()
oldWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)&Window::WndProcThunk);
procHooked = (oldWndProc != nullptr);
}
if (!headline.empty())
{
SetWindowText(hWnd, headline.c_str());
}
ApplyResizableStyle(hWnd, useComposited);
// 关闭类样式的整窗重绘标志(减少尺寸变化时的整窗 redraw)
@@ -470,6 +473,18 @@ int Window::runEventLoop()
// 调整底层画布尺寸
if (finalW != width || finalH != height)
{
// 批量通知控件“窗口尺寸变化”,并标记重绘
for (auto& c : controls)
adaptiveLayout(c, finalH, finalW);
for (auto& d : dialogs)
{
if (auto dd = dynamic_cast<Dialog*>(d.get()))
{
dd->setDirty(true);
dd->setInitialization(true);
}
}
//重绘窗口
Resize(nullptr, finalW, finalH);
// 重取一次实际客户区尺寸做确认
@@ -499,21 +514,6 @@ int Window::runEventLoop()
height = renderHeight;
}
// 批量通知控件“窗口尺寸变化”,并标记重绘
for (auto& c : controls)
{
adaptiveLayout(c,finalH,finalW);
c->onWindowResize();
}
for (auto& d : dialogs)
{
if (auto dd = dynamic_cast<Dialog*>(d.get()))
{
dd->setDirty(true);
dd->setInitialization(true);
}
}
// 统一批量绘制
for (auto& c : controls) c->draw();
for (auto& d : dialogs) d->draw();
@@ -809,11 +809,13 @@ void Window::adaptiveLayout(std::unique_ptr<Control>& c, const int finalH, const
c->setHeight(c->getLocalHeight());
c->setY(finalH - origBottomDist - c->getHeight());
}
else {
else
{
// 垂直无锚点:默认为顶部定位,高度固定
c->setY(c->getLocalY());
c->setHeight(c->getLocalHeight());
}
c->onWindowResize();
}
}