Skip to content

Commit f8b0f8b

Browse files
committed
fix(renderer): widget content rendering incorrect
1 parent 5164955 commit f8b0f8b

File tree

1 file changed

+58
-83
lines changed

1 file changed

+58
-83
lines changed

src/gui/widget_paint.c

+58-83
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ typedef struct LCUI_WidgetRendererRec_ {
9595
LCUI_BOOL has_content_graph;
9696
LCUI_BOOL has_self_graph;
9797
LCUI_BOOL has_layer_graph;
98-
LCUI_BOOL is_cover_border;
9998
LCUI_BOOL can_render_self;
10099
LCUI_BOOL can_render_centent;
101100
} LCUI_WidgetRendererRec, *LCUI_WidgetRenderer;
@@ -120,6 +119,14 @@ static LCUI_BOOL Widget_IsPaintable(LCUI_Widget w)
120119
return w->proto && w->proto->paint;
121120
}
122121

122+
static LCUI_BOOL Widget_HasRoundBorder(LCUI_Widget w)
123+
{
124+
const LCUI_BorderStyle *s = &w->computed_style.border;
125+
126+
return s->top_left_radius || s->top_right_radius ||
127+
s->bottom_left_radius || s->bottom_right_radius;
128+
}
129+
123130
/**
124131
* 根据所处框区域,调整矩形
125132
* @param[in] w 目标部件
@@ -334,7 +341,6 @@ static LCUI_WidgetRenderer WidgetRenderer(LCUI_Widget w,
334341
that->target = w;
335342
that->style = style;
336343
that->paint = paint;
337-
that->is_cover_border = FALSE;
338344
that->has_self_graph = FALSE;
339345
that->has_layer_graph = FALSE;
340346
that->has_content_graph = FALSE;
@@ -350,14 +356,8 @@ static LCUI_WidgetRenderer WidgetRenderer(LCUI_Widget w,
350356
that->has_self_graph = TRUE;
351357
that->has_content_graph = TRUE;
352358
that->has_layer_graph = TRUE;
353-
} else {
354-
/* if target has rounded corners border...
355-
...
356-
if( ... ) {
357-
that->has_content_graph = TRUE;
358-
that->is_cover_border = TRUE;
359-
}
360-
*/
359+
} else if (Widget_HasRoundBorder(w)) {
360+
that->has_content_graph = TRUE;
361361
}
362362
Graph_Init(&that->self_graph);
363363
Graph_Init(&that->layer_graph);
@@ -479,7 +479,7 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
479479
LCUI_Rect paint_rect;
480480
LCUI_RectF child_rect;
481481
LinkedListNode *node;
482-
LCUI_PaintContextRec paint;
482+
LCUI_PaintContextRec child_paint;
483483
LCUI_WidgetRenderer renderer;
484484
LCUI_WidgetActualStyleRec style;
485485

@@ -529,69 +529,40 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
529529
++count;
530530
Widget_ComputeActualPaddingBox(child, &style);
531531
Widget_ComputeActualContentBox(child, &style);
532+
child_paint.rect = paint_rect;
533+
child_paint.rect.x -= style.canvas_box.x;
534+
child_paint.rect.y -= style.canvas_box.y;
532535
if (that->has_content_graph) {
533-
paint.with_alpha = TRUE;
536+
child_paint.with_alpha = TRUE;
537+
paint_rect.x -= that->actual_content_rect.x;
538+
paint_rect.y -= that->actual_content_rect.y;
539+
Graph_Quote(&child_paint.canvas, &that->content_graph,
540+
&paint_rect);
534541
} else {
535-
paint.with_alpha = that->paint->with_alpha;
542+
child_paint.with_alpha = that->paint->with_alpha;
543+
paint_rect.x -= that->actual_paint_rect.x;
544+
paint_rect.y -= that->actual_paint_rect.y;
545+
Graph_Quote(&child_paint.canvas,
546+
&that->paint->canvas, &paint_rect);
536547
}
537-
paint.rect = paint_rect;
538-
/* 转换绘制区域坐标为相对于自身图层区域 */
539-
paint.rect.x -= style.canvas_box.x;
540-
paint.rect.y -= style.canvas_box.y;
541-
/* 转换绘制区域坐标为相对于部件内容区域,作为子部件的绘制区域 */
542-
paint_rect.x -= that->root_paint->rect.x;
543-
paint_rect.y -= that->root_paint->rect.y;
544-
DEBUG_MSG("root paint rect: (%d, %d, %d, %d)\n",
545-
that->root_paint->rect.x, that->root_paint->rect.y,
546-
that->root_paint->rect.width,
547-
that->root_paint->rect.height);
548548
DEBUG_MSG("child paint rect: (%d, %d, %d, %d)\n", paint_rect.x,
549549
paint_rect.y, paint_rect.width, paint_rect.height);
550-
Graph_Quote(&paint.canvas, &that->root_paint->canvas,
551-
&paint_rect);
552-
renderer = WidgetRenderer(child, &paint, &style, that);
550+
renderer = WidgetRenderer(child, &child_paint, &style, that);
553551
total += WidgetRenderer_Render(renderer);
554552
WidgetRenderer_Delete(renderer);
555553
}
556554
return total;
557555
}
558556

559-
static size_t WidgetRenderer_RenderContent(LCUI_WidgetRenderer that)
560-
{
561-
size_t count;
562-
LCUI_PaintContextRec paint;
563-
LCUI_WidgetRenderer renderer = that;
564-
LCUI_WidgetActualStyleRec style;
565-
566-
if (!that->can_render_centent) {
567-
return 0;
568-
}
569-
if (that->has_content_graph) {
570-
/* create a render context and it's render rectangle is relative
571-
* to this widget canvas */
572-
style.x = that->style->x - that->style->canvas_box.x;
573-
style.y = that->style->y - that->style->canvas_box.y;
574-
paint.rect = that->actual_content_rect;
575-
paint.rect.x -= that->style->canvas_box.x;
576-
paint.rect.y -= that->style->canvas_box.y;
577-
Widget_ComputeActualBorderBox(that->target, &style);
578-
Widget_ComputeActualCanvasBox(that->target, &style);
579-
Widget_ComputeActualPaddingBox(that->target, &style);
580-
Widget_ComputeActualContentBox(that->target, &style);
581-
Graph_Quote(&paint.canvas, &that->content_graph, NULL);
582-
renderer = WidgetRenderer(that->target, &paint, &style, NULL);
583-
count = WidgetRenderer_RenderChildren(renderer);
584-
WidgetRenderer_Delete(renderer);
585-
return count;
586-
}
587-
return WidgetRenderer_RenderChildren(renderer);
588-
}
589-
590557
static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
591558
{
592559
size_t count = 0;
593560
LCUI_PaintContextRec self_paint;
594561
LCUI_WidgetRenderer that = renderer;
562+
563+
int content_x = that->actual_content_rect.x - that->actual_paint_rect.x;
564+
int content_y = that->actual_content_rect.y - that->actual_paint_rect.y;
565+
595566
#ifdef DEBUG_FRAME_RENDER
596567
char filename[256];
597568
static size_t frame = 0;
@@ -606,10 +577,10 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
606577
Widget_OnPaint(that->target, &self_paint, that->style);
607578
#ifdef DEBUG_FRAME_RENDER
608579
sprintf(filename,
609-
"frame-%lu-%s-self-paint-(%d,%d,%d,%d)-L%d.png",
610-
frame++, renderer->target->id, self_paint.rect.x,
611-
self_paint.rect.y, self_paint.rect.width,
612-
self_paint.rect.height, __LINE__);
580+
"frame-%lu-L%d-%s-self-paint-(%d,%d,%d,%d).png",
581+
frame++, __LINE__, renderer->target->id,
582+
self_paint.rect.x, self_paint.rect.y,
583+
self_paint.rect.width, self_paint.rect.height);
613584
LCUI_WritePNGFile(filename, &self_paint.canvas);
614585
#endif
615586
/* 若不需要缓存自身位图则直接绘制到画布上 */
@@ -618,26 +589,26 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
618589
that->paint->with_alpha);
619590
#ifdef DEBUG_FRAME_RENDER
620591
Graph_PrintInfo(&that->paint->canvas);
621-
sprintf(filename, "frame-%lu-%s-canvas-L%d.png",
622-
frame++, renderer->target->id, __LINE__);
592+
sprintf(filename, "frame-%lu-L%d-%s-root-canvas.png",
593+
frame++, __LINE__, renderer->target->id);
623594
LCUI_WritePNGFile(filename, &that->root_paint->canvas);
624595
#endif
625596
}
626597
}
627-
count += WidgetRenderer_RenderContent(that);
628-
/* 如果与圆角边框重叠,则裁剪掉边框外的内容 */
629-
if (that->is_cover_border) {
630-
/* content_graph ... */
598+
if (that->can_render_centent) {
599+
count += WidgetRenderer_RenderChildren(that);
631600
}
632601
if (!that->has_layer_graph) {
633602
if (that->has_content_graph) {
634603
Graph_Mix(&that->paint->canvas, &that->content_graph,
635-
iround(that->content_left),
636-
iround(that->content_top), TRUE);
604+
content_x, content_y, TRUE);
637605
}
638606
#ifdef DEBUG_FRAME_RENDER
639-
sprintf(filename, "frame-%lu-%s-canvas-L%d.png", frame++,
640-
renderer->target->id, __LINE__);
607+
sprintf(filename, "frame-%lu-L%d-%s-canvas.png", frame++,
608+
__LINE__, renderer->target->id);
609+
LCUI_WritePNGFile(filename, &that->paint->canvas);
610+
sprintf(filename, "frame-%lu-L%d-%s-root-canvas.png", frame++,
611+
__LINE__, renderer->target->id);
641612
LCUI_WritePNGFile(filename, &that->root_paint->canvas);
642613
#endif
643614
DEBUG_MSG("[%d] %s: end render, count: %lu\n",
@@ -649,18 +620,22 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
649620
*/
650621
if (that->can_render_self) {
651622
Graph_Copy(&that->layer_graph, &that->self_graph);
652-
Graph_Mix(
653-
&that->layer_graph, &that->content_graph,
654-
that->actual_content_rect.x - that->actual_paint_rect.x,
655-
that->actual_content_rect.y - that->actual_paint_rect.y,
656-
TRUE);
623+
Graph_Mix(&that->layer_graph, &that->content_graph, content_x,
624+
content_y, TRUE);
625+
#ifdef DEBUG_FRAME_RENDER
626+
sprintf(filename, "frame-%lu-L%d-%s-content-grpah-%d-%d.png",
627+
frame++, __LINE__, renderer->target->id, content_x,
628+
content_y);
629+
LCUI_WritePNGFile(filename, &that->content_graph);
630+
sprintf(filename, "frame-%lu-L%d-%s-self-graph.png", frame++,
631+
__LINE__, renderer->target->id);
632+
LCUI_WritePNGFile(filename, &that->layer_graph);
633+
#endif
657634
} else {
658635
Graph_Create(&that->layer_graph, that->paint->rect.width,
659636
that->paint->rect.height);
660-
Graph_Replace(
661-
&that->layer_graph, &that->content_graph,
662-
that->actual_content_rect.x - that->actual_paint_rect.x,
663-
that->actual_content_rect.y - that->actual_paint_rect.y);
637+
Graph_Replace(&that->layer_graph, &that->content_graph,
638+
content_x, content_y);
664639
}
665640
that->layer_graph.opacity = that->target->computed_style.opacity;
666641
Graph_Mix(&that->paint->canvas, &that->layer_graph, 0, 0,
@@ -669,8 +644,8 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
669644
sprintf(filename, "frame-%lu-%s-layer.png", frame++,
670645
renderer->target->id);
671646
LCUI_WritePNGFile(filename, &that->layer_graph);
672-
sprintf(filename, "frame-%lu-%s-canvas-%d.png", frame++,
673-
renderer->target->id, __LINE__);
647+
sprintf(filename, "frame-%lu-L%d-%s-root-canvas.png", frame++, __LINE__,
648+
renderer->target->id);
674649
LCUI_WritePNGFile(filename, &that->root_paint->canvas);
675650
#endif
676651
DEBUG_MSG("[%d] %s: end render, count: %lu\n", that->target->index,

0 commit comments

Comments
 (0)