@@ -8,6 +8,16 @@ Widget* focusingWidget = nullptr;
88vector<Widget*> widgets;
99double absolutPosDeltaX = 0 ,absolutPosDeltaY = 0 ;
1010bool PanelScaleChanged = false ;
11+ bool BackendFlag = false ;
12+ std::vector<Widget*> widgetBackendRedraw;
13+
14+ void markWidgetBackendRedraw (Widget* widget) {
15+ if (!widget) return ;
16+ auto it = std::find (widgetBackendRedraw.begin (), widgetBackendRedraw.end (), widget);
17+ if (it == widgetBackendRedraw.end ()) {
18+ widgetBackendRedraw.push_back (widget);
19+ }
20+ }
1121
1222// 当前可绘制区域(全局坐标系),Panel绘制时逐层收窄
1323static constexpr double DRAWING_BOUND_MIN = -1e9 ;
@@ -55,6 +65,17 @@ int Widget::getDrawingState() const {
5565 return this ->m_drawing ;
5666}
5767
68+ bool Widget::isBackendDirty () const {
69+ return needRedraw || m_drawing > 0 ;
70+ }
71+
72+ void Widget::setNeedRedraw (bool b) {
73+ needRedraw = b;
74+ if (b) {
75+ markWidgetBackendRedraw (this );
76+ }
77+ }
78+
5879void Widget::reset () {
5980
6081}
@@ -105,6 +126,7 @@ void Panel::draw() {
105126}
106127
107128void Panel::draw (PIMAGE dst, double x, double y) {
129+ if (BackendFlag) return ;
108130 double left = x - width / 2 - 4 ;
109131 double top = y - height / 2 - 4 ;
110132 double layerWidth = this ->width + 8 ;
@@ -236,6 +258,9 @@ Panel::~Panel(){
236258
237259void Panel::setAlwaysDirty (bool d) {
238260 this ->needRedrawAlways += ((int )d + d - 1 );
261+ if (d) {
262+ markWidgetBackendRedraw (this );
263+ }
239264 if (this ->parent != nullptr ){
240265 if (Panel* p = dynamic_cast <Panel*>(this ->parent )) {
241266 p->setAlwaysDirty (d);
@@ -245,6 +270,7 @@ void Panel::setAlwaysDirty(bool d) {
245270
246271void Panel::setDirty () {
247272 this ->needRedraw = true ;
273+ markWidgetBackendRedraw (this );
248274 if (this ->parent != nullptr ){
249275 if (Panel* p = dynamic_cast <Panel*>(this ->parent )) {
250276 p->setDirty ();
@@ -256,6 +282,10 @@ int Panel::getAlwaysDirtyState() {
256282 return this ->needRedrawAlways ;
257283}
258284
285+ bool Panel::isBackendDirty () const {
286+ return needRedraw || needRedrawAlways > 0 || scaleChanged;
287+ }
288+
259289void Panel::setPosition (double x,double y){
260290 cx = x;
261291 cy = y;
@@ -650,6 +680,7 @@ void Ripple::update() {
650680}
651681
652682void Ripple::draw (PIMAGE dst) const {
683+ if (BackendFlag) return ;
653684 double progress = (double )age / life;
654685 double r = maxRadius * progress;
655686 int alpha = static_cast <int >(120 * std::cos (progress * PI / 2 ));
@@ -658,6 +689,7 @@ void Ripple::draw(PIMAGE dst) const {
658689}
659690
660691void Ripple::draw_aa (PIMAGE dst) const {
692+ if (BackendFlag) return ;
661693 double progress = (double )age / life;
662694 double r = maxRadius * progress;
663695 int alpha = static_cast <int >(120 * std::cos (progress * PI / 2 ));
@@ -686,6 +718,7 @@ Button::~Button() {
686718}
687719
688720void Button::draw (PIMAGE dst,double x,double y){
721+ if (BackendFlag) return ;
689722 double left = x - width / 2 - 4 ;
690723 double top = y - height / 2 - 4 ;
691724 double width = this ->width + 8 ;
@@ -752,6 +785,10 @@ void Button::draw(){
752785 draw (nullptr ,cx,cy);
753786}
754787
788+ bool Button::isBackendDirty () const {
789+ return needRedraw || !ripples.empty ();
790+ }
791+
755792void Button::releaseMouseOwningFlag (const mouse_msg& msg){
756793 if (!msg.is_left () || !msg.is_up () || !m_clicking) return ;
757794 bool inside = isInside (msg.x , msg.y );
@@ -1039,6 +1076,7 @@ double InputBoxSinDoubleForCursor(double time) {
10391076}
10401077
10411078void InputBox::draw (PIMAGE dst, double x, double y) {
1079+ if (BackendFlag) return ;
10421080 double left = x - width / 2 - 4 ;
10431081 double top = y - height / 2 - 4 ;
10441082 double width = this ->width + 8 ;
@@ -1213,6 +1251,10 @@ void InputBox::draw(){
12131251 draw (nullptr ,cx,cy);
12141252}
12151253
1254+ bool InputBox::isBackendDirty () const {
1255+ return needRedraw || on_focus || !ripples.empty () || scaleChanged || PanelScaleChanged;
1256+ }
1257+
12161258void InputBox::deleteFocus (const mouse_msg& msg){
12171259 on_focus = false ;
12181260 dragging = false ;
@@ -1798,6 +1840,7 @@ void Slider::create(double x, double y, double w, double h) {
17981840}
17991841
18001842void Slider::draw (PIMAGE dst,double x,double y){
1843+ if (BackendFlag) return ;
18011844 double left = x - width / 2 ;
18021845 double top = y - height / 2 ;
18031846 // 动态更新缩放比例
@@ -1885,6 +1928,12 @@ void Slider::draw(){
18851928 draw (nullptr ,cx,cy);
18861929}
18871930
1931+ bool Slider::isBackendDirty () const {
1932+ bool scaleAnimating = std::fabs (m_scale - (m_pressed ? 0 .8f : 1 .0f )) > 0.01 ;
1933+ bool progressAnimating = std::fabs (m_progress - m_finalprogress) > 0.005 ;
1934+ return m_dragging || m_pressed || m_hover || scaleAnimating || progressAnimating;
1935+ }
1936+
18881937bool Slider::isInside (double x, double y){
18891938 double knobX, knobY;
18901939 if (m_orientation == Orientation::Column) {
@@ -2199,6 +2248,7 @@ void ProgressBar::setBackground(color_t bg) {
21992248}
22002249
22012250void ProgressBar::draw (PIMAGE dst, double x, double y) {
2251+ if (BackendFlag) return ;
22022252 double left = x - width / 2 ;
22032253 double top = y - height / 2 ;
22042254
@@ -2231,6 +2281,10 @@ void ProgressBar::draw() {
22312281 draw (nullptr , cx, cy);
22322282}
22332283
2284+ bool ProgressBar::isBackendDirty () const {
2285+ return needRedraw || std::fabs (currentProgress - targetProgress) > 1e-4 ;
2286+ }
2287+
22342288bool ProgressBar::handleEvent (const mouse_msg& msg){
22352289 return false ;
22362290}
@@ -2360,6 +2414,7 @@ void Dropdown::updateDropdownLayout() {
23602414}
23612415
23622416void Dropdown::draw (PIMAGE dst, double x, double y) {
2417+ if (BackendFlag) return ;
23632418 // 主按钮正常绘制
23642419 mainButton->draw (dst, x, y);
23652420
@@ -2395,6 +2450,13 @@ void Dropdown::draw() {
23952450 draw (nullptr , cx, cy);
23962451}
23972452
2453+ bool Dropdown::isBackendDirty () const {
2454+ bool fading = fadingIn || fadingOut || fadeAlpha > 0.08 ;
2455+ bool mainDirty = mainButton && mainButton->isBackendDirty ();
2456+ bool panelDirty = dropdownPanel && dropdownPanel->isBackendDirty ();
2457+ return expanded || fading || mainDirty || panelDirty;
2458+ }
2459+
23982460bool Dropdown::handleEvent (const mouse_msg& msg) {
23992461 if (expanded) {
24002462 dropdownPanel->handleEvent (msg);
@@ -2549,6 +2611,7 @@ bool Radio::isChecked() const {
25492611}
25502612
25512613void Radio::draw (PIMAGE dst, double x, double y) {
2614+ if (BackendFlag) return ;
25522615 bool nowChecked = isChecked ();
25532616 bool showDot = isChecked () || (animOut && animProgress < 1.0 );
25542617 if (!nowChecked && wasChecked && !animOut) {
@@ -2626,6 +2689,10 @@ void Radio::draw() {
26262689 draw (nullptr , cx, cy);
26272690}
26282691
2692+ bool Radio::isBackendDirty () const {
2693+ return hovered || animIn || animOut;
2694+ }
2695+
26292696bool Radio::handleEvent (const mouse_msg& msg) {
26302697 int dx = msg.x - cx;
26312698 int dy = msg.y - cy;
@@ -2873,6 +2940,7 @@ color_t mixColor(color_t c1, color_t c2, double ratio) {
28732940}
28742941
28752942void Toggle::draw (PIMAGE dst, double x, double y) {
2943+ if (BackendFlag) return ;
28762944 // === 动画推进 ===
28772945 if (std::abs (knobOffset - knobTarget) > 1e-3 )
28782946 knobOffset += (knobTarget - knobOffset) * animationSpeed;
@@ -2933,6 +3001,10 @@ void Toggle::draw() {
29333001 draw (nullptr , cx, cy);
29343002}
29353003
3004+ bool Toggle::isBackendDirty () const {
3005+ return hovered || pressedIn || std::fabs (knobOffset - knobTarget) > 1e-3 ;
3006+ }
3007+
29363008ToggleBuilder& ToggleBuilder::setCenter (double x, double y) {
29373009 cx = x; cy = y;
29383010 return *this ;
@@ -3089,6 +3161,7 @@ void Text::draw() {
30893161}
30903162
30913163void Text::draw (PIMAGE dst, double x, double y) {
3164+ if (BackendFlag) return ;
30923165 ege_setfont (fontSize * scale, fontName.c_str (), dst);
30933166 settextcolor (color, dst);
30943167
@@ -3352,6 +3425,7 @@ bool Knob::isInside(double x, double y) const {
33523425}
33533426
33543427void Knob::draw (PIMAGE dst, double x, double y) {
3428+ if (BackendFlag) return ;
33553429 ege_enable_aa (true ,dst);
33563430 double r = radius;
33573431
@@ -3455,6 +3529,10 @@ void Knob::draw() {
34553529 draw (nullptr , cx, cy);
34563530}
34573531
3532+ bool Knob::isBackendDirty () const {
3533+ return dragging || hovered || std::fabs (displayValue - value) >= 0.01 ;
3534+ }
3535+
34583536void Knob::releaseMouseOwningFlag (const mouse_msg& msg){
34593537 dragging = false ;
34603538 mouseOwningFlag = nullptr ;
0 commit comments