mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
Update the calculation of the drawing area
This commit is contained in:
@@ -289,16 +289,18 @@ LCUI_API int Widget_SetId( LCUI_Widget w, const char *idstr );
|
||||
LCUI_API void Widget_SetBorder( LCUI_Widget w, int width, int style, LCUI_Color clr );
|
||||
|
||||
/** 设置内边距 */
|
||||
LCUI_API void Widget_SetPadding( LCUI_Widget w, int top, int right, int bottom, int left );
|
||||
LCUI_API void Widget_SetPadding( LCUI_Widget w, float top, float right,
|
||||
float bottom, float left );
|
||||
|
||||
/** 设置外边距 */
|
||||
LCUI_API void Widget_SetMargin( LCUI_Widget w, int top, int right, int bottom, int left );
|
||||
LCUI_API void Widget_SetMargin( LCUI_Widget w, float top, float right,
|
||||
float bottom, float left );
|
||||
|
||||
/** 移动部件位置 */
|
||||
LCUI_API void Widget_Move( LCUI_Widget w, int left, int top );
|
||||
LCUI_API void Widget_Move( LCUI_Widget w, float left, float top );
|
||||
|
||||
/** 调整部件尺寸 */
|
||||
LCUI_API void Widget_Resize( LCUI_Widget w, int width, int height );
|
||||
LCUI_API void Widget_Resize( LCUI_Widget w, float width, float height );
|
||||
|
||||
LCUI_API void Widget_Show( LCUI_Widget w );
|
||||
|
||||
|
||||
@@ -77,6 +77,10 @@ LCUI_API LCUI_BOOL LCUIRect_GetOverlayRect( const LCUI_Rect *a,
|
||||
const LCUI_Rect *b,
|
||||
LCUI_Rect *out );
|
||||
|
||||
LCUI_API LCUI_BOOL LCUIRectF_GetOverlayRect( const LCUI_RectF *a,
|
||||
const LCUI_RectF *b,
|
||||
LCUI_RectF *out );
|
||||
|
||||
/** 合并两个矩形 */
|
||||
LCUI_API void LCUIRect_MergeRect( LCUI_Rect *big, LCUI_Rect *a, LCUI_Rect *b );
|
||||
|
||||
|
||||
+8
-6
@@ -120,8 +120,9 @@ static void LCUIDisplay_Update(void)
|
||||
continue;
|
||||
}
|
||||
DEBUG_MSG( "[%s]: render rect: (%d,%d,%d,%d)\n",
|
||||
p_sr->widget->type, paint->rect.left,
|
||||
paint->rect.top, paint->rect.width, paint->rect.height );
|
||||
p_sr->widget->type,
|
||||
paint->rect.x, paint->rect.y,
|
||||
paint->rect.width, paint->rect.height );
|
||||
Widget_Render( p_sr->widget, paint );
|
||||
if( display.show_rect_border ) {
|
||||
DrawBorder( paint );
|
||||
@@ -579,12 +580,13 @@ static void OnResize( LCUI_Event e, void *arg )
|
||||
{
|
||||
LCUI_Widget widget;
|
||||
LCUI_DisplayEvent dpy_ev = arg;
|
||||
float width = (float)( dpy_ev->resize.width );
|
||||
float height = (float)( dpy_ev->resize.height );
|
||||
LOG( "[display] resize: (%.2f,%.2f)\n", width, height );
|
||||
widget = LCUIDisplay_GetBindWidget( dpy_ev->surface );
|
||||
LOG( "[display] resize: (%d,%d)\n", dpy_ev->resize.width, dpy_ev->resize.height );
|
||||
if( !widget ) {
|
||||
return;
|
||||
if( widget ) {
|
||||
Widget_Resize( widget, width, height );
|
||||
}
|
||||
Widget_Resize( widget, dpy_ev->resize.width, dpy_ev->resize.height );
|
||||
}
|
||||
|
||||
int LCUIDisplay_BindEvent( int event_id,
|
||||
|
||||
@@ -1414,7 +1414,7 @@ void Widget_SetBorder( LCUI_Widget w, int width, int style, LCUI_Color clr )
|
||||
Widget_UpdateStyle( w, FALSE );
|
||||
}
|
||||
|
||||
void Widget_SetPadding( LCUI_Widget w, int top, int right, int bottom, int left )
|
||||
void Widget_SetPadding( LCUI_Widget w, float top, float right, float bottom, float left )
|
||||
{
|
||||
Widget_SetStyle( w, key_padding_top, top, px );
|
||||
Widget_SetStyle( w, key_padding_right, right, px );
|
||||
@@ -1423,7 +1423,7 @@ void Widget_SetPadding( LCUI_Widget w, int top, int right, int bottom, int left
|
||||
Widget_UpdateStyle( w, FALSE );
|
||||
}
|
||||
|
||||
void Widget_SetMargin( LCUI_Widget w, int top, int right, int bottom, int left )
|
||||
void Widget_SetMargin( LCUI_Widget w, float top, float right, float bottom, float left )
|
||||
{
|
||||
Widget_SetStyle( w, key_margin_top, top, px );
|
||||
Widget_SetStyle( w, key_margin_right, right, px );
|
||||
@@ -1432,7 +1432,7 @@ void Widget_SetMargin( LCUI_Widget w, int top, int right, int bottom, int left )
|
||||
Widget_UpdateStyle( w, FALSE );
|
||||
}
|
||||
|
||||
void Widget_Move( LCUI_Widget w, int left, int top )
|
||||
void Widget_Move( LCUI_Widget w, float left, float top )
|
||||
{
|
||||
SetStyle( w->custom_style, key_top, top, px );
|
||||
SetStyle( w->custom_style, key_left, left, px );
|
||||
@@ -1440,7 +1440,7 @@ void Widget_Move( LCUI_Widget w, int left, int top )
|
||||
Widget_UpdateStyle( w, FALSE );
|
||||
}
|
||||
|
||||
void Widget_Resize( LCUI_Widget w, int width, int height )
|
||||
void Widget_Resize( LCUI_Widget w, float width, float height )
|
||||
{
|
||||
SetStyle( w->custom_style, key_width, width, px );
|
||||
SetStyle( w->custom_style, key_height, height, px );
|
||||
|
||||
+35
-32
@@ -79,15 +79,16 @@ static void Widget_AdjustArea( LCUI_Widget w, LCUI_Rect *in_rect,
|
||||
/* 如果为NULL,则视为使用整个部件区域 */
|
||||
if( !in_rect ) {
|
||||
out_rect->x = out_rect->y = 0;
|
||||
out_rect->width = box->width;
|
||||
out_rect->height = box->height;
|
||||
out_rect->width = roundi( box->width );
|
||||
out_rect->height = roundi( box->height );
|
||||
} else {
|
||||
*out_rect = *in_rect;
|
||||
LCUIRect_ValidateArea( out_rect, box->width, box->height );
|
||||
LCUIRect_ValidateArea( out_rect, roundi( box->width ),
|
||||
roundi( box->height ) );
|
||||
}
|
||||
/* 将坐标转换成相对于图像呈现区的坐标 */
|
||||
out_rect->x += (box->x - w->box.graph.x);
|
||||
out_rect->y += (box->y - w->box.graph.y);
|
||||
out_rect->x += roundi( box->x - w->box.graph.x );
|
||||
out_rect->y += roundi( box->y - w->box.graph.y );
|
||||
}
|
||||
|
||||
void Widget_InvalidateArea( LCUI_Widget w, LCUI_Rect *r, int box_type )
|
||||
@@ -115,8 +116,8 @@ LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget,
|
||||
rect.x += w->box.graph.x;
|
||||
rect.y += w->box.graph.y;
|
||||
while( w && w->parent ) {
|
||||
int width = w->parent->box.padding.width;
|
||||
int height = w->parent->box.padding.height;
|
||||
int width = roundi( w->parent->box.padding.width );
|
||||
int height = roundi( w->parent->box.padding.height );
|
||||
LCUIRect_ValidateArea( &rect, width, height );
|
||||
if( rect.width < 0 || rect.height < 0 ) {
|
||||
return FALSE;
|
||||
@@ -188,16 +189,17 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint )
|
||||
* @param[out] rlist 收集到的无效区域列表
|
||||
*/
|
||||
static int _Widget_ProcInvalidArea( LCUI_Widget w, float x, float y,
|
||||
LCUI_Rect *valid_box,
|
||||
LCUI_RectF *valid_box,
|
||||
LinkedList *rlist )
|
||||
{
|
||||
int count;
|
||||
LCUI_Widget child;
|
||||
LinkedListNode *node;
|
||||
LCUI_Rect child_box, rect;
|
||||
LCUI_RectF child_box;
|
||||
count = w->dirty_rects.length;
|
||||
/* 取出当前记录的无效区域 */
|
||||
for( LinkedList_Each( node, &w->dirty_rects ) ) {
|
||||
LCUI_Rect rect;
|
||||
LCUI_Rect *r = node->data;
|
||||
/* 若有独立位图缓存,则重绘脏矩形区域 */
|
||||
if( w->enable_graph && Graph_IsValid( &w->graph ) ) {
|
||||
@@ -206,11 +208,12 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, float x, float y,
|
||||
Graph_Quote( &paint.canvas, &w->graph, &paint.rect );
|
||||
Widget_OnPaint( w, &paint );
|
||||
}
|
||||
RectF2Rect( *valid_box, rect );
|
||||
/* 取出与容器内有效区域相交的区域 */
|
||||
if( LCUIRect_GetOverlayRect( r, valid_box, &rect ) ) {
|
||||
if( LCUIRect_GetOverlayRect( r, &rect, &rect ) ) {
|
||||
/* 转换成绝对坐标 */
|
||||
rect.x += x;
|
||||
rect.y += y;
|
||||
rect.x = roundi( rect.x + x );
|
||||
rect.y = roundi( rect.y + y );
|
||||
RectList_Add( rlist, &rect );
|
||||
}
|
||||
}
|
||||
@@ -232,20 +235,20 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, float x, float y,
|
||||
}
|
||||
child_x = child->box.graph.x + x;
|
||||
child_y = child->box.graph.y + y;
|
||||
RectF2Rect( child->box.graph, child_box );
|
||||
child_box = child->box.graph;
|
||||
/* 部件坐标是相对于内容框的,所以加上内容框XY坐标 */
|
||||
child_box.x += w->box.padding.x - w->box.graph.x;
|
||||
child_box.y += w->box.padding.y - w->box.graph.y;
|
||||
/* 若有效框与子部件没有重叠区域,则不向子级部件递归 */
|
||||
if( !LCUIRect_GetOverlayRect( valid_box, &child_box,
|
||||
&child_box ) ) {
|
||||
if( !LCUIRectF_GetOverlayRect( valid_box, &child_box,
|
||||
&child_box ) ) {
|
||||
continue;
|
||||
}
|
||||
/* 转换为相对于子部件的坐标 */
|
||||
child_box.x -= (int)(child->box.graph.x + w->box.padding.x -
|
||||
w->box.graph.x + 0.5);
|
||||
child_box.y -= (int)(child->box.graph.y + w->box.padding.y -
|
||||
w->box.graph.y + 0.5);
|
||||
child_box.x -= child->box.graph.x;
|
||||
child_box.y -= child->box.graph.y;
|
||||
child_box.x -= w->box.padding.x - w->box.graph.x;
|
||||
child_box.y -= w->box.padding.y - w->box.graph.y;
|
||||
count += _Widget_ProcInvalidArea( child, child_x, child_y,
|
||||
&child_box, rlist );
|
||||
}
|
||||
@@ -255,8 +258,8 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, float x, float y,
|
||||
|
||||
int Widget_ProcInvalidArea( LCUI_Widget w, LinkedList *rlist )
|
||||
{
|
||||
LCUI_Rect valid_box;
|
||||
RectF2Rect( w->box.graph, valid_box );
|
||||
LCUI_RectF valid_box;
|
||||
valid_box = w->box.graph;
|
||||
valid_box.x = valid_box.y = 0;
|
||||
return _Widget_ProcInvalidArea( w, 0, 0, &valid_box, rlist );
|
||||
}
|
||||
@@ -366,10 +369,10 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint )
|
||||
content_left = w->box.padding.x - w->box.graph.x;
|
||||
content_top = w->box.padding.y - w->box.graph.y;
|
||||
/* 获取内容框 */
|
||||
content_rect.x = content_left;
|
||||
content_rect.y = content_top;
|
||||
content_rect.width = w->box.padding.width;
|
||||
content_rect.height = w->box.padding.height;
|
||||
content_rect.x = roundi( content_left );
|
||||
content_rect.y = roundi( content_top );
|
||||
content_rect.width = roundi( w->box.padding.width );
|
||||
content_rect.height = roundi( w->box.padding.height );
|
||||
/* 获取内容框与脏矩形重叠的区域 */
|
||||
has_overlay = LCUIRect_GetOverlayRect(
|
||||
&content_rect, &paint->rect, &content_rect
|
||||
@@ -401,10 +404,10 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint )
|
||||
continue;
|
||||
}
|
||||
/* 转换子部件区域,由相对于内容框转换为相对于当前脏矩形 */
|
||||
child_rect.x = (int)(child->box.graph.x + content_left + 0.5);
|
||||
child_rect.y = (int)(child->box.graph.y + content_top + 0.5);
|
||||
child_rect.width = (int)(child->box.graph.width + 0.5);
|
||||
child_rect.height = (int)(child->box.graph.height + 0.5);
|
||||
child_rect.x = roundi( child->box.graph.x + content_left );
|
||||
child_rect.y = roundi( child->box.graph.y + content_top );
|
||||
child_rect.width = roundi( child->box.graph.width );
|
||||
child_rect.height = roundi( child->box.graph.height );
|
||||
child_rect.x -= paint->rect.x;
|
||||
child_rect.y -= paint->rect.y;
|
||||
/* 获取与内容框重叠的区域,作为子部件的绘制区域 */
|
||||
@@ -423,9 +426,9 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint )
|
||||
/* 将绘制区域转换为相对于子部件 */
|
||||
child_paint.rect.x -= child_rect.x;
|
||||
child_paint.rect.y -= child_rect.y;
|
||||
DEBUG_MSG("[%s]: canvas_rect:(%d,%d,%d,%d)\n", w->type,
|
||||
canvas_rect.left, canvas_rect.top,
|
||||
canvas_rect.width, canvas_rect.height);
|
||||
DEBUG_MSG( "[%s]: canvas_rect:(%d,%d,%d,%d)\n", w->type,
|
||||
canvas_rect.x, canvas_rect.y,
|
||||
canvas_rect.width, canvas_rect.height );
|
||||
/* 在内容位图中引用所需的区域,作为子部件的画布 */
|
||||
Graph_Quote( &child_paint.canvas, &content_graph, &canvas_rect );
|
||||
Widget_Render( child, &child_paint );
|
||||
|
||||
@@ -184,6 +184,46 @@ LCUI_BOOL LCUIRect_GetOverlayRect( const LCUI_Rect *a,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LCUI_BOOL LCUIRectF_GetOverlayRect( const LCUI_RectF *a,
|
||||
const LCUI_RectF *b,
|
||||
LCUI_RectF *out )
|
||||
{
|
||||
if( a->x > b->x ) {
|
||||
if( b->x + b->width > a->x + a->width ) {
|
||||
out->width = a->width;
|
||||
} else {
|
||||
out->width = b->x + b->width - a->x;
|
||||
}
|
||||
out->x = a->x;
|
||||
} else {
|
||||
if( a->x + a->width > b->x + b->width ) {
|
||||
out->width = b->width;
|
||||
} else {
|
||||
out->width = a->x + a->width - b->x;
|
||||
}
|
||||
out->x = b->x;
|
||||
}
|
||||
if( a->y > b->y ) {
|
||||
if( b->y + b->height > a->y + a->height ) {
|
||||
out->height = a->height;
|
||||
} else {
|
||||
out->height = b->y + b->height - a->y;
|
||||
}
|
||||
out->y = a->y;
|
||||
} else {
|
||||
if( a->y + a->height > b->y + b->height ) {
|
||||
out->height = b->height;
|
||||
} else {
|
||||
out->height = a->y + a->height - b->y;
|
||||
}
|
||||
out->y = b->y;
|
||||
}
|
||||
if( out->width <= 0 || out->height <= 0 ) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void LCUIRect_MergeRect( LCUI_Rect *big, LCUI_Rect *a, LCUI_Rect *b )
|
||||
{
|
||||
if( a->x < b->x ) {
|
||||
|
||||
Reference in New Issue
Block a user