From 3b2fa43bb7362fdfd879caa6b25e6b62e5317382 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 13 Mar 2013 18:26:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9F=A9=E5=BD=A2=E5=A1=AB?= =?UTF-8?q?=E5=85=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI_Graph.h | 6 ++++- src/LCUI_Graph.c | 51 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/include/LCUI/LCUI_Graph.h b/include/LCUI/LCUI_Graph.h index f2aabe16..8f8f5972 100755 --- a/include/LCUI/LCUI_Graph.h +++ b/include/LCUI/LCUI_Graph.h @@ -201,8 +201,12 @@ Graph_Cut( LCUI_Graph *src, LCUI_Rect rect, LCUI_Graph *out ); /* 将图像进行水平翻转 */ LCUI_EXPORT(int) Graph_HorizFlip( LCUI_Graph *src, LCUI_Graph *out ); + +/* 填充矩形 */ +LCUI_EXPORT(int) +Graph_FillRect( LCUI_Graph *graph, LCUI_RGB color, LCUI_Rect rect ); -/* 为传入的图形填充颜色 */ +/* 填充颜色 */ LCUI_EXPORT(int) Graph_FillColor( LCUI_Graph *graph, LCUI_RGB color ); diff --git a/src/LCUI_Graph.c b/src/LCUI_Graph.c index bd03e15f..8cc4cb67 100755 --- a/src/LCUI_Graph.c +++ b/src/LCUI_Graph.c @@ -759,9 +759,58 @@ Graph_HorizFlip( LCUI_Graph *src, LCUI_Graph *out ) return 0; } -/* 为传入的图形填充颜色 */ +/* 填充矩形 */ +LCUI_EXPORT(int) +Graph_FillRect( LCUI_Graph *graph, LCUI_RGB color, LCUI_Rect rect ) +{ + int pos, i, size; + LCUI_Rect src_rect; + uchar_t *r_ptr, *g_ptr, *b_ptr; + + src_rect = Graph_GetValidRect( graph ); + graph = Graph_GetQuote( graph ); + + if(! Graph_IsValid(graph) ) { + return -1; + } + rect.x = rect.x + src_rect.x; + rect.y = rect.y + src_rect.y; + + if( rect.x < src_rect.x ) { + rect.width -= (src_rect.x-rect.x); + rect.x = src_rect.x; + } + if( rect.x + rect.width > src_rect.x + src_rect.width ) { + rect.width = src_rect.x + src_rect.width - rect.x; + } + + if( rect.y < src_rect.y ) { + rect.height -= (src_rect.y-rect.y); + rect.y = src_rect.y; + } + if( rect.y + rect.height > src_rect.x + src_rect.height ) { + rect.height = src_rect.y + src_rect.height - rect.y; + } + + size = sizeof(uchar_t) * rect.width; + pos = rect.x + rect.y * graph->width; + r_ptr = graph->rgba[0] + pos; + g_ptr = graph->rgba[1] + pos; + b_ptr = graph->rgba[2] + pos; + for(i=0; iwidth; + g_ptr += graph->width; + b_ptr += graph->width; + } + return 0; +} + LCUI_EXPORT(int) Graph_FillColor( LCUI_Graph *graph, LCUI_RGB color ) +/* 填充颜色 */ { int i, pos; size_t size;