@@ -95,7 +95,6 @@ typedef struct LCUI_WidgetRendererRec_ {
95
95
LCUI_BOOL has_content_graph ;
96
96
LCUI_BOOL has_self_graph ;
97
97
LCUI_BOOL has_layer_graph ;
98
- LCUI_BOOL is_cover_border ;
99
98
LCUI_BOOL can_render_self ;
100
99
LCUI_BOOL can_render_centent ;
101
100
} LCUI_WidgetRendererRec , * LCUI_WidgetRenderer ;
@@ -120,6 +119,14 @@ static LCUI_BOOL Widget_IsPaintable(LCUI_Widget w)
120
119
return w -> proto && w -> proto -> paint ;
121
120
}
122
121
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
+
123
130
/**
124
131
* 根据所处框区域,调整矩形
125
132
* @param[in] w 目标部件
@@ -334,7 +341,6 @@ static LCUI_WidgetRenderer WidgetRenderer(LCUI_Widget w,
334
341
that -> target = w ;
335
342
that -> style = style ;
336
343
that -> paint = paint ;
337
- that -> is_cover_border = FALSE;
338
344
that -> has_self_graph = FALSE;
339
345
that -> has_layer_graph = FALSE;
340
346
that -> has_content_graph = FALSE;
@@ -350,14 +356,8 @@ static LCUI_WidgetRenderer WidgetRenderer(LCUI_Widget w,
350
356
that -> has_self_graph = TRUE;
351
357
that -> has_content_graph = TRUE;
352
358
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;
361
361
}
362
362
Graph_Init (& that -> self_graph );
363
363
Graph_Init (& that -> layer_graph );
@@ -479,7 +479,7 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
479
479
LCUI_Rect paint_rect ;
480
480
LCUI_RectF child_rect ;
481
481
LinkedListNode * node ;
482
- LCUI_PaintContextRec paint ;
482
+ LCUI_PaintContextRec child_paint ;
483
483
LCUI_WidgetRenderer renderer ;
484
484
LCUI_WidgetActualStyleRec style ;
485
485
@@ -529,69 +529,40 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
529
529
++ count ;
530
530
Widget_ComputeActualPaddingBox (child , & style );
531
531
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 ;
532
535
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 );
534
541
} 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 );
536
547
}
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 );
548
548
DEBUG_MSG ("child paint rect: (%d, %d, %d, %d)\n" , paint_rect .x ,
549
549
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 );
553
551
total += WidgetRenderer_Render (renderer );
554
552
WidgetRenderer_Delete (renderer );
555
553
}
556
554
return total ;
557
555
}
558
556
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
-
590
557
static size_t WidgetRenderer_Render (LCUI_WidgetRenderer renderer )
591
558
{
592
559
size_t count = 0 ;
593
560
LCUI_PaintContextRec self_paint ;
594
561
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
+
595
566
#ifdef DEBUG_FRAME_RENDER
596
567
char filename [256 ];
597
568
static size_t frame = 0 ;
@@ -606,10 +577,10 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
606
577
Widget_OnPaint (that -> target , & self_paint , that -> style );
607
578
#ifdef DEBUG_FRAME_RENDER
608
579
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 );
613
584
LCUI_WritePNGFile (filename , & self_paint .canvas );
614
585
#endif
615
586
/* 若不需要缓存自身位图则直接绘制到画布上 */
@@ -618,26 +589,26 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
618
589
that -> paint -> with_alpha );
619
590
#ifdef DEBUG_FRAME_RENDER
620
591
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 );
623
594
LCUI_WritePNGFile (filename , & that -> root_paint -> canvas );
624
595
#endif
625
596
}
626
597
}
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 );
631
600
}
632
601
if (!that -> has_layer_graph ) {
633
602
if (that -> has_content_graph ) {
634
603
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);
637
605
}
638
606
#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 );
641
612
LCUI_WritePNGFile (filename , & that -> root_paint -> canvas );
642
613
#endif
643
614
DEBUG_MSG ("[%d] %s: end render, count: %lu\n" ,
@@ -649,18 +620,22 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
649
620
*/
650
621
if (that -> can_render_self ) {
651
622
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
657
634
} else {
658
635
Graph_Create (& that -> layer_graph , that -> paint -> rect .width ,
659
636
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 );
664
639
}
665
640
that -> layer_graph .opacity = that -> target -> computed_style .opacity ;
666
641
Graph_Mix (& that -> paint -> canvas , & that -> layer_graph , 0 , 0 ,
@@ -669,8 +644,8 @@ static size_t WidgetRenderer_Render(LCUI_WidgetRenderer renderer)
669
644
sprintf (filename , "frame-%lu-%s-layer.png" , frame ++ ,
670
645
renderer -> target -> id );
671
646
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 );
674
649
LCUI_WritePNGFile (filename , & that -> root_paint -> canvas );
675
650
#endif
676
651
DEBUG_MSG ("[%d] %s: end render, count: %lu\n" , that -> target -> index ,
0 commit comments