Skip to content

Commit 05eaa57

Browse files
committed
Fixed backround rendering for widgets
1 parent 9243bc8 commit 05eaa57

12 files changed

Lines changed: 138 additions & 120 deletions

File tree

include/lsp-plug.in/tk/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ namespace lsp
197197
DRAW_NONE = 0,
198198
DRAW_SURFACE = 1 << 0,
199199
DRAW_CHILD = 1 << 1,
200+
DRAW_BG = 1 << 2,
200201

201202
DRAW_DEFAULT = DRAW_SURFACE,
202-
DRAW_ALL = DRAW_SURFACE | DRAW_CHILD
203+
DRAW_ALL = DRAW_SURFACE | DRAW_CHILD | DRAW_BG
203204
};
204205

205206
typedef struct w_class_t

include/lsp-plug.in/tk/widgets/base/Widget.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ namespace lsp
9393
REALIZED = 1 << 3, // Widget has been at least once realized
9494
REDRAW_SURFACE = 1 << 4, // Need to redraw surface
9595
REDRAW_CHILD = 1 << 5, // Need to redraw child only
96-
SIZE_INVALID = 1 << 6, // Size limit structure is valid
97-
RESIZE_PENDING = 1 << 7, // The resize request is pending
98-
REALIZE_ACTIVE = 1 << 8, // Realize is active, no need to trigger for realize
96+
REDRAW_BG = 1 << 6, // Need to redraw surface
97+
SIZE_INVALID = 1 << 7, // Size limit structure is valid
98+
RESIZE_PENDING = 1 << 8, // The resize request is pending
99+
REALIZE_ACTIVE = 1 << 9, // Realize is active, no need to trigger for realize
99100

100101
REDRAW_DEFAULT = REDRAW_SURFACE
101102
};
@@ -371,7 +372,13 @@ namespace lsp
371372
*
372373
* @return true if there is redraw request pending
373374
*/
374-
inline bool redraw_pending() const { return nFlags & (REDRAW_SURFACE | REDRAW_CHILD); }
375+
inline bool redraw_pending() const { return nFlags & (REDRAW_SURFACE | REDRAW_CHILD | REDRAW_BG); }
376+
377+
/** Check if there is backround redraw request pending
378+
*
379+
* @return true if there is redraw request pending
380+
*/
381+
inline bool redraw_bg_pending() const { return nFlags & REDRAW_BG; }
375382

376383
/** Check if there is resize request pending
377384
*

src/main/widgets/base/Widget.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3-
* (C) 2025 Vladimir Sadovnikov <sadko4u@gmail.com>
2+
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2026 Vladimir Sadovnikov <sadko4u@gmail.com>
44
*
55
* This file is part of lsp-tk-lib
66
* Created on: 15 июн. 2017 г.
@@ -273,7 +273,7 @@ namespace lsp
273273
const style::WidgetColors *colors = select_colors();
274274
const size_t redraw = redraw_flags(colors->property_changed(prop));
275275
if (redraw != 0)
276-
query_draw(REDRAW_CHILD);
276+
query_draw(redraw & (REDRAW_CHILD | REDRAW_BG));
277277

278278
if (sActive.is(prop))
279279
query_draw();
@@ -302,8 +302,12 @@ namespace lsp
302302

303303
size_t Widget::redraw_flags(size_t draw_flags)
304304
{
305-
size_t result = (draw_flags & DRAW_SURFACE) ? REDRAW_SURFACE : 0;
306-
return lsp_setflag(result, REDRAW_CHILD, draw_flags & DRAW_CHILD);
305+
size_t result = (draw_flags & DRAW_SURFACE) ? REDRAW_SURFACE : 0;
306+
if (draw_flags & DRAW_CHILD)
307+
result |= REDRAW_CHILD;
308+
if (draw_flags & DRAW_BG)
309+
result |= REDRAW_BG;
310+
return result;
307311
}
308312

309313
const style::WidgetColors *Widget::select_colors() const
@@ -595,7 +599,7 @@ namespace lsp
595599
void Widget::show_widget()
596600
{
597601
query_resize();
598-
query_draw(REDRAW_CHILD | REDRAW_SURFACE);
602+
query_draw(REDRAW_CHILD | REDRAW_SURFACE | REDRAW_BG);
599603
sSlots.execute(SLOT_SHOW, this);
600604
}
601605

@@ -646,7 +650,7 @@ namespace lsp
646650
return;
647651

648652
// Check that flags have been changed
649-
flags = nFlags | (flags & (REDRAW_CHILD | REDRAW_SURFACE));
653+
flags = nFlags | (flags & (REDRAW_CHILD | REDRAW_SURFACE | REDRAW_BG));
650654
if (flags == nFlags)
651655
return;
652656

@@ -658,7 +662,7 @@ namespace lsp
658662

659663
void Widget::commit_redraw()
660664
{
661-
nFlags &= ~(REDRAW_SURFACE | REDRAW_CHILD);
665+
nFlags &= ~(REDRAW_SURFACE | REDRAW_CHILD | REDRAW_BG);
662666
}
663667

664668
void Widget::show()

src/main/widgets/containers/Align.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,29 @@ namespace lsp
124124
return;
125125
}
126126

127-
if ((force) || (pWidget->redraw_pending()))
128-
{
129-
// Draw the child only if it is visible in the area
130-
ws::rectangle_t xr;
131-
pWidget->get_rectangle(&xr);
132-
if (Size::intersection(&xr, area))
133-
pWidget->render(s, &xr, force);
134-
135-
pWidget->commit_redraw();
136-
}
127+
ws::rectangle_t xr;
128+
pWidget->get_rectangle(&xr);
137129

138-
if (force)
130+
if ((force) || (pWidget->redraw_bg_pending()))
139131
{
140-
ws::rectangle_t cr;
141-
142-
pWidget->get_rectangle(&cr);
143132
if (Size::overlap(area, &sSize))
144133
{
145134
s->clip_begin(area);
146135
{
147136
pWidget->get_actual_bg_color(bg_color);
148-
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &sSize, &cr);
137+
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &sSize, &xr);
149138
}
150139
s->clip_end();
151140
}
152141
}
142+
143+
if ((force) || (pWidget->redraw_pending()))
144+
{
145+
// Draw the child only if it is visible in the area
146+
if (Size::intersection(&xr, area))
147+
pWidget->render(s, &xr, force);
148+
pWidget->commit_redraw();
149+
}
153150
}
154151

155152
status_t Align::add(Widget *widget)

src/main/widgets/containers/Box.cpp

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,20 @@ namespace lsp
225225

226226
// Estimate palette
227227
ws::rectangle_t xr;
228+
lsp::Color bg_color, border_color;
229+
float scaling = lsp_max(0.0f, sScaling.get());
230+
float bright = select_brightness();
231+
size_t border = (sBorder.get() > 0) ? lsp_max(1.0f, sBorder.get() * scaling) : 0;
232+
get_actual_bg_color(bg_color);
228233

229-
if (force)
234+
// Draw backround of the widget if needed
230235
{
231-
lsp::Color bg_color, border_color;
232-
float scaling = lsp_max(0.0f, sScaling.get());
233-
float bright = select_brightness();
234-
size_t border = (sBorder.get() > 0) ? lsp_max(1.0f, sBorder.get() * scaling) : 0;
235-
get_actual_bg_color(bg_color);
236-
237236
// Enable clipping
238237
s->clip_begin(area);
239238
lsp_finally { s->clip_end(); };
240239

241240
// Draw background if no child widget is present
242-
if (vVisible.is_empty())
241+
if ((vVisible.is_empty()) && (force))
243242
{
244243
s->fill_rect(bg_color, SURFMASK_NONE, 0.0f, &sSize);
245244
if (border > 0)
@@ -262,40 +261,44 @@ namespace lsp
262261
cell_t *wc = vVisible.uget(i);
263262
Widget *w = wc->pWidget;
264263

265-
w->get_actual_bg_color(bg_color);
266-
if (Size::overlap(area, &wc->a))
267-
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &wc->a, &wc->s);
268-
269-
// Draw spacing
270-
if (((i + 1) < n) && (spacing > 0))
264+
// Render the frame around child widget
265+
if ((force) || (w->redraw_bg_pending()))
271266
{
272-
get_actual_bg_color(bg_color);
273-
if (horizontal)
267+
w->get_actual_bg_color(bg_color);
268+
if (Size::overlap(area, &wc->a))
269+
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &wc->a, &wc->s);
270+
271+
// Draw spacing
272+
if (((i + 1) < n) && (spacing > 0))
274273
{
275-
xr.nLeft = wc->a.nLeft + wc->a.nWidth;
276-
xr.nTop = wc->a.nTop;
277-
xr.nWidth = spacing;
278-
xr.nHeight = wc->a.nHeight;
274+
get_actual_bg_color(bg_color);
275+
if (horizontal)
276+
{
277+
xr.nLeft = wc->a.nLeft + wc->a.nWidth;
278+
xr.nTop = wc->a.nTop;
279+
xr.nWidth = spacing;
280+
xr.nHeight = wc->a.nHeight;
281+
}
282+
else
283+
{
284+
xr.nLeft = wc->a.nLeft;
285+
xr.nTop = wc->a.nTop + wc->a.nHeight;
286+
xr.nWidth = wc->a.nWidth;
287+
xr.nHeight = spacing;
288+
}
289+
290+
if (Size::overlap(area, &xr))
291+
s->fill_rect(bg_color, SURFMASK_NONE, 0.0f, &xr);
279292
}
280-
else
293+
294+
// Draw border
295+
if (border > 0)
281296
{
282-
xr.nLeft = wc->a.nLeft;
283-
xr.nTop = wc->a.nTop + wc->a.nHeight;
284-
xr.nWidth = wc->a.nWidth;
285-
xr.nHeight = spacing;
297+
border_color.copy(sBorderColor);
298+
border_color.scale_lch_luminance(bright);
299+
Rectangle::enter_border(&xr, &sSize, border);
300+
s->fill_frame(border_color, SURFMASK_NONE, 0.0f, &sSize, &xr);
286301
}
287-
288-
if (Size::overlap(area, &xr))
289-
s->fill_rect(bg_color, SURFMASK_NONE, 0.0f, &xr);
290-
}
291-
292-
// Draw border
293-
if (border > 0)
294-
{
295-
border_color.copy(sBorderColor);
296-
border_color.scale_lch_luminance(bright);
297-
Rectangle::enter_border(&xr, &sSize, border);
298-
s->fill_frame(border_color, SURFMASK_NONE, 0.0f, &sSize, &xr);
299302
}
300303
}
301304
}

src/main/widgets/containers/Grid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ namespace lsp
250250
}
251251

252252
// Fill unused space by child widget with background
253-
if ((force) || (w->pWidget->redraw_pending()))
253+
if ((force) || (w->pWidget->redraw_bg_pending()))
254254
{
255255
// Draw widget area
256256
if (Size::overlap(area, &w->a))

src/main/widgets/containers/Group.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ namespace lsp
330330
{
331331
pWidget->get_rectangle(&xr);
332332

333-
if (force)
333+
// Render the child background
334+
if ((force) || (pWidget->redraw_bg_pending()))
334335
{
335-
// Render the child background
336336
if (Size::overlap(area, &sSize))
337337
{
338338
s->clip_begin(area);
@@ -341,6 +341,7 @@ namespace lsp
341341
s->fill_frame(color, SURFMASK_NONE, 0.0f, &sSize, &xr);
342342
}
343343
s->clip_end();
344+
bg = true;
344345
}
345346
}
346347

@@ -364,7 +365,7 @@ namespace lsp
364365
}
365366

366367
// Render frame
367-
if (!force)
368+
if ((!force) && (!bg))
368369
return;
369370

370371
ssize_t ir, xg;

src/main/widgets/containers/Overlay.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,20 @@ namespace lsp
249249
const ws::point_t origin = s->set_origin(bw - xr.nLeft, bw - xr.nTop);
250250
lsp_finally { s->set_origin(origin); };
251251

252-
// Draw the child widget
253-
wWidget->render(s, &xr, force);
254-
wWidget->commit_redraw();
255-
256-
if (force)
252+
// Draw rectangle around widget
253+
if ((force) || (wWidget->redraw_bg_pending()))
257254
{
258-
// Draw rectangle around widget
259255
ws::rectangle_t sr = sSize;
260256
sr.nLeft -= xr.nLeft;
261257
sr.nTop -= xr.nTop;
262258

263259
wWidget->get_actual_bg_color(bg_color);
264260
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &sSize, &xr);
265261
}
262+
263+
// Draw the child widget
264+
wWidget->render(s, &xr, force);
265+
wWidget->commit_redraw();
266266
}
267267

268268
// Draw border

src/main/widgets/containers/ScrollArea.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,8 @@ namespace lsp
405405
if (!Size::intersection(&xa, area))
406406
return;
407407

408-
if ((force) || (pWidget->redraw_pending()))
409-
{
410-
// Draw the child only if it is visible in the area
411-
pWidget->get_rectangle(&xr);
412-
if (Size::intersection(&xr, &xa))
413-
pWidget->render(s, &xr, force);
414-
415-
pWidget->commit_redraw();
416-
}
417-
418-
if (force)
408+
// Draw backround around the widget
409+
if ((force) || (pWidget->redraw_bg_pending()))
419410
{
420411
pWidget->get_rectangle(&xr);
421412
if ((Size::is_empty(&xr)) || (Size::overlap(&xr, &xa)))
@@ -428,6 +419,17 @@ namespace lsp
428419
s->clip_end();
429420
}
430421
}
422+
423+
// Draw the widget
424+
if ((force) || (pWidget->redraw_pending()))
425+
{
426+
// Draw the child only if it is visible in the area
427+
pWidget->get_rectangle(&xr);
428+
if (Size::intersection(&xr, &xa))
429+
pWidget->render(s, &xr, force);
430+
431+
pWidget->commit_redraw();
432+
}
431433
}
432434

433435
status_t ScrollArea::add(Widget *widget)

src/main/widgets/containers/Tab.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -341,32 +341,32 @@ namespace lsp
341341
return;
342342
}
343343

344-
if ((force) || (pWidget->redraw_pending()))
344+
if ((force) || (pWidget->redraw_bg_pending()))
345345
{
346-
// Draw the child only if it is visible in the area
347346
ws::rectangle_t xr;
348347
pWidget->get_rectangle(&xr);
349-
if (Size::intersection(&xr, area))
350-
pWidget->render(s, &xr, force);
351-
352-
pWidget->commit_redraw();
353-
}
354348

355-
if (force)
356-
{
357-
ws::rectangle_t cr;
358-
359-
pWidget->get_rectangle(&cr);
360349
if (Size::overlap(area, &sSize))
361350
{
362351
s->clip_begin(area);
363352
{
364353
pWidget->get_actual_bg_color(bg_color);
365-
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &sSize, &cr);
354+
s->fill_frame(bg_color, SURFMASK_NONE, 0.0f, &sSize, &xr);
366355
}
367356
s->clip_end();
368357
}
369358
}
359+
360+
if ((force) || (pWidget->redraw_pending()))
361+
{
362+
// Draw the child only if it is visible in the area
363+
ws::rectangle_t xr;
364+
pWidget->get_rectangle(&xr);
365+
if (Size::intersection(&xr, area))
366+
pWidget->render(s, &xr, force);
367+
368+
pWidget->commit_redraw();
369+
}
370370
}
371371

372372
status_t Tab::add(Widget *widget)

0 commit comments

Comments
 (0)