feat: add a new awesome feature

This commit is contained in:
2025-11-02 18:04:55 +08:00
parent c4852d080f
commit 4bb0352088
23 changed files with 4712 additions and 1899 deletions

View File

@@ -1,10 +1,16 @@
#include "Canvas.h"
Canvas::Canvas()
:Control(0, 0, 100, 100) {}
:Control(0, 0, 100, 100)
{
this->id = "Canvas";
}
Canvas::Canvas(int x, int y, int width, int height)
:Control(x, y, width, height) {}
:Control(x, y, width, height)
{
this->id = "Canvas";
}
void Canvas::clearAllControls()
{
@@ -14,14 +20,17 @@ void Canvas::clearAllControls()
void Canvas::draw()
{
if (!dirty && !show)return;
if (!dirty||!show)return;
saveStyle();
setlinecolor(canvasBorderClor);//设置线色
setfillcolor(canvasBkClor);//设置填充色
setfillstyle((int)canvasFillMode);//设置填充模式
setlinestyle((int)canvasLineStyle, canvaslinewidth);
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
saveBackground(this->x, this->y, this->width, this->height);
// 恢复背景(清除旧内容)
restBackground();
//根据画布形状绘制
switch (shape)
{
@@ -51,16 +60,22 @@ void Canvas::draw()
bool Canvas::handleEvent(const ExMessage& msg)
{
if(!show)return false;
if (!show)return false;
bool consumed = false;
bool anyDirty = false;
for (auto it = controls.rbegin(); it != controls.rend(); ++it)
if ((*it)->handleEvent(msg))
return true; // 事件被消费短路传递立即返回true 否则返回false
return false;
for (auto it = controls.rbegin(); it != controls.rend(); ++it)
{
consumed |= it->get()->handleEvent(msg);
if (it->get()->isDirty()) anyDirty = true;
}
if (anyDirty) requestRepaint();
return consumed;
}
void Canvas::addControl(std::unique_ptr<Control> control)
{
control->setParent(this);
controls.push_back(std::move(control));
dirty = true;
}
@@ -117,5 +132,32 @@ void Canvas::setLinewidth(int width)
dirty = true;
}
void Canvas::setIsVisible(bool visible)
{
this->show = visible;
dirty = true;
for (auto& control : controls)
{
control->setIsVisible(visible);
control->setDirty(true);
}
if (!visible)
this->updateBackground();
}
void Canvas::setDirty(bool dirty)
{
this->dirty = dirty;
for(auto& control : controls)
control->setDirty(dirty);
}
void Canvas::onWindowResize()
{
Control::onWindowResize(); // 先处理自己
for (auto& ch : controls) // 再转发给所有子控件
ch->onWindowResize();
}