From 80ceeab03427908a4e94db686708e94ac09fff85 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 1 Feb 2017 21:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=B5=AE=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E9=83=A8=E4=BB=B6=E7=9A=84=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E3=80=81=E5=B0=BA=E5=AF=B8=E7=AD=89=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E5=80=BC=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI.h | 34 +++--- include/LCUI/draw/background.h | 4 +- include/LCUI/graph.h | 14 +-- include/LCUI/gui/widget_base.h | 28 ++--- include/LCUI/util/rect.h | 23 ++-- src/bmp/png.c | 6 +- src/display.c | 60 ++++++---- src/draw/background.c | 36 +++--- src/draw/boxshadow.c | 136 +++++++++++----------- src/font/fontlibrary.c | 8 +- src/font/textlayer.c | 4 +- src/graph.c | 207 ++++++++++++++++----------------- src/gui/css_library.c | 2 +- src/gui/widget/textedit.c | 24 ++-- src/gui/widget/textview.c | 14 +-- src/gui/widget_base.c | 153 +++++++++++++----------- src/gui/widget_paint.c | 76 ++++++------ src/util/parse.c | 6 +- src/util/rect.c | 86 +++++++------- 19 files changed, 479 insertions(+), 442 deletions(-) diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 1b05fa36..3dc33059 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -2,7 +2,7 @@ * LCUI.h -- Records with common data type definitions, macro definitions and * function declarations * - * Copyright (C) 2012-2016 by Liu Chao + * Copyright (C) 2012-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -23,7 +23,7 @@ /* **************************************************************************** * LCUI.h -- 记录着常用的数据类型定义,宏定义,以及函数声明 * - * 版权所有 (C) 2012-2016 归属于 刘超 + * 版权所有 (C) 2012-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -105,19 +105,21 @@ typedef struct LCUI_Size_ { } LCUI_Size; typedef struct LCUI_Rect_ { - union { int x, left; }; - union { int y, top; }; - union { int w, width; }; - union { int h, height; }; + int x, y, width, height; } LCUI_Rect; typedef struct LCUI_Rect2_ { - union { int left, l; }; - union { int top, t; }; - union { int right, r; }; - union { int bottom, b; }; + int left, top, right, bottom; } LCUI_Rect2; +typedef struct LCUI_RectF_ { + float x, y, width, height; +} LCUI_RectF; + +typedef struct LCUI_Rect2F_ { + float left, top, right, bottom; +} LCUI_Rect2F; + /** 样式变量类型 */ typedef enum LCUI_StyleType { SVT_NONE, @@ -240,12 +242,12 @@ typedef struct LCUI_StyleRec_ { int val_int; int val_0; int val_none; - int px; - int val_px; - int pt; - int val_pt; - int dp; - int val_dp; + float px; + float val_px; + float pt; + float val_pt; + float dp; + float val_dp; int style; int val_style; float scale; diff --git a/include/LCUI/draw/background.h b/include/LCUI/draw/background.h index 7a62b289..1ffdb355 100644 --- a/include/LCUI/draw/background.h +++ b/include/LCUI/draw/background.h @@ -1,7 +1,7 @@ /* *************************************************************************** * background.h -- graph background image draw support. * - * Copyright (C) 2015-2016 by Liu Chao + * Copyright (C) 2015-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * background.h -- 背景图像绘制支持 * - * 版权所有 (C) 2015-2016 归属于 刘超 + * 版权所有 (C) 2015-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * diff --git a/include/LCUI/graph.h b/include/LCUI/graph.h index 6b63ff39..e06a1d81 100644 --- a/include/LCUI/graph.h +++ b/include/LCUI/graph.h @@ -1,7 +1,7 @@ /* *************************************************************************** * graph.h -- The base graphics handling module for LCUI * - * Copyright (C) 2012-2016 by Liu Chao + * Copyright (C) 2012-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * graph.h -- LCUI的基本图形处理模块 * - * 版权所有 (C) 2012-2016 归属于 刘超 + * 版权所有 (C) 2012-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -149,11 +149,11 @@ LCUI_API void Graph_Copy( LCUI_Graph *des, const LCUI_Graph *src ); LCUI_API void Graph_Free( LCUI_Graph *graph ); /** -* 为图像创建一个引用 -* @param self 用于存放图像引用的缓存区 -* @param source 引用的源图像 -* ¶m rect 引用的区域,若为NULL,则引用整个图像 -*/ + * 为图像创建一个引用 + * @param self 用于存放图像引用的缓存区 + * @param source 引用的源图像 + * ¶m rect 引用的区域,若为NULL,则引用整个图像 + */ LCUI_API int Graph_Quote( LCUI_Graph *self, LCUI_Graph *source, const LCUI_Rect *rect ); /** 判断图像是否有Alpha透明通道 */ diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index f9cb92e0..a75190a3 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -49,8 +49,8 @@ LCUI_BEGIN_HEADER typedef struct LCUI_WidgetStyle { LCUI_BOOL visible; /**< 是否可见 */ LCUI_BOOL focusable; /**< 是否能够得到焦点 */ - int left, top; /**< 左边界、顶边界的偏移距离 */ - int right, bottom; /**< 右边界、底边界的偏移距离 */ + float left, top; /**< 左边界、顶边界的偏移距离 */ + float right, bottom; /**< 右边界、底边界的偏移距离 */ int z_index; /**< 堆叠顺序,该值越高,部件显示得越靠前 */ float opacity; /**< 不透明度,有效范围从 0.0 (完全透明)到 1.0(完全不透明) */ LCUI_StyleValue position; /**< 定位方式 */ @@ -90,11 +90,11 @@ enum WidgetTaskType { }; typedef struct LCUI_WidgetBoxRect { - LCUI_Rect content; /**< 内容框的区域 */ - LCUI_Rect padding; /**< 内边距框的区域 */ - LCUI_Rect border; /**< 边框盒的区域,包括内边距框和内容框区域 */ - LCUI_Rect outer; /**< 外边距框的区域,包括边框盒和外边距框区域 */ - LCUI_Rect graph; /**< 图层的区域,包括边框盒和阴影区域 */ + LCUI_RectF content; /**< 内容框的区域 */ + LCUI_RectF padding; /**< 内边距框的区域 */ + LCUI_RectF border; /**< 边框盒的区域,包括内边距框和内容框区域 */ + LCUI_RectF outer; /**< 外边距框的区域,包括边框盒和外边距框区域 */ + LCUI_RectF graph; /**< 图层的区域,包括边框盒和阴影区域 */ } LCUI_WidgetBoxRect; typedef struct LCUI_WidgetTaskBoxRec_ { @@ -118,7 +118,7 @@ typedef struct LCUI_WidgetPrototypeRec_ *LCUI_WidgetPrototype; typedef const struct LCUI_WidgetPrototypeRec_ *LCUI_WidgetPrototypeC; typedef void( *LCUI_WidgetFunction )(LCUI_Widget); -typedef void( *LCUI_WidgetResizer )(LCUI_Widget, int*, int*); +typedef void( *LCUI_WidgetResizer )(LCUI_Widget, float*, float*); typedef void( *LCUI_WidgetAttrSetter )(LCUI_Widget, const char*, const char*); typedef void( *LCUI_WidgetTextSetter )(LCUI_Widget, const char*); typedef void( *LCUI_WidgetPainter )(LCUI_Widget, LCUI_PaintContext); @@ -162,17 +162,17 @@ typedef struct LCUI_WidgetAttributeRec_ { /** 部件结构 */ typedef struct LCUI_WidgetRec_ { int state; /**< 状态 */ - int x, y; /**< 当前坐标(由 origin 计算而来) */ - int origin_x, origin_y; /**< 当前布局下计算出的坐标 */ - int width, height; /**< 部件区域大小,包括边框和内边距占用区域 */ + float x, y; /**< 当前坐标(由 origin 计算而来) */ + float origin_x, origin_y; /**< 当前布局下计算出的坐标 */ + float width, height; /**< 部件区域大小,包括边框和内边距占用区域 */ int index; /**< 部件索引位置 */ char *id; /**< ID */ char *type; /**< 类型 */ char **classes; /**< 类列表 */ char **status; /**< 状态列表 */ wchar_t *title; /**< 标题 */ - LCUI_Rect2 padding; /**< 内边距框 */ - LCUI_Rect2 margin; /**< 外边距框 */ + LCUI_Rect2F padding; /**< 内边距框 */ + LCUI_Rect2F margin; /**< 外边距框 */ LCUI_WidgetBoxRect box; /**< 部件的各个区域信息 */ LCUI_StyleSheet style; /**< 当前完整样式表 */ LCUI_StyleSheet custom_style; /**< 自定义样式表 */ @@ -343,7 +343,7 @@ LCUI_API LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ); LCUI_API void Widget_SetDisabled( LCUI_Widget w, LCUI_BOOL disabled ); /** 计算部件的最大宽度 */ -LCUI_API int Widget_ComputeMaxWidth( LCUI_Widget w ); +LCUI_API float Widget_ComputeMaxWidth( LCUI_Widget w ); /** 锁定子部件的布局,让 LCUI 不自动更新布局 */ LCUI_API void Widget_LockLayout( LCUI_Widget w ); diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index 93f1e137..801c01a4 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -1,7 +1,7 @@ /* *************************************************************************** * rect.h -- Rectangle area handling * - * Copyright (C) 2012-2016 by Liu Chao + * Copyright (C) 2012-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * rect.h -- 矩形区域处理 * - * 版权所有 (C) 2012-2016 归属于 刘超 + * 版权所有 (C) 2012-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -42,6 +42,13 @@ LCUI_BEGIN_HEADER +#define RectF2Rect(rf, r) do { \ + (r).x = (int)((rf).x + 0.5); \ + (r).y = (int)((rf).y + 0.5); \ + (r).width = (int)((rf).width + 0.5); \ + (r).height = (int)((rf).height + 0.5); \ +} while( 0 ); + /* 将数值转换成LCUI_Rect型结构体 */ LCUI_API LCUI_Rect Rect( int x, int y, int w, int h ); @@ -76,14 +83,14 @@ LCUI_API void LCUIRect_MergeRect( LCUI_Rect *big, LCUI_Rect *a, LCUI_Rect *b ); /** * 根据重叠矩形 rect1,将矩形 rect2 分割成四个矩形 * 分割方法如下: - * ┏━━━━┳━━━━━━━━━━━┓ + * ┏━━┳━━━━━━┓ * ┃ ┃ 3 ┃ - * ┃ 0 ┣━━━━━━┳━━━━┃ - * ┃ ┃rect1 ┃ ┃ - * ┃ ┃ ┃ 2 ┃ - * ┣━━━━┻━━━━━━┫ ┃ + * ┃ 0 ┣━━━┳━━┃ + * ┃ ┃rect1 ┃ ┃ + * ┃ ┃ ┃ 2 ┃ + * ┣━━┻━━━┫ ┃ * ┃ 1 ┃ ┃ - * ┗━━━━━━━━━━━┻━━━━┛ + * ┗━━━━━━┻━━┛ * * rect2 必须被 rect1 完全包含 */ diff --git a/src/bmp/png.c b/src/bmp/png.c index 6404d13f..1faa66ec 100644 --- a/src/bmp/png.c +++ b/src/bmp/png.c @@ -252,7 +252,7 @@ int Graph_WritePNG( const char *file_name, const LCUI_Graph *graph ) LCUI_ARGB *px_ptr, *px_row_ptr; row_size = png_get_rowbytes( png_ptr, info_ptr ); - px_row_ptr = graph->argb + rect.top * graph->width + rect.left; + px_row_ptr = graph->argb + rect.y * graph->width + rect.x; row_pointers = (png_bytep*)malloc( rect.height*sizeof( png_bytep ) ); for( y = 0; y < rect.height; ++y ) { row_pointers[y] = png_malloc( png_ptr, row_size ); @@ -269,8 +269,8 @@ int Graph_WritePNG( const char *file_name, const LCUI_Graph *graph ) uchar_t *px_ptr, *px_row_ptr; row_size = png_get_rowbytes( png_ptr, info_ptr ); - px_row_ptr = graph->bytes + rect.top * graph->bytes_per_row; - px_row_ptr += rect.left * graph->bytes_per_pixel; + px_row_ptr = graph->bytes + rect.y * graph->bytes_per_row; + px_row_ptr += rect.x * graph->bytes_per_pixel; row_pointers = (png_bytep*)malloc( rect.height*sizeof( png_bytep ) ); for( y = 0; y < rect.height; ++y ) { row_pointers[y] = (png_bytep)malloc( row_size ); diff --git a/src/display.c b/src/display.c index 355291f2..dd1fd7d2 100644 --- a/src/display.c +++ b/src/display.c @@ -1,7 +1,7 @@ /* *************************************************************************** * display.c -- graphical display control * - * Copyright (C) 2012-2016 by Liu Chao + * Copyright (C) 2012-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * display.c -- 图形显示控制 * - * 版权所有 (C) 2012-2016 归属于 刘超 + * 版权所有 (C) 2012-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -121,7 +121,7 @@ static void LCUIDisplay_Update(void) } DEBUG_MSG( "[%s]: render rect: (%d,%d,%d,%d)\n", p_sr->widget->type, paint->rect.left, - paint->rect.top, paint->rect.w, paint->rect.h ); + paint->rect.top, paint->rect.width, paint->rect.height ); Widget_Render( p_sr->widget, paint ); if( display.show_rect_border ) { DrawBorder( paint ); @@ -182,28 +182,32 @@ LCUI_Surface LCUIDisplay_GetSurfaceOwner( LCUI_Widget w ) /** 将 widget 与 sruface 进行绑定 */ static void LCUIDisplay_BindSurface( LCUI_Widget widget ) { - LCUI_Rect *p_rect; - SurfaceRecord *p_sr; + LCUI_RectF *rect; + SurfaceRecord *sr; + int width, height; + if( LCUIDisplay_GetBindSurface(widget) ) { return; } - p_sr = NEW( SurfaceRecord, 1 ); - p_sr->widget = widget; - p_sr->surface = Surface_New(); - Surface_SetCaptionW( p_sr->surface, widget->title ); - p_rect = &widget->box.graph; + rect = &widget->box.graph; + sr = NEW( SurfaceRecord, 1 ); + sr->surface = Surface_New(); + sr->widget = widget; + Surface_SetCaptionW( sr->surface, widget->title ); if( widget->style->sheet[key_top].is_valid && widget->style->sheet[key_left].is_valid ) { - Surface_Move( p_sr->surface, p_rect->x, p_rect->y ); + Surface_Move( sr->surface, rect->x, rect->y ); } - Surface_Resize( p_sr->surface, p_rect->w, p_rect->h ); + width = (int)(rect->width + 0.5); + height = (int)(rect->height + 0.5); + Surface_Resize( sr->surface, width, height ); if( widget->computed_style.visible ) { - Surface_Show( p_sr->surface ); + Surface_Show( sr->surface ); } else { - Surface_Hide( p_sr->surface ); + Surface_Hide( sr->surface ); } Widget_InvalidateArea( widget, NULL, SV_GRAPH_BOX ); - LinkedList_Append( &display.surfaces, p_sr ); + LinkedList_Append( &display.surfaces, sr ); } /** 解除 widget 与 sruface 的绑定 */ @@ -492,7 +496,7 @@ static void OnSurfaceEvent( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) { int e_type; LCUI_Widget root; - LCUI_Rect *p_rect; + LCUI_RectF *rect; LCUI_Surface surface; e_type = *((int*)&arg); root = LCUIWidget_GetRoot(); @@ -508,7 +512,7 @@ static void OnSurfaceEvent( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) } else { return; } - p_rect = &e->target->box.graph; + rect = &e->target->box.graph; switch( e_type ) { case WET_ADD: LCUIDisplay_BindSurface( e->target ); @@ -528,21 +532,29 @@ static void OnSurfaceEvent( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) Surface_SetCaptionW( surface, e->target->title ); break; case WET_RESIZE: - DEBUG_MSG( "resize, w: %d, h: %d\n", p_rect->w, p_rect->h ); - Surface_Resize( surface, p_rect->w, p_rect->h ); + { + int width = (int)(rect->width + 0.5); + int height = (int)(rect->height + 0.5); + DEBUG_MSG( "resize, w: %d, h: %d\n", width, height ); + Surface_Resize( surface, width, height ); Widget_InvalidateArea( w, NULL, SV_GRAPH_BOX ); if( w == root && display.mode != LCDM_SEAMLESS ) { - LCUIDisplay_ExecResize( p_rect->w, p_rect->h ); + LCUIDisplay_ExecResize( width, height ); } break; + } case WET_MOVE: + { + int x = (int)(rect->x + 0.5); + int y = (int)(rect->y + 0.5); if( !w->style->sheet[key_top].is_valid || !w->style->sheet[key_left].is_valid ) { break; } - DEBUG_MSG( "x: %d, y: %d\n", p_rect->left, p_rect->top ); - Surface_Move( surface, p_rect->left, p_rect->top ); + DEBUG_MSG( "x: %d, y: %d\n", x, y ); + Surface_Move( surface, x, y ); break; + } default: break; } } @@ -568,13 +580,15 @@ static void OnResize( LCUI_Event e, void *arg ) LCUI_Widget widget; LCUI_DisplayEvent dpy_ev = arg; widget = LCUIDisplay_GetBindWidget( dpy_ev->surface ); + LOG( "[display] resize: (%d,%d)\n", dpy_ev->resize.width, dpy_ev->resize.height ); if( !widget ) { return; } Widget_Resize( widget, dpy_ev->resize.width, dpy_ev->resize.height ); } -int LCUIDisplay_BindEvent( int event_id, LCUI_EventFunc func, void *arg, +int LCUIDisplay_BindEvent( int event_id, + LCUI_EventFunc func, void *arg, void *data, void( *destroy_data )(void*) ) { if( display.is_working ) { diff --git a/src/draw/background.c b/src/draw/background.c index 049e4bd4..bd33674e 100644 --- a/src/draw/background.c +++ b/src/draw/background.c @@ -1,7 +1,7 @@ /* *************************************************************************** * background.c -- graph background image draw support. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * background.c -- 背景图像绘制支持 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -92,7 +92,7 @@ void Graph_DrawBackground( LCUI_PaintContext paint, const LCUI_Rect *box, } else { switch( bg->size.w.type ) { case SVT_SCALE: - image_w = box->w * bg->size.w.scale; + image_w = box->width * bg->size.w.scale; break; case SVT_PX: image_w = bg->size.w.px; @@ -103,7 +103,7 @@ void Graph_DrawBackground( LCUI_PaintContext paint, const LCUI_Rect *box, } switch( bg->size.h.type ) { case SVT_SCALE: - image_h = box->h * bg->size.h.scale; + image_h = box->height * bg->size.h.scale; break; case SVT_PX: image_h = bg->size.h.px; @@ -118,37 +118,37 @@ void Graph_DrawBackground( LCUI_PaintContext paint, const LCUI_Rect *box, switch( bg->position.value ) { case SV_TOP: case SV_TOP_CENTER: - image_x = (box->w - image_w) / 2; + image_x = (box->width - image_w) / 2; image_y = 0; break; case SV_TOP_RIGHT: - image_x = box->w - image_w; + image_x = box->width - image_w; image_y = 0; break; case SV_CENTER_LEFT: image_x = 0; - image_y = (box->h - image_h) / 2; + image_y = (box->height - image_h) / 2; break; case SV_CENTER: case SV_CENTER_CENTER: - image_x = (box->w - image_w) / 2; - image_y = (box->h - image_h) / 2; + image_x = (box->width - image_w) / 2; + image_y = (box->height - image_h) / 2; break; case SV_CENTER_RIGHT: - image_x = box->w - image_w; - image_y = (box->h - image_h) / 2; + image_x = box->width - image_w; + image_y = (box->height - image_h) / 2; break; case SV_BOTTOM_LEFT: image_x = 0; - image_y = box->h - image_h; + image_y = box->height - image_h; break; case SV_BOTTOM_CENTER: - image_x = (box->w - image_w) / 2; - image_y = box->h - image_h; + image_x = (box->width - image_w) / 2; + image_y = box->height - image_h; break; case SV_BOTTOM_RIGHT: - image_x = box->w - image_w; - image_y = box->h - image_h; + image_x = box->width - image_w; + image_y = box->height - image_h; break; case SV_TOP_LEFT: default:image_x = image_y = 0; break; @@ -156,7 +156,7 @@ void Graph_DrawBackground( LCUI_PaintContext paint, const LCUI_Rect *box, } else { switch( bg->position.x.type ) { case SVT_SCALE: - image_x = box->w - image_w; + image_x = box->width - image_w; image_x *= bg->position.x.scale; break; case SVT_PX: @@ -166,7 +166,7 @@ void Graph_DrawBackground( LCUI_PaintContext paint, const LCUI_Rect *box, } switch( bg->position.y.type ) { case SVT_SCALE: - image_y = box->h - image_h; + image_y = box->height - image_h; image_y *= bg->position.y.scale; break; case SVT_PX: diff --git a/src/draw/boxshadow.c b/src/draw/boxshadow.c index 7de53d4e..4c94ae33 100644 --- a/src/draw/boxshadow.c +++ b/src/draw/boxshadow.c @@ -1,7 +1,7 @@ /* **************************************************************************** * boxshadow.c -- graph box shadow draw support. * -* Copyright (C) 2014-2016 by Liu Chao +* Copyright (C) 2014-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * boxshadow.c -- 矩形阴影绘制支持 * -* 版权所有 (C) 2014-2016 归属于 刘超 +* 版权所有 (C) 2014-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -167,34 +167,34 @@ static void DrawCircle( LCUI_Graph *graph, LCUI_Pos center, src = Graph_GetQuote( graph ); center.x += area.x; center.y += area.y; - circle.r = center.x + r; - circle.l = center.x - r; - circle.b = center.y + r; - circle.t = center.y - r; + circle.right = center.x + r; + circle.left = center.x - r; + circle.bottom = center.y + r; + circle.top = center.y - r; /* 先填充 圆外切矩形 外的矩形区域 */ box_rect.x = area.x; box_rect.y = area.y; - box_rect.w = area.w; - box_rect.h = circle.t - area.y; + box_rect.width = area.width; + box_rect.height = circle.top - area.y; Graph_Quote( &box_graph, src, &box_rect ); Graph_FillAlpha( &box_graph, 0 ); - box_rect.y = circle.t; - box_rect.w = circle.l - area.x; - box_rect.h = area.y + area.h - circle.t; + box_rect.y = circle.top; + box_rect.width = circle.left - area.x; + box_rect.height = area.y + area.height - circle.top; Graph_Quote( &box_graph, src, &box_rect ); Graph_FillAlpha( &box_graph, 0 ); /* 调整圆的区域 */ - if( circle.l < area.x ) { - circle.l = area.x; + if( circle.left < area.x ) { + circle.left = area.x; } - if( circle.t < area.y ) { - circle.t = area.y; + if( circle.top < area.y ) { + circle.top = area.y; } - if( circle.r > area.x + area.w ) { - circle.r = area.x + area.w; + if( circle.right > area.x + area.width ) { + circle.right = area.x + area.width; } - if( circle.b > area.y + area.h ) { - circle.b = area.y + area.h; + if( circle.bottom > area.y + area.height ) { + circle.bottom = area.y + area.height; } if( src->color_type != COLOR_TYPE_ARGB ) { return; @@ -226,7 +226,7 @@ static void Graph_DrawTopLeftShadow( LCUI_PaintContext paint, LCUI_Rect *box, LCUI_Pos pos; LCUI_Rect bound; LCUI_Graph canvas; - bound.w = bound.h = BLUR_WIDTH(shadow); + bound.width = bound.height = BLUR_WIDTH(shadow); bound.x = box->x + BoxShadow_GetX( shadow ); bound.y = box->y + BoxShadow_GetY( shadow ); if( LCUIRect_GetOverlayRect( &bound, &paint->rect, &bound ) ) { @@ -236,7 +236,7 @@ static void Graph_DrawTopLeftShadow( LCUI_PaintContext paint, LCUI_Rect *box, pos.x = bound.x + BLUR_WIDTH( shadow ); pos.y = bound.y + BLUR_WIDTH( shadow ); Graph_Quote( &canvas, &paint->canvas, &bound ); - DrawCircle( &canvas, pos, bound.w, shadow->color ); + DrawCircle( &canvas, pos, bound.width, shadow->color ); } } @@ -248,17 +248,17 @@ static void Graph_DrawTopRightShadow( LCUI_PaintContext paint, LCUI_Rect *box, LCUI_Graph canvas; pos.x = 0; pos.y = BLUR_WIDTH( shadow ); - bound.w = bound.h = BLUR_WIDTH( shadow ); + bound.width = bound.height = BLUR_WIDTH( shadow ); bound.y = box->y + BoxShadow_GetY( shadow ); bound.x = box->x + BoxShadow_GetX( shadow ); - bound.x += BoxShadow_GetBoxWidth( shadow, box->w ); + bound.x += BoxShadow_GetBoxWidth( shadow, box->width ); bound.x += BLUR_WIDTH( shadow ) + INNER_SHADOW_WIDTH( shadow ) * 2; if( LCUIRect_GetOverlayRect( &bound, &paint->rect, &bound ) ) { Graph_Init( &canvas ); bound.x -= paint->rect.x; bound.y -= paint->rect.y; Graph_Quote( &canvas, &paint->canvas, &bound ); - DrawCircle( &canvas, pos, bound.w, shadow->color ); + DrawCircle( &canvas, pos, bound.width, shadow->color ); } } @@ -271,15 +271,15 @@ static void Graph_DrawBottomLeftShadow( LCUI_PaintContext paint, LCUI_Rect *box, pos.y = 0; bound.x = box->x + BoxShadow_GetX( shadow ); - pos.x = bound.w = bound.h = BLUR_WIDTH( shadow ); + pos.x = bound.width = bound.height = BLUR_WIDTH( shadow ); bound.y = box->y + BoxShadow_GetY( shadow ); - bound.y += BoxShadow_GetBoxHeight( shadow, box->h ); + bound.y += BoxShadow_GetBoxHeight( shadow, box->height ); bound.y += INNER_SHADOW_WIDTH( shadow ) * 2 + BLUR_WIDTH( shadow ); if( LCUIRect_GetOverlayRect( &bound, &paint->rect, &bound ) ) { bound.x -= paint->rect.x; bound.y -= paint->rect.y; Graph_Quote( &canvas, &paint->canvas, &bound ); - DrawCircle( &canvas, pos, bound.w, shadow->color ); + DrawCircle( &canvas, pos, bound.width, shadow->color ); } } @@ -291,19 +291,19 @@ static void Graph_DrawBottomRightShadow( LCUI_PaintContext paint, LCUI_Rect *box LCUI_Graph canvas; pos.x = pos.y = 0; bound.x = BoxShadow_GetX( shadow ) + BLUR_WIDTH(shadow); - bound.x += BoxShadow_GetBoxWidth( shadow, box->w ); + bound.x += BoxShadow_GetBoxWidth( shadow, box->width ); bound.x += INNER_SHADOW_WIDTH(shadow)*2; bound.y = BoxShadow_GetY( shadow ) + BLUR_WIDTH(shadow); - bound.y += BoxShadow_GetBoxHeight( shadow, box->h ); + bound.y += BoxShadow_GetBoxHeight( shadow, box->height ); bound.y += INNER_SHADOW_WIDTH(shadow)*2; - bound.w = bound.h = BLUR_WIDTH(shadow); + bound.width = bound.height = BLUR_WIDTH(shadow); bound.x += box->x; bound.y += box->y; if( LCUIRect_GetOverlayRect( &bound, &paint->rect, &bound ) ) { bound.x -= paint->rect.x; bound.y -= paint->rect.y; Graph_Quote( &canvas, &paint->canvas, &bound ); - DrawCircle( &canvas, pos, bound.w, shadow->color ); + DrawCircle( &canvas, pos, bound.width, shadow->color ); } } @@ -334,13 +334,13 @@ static void Graph_DrawTopShadow( LCUI_PaintContext paint, LCUI_Rect *box, /* 计算阴影内框区域 */ box_area.x = BoxShadow_GetBoxX( shadow ); box_area.y = BoxShadow_GetBoxY( shadow ); - box_area.w = BoxShadow_GetBoxWidth( shadow, box->w ); - box_area.h = BoxShadow_GetBoxHeight( shadow, box->h ); + box_area.width = BoxShadow_GetBoxWidth( shadow, box->width ); + box_area.height = BoxShadow_GetBoxHeight( shadow, box->height ); /* 计算需要绘制的阴影区域 */ shadow_area.x = BoxShadow_GetX( shadow ) + BLUR_WIDTH(shadow); shadow_area.y = BoxShadow_GetY( shadow ); - shadow_area.w = box_area.w + INNER_SHADOW_WIDTH(shadow)*2; - shadow_area.h = BLUR_WIDTH(shadow); + shadow_area.width = box_area.width + INNER_SHADOW_WIDTH(shadow)*2; + shadow_area.height = BLUR_WIDTH(shadow); /* 调整坐标 */ box_area.x += box->x; box_area.y += box->y; @@ -375,8 +375,8 @@ static void Graph_DrawTopShadow( LCUI_PaintContext paint, LCUI_Rect *box, color.alpha = (uchar_t)(s - (v*t - (a*t*t) / 2)); color.alpha *= shadow->color.a / 255.0; for( x = area.x; x < bound_x; ++x ) { - if( y >= box_area.y && y < box_area.y + box_area.h - && x >= box_area.x && x < box_area.x + box_area.w ) { + if( y >= box_area.y && y < box_area.y + box_area.height + && x >= box_area.x && x < box_area.x + box_area.width ) { continue; } Graph_SetPixel( graph, x, y, color ); @@ -400,13 +400,13 @@ static void Graph_DrawBottomShadow( LCUI_PaintContext paint, LCUI_Rect *box, color = shadow->color; box_area.x = BoxShadow_GetBoxX( shadow ); box_area.y = BoxShadow_GetBoxY( shadow ); - box_area.w = BoxShadow_GetBoxWidth( shadow, box->w ); - box_area.h = BoxShadow_GetBoxHeight( shadow, box->h ); + box_area.width = BoxShadow_GetBoxWidth( shadow, box->width ); + box_area.height = BoxShadow_GetBoxHeight( shadow, box->height ); shadow_area.x = BoxShadow_GetX( shadow ) + BLUR_WIDTH( shadow ); shadow_area.y = BoxShadow_GetY( shadow ) + BLUR_WIDTH( shadow ); - shadow_area.y += box_area.h + INNER_SHADOW_WIDTH( shadow ) * 2; - shadow_area.w = box_area.w + INNER_SHADOW_WIDTH( shadow ) * 2; - shadow_area.h = BLUR_WIDTH( shadow ); + shadow_area.y += box_area.height + INNER_SHADOW_WIDTH( shadow ) * 2; + shadow_area.width = box_area.width + INNER_SHADOW_WIDTH( shadow ) * 2; + shadow_area.height = BLUR_WIDTH( shadow ); box_area.x += box->x; box_area.y += box->y; shadow_area.x += box->x; @@ -434,8 +434,8 @@ static void Graph_DrawBottomShadow( LCUI_PaintContext paint, LCUI_Rect *box, color.alpha = (uchar_t)(s - (v*t - (a*t*t) / 2)); color.alpha *= shadow->color.a / 255.0; for( x = area.x; x < bound_x; ++x ) { - if( y >= box_area.y && y < box_area.y + box_area.h && - x >= box_area.x && x < box_area.x + box_area.w ) { + if( y >= box_area.y && y < box_area.y + box_area.height && + x >= box_area.x && x < box_area.x + box_area.width ) { continue; } Graph_SetPixel( graph, x, y, color ); @@ -459,12 +459,12 @@ static void Graph_DrawLeftShadow( LCUI_PaintContext paint, LCUI_Rect *box, color = shadow->color; box_area.x = BoxShadow_GetBoxX( shadow ); box_area.y = BoxShadow_GetBoxY( shadow ); - box_area.w = BoxShadow_GetBoxWidth( shadow, box->w ); - box_area.h = BoxShadow_GetBoxHeight( shadow, box->h ); + box_area.width = BoxShadow_GetBoxWidth( shadow, box->width ); + box_area.height = BoxShadow_GetBoxHeight( shadow, box->height ); shadow_area.x = BoxShadow_GetX( shadow ); shadow_area.y = BoxShadow_GetY( shadow ) + BLUR_WIDTH(shadow); - shadow_area.w = BLUR_WIDTH(shadow); - shadow_area.h = box_area.h + INNER_SHADOW_WIDTH(shadow)*2; + shadow_area.width = BLUR_WIDTH(shadow); + shadow_area.height = box_area.height + INNER_SHADOW_WIDTH(shadow)*2; box_area.x += box->x; box_area.y += box->y; shadow_area.x += box->x; @@ -493,8 +493,8 @@ static void Graph_DrawLeftShadow( LCUI_PaintContext paint, LCUI_Rect *box, color.alpha = (uchar_t)(s - (v*t - (a*t*t) / 2)); color.alpha *= shadow->color.a / 255.0; for( y = area.y; y < bound_y; ++y ) { - if( y >= box_area.y && y < box_area.y + box_area.h && - x >= box_area.x && x < box_area.x + box_area.w ) { + if( y >= box_area.y && y < box_area.y + box_area.height && + x >= box_area.x && x < box_area.x + box_area.width ) { continue; } Graph_SetPixel( graph, x, y, color ); @@ -518,13 +518,13 @@ static void Graph_DrawRightShadow( LCUI_PaintContext paint, LCUI_Rect *box, color = shadow->color; box_area.x = BoxShadow_GetBoxX( shadow ); box_area.y = BoxShadow_GetBoxY( shadow ); - box_area.w = BoxShadow_GetBoxWidth( shadow, box->w ); - box_area.h = BoxShadow_GetBoxHeight( shadow, box->h ); + box_area.width = BoxShadow_GetBoxWidth( shadow, box->width ); + box_area.height = BoxShadow_GetBoxHeight( shadow, box->height ); shadow_area.x = BoxShadow_GetX( shadow ) + SHADOW_WIDTH(shadow); - shadow_area.x += box_area.w + INNER_SHADOW_WIDTH(shadow); + shadow_area.x += box_area.width + INNER_SHADOW_WIDTH(shadow); shadow_area.y = BoxShadow_GetY( shadow ) + BLUR_WIDTH(shadow); - shadow_area.w = BLUR_WIDTH(shadow); - shadow_area.h = box_area.h + INNER_SHADOW_WIDTH(shadow)*2; + shadow_area.width = BLUR_WIDTH(shadow); + shadow_area.height = box_area.height + INNER_SHADOW_WIDTH(shadow)*2; box_area.x += box->x; box_area.y += box->y; shadow_area.x += box->x; @@ -550,14 +550,14 @@ static void Graph_DrawRightShadow( LCUI_PaintContext paint, LCUI_Rect *box, } t = area.x - shadow_area.x; for( x = shadow_area.x; x < bound_x; ++x, ++t ) { - if( x < area.x || x >= area.x + area.w ) { + if( x < area.x || x >= area.x + area.width ) { continue; } color.alpha = (uchar_t)(s - (v*t - (a*t*t) / 2)); color.alpha *= shadow->color.a / 255.0; for( y = area.y; y < bound_y; ++y ) { - if( y >= box_area.y && y < box_area.y + box_area.h - && x >= box_area.x && x < box_area.x + box_area.w ) { + if( y >= box_area.y && y < box_area.y + box_area.height + && x >= box_area.x && x < box_area.x + box_area.width ) { continue; } Graph_SetPixel( graph, x, y, color ); @@ -572,14 +572,14 @@ void Graph_ClearShadowArea( LCUI_PaintContext paint, LCUI_Rect *box, LCUI_Graph canvas; LCUI_Rect rect, box_area, rects[4]; - rect.w = box->w; - rect.h = box->h; + rect.width = box->width; + rect.height = box->height; rect.x = rect.y = 0; /* 获取内容框区域 */ box_area.x = box->x + BoxShadow_GetBoxX( shadow ); box_area.y = box->y + BoxShadow_GetBoxY( shadow ); - box_area.w = BoxShadow_GetBoxWidth( shadow, box->w ); - box_area.h = BoxShadow_GetBoxHeight( shadow, box->h ); + box_area.width = BoxShadow_GetBoxWidth( shadow, box->width ); + box_area.height = BoxShadow_GetBoxHeight( shadow, box->height ); /* 获取内容框外的阴影区域 */ LCUIRect_CutFourRect( &box_area, &rect, rects ); for( i=0; i<4; ++i ) { @@ -600,12 +600,12 @@ static void Graph_DrawInnerShadow( LCUI_PaintContext paint, LCUI_Rect *box, LCUI_Rect rsd, rb, rects[4]; rb.x = BoxShadow_GetBoxX( s ); rb.y = BoxShadow_GetBoxY( s ); - rb.w = BoxShadow_GetBoxWidth( s, box->w ); - rb.h = BoxShadow_GetBoxHeight( s, box->h ); + rb.width = BoxShadow_GetBoxWidth( s, box->width ); + rb.height = BoxShadow_GetBoxHeight( s, box->height ); rsd.x = BoxShadow_GetX( s ) + BLUR_WIDTH(s); rsd.y = BoxShadow_GetY( s ) + BLUR_WIDTH(s); - rsd.w = rb.w + INNER_SHADOW_WIDTH(s)*2; - rsd.h = rb.h + INNER_SHADOW_WIDTH(s)*2; + rsd.width = rb.width + INNER_SHADOW_WIDTH(s)*2; + rsd.height = rb.height + INNER_SHADOW_WIDTH(s)*2; /* 截取出与内容区重叠的区域 */ if( LCUIRect_GetOverlayRect(&rb, &rsd, &rb) ) { LCUIRect_CutFourRect( &rb, &rsd, rects ); @@ -646,8 +646,8 @@ int Graph_DrawBoxShadow( LCUI_PaintContext paint, LCUI_Rect *box, LCUI_BoxShadow *shadow ) { /* 判断容器尺寸是否低于阴影占用的最小尺寸 */ - if( box->w < BoxShadow_GetWidth(shadow, 0) - || box->h < BoxShadow_GetHeight(shadow, 0) ) { + if( box->width < BoxShadow_GetWidth(shadow, 0) + || box->height < BoxShadow_GetHeight(shadow, 0) ) { return -1; } Graph_DrawInnerShadow( paint, box, shadow ); diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 62b493f8..8e0ff33a 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -428,10 +428,10 @@ static void FontBitmap_MixARGB( LCUI_Graph *graph, LCUI_Rect *write_rect, byte_row_ptr += read_rect->x; px_row_des = graph->argb + write_rect->y * graph->w; px_row_des += write_rect->x; - for( y = 0; y < read_rect->h; ++y ) { + for( y = 0; y < read_rect->height; ++y ) { px = px_row_des; byte_ptr = byte_row_ptr; - for( x = 0; x < read_rect->w; ++x, ++byte_ptr, ++px ) { + for( x = 0; x < read_rect->width; ++x, ++byte_ptr, ++px ) { src_a = *byte_ptr / 255.0; a = (1.0 - src_a) * px->a / 255.0; out_r = px->r * a + color.r * src_a; @@ -462,10 +462,10 @@ static void FontBitmap_MixRGB( LCUI_Graph *graph, LCUI_Rect *write_rect, byte_row_src = bmp->buffer + read_rect->y*bmp->width + read_rect->x; byte_row_des = graph->bytes + write_rect->y * graph->bytes_per_row; byte_row_des += write_rect->x*graph->bytes_per_pixel; - for( y=0; yh; ++y ) { + for( y=0; yheight; ++y ) { byte_src = byte_row_src; byte_des = byte_row_des; - for( x=0; xw; ++x ) { + for( x=0; xwidth; ++x ) { ALPHA_BLEND( *byte_des, color.b, *byte_src ); byte_des++; ALPHA_BLEND( *byte_des, color.g, *byte_src ); diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 8b2b047f..1f76b2af 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -1322,8 +1322,8 @@ int TextLayer_Draw( LCUI_TextLayer layer ) } rect.x = 0; rect.y = 0; - rect.w = layer->max_width; - rect.h = layer->max_height; + rect.width = layer->max_width; + rect.height = layer->max_height; return TextLayer_DrawToGraph( layer, rect, pos, &layer->graph ); } diff --git a/src/graph.c b/src/graph.c index a4cf71c9..67e24a9b 100644 --- a/src/graph.c +++ b/src/graph.c @@ -1,7 +1,7 @@ /* *************************************************************************** * graph.c -- LCUI base graphics processing module. * - * Copyright (C) 2012-2016 by Liu Chao + * Copyright (C) 2012-2017 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -22,7 +22,7 @@ /* **************************************************************************** * graph.c -- LCUI 的基础图形处理模块 * - * 版权所有 (C) 2012-2016 归属于 刘超 + * 版权所有 (C) 2012-2017 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -37,6 +37,7 @@ * 没有,请查看:. * ***************************************************************************/ +#include #include #include #include @@ -46,18 +47,18 @@ void Graph_PrintInfo( LCUI_Graph *graph ) { - printf("address:%p\n", graph); + LOG( "address:%p\n", graph ); if( !graph ) { return; } - printf("width:%d, ", graph->w); - printf("height:%d, ", graph->h); - printf("opacity:%.2f, ", graph->opacity); - printf("%s\n", graph->color_type == COLOR_TYPE_ARGB ? "RGBA":"RGB"); + LOG( "width:%d, ", graph->w ); + LOG( "height:%d, ", graph->h ); + LOG( "opacity:%.2f, ", graph->opacity ); + LOG( "%s\n", graph->color_type == COLOR_TYPE_ARGB ? "RGBA" : "RGB" ); if( graph->quote.is_valid ) { - printf("graph src:"); - Graph_PrintInfo(Graph_GetQuote(graph)); + LOG( "graph src:" ); + Graph_PrintInfo( Graph_GetQuote( graph ) ); } } @@ -71,16 +72,16 @@ void Graph_Init( LCUI_Graph *graph ) graph->color_type = COLOR_TYPE_RGB; graph->bytes = NULL; graph->opacity = 1.0; - graph->mem_size = 0; + graph->mem_size = 0; graph->width = 0; graph->height = 0; graph->bytes_per_pixel = 3; graph->bytes_per_row = 0; } -LCUI_Graph *Graph_New(void) +LCUI_Graph *Graph_New( void ) { - LCUI_Graph *g = (LCUI_Graph*)malloc(sizeof(LCUI_Graph)); + LCUI_Graph *g = (LCUI_Graph*)malloc( sizeof( LCUI_Graph ) ); Graph_Init( g ); return g; } @@ -112,7 +113,7 @@ static size_t get_pixel_size( int color_type ) case COLOR_TYPE_GRAY8: case COLOR_TYPE_RGB323: case COLOR_TYPE_ARGB2222: - return 1; + return 1; case COLOR_TYPE_RGB555: case COLOR_TYPE_RGB565: return 2; @@ -197,16 +198,16 @@ static int Graph_RGBToARGB( LCUI_Graph *graph ) LCUI_ARGB *px_des, *px_row_des, *buffer; uchar_t *byte_row_src, *byte_src; - buffer = (LCUI_ARGB*)malloc( sizeof(LCUI_ARGB)*graph->w*graph->h ); + buffer = (LCUI_ARGB*)malloc( sizeof( LCUI_ARGB )*graph->w*graph->h ); if( !buffer ) { return -1; } px_row_des = buffer; byte_row_src = graph->bytes; - for( y=0; yh; ++y ) { + for( y = 0; y < graph->h; ++y ) { px_des = px_row_des; byte_src = byte_row_src; - for( x=0; xw; ++x ) { + for( x = 0; x < graph->w; ++x ) { px_des->b = *byte_src++; px_des->g = *byte_src++; px_des->r = *byte_src++; @@ -218,7 +219,7 @@ static int Graph_RGBToARGB( LCUI_Graph *graph ) } free( graph->argb ); graph->argb = buffer; - graph->mem_size = sizeof(LCUI_ARGB)*graph->w*graph->h; + graph->mem_size = sizeof( LCUI_ARGB )*graph->w*graph->h; graph->color_type = COLOR_TYPE_ARGB8888; return 0; } @@ -230,14 +231,14 @@ static int Graph_CutRGB( const LCUI_Graph *graph, LCUI_Rect rect, uchar_t *byte_src_row, *byte_des_row; buff->color_type = graph->color_type; - if( 0 != Graph_Create(buff, rect.width, rect.height) ) { + if( 0 != Graph_Create( buff, rect.width, rect.height ) ) { return -1; } buff->opacity = graph->opacity; byte_des_row = buff->bytes; byte_src_row = graph->bytes + rect.y*graph->bytes_per_row; byte_src_row += rect.x * graph->bytes_per_pixel; - for( y=0; ybytes_per_row ); byte_des_row += buff->bytes_per_row; byte_src_row += graph->bytes_per_row; @@ -255,10 +256,10 @@ static void Graph_ARGBReplaceRGB( LCUI_Graph *des, LCUI_Rect des_rect, byte_row_src += src_x * src->bytes_per_pixel; byte_row_des = des->bytes + des_rect.y * des->bytes_per_row; byte_row_des += des_rect.x * des->bytes_per_pixel; - for( y = 0; y < des_rect.h; ++y ) { + for( y = 0; y < des_rect.height; ++y ) { /* 将前景图当前行像素转换成ARGB格式,并直接覆盖至背景图上 */ PixelsFormat( byte_row_src, src->color_type, - byte_row_des, des->color_type, des_rect.w ); + byte_row_des, des->color_type, des_rect.width ); byte_row_src += src->bytes_per_row; byte_row_des += des->bytes_per_row; } @@ -271,9 +272,9 @@ static void Graph_RGBReplaceRGB( LCUI_Graph *des, LCUI_Rect des_rect, uchar_t *byte_row_des, *byte_row_src; byte_row_src = src->bytes + src_y * src->bytes_per_row; byte_row_src += src_x * src->bytes_per_pixel; - row_size = 3 * des_rect.w; + row_size = 3 * des_rect.width; byte_row_des = des->bytes + (des_rect.y * des->w + des_rect.x) * 3; - for( y = 0; y < des_rect.h; ++y ) { + for( y = 0; y < des_rect.height; ++y ) { memcpy( byte_row_des, byte_row_src, row_size ); byte_row_src += src->bytes_per_row; byte_row_des += des->bytes_per_row; @@ -288,7 +289,7 @@ static int Graph_HorizFlipRGB( const LCUI_Graph *graph, LCUI_Graph *buff ) LCUI_Rect rect; uchar_t *byte_src, *byte_des; - if(!Graph_IsValid(graph)) { + if( !Graph_IsValid( graph ) ) { return -1; } Graph_GetValidRect( graph, &rect ); @@ -298,11 +299,11 @@ static int Graph_HorizFlipRGB( const LCUI_Graph *graph, LCUI_Graph *buff ) return -2; } - for( y=0; ybytes + y*buff->w*3; - n = ((rect.y+y)*graph->w + rect.x + rect.w - 1)*3; + for( y = 0; y < rect.height; ++y ) { + byte_des = buff->bytes + y*buff->w * 3; + n = ((rect.y + y)*graph->w + rect.x + rect.width - 1) * 3; byte_src = buff->bytes + n; - for( x=0; xbytes + (rect.y + rect.h - 1)*graph->bytes_per_row; + byte_src = graph->bytes + (rect.y + rect.height - 1)*graph->bytes_per_row; byte_src += rect.x * graph->bytes_per_pixel; byte_des = buff->bytes; /* 交换上下每行像素 */ - for( y=0; yw*3 ); + for( y = 0; y < rect.height; ++y ) { + memcpy( byte_des, byte_src, buff->w * 3 ); byte_src -= graph->bytes_per_row; byte_des += buff->bytes_per_row; } @@ -346,7 +347,7 @@ static int Graph_FillRectRGB( LCUI_Graph *graph, LCUI_Color color, LCUI_Rect rec LCUI_Graph canvas; uchar_t *rowbytep, *bytep; - if(!Graph_IsValid(graph)) { + if( !Graph_IsValid( graph ) ) { return -1; } Graph_Quote( &canvas, graph, &rect ); @@ -354,9 +355,9 @@ static int Graph_FillRectRGB( LCUI_Graph *graph, LCUI_Color color, LCUI_Rect rec graph = Graph_GetQuote( &canvas ); rowbytep = graph->bytes + rect.y*graph->bytes_per_row; rowbytep += rect.x*graph->bytes_per_pixel; - for( y=0; yw*graph->h*3 ); + buffer = (uchar_t*)malloc( sizeof( uchar_t )*graph->w*graph->h * 3 ); if( !buffer ) { return -1; } byte_row_des = buffer; px_row_src = graph->argb; - for( y=0; yh; ++y ) { + for( y = 0; y < graph->h; ++y ) { px_src = px_row_src; byte_des = byte_row_des; - for( x=0; xw; ++x ) { + for( x = 0; x < graph->w; ++x ) { px_src->b = *byte_des++; px_src->g = *byte_des++; px_src->r = *byte_des++; @@ -397,7 +398,7 @@ static int Graph_ARGBToRGB( LCUI_Graph *graph ) } free( graph->argb ); graph->bytes = buffer; - graph->mem_size = sizeof(uchar_t)*graph->w*graph->h*3; + graph->mem_size = sizeof( uchar_t )*graph->w*graph->h * 3; graph->color_type = COLOR_TYPE_RGB888; graph->bytes_per_pixel = 3; return 0; @@ -410,16 +411,16 @@ static int Graph_CutARGB( const LCUI_Graph *graph, LCUI_Rect rect, LCUI_ARGB *pixel_src, *pixel_des; buff->color_type = graph->color_type; - if( 0 != Graph_Create(buff, rect.width, rect.height) ) { + if( 0 != Graph_Create( buff, rect.width, rect.height ) ) { return -1; } buff->opacity = graph->opacity; - for( y=0; yargb + y*buff->w; pixel_src = graph->argb; - pixel_src += (rect.y+y)*graph->w + rect.x; - for( x=0; xw + rect.x; + for( x = 0; x < rect.width; ++x ) { *pixel_des++ = *pixel_src++; } } @@ -438,10 +439,10 @@ static void Graph_ARGBMixARGB( LCUI_Graph *dst, LCUI_Rect des_rect, if( src->opacity < 1.0 ) { goto mix_with_opacity; } - for( y=0; ya / 255.0; a = (1.0 - src_a) * px_dst->a / 255.0; out_r = px_dst->r * a + px_src->r * src_a; @@ -466,10 +467,10 @@ static void Graph_ARGBMixARGB( LCUI_Graph *dst, LCUI_Rect des_rect, return; mix_with_opacity: - for( y=0; ya / 255.0 * src->opacity; a = (1.0 - src_a) * px_dst->a / 255.0; out_r = px_dst->r * a + px_src->r * src_a; @@ -504,10 +505,10 @@ static void Graph_ARGBMixARGB2( LCUI_Graph *dest, LCUI_Rect des_rect, if( src->opacity < 1.0 ) { goto mix_with_opacity; } - for( y=0; ya ); ++px_src; ++px_dest; @@ -518,10 +519,10 @@ static void Graph_ARGBMixARGB2( LCUI_Graph *dest, LCUI_Rect des_rect, return; mix_with_opacity: - for( y=0; ya * src->opacity; PIXEL_BLEND( px_dest, px_src, a ); ++px_src; @@ -547,10 +548,10 @@ static void Graph_RGBMixARGB( LCUI_Graph *des, LCUI_Rect des_rect, if( src->opacity < 1.0 ) { goto mix_with_opacity; } - for( y=0; yb, px->a ); ++bytep; *bytep = _ALPHA_BLEND( *bytep, px->g, px->a ); @@ -564,10 +565,10 @@ static void Graph_RGBMixARGB( LCUI_Graph *des, LCUI_Rect des_rect, return; mix_with_opacity: - for( y=0; ya * src->opacity; *bytep = _ALPHA_BLEND( *bytep, px->b, a ); ++bytep; @@ -589,10 +590,10 @@ static int Graph_ARGBReplaceARGB( LCUI_Graph *des, LCUI_Rect des_rect, px_row_src = src->argb + src_y*src->w + src_x; px_row_des = des->argb + des_rect.y*des->w + des_rect.x; if( src->opacity < 1.0 ) { - for( y=0; yb = px_src->b; px_des->g = px_src->g; px_des->r = px_src->r; @@ -603,8 +604,8 @@ static int Graph_ARGBReplaceARGB( LCUI_Graph *des, LCUI_Rect des_rect, } return 0; } - row_size = sizeof(LCUI_ARGB)*des_rect.w; - for( y=0; yw; px_row_des += des->w; @@ -618,7 +619,7 @@ static int Graph_HorizFlipARGB( const LCUI_Graph *graph, LCUI_Graph *buff ) LCUI_Rect rect; LCUI_ARGB *pixel_src, *pixel_des; - if(!Graph_IsValid(graph)) { + if( !Graph_IsValid( graph ) ) { return -1; } Graph_GetValidRect( graph, &rect ); @@ -629,11 +630,11 @@ static int Graph_HorizFlipARGB( const LCUI_Graph *graph, LCUI_Graph *buff ) return -2; } - for( y=0; yargb + y*buff->w; - pixel_src = graph->argb + (rect.y+y)*graph->w; - pixel_src += rect.x + rect.w - 1; - for( x=0; xargb + (rect.y + y)*graph->w; + pixel_src += rect.x + rect.width - 1; + for( x = 0; x < rect.width; ++x ) { *pixel_des++ = *pixel_src--; } } @@ -646,7 +647,7 @@ static int Graph_VertiFlipARGB( const LCUI_Graph *graph, LCUI_Graph *buff ) LCUI_Rect rect; uchar_t *byte_src, *byte_des; - if(!Graph_IsValid(graph)) { + if( !Graph_IsValid( graph ) ) { return -1; } Graph_GetValidRect( graph, &rect ); @@ -656,10 +657,10 @@ static int Graph_VertiFlipARGB( const LCUI_Graph *graph, LCUI_Graph *buff ) if( 0 != Graph_Create( buff, rect.width, rect.height ) ) { return -2; } - byte_src = graph->bytes + (rect.y + rect.h - 1)*graph->bytes_per_row; + byte_src = graph->bytes + (rect.y + rect.height - 1)*graph->bytes_per_row; byte_src += rect.x * graph->bytes_per_pixel; byte_des = buff->bytes; - for( y=0; ybytes_per_row ); byte_src -= graph->bytes_per_row; byte_des += buff->bytes_per_row; @@ -674,25 +675,25 @@ static int Graph_FillRectARGB( LCUI_Graph *graph, LCUI_Color color, LCUI_Rect rect_src; LCUI_ARGB *px_p, *px_row_p; - if(!Graph_IsValid(graph)) { + if( !Graph_IsValid( graph ) ) { return -1; } Graph_GetValidRect( graph, &rect_src ); graph = Graph_GetQuote( graph ); - px_row_p = graph->argb + (rect_src.y+rect.y)*graph->w; + px_row_p = graph->argb + (rect_src.y + rect.y)*graph->w; px_row_p += rect.x + rect_src.x; if( with_alpha ) { - for( y = 0; y < rect.h; ++y ) { + for( y = 0; y < rect.height; ++y ) { px_p = px_row_p; - for( x = 0; x < rect.w; ++x ) { + for( x = 0; x < rect.width; ++x ) { *px_p++ = color; } px_row_p += graph->w; } } else { - for( y = 0; y < rect.h; ++y ) { + for( y = 0; y < rect.height; ++y ) { px_p = px_row_p; - for( x = 0; x < rect.w; ++x ) { + for( x = 0; x < rect.width; ++x ) { color.alpha = px_p->alpha; *px_p++ = color; } @@ -734,7 +735,7 @@ int Graph_Create( LCUI_Graph *graph, int w, int h ) { size_t size; if( w > 10000 || h > 10000 ) { - _DEBUG_MSG("graph size is too large!"); + _DEBUG_MSG( "graph size is too large!" ); abort(); } if( h <= 0 || w <= 0 ) { @@ -744,7 +745,7 @@ int Graph_Create( LCUI_Graph *graph, int w, int h ) graph->bytes_per_pixel = get_pixel_size( graph->color_type ); graph->bytes_per_row = graph->bytes_per_pixel * w; size = graph->bytes_per_row * h; - if( Graph_IsValid(graph) ) { + if( Graph_IsValid( graph ) ) { /* 如果现有图形尺寸大于要创建的图形的尺寸,直接改尺寸即可 */ if( graph->mem_size >= size ) { memset( graph->bytes, 0, graph->mem_size ); @@ -770,7 +771,7 @@ int Graph_Create( LCUI_Graph *graph, int w, int h ) void Graph_Copy( LCUI_Graph *des, const LCUI_Graph *src ) { const LCUI_Graph *graph; - if( !des || !Graph_IsValid(src) ) { + if( !des || !Graph_IsValid( src ) ) { return; } graph = Graph_GetQuote( src ); @@ -798,12 +799,6 @@ void Graph_Free( LCUI_Graph *graph ) graph->mem_size = 0; } -/** -* 为图像创建一个引用 -* @param self 用于存放图像引用的缓存区 -* @param source 引用的源图像 -* ¶m rect 引用的区域,若为NULL,则引用整个图像 -*/ int Graph_Quote( LCUI_Graph *self, LCUI_Graph *source, const LCUI_Rect *rect ) { LCUI_Rect quote_rect; @@ -822,7 +817,7 @@ int Graph_Quote( LCUI_Graph *self, LCUI_Graph *source, const LCUI_Rect *rect ) quote_rect.y += source->quote.top; source = source->quote.source; } - if( quote_rect.w <= 0 || quote_rect.h <= 0 ) { + if( quote_rect.width <= 0 || quote_rect.height <= 0 ) { self->width = 0; self->height = 0; self->opacity = 1.0; @@ -870,7 +865,7 @@ int Graph_SetAlphaBits( LCUI_Graph *graph, uchar_t *a, size_t size ) if( graph->color_type != COLOR_TYPE_ARGB ) { return -2; } - for( i=0; iargb[i].a = a[i]; } return 0; @@ -885,12 +880,12 @@ int Graph_SetRedBits( LCUI_Graph *graph, uchar_t *r, size_t size ) size = (size_t)(graph->w*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { - for( i=0; iargb[i].r = r[i]; } } else { pByte = graph->bytes + 2; - for( i=0; iw*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { - for( i=0; iargb[i].g = g[i]; } } else { pByte = graph->bytes + 1; - for( i=0; iw*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { - for( i=0; iargb[i].b = b[i]; } } else { pByte = graph->bytes; - for( i=0; icolor_type = graph->color_type; - if( Graph_Create(buff, width, height) < 0 ) { + if( Graph_Create( buff, width, height ) < 0 ) { return -2; } if( graph->color_type == COLOR_TYPE_ARGB ) { LCUI_ARGB *px_src, *px_des, *px_row_src; - for( y=0; y < height; ++y ) { + for( y = 0; y < height; ++y ) { src_y = y * scale_y; px_row_src = graph->argb; px_row_src += (src_y + rect.y) * graph->w + rect.x; px_des = buff->argb + y * width; - for( x=0; x < width; ++x ) { + for( x = 0; x < width; ++x ) { src_x = x * scale_x; px_src = px_row_src + src_x; *px_des++ = *px_src; @@ -1015,13 +1010,13 @@ int Graph_Zoom( const LCUI_Graph *graph, LCUI_Graph *buff, } int Graph_Cut( const LCUI_Graph *graph, LCUI_Rect rect, - LCUI_Graph *buff ) + LCUI_Graph *buff ) { if( !Graph_IsValid( graph ) ) { return -2; } LCUIRect_ValidateArea( &rect, graph->w, graph->h ); - if( rect.width <= 0 || rect.height <= 0) { + if( rect.width <= 0 || rect.height <= 0 ) { return -3; } switch( graph->color_type ) { @@ -1088,16 +1083,16 @@ int Graph_FillAlpha( LCUI_Graph *graph, uchar_t alpha ) Graph_GetValidRect( graph, &rect ); graph = Graph_GetQuote( graph ); - if( !Graph_IsValid(graph) ) { + if( !Graph_IsValid( graph ) ) { return -1; } - if( !Graph_HasAlpha(graph) ) { + if( !Graph_HasAlpha( graph ) ) { return -2; } pixel_row = graph->argb + rect.y*graph->w + rect.x; - for(y=0; yalpha = alpha; ++pixel; } @@ -1110,7 +1105,7 @@ int Graph_Tile( LCUI_Graph *buff, const LCUI_Graph *graph, LCUI_BOOL replace, LCUI_BOOL with_alpha ) { int ret = 0, x, y; - if( !Graph_IsValid(graph) || !Graph_IsValid(buff) ) { + if( !Graph_IsValid( graph ) || !Graph_IsValid( buff ) ) { return -1; } for( y = 0; y < buff->h; y += graph->h ) { @@ -1125,7 +1120,7 @@ int Graph_Tile( LCUI_Graph *buff, const LCUI_Graph *graph, return ret; } -typedef void(*MixerPtr)(LCUI_Graph*, LCUI_Rect, const LCUI_Graph *, int, int); +typedef void( *MixerPtr )(LCUI_Graph*, LCUI_Rect, const LCUI_Graph *, int, int); int Graph_Mix( LCUI_Graph *back, const LCUI_Graph *fore, int left, int top, LCUI_BOOL with_alpha ) @@ -1134,7 +1129,7 @@ int Graph_Mix( LCUI_Graph *back, const LCUI_Graph *fore, LCUI_Rect r_rect, w_rect; MixerPtr mixer = NULL; - if( !Graph_IsValid(back) || !Graph_IsValid(fore) ) { + if( !Graph_IsValid( back ) || !Graph_IsValid( fore ) ) { return -1; } w_rect.x = left; @@ -1189,9 +1184,9 @@ int Graph_Mix( LCUI_Graph *back, const LCUI_Graph *fore, int Graph_Replace( LCUI_Graph *back, const LCUI_Graph *fore, int left, int top ) { LCUI_Graph write_slot; - LCUI_Rect read_rect,write_rect; + LCUI_Rect read_rect, write_rect; - if( !Graph_IsValid(back) || !Graph_IsValid(fore) ) { + if( !Graph_IsValid( back ) || !Graph_IsValid( fore ) ) { return -1; } write_rect.x = left; @@ -1201,8 +1196,8 @@ int Graph_Replace( LCUI_Graph *back, const LCUI_Graph *fore, int left, int top ) Graph_Quote( &write_slot, back, &write_rect ); Graph_GetValidRect( &write_slot, &write_rect ); Graph_GetValidRect( fore, &read_rect ); - if( write_rect.width <= 0 || write_rect.height <= 0 - || read_rect.width <= 0 || read_rect.height <= 0 ) { + if( write_rect.width <= 0 || write_rect.height <= 0 || + read_rect.width <= 0 || read_rect.height <= 0 ) { return -2; } left = read_rect.x; diff --git a/src/gui/css_library.c b/src/gui/css_library.c index a49a69da..981fecc1 100644 --- a/src/gui/css_library.c +++ b/src/gui/css_library.c @@ -1269,7 +1269,7 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) break; } case SVT_PX: - LOG( "%dpx", s->val_px ); + LOG( "%.4fpx", s->val_px ); break; case SVT_STRING: LOG( "%s", s->val_string ); diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index 74392ae8..39c7259c 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -414,21 +414,21 @@ static void TextEdit_OnTask( LCUI_Widget widget ) } } -static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) +static void TextEdit_AutoSize( LCUI_Widget widget, + float *width, float *height ) { LCUI_TextEdit edit = Widget_GetData( widget, self.prototype ); if( edit->is_multiline_mode ) { - int i, n; - *height = 0; - n = TextLayer_GetRowTotal( edit->layer ); - n = n > 3 ? 3 : n; + int i, n, h = 0; + n = max( TextLayer_GetRowTotal( edit->layer ), 3); for( i = 0; i < n; ++i ) { - *height += TextLayer_GetRowHeight( edit->layer, i ); + h += TextLayer_GetRowHeight( edit->layer, i ); } + *height = 1.0 * h; } else { - *height = TextLayer_GetHeight( edit->layer ); + *height = TextLayer_GetHeight( edit->layer ) * 1.0; } - *width = 176; + *width = 176.0; } /*----------------------------- End TextBlock ---------------------------------*/ @@ -726,8 +726,8 @@ static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) { LinkedList rects; LinkedListNode *node; - int width = 0, height = 0; - int max_width = 0, max_height = 0; + float width = 0, height = 0; + float max_width = 0, max_height = 0; LCUI_TextEdit edit = Widget_GetData( w, self.prototype ); if( !w->style->sheet[key_width].is_valid || w->style->sheet[key_width].type == SVT_AUTO ) { @@ -854,8 +854,8 @@ static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) LCUI_TextEdit edit = Widget_GetData( w, self.prototype ); content_rect.width = w->box.content.width; content_rect.height = w->box.content.height; - content_rect.y = w->box.content.top - w->box.graph.top; - content_rect.x = w->box.content.left - w->box.graph.left; + content_rect.y = (int)(w->box.content.y - w->box.graph.y + 0.5); + content_rect.x = (int)(w->box.content.x - w->box.graph.x + 0.5); LCUIRect_GetOverlayRect( &content_rect, &paint->rect, &rect ); layer_pos.x = content_rect.x - paint->rect.x; layer_pos.y = content_rect.y - paint->rect.y; diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 549e94a0..8b57a987 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -391,7 +391,7 @@ static void TextView_OnDestroy( LCUI_Widget w ) TextLayer_Destroy( txt->layer ); } -static void TextView_AutoSize( LCUI_Widget w, int *width, int *height ) +static void TextView_AutoSize( LCUI_Widget w, float *width, float *height ) { LCUI_TextView txt = Widget_GetData( w, self.prototype ); /*如果自身的宽度单位是百分比,且父级部件宽度为自适应 */ @@ -405,14 +405,14 @@ static void TextView_AutoSize( LCUI_Widget w, int *width, int *height ) } TextLayer_SetFixedSize( txt->layer, 0, 0 ); TextLayer_Update( txt->layer, NULL ); - *width = TextLayer_GetWidth( txt->layer ); - *height = TextLayer_GetHeight( txt->layer ); + *width = TextLayer_GetWidth( txt->layer ) * 1.0; + *height = TextLayer_GetHeight( txt->layer ) * 1.0; TextLayer_SetFixedSize( txt->layer, fixed_w, fixed_h ); TextLayer_Update( txt->layer, NULL ); return; } - *width = TextLayer_GetWidth( txt->layer ); - *height = TextLayer_GetHeight( txt->layer ); + *width = TextLayer_GetWidth( txt->layer ) * 1.0; + *height = TextLayer_GetHeight( txt->layer ) * 1.0; } /** 私有的任务处理接口 */ @@ -467,10 +467,10 @@ static void TextView_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) LCUI_Pos layer_pos; LCUI_Rect content_rect, rect; txt = Widget_GetData( w, self.prototype ); - content_rect.x = w->box.content.left - w->box.graph.left; - content_rect.y = w->box.content.top - w->box.graph.top; content_rect.width = w->box.content.width; content_rect.height = w->box.content.height; + content_rect.x = (int)(w->box.content.x - w->box.graph.x + 0.5); + content_rect.y = (int)(w->box.content.y - w->box.graph.y + 0.5); LCUIRect_GetOverlayRect( &content_rect, &paint->rect, &rect ); layer_pos.x = content_rect.x - paint->rect.x; layer_pos.y = content_rect.y - paint->rect.y; diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 8a719947..7d6c7a3f 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -37,7 +37,6 @@ * 没有,请查看:. * ****************************************************************************/ -#define ENABLE_MEMDEBUG #include #include #include @@ -513,7 +512,7 @@ int Widget_SetId( LCUI_Widget w, const char *idstr ) return -2; } -static int ComputeXNumber( LCUI_Widget w, int key ) +static float ComputeXNumber( LCUI_Widget w, int key ) { LCUI_Style s = &w->style->sheet[key]; switch( s->type ) { @@ -531,7 +530,7 @@ static int ComputeXNumber( LCUI_Widget w, int key ) return 0; } -static int ComputeYNumber( LCUI_Widget w, int key ) +static float ComputeYNumber( LCUI_Widget w, int key ) { LCUI_Style s = &w->style->sheet[key]; switch( s->type ) { @@ -549,7 +548,7 @@ static int ComputeYNumber( LCUI_Widget w, int key ) return 0; } -static int ComputeSelfXNumber( LCUI_Widget w, int key ) +static float ComputeSelfXNumber( LCUI_Widget w, int key ) { LCUI_Style s = &w->style->sheet[key]; switch( s->type ) { @@ -564,7 +563,7 @@ static int ComputeSelfXNumber( LCUI_Widget w, int key ) return 0; } -static int ComputeSelfYNumber( LCUI_Widget w, int key ) +static float ComputeSelfYNumber( LCUI_Widget w, int key ) { LCUI_Style s = &w->style->sheet[key]; switch( s->type ) { @@ -596,6 +595,8 @@ static void Widget_ComputeBorder( LCUI_Widget w ) LCUI_StyleSheet ss = w->style; LCUI_Border *b = &w->computed_style.border; int key = key_border_start ; + unsigned int val; + for( ; key <= key_border_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { @@ -615,16 +616,16 @@ static void Widget_ComputeBorder( LCUI_Widget w ) b->left.color = style->color; break; case key_border_top_width: - b->top.width = style->value; + b->top.width = (unsigned int)style->px; break; case key_border_right_width: - b->right.width = style->value; + b->right.width = (unsigned int)style->px; break; case key_border_bottom_width: - b->bottom.width = style->value; + b->bottom.width = (unsigned int)style->px; break; case key_border_left_width: - b->left.width = style->value; + b->left.width = (unsigned int)style->px; break; case key_border_top_style: b->top.style = style->value; @@ -639,16 +640,20 @@ static void Widget_ComputeBorder( LCUI_Widget w ) b->left.style = style->value; break; case key_border_top_left_radius: - b->top_left_radius = ComputeSelfXNumber( w, key ); + val = (unsigned int)ComputeSelfXNumber( w, key ); + b->top_left_radius = val; break; case key_border_top_right_radius: - b->top_right_radius = ComputeSelfXNumber( w, key ); + val = (unsigned int)ComputeSelfXNumber( w, key ); + b->top_right_radius = val; break; case key_border_bottom_left_radius: - b->bottom_left_radius = ComputeSelfXNumber( w, key ); + val = (unsigned int)ComputeSelfXNumber( w, key ); + b->bottom_left_radius = val; break; case key_border_bottom_right_radius: - b->bottom_right_radius = ComputeSelfXNumber( w, key ); + val = (unsigned int)ComputeSelfXNumber( w, key ); + b->bottom_right_radius = val; break; default: break; } @@ -677,7 +682,7 @@ void Widget_UpdateBorder( LCUI_Widget w ) rect.height = max( ob.top_left_radius, ob.top.width ); /* 上 */ Widget_InvalidateArea( w, &rect, SV_BORDER_BOX ); - rect.x = w->box.border.w; + rect.x = w->box.border.width; rect.width = max( ob.top_right_radius, ob.right.width ); rect.x -= rect.width; rect.height = w->box.border.height; @@ -713,11 +718,21 @@ static void ComputeBoxShadowStyle( LCUI_StyleSheet ss, LCUI_BoxShadow *bsd ) continue; } switch( key ) { - case key_box_shadow_x: bsd->x = style->value; break; - case key_box_shadow_y: bsd->y = style->value; break; - case key_box_shadow_spread: bsd->spread = style->value; break; - case key_box_shadow_blur: bsd->blur = style->value; break; - case key_box_shadow_color: bsd->color = style->color; break; + case key_box_shadow_x: + bsd->x = (int)style->px; + break; + case key_box_shadow_y: + bsd->y = (int)style->px; + break; + case key_box_shadow_spread: + bsd->spread = (int)style->px; + break; + case key_box_shadow_blur: + bsd->blur = (int)style->px; + break; + case key_box_shadow_color: + bsd->color = style->color; + break; default: break; } } @@ -732,9 +747,10 @@ void Widget_UpdateBoxShadow( LCUI_Widget w ) bs.y == w->computed_style.shadow.y && bs.blur == w->computed_style.shadow.blur ) { int i; - LCUI_Rect rects[4]; - LCUIRect_CutFourRect( &w->box.border, - &w->box.graph, rects ); + LCUI_Rect rects[4], rb, rg; + RectF2Rect( w->box.border, rb ); + RectF2Rect( w->box.graph, rg ); + LCUIRect_CutFourRect( &rb, &rg, rects ); for( i = 0; i < 4; ++i ) { rects[i].x -= w->box.graph.x; rects[i].y -= w->box.graph.y; @@ -898,7 +914,7 @@ static void Widget_UpdateChildrenSize( LCUI_Widget w ) void Widget_UpdatePosition( LCUI_Widget w ) { - LCUI_Rect rect = w->box.graph; + LCUI_Rect rect; int position = ComputeStyleOption( w, key_position, SV_STATIC ); int valign = ComputeStyleOption( w, key_vertical_align, SV_TOP ); w->computed_style.vertical_align = valign; @@ -912,6 +928,7 @@ void Widget_UpdatePosition( LCUI_Widget w ) Widget_UpdateChildrenSize( w ); } w->computed_style.position = position; + RectF2Rect( w->box.graph, rect ); Widget_UpdateZIndex( w ); w->x = w->origin_x; w->y = w->origin_y; @@ -991,7 +1008,7 @@ void Widget_UpdatePosition( LCUI_Widget w ) w->box.graph.y -= BoxShadow_GetBoxY( &w->computed_style.shadow ); if( w->parent ) { DEBUG_MSG("new-rect: %d,%d,%d,%d\n", w->box.graph.x, w->box.graph.y, w->box.graph.w, w->box.graph.h); - DEBUG_MSG("old-rect: %d,%d,%d,%d\n", rect.x, rect.y, rect.w, rect.h); + DEBUG_MSG("old-rect: %d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height); /* 标记移动前后的区域 */ Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); Widget_PushInvalidArea( w->parent, &rect, SV_PADDING_BOX ); @@ -1003,8 +1020,8 @@ void Widget_UpdatePosition( LCUI_Widget w ) /** 更新位图尺寸 */ static void Widget_UpdateGraphBox( LCUI_Widget w ) { - LCUI_Rect *rb = &w->box.border; - LCUI_Rect *rg = &w->box.graph; + LCUI_RectF *rb = &w->box.border; + LCUI_RectF *rg = &w->box.graph; LCUI_BoxShadow *shadow = &w->computed_style.shadow; rg->x = w->x - BoxShadow_GetBoxX( shadow ); rg->y = w->y - BoxShadow_GetBoxY( shadow ); @@ -1029,20 +1046,18 @@ static void Widget_UpdateGraphBox( LCUI_Widget w ) } /** 计算合适的内容框大小 */ -static void Widget_ComputeContentSize( LCUI_Widget w, int *width, int *height ) +static void Widget_ComputeContentSize( LCUI_Widget w, + float *width, float *height ) { - int n; + float n; LCUI_Style s; - LCUI_Widget child; LinkedListNode *node; - *width = *height = 0; + *width = *height = 0.0; for( LinkedList_Each( node, &w->children_show ) ) { - LCUI_WidgetBoxRect *box; - LCUI_WidgetStyle *style; - child = node->data; - box = &child->box; - style = &child->computed_style; + LCUI_Widget child = node->data; + LCUI_WidgetBoxRect *box = &child->box; + LCUI_WidgetStyle *style = &child->computed_style; /* 忽略不可见、绝对定位的部件 */ if( !style->visible || style->position == SV_ABSOLUTE ) { continue; @@ -1094,8 +1109,8 @@ static void Widget_ComputeContentSize( LCUI_Widget w, int *width, int *height ) /** 计算尺寸 */ static void Widget_ComputeSize( LCUI_Widget w ) { - int n, width, height; - LCUI_Rect *box, *pbox = &w->box.padding; + float n, width, height; + LCUI_RectF *box, *pbox = &w->box.padding; LCUI_Style sw = &w->style->sheet[key_width]; LCUI_Style sh = &w->style->sheet[key_height]; LCUI_Border *bbox = &w->computed_style.border; @@ -1123,7 +1138,9 @@ static void Widget_ComputeSize( LCUI_Widget w ) width -= w->margin.left + w->margin.right; if( w->computed_style.box_sizing != SV_BORDER_BOX ) { width -= w->padding.left + w->padding.right; - width -= bbox->left.width + bbox->right.width; + /* 边框的宽度为整数,不使用浮点数 */ + width -= bbox->left.width * 1.0; + width -= bbox->right.width * 1.0; } } if( sw->type == SVT_AUTO ) { @@ -1231,7 +1248,7 @@ void Widget_UpdateMargin( LCUI_Widget w ) LCUI_BoundBox *mbox = &w->computed_style.margin; struct { LCUI_Style sval; - int *ival; + float *fval; int key; } pd_map[4] = { { &mbox->top, &w->margin.top, key_margin_top }, @@ -1243,12 +1260,12 @@ void Widget_UpdateMargin( LCUI_Widget w ) LCUI_Style s = &w->style->sheet[pd_map[i].key]; if( !s->is_valid || s->type != SVT_PX ) { pd_map[i].sval->type = SVT_PX; - pd_map[i].sval->px = 0; - *pd_map[i].ival = 0; + pd_map[i].sval->px = 0.0; + *pd_map[i].fval = 0.0; continue; } *pd_map[i].sval = *s; - *pd_map[i].ival = s->px; + *pd_map[i].fval = s->px; } /* 如果有父级部件,则处理 margin-left 和 margin-right 的值 */ if( w->parent ) { @@ -1297,13 +1314,13 @@ void Widget_UpdateMargin( LCUI_Widget w ) void Widget_UpdateSize( LCUI_Widget w ) { - LCUI_Rect rect; + LCUI_RectF rect; int i, box_sizing; - LCUI_Rect2 padding = w->padding; + LCUI_Rect2F padding = w->padding; LCUI_BoundBox *pbox = &w->computed_style.padding; struct { LCUI_Style sval; - int *ival; + float *ival; int key; } pd_map[4] = { { &pbox->top, &w->padding.top, key_padding_top }, @@ -1317,8 +1334,8 @@ void Widget_UpdateSize( LCUI_Widget w ) LCUI_Style s = &w->style->sheet[pd_map[i].key]; if( !s->is_valid || s->type != SVT_PX ) { pd_map[i].sval->type = SVT_PX; - pd_map[i].sval->px = 0; - *pd_map[i].ival = 0; + pd_map[i].sval->px = 0.0; + *pd_map[i].ival = 0.0; continue; } *pd_map[i].sval = *s; @@ -1364,10 +1381,12 @@ void Widget_UpdateSize( LCUI_Widget w ) } } if( w->parent ) { - Widget_InvalidateArea( w->parent, &rect, SV_PADDING_BOX ); - rect.width = w->box.graph.width; - rect.height = w->box.graph.height; - Widget_InvalidateArea( w->parent, &rect, SV_PADDING_BOX ); + LCUI_Rect r; + RectF2Rect( rect, r ); + Widget_InvalidateArea( w->parent, &r, SV_PADDING_BOX ); + r.width = (int)(w->box.graph.width + 0.5); + r.height = (int)(w->box.graph.height + 0.5); + Widget_InvalidateArea( w->parent, &r, SV_PADDING_BOX ); if( w->parent->style->sheet[key_width].type == SVT_AUTO || w->parent->style->sheet[key_height].type == SVT_AUTO ) { Widget_AddTask( w->parent, WTT_RESIZE ); @@ -1649,12 +1668,12 @@ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) return 0; } -int Widget_ComputeMaxWidth( LCUI_Widget w ) +float Widget_ComputeMaxWidth( LCUI_Widget w ) { LCUI_Style s; LCUI_Widget child; float scale = 1.0; - int width, padding = 0; + float width, padding = 0; width = LCUIWidget.root->box.padding.width; for( child = w; child->parent; child = child->parent ) { s = &child->style->sheet[key_width]; @@ -1702,11 +1721,11 @@ void Widget_UpdateLayout( LCUI_Widget w ) void Widget_ExecUpdateLayout( LCUI_Widget w ) { struct { - int x, y; - int line_height; + float x, y; + float line_height; LCUI_Widget prev; int prev_display; - int max_width; + float max_width; } ctx = { 0 }; LCUI_Widget child; LCUI_WidgetEventRec e; @@ -1811,14 +1830,14 @@ static void _LCUIWidget_PrintTree( LCUI_Widget w, int depth, const char *prefix strcat( str, "┬" ); } snode = Widget_GetSelectorNode( child ); - LOG( "%s%s %s, xy:(%d,%d), size:(%d,%d), " - "visible: %s, padding: (%d,%d,%d,%d), margin: (%d,%d,%d,%d)\n", - prefix, str, snode->fullname, child->x, child->y, - child->width, child->height, - child->computed_style.visible ? "true" : "false", - child->padding.top, child->padding.right, child->padding.bottom, - child->padding.left, child->margin.top, child->margin.right, - child->margin.bottom, child->margin.left ); + LOG( "%s%s %s, xy:(%.2f,%.2f), size:(%.2f,%.2f), " + "visible: %s, padding: (%.2f,%.2f,%.2f,%.2f), margin: (%.2f,%.2f,%.2f,%.2f)\n", + prefix, str, snode->fullname, child->x, child->y, + child->width, child->height, + child->computed_style.visible ? "true" : "false", + child->padding.top, child->padding.right, child->padding.bottom, + child->padding.left, child->margin.top, child->margin.right, + child->margin.bottom, child->margin.left ); SelectorNode_Delete( snode ); _LCUIWidget_PrintTree( child, depth+1, child_prefix ); } @@ -1829,9 +1848,9 @@ void Widget_PrintTree( LCUI_Widget w ) LCUI_SelectorNode node; w = w ? w : LCUIWidget.root; node = Widget_GetSelectorNode( w ); - LOG("%s, xy:(%d,%d), size:(%d,%d), visible: %s\n", - node->fullname, w->x, w->y, w->width, w->height, - w->computed_style.visible ? "true":"false"); + LOG( "%s, xy:(%.2f,%.2f), size:(%.2f,%.2f), visible: %s\n", + node->fullname, w->x, w->y, w->width, w->height, + w->computed_style.visible ? "true" : "false" ); SelectorNode_Delete( node ); _LCUIWidget_PrintTree( w, 0, " " ); } diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 5afd5913..b8cb5e21 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -68,7 +68,7 @@ static LCUI_BOOL Widget_IsPaintable( LCUI_Widget w ) static void Widget_AdjustArea( LCUI_Widget w, LCUI_Rect *in_rect, LCUI_Rect *out_rect, int box_type ) { - LCUI_Rect *box; + LCUI_RectF *box; switch( box_type ) { case SV_BORDER_BOX: box = &w->box.border; break; case SV_GRAPH_BOX: box = &w->box.graph; break; @@ -79,11 +79,11 @@ static void Widget_AdjustArea( LCUI_Widget w, LCUI_Rect *in_rect, /* 如果为NULL,则视为使用整个部件区域 */ if( !in_rect ) { out_rect->x = out_rect->y = 0; - out_rect->w = box->w; - out_rect->h = box->h; + out_rect->width = box->width; + out_rect->height = box->height; } else { *out_rect = *in_rect; - LCUIRect_ValidateArea( out_rect, box->w, box->h ); + LCUIRect_ValidateArea( out_rect, box->width, box->height ); } /* 将坐标转换成相对于图像呈现区的坐标 */ out_rect->x += (box->x - w->box.graph.x); @@ -139,7 +139,7 @@ int Widget_GetInvalidArea( LCUI_Widget widget, LCUI_Rect *area ) if( !rect ) { return -2; } - DEBUG_MSG("p_rect: %d,%d,%d,%d\n", rect->x, rect->y, rect->w, rect->h); + DEBUG_MSG("p_rect: %d,%d,%d,%d\n", rect->x, rect->y, rect->width, rect->height); *area = *rect; return 0; } @@ -187,18 +187,18 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) * @param[in] valid_box 当前部件内的有效框 * @param[out] rlist 收集到的无效区域列表 */ -static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, +static int _Widget_ProcInvalidArea( LCUI_Widget w, float x, float y, LCUI_Rect *valid_box, LinkedList *rlist ) { int count; LCUI_Widget child; LinkedListNode *node; - LCUI_Rect rect, child_box, *r; + LCUI_Rect child_box, rect; count = w->dirty_rects.length; /* 取出当前记录的无效区域 */ for( LinkedList_Each( node, &w->dirty_rects ) ) { - r = node->data; + LCUI_Rect *r = node->data; /* 若有独立位图缓存,则重绘脏矩形区域 */ if( w->enable_graph && Graph_IsValid( &w->graph ) ) { LCUI_PaintContextRec paint; @@ -224,7 +224,7 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, y += w->box.padding.y - w->box.graph.y; /* 向子级部件递归 */ for( LinkedList_Each( node, &w->children ) ) { - int child_x, child_y; + float child_x, child_y; child = node->data; if( !child->computed_style.visible || child->state != WSTATE_NORMAL ) { @@ -232,7 +232,7 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, } child_x = child->box.graph.x + x; child_y = child->box.graph.y + y; - child_box = child->box.graph; + RectF2Rect( child->box.graph, child_box ); /* 部件坐标是相对于内容框的,所以加上内容框XY坐标 */ child_box.x += w->box.padding.x - w->box.graph.x; child_box.y += w->box.padding.y - w->box.graph.y; @@ -242,10 +242,10 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, continue; } /* 转换为相对于子部件的坐标 */ - 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; + 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); count += _Widget_ProcInvalidArea( child, child_x, child_y, &child_box, rlist ); } @@ -256,17 +256,15 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, int Widget_ProcInvalidArea( LCUI_Widget w, LinkedList *rlist ) { LCUI_Rect valid_box; - valid_box.x = 0; - valid_box.y = 0; - valid_box.w = w->box.graph.w; - valid_box.h = w->box.graph.h; + RectF2Rect( w->box.graph, valid_box ); + valid_box.x = valid_box.y = 0; return _Widget_ProcInvalidArea( w, 0, 0, &valid_box, rlist ); } int Widget_ConvertArea( LCUI_Widget w, LCUI_Rect *in_rect, LCUI_Rect *out_rect, int box_type ) { - LCUI_Rect rect; + LCUI_RectF rect; if( !in_rect ) { return -1; } @@ -278,10 +276,10 @@ int Widget_ConvertArea( LCUI_Widget w, LCUI_Rect *in_rect, rect = w->box.content; rect.x -= w->padding.left; rect.y -= w->padding.top; - rect.w += w->padding.left; - rect.w += w->padding.right; - rect.h += w->padding.top; - rect.h += w->padding.bottom; + rect.width += w->padding.left; + rect.width += w->padding.right; + rect.height += w->padding.top; + rect.height += w->padding.bottom; break; case SV_BORDER_BOX: rect = w->box.border; @@ -295,22 +293,22 @@ int Widget_ConvertArea( LCUI_Widget w, LCUI_Rect *in_rect, rect.y -= w->box.graph.y; out_rect->x = in_rect->x - rect.x; out_rect->y = in_rect->y - rect.y; - out_rect->w = in_rect->w; - out_rect->h = in_rect->h; + out_rect->width = in_rect->width; + out_rect->height = in_rect->height; /* 裁剪掉超出范围的区域 */ if( out_rect->x < 0 ) { - out_rect->w += out_rect->x; + out_rect->width += out_rect->x; out_rect->x = 0; } if( out_rect->y < 0 ) { - out_rect->h += out_rect->y; + out_rect->height += out_rect->y; out_rect->y = 0; } - if( out_rect->x + out_rect->w > rect.w ) { - out_rect->w = rect.w - out_rect->x; + if( out_rect->x + out_rect->width > rect.width ) { + out_rect->width = rect.width - out_rect->x; } - if( out_rect->y + out_rect->h > rect.h ) { - out_rect->h = rect.h - out_rect->y; + if( out_rect->y + out_rect->height > rect.height ) { + out_rect->height = rect.height - out_rect->y; } return 0; } @@ -318,7 +316,7 @@ int Widget_ConvertArea( LCUI_Widget w, LCUI_Rect *in_rect, void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) { LinkedListNode *node; - int content_left, content_top; + float content_left, content_top; LCUI_PaintContextRec self_paint; LCUI_PaintContextRec child_paint; LCUI_Rect canvas_rect, content_rect; @@ -387,7 +385,8 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) if( has_content_graph ) { child_paint.with_alpha = TRUE; content_graph.color_type = COLOR_TYPE_ARGB; - Graph_Create( &content_graph, content_rect.w, content_rect.h ); + Graph_Create( &content_graph, + content_rect.width, content_rect.height ); } else { child_paint.with_alpha = paint->with_alpha; /* 引用该区域的位图,作为内容框的位图 */ @@ -402,9 +401,12 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) continue; } /* 转换子部件区域,由相对于内容框转换为相对于当前脏矩形 */ - child_rect = child->box.graph; - child_rect.x += (content_left - paint->rect.x); - child_rect.y += (content_top - paint->rect.y); + 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 -= paint->rect.x; + child_rect.y -= paint->rect.y; /* 获取与内容框重叠的区域,作为子部件的绘制区域 */ has_overlay = LCUIRect_GetOverlayRect( &content_rect, &child_rect, &child_paint.rect @@ -423,7 +425,7 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) 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.w, canvas_rect.h); + canvas_rect.width, canvas_rect.height); /* 在内容位图中引用所需的区域,作为子部件的画布 */ Graph_Quote( &child_paint.canvas, &content_graph, &canvas_rect ); Widget_Render( child, &child_paint ); diff --git a/src/util/parse.c b/src/util/parse.c index 11b448d9..9414b8c7 100644 --- a/src/util/parse.c +++ b/src/util/parse.c @@ -78,7 +78,7 @@ LCUI_BOOL ParseNumber( LCUI_Style s, const char *str ) case 'D': if( p[1] == 'p' || p[1] == 'P' ) { s->type = SVT_DP; - sscanf( num_str, "%d", &s->dp ); + sscanf( num_str, "%f", &s->dp ); } else { s->type = SVT_NONE; } @@ -87,10 +87,10 @@ LCUI_BOOL ParseNumber( LCUI_Style s, const char *str ) case 'p': if( p[1] == 'x' || p[1] == 'X' ) { s->type = SVT_PX; - sscanf( num_str, "%d", &s->px ); + sscanf( num_str, "%f", &s->px ); } else if( p[1] == 't' || p[1] == 'T' ) { s->type = SVT_PT; - sscanf( num_str, "%d", &s->pt ); + sscanf( num_str, "%f", &s->pt ); } else { s->type = SVT_NONE; } diff --git a/src/util/rect.c b/src/util/rect.c index a3d99d2e..af594406 100644 --- a/src/util/rect.c +++ b/src/util/rect.c @@ -45,10 +45,8 @@ #include #define LCUIRect_IsIncludeRect(a,b) \ - b->x >= a->x && b->x + b->w <= a->x + a->w \ - && b->y >= a->y && b->y + b->h <= a->y + a->h - -#define LCUIRect_IsMergeable(a, b) + b->x >= a->x && b->x + b->width <= a->x + a->width \ + && b->y >= a->y && b->y + b->height <= a->y + a->height /* 将数值转换成LCUI_Rect型结构体 */ LCUI_Rect Rect( int x, int y, int w, int h ) @@ -56,8 +54,8 @@ LCUI_Rect Rect( int x, int y, int w, int h ) LCUI_Rect r; r.x = x; r.y = y; - r.w = w; - r.h = h; + r.width = w; + r.height = h; return r; } @@ -119,20 +117,20 @@ void LCUIRect_ValidateArea( LCUI_Rect *rect, int box_w, int box_h ) LCUI_BOOL LCUIRect_IsCoverRect( LCUI_Rect *rect1, LCUI_Rect *rect2 ) { if( rect1->x > rect2->x ) { - if( rect2->x + rect2->w <= rect1->x ) { + if( rect2->x + rect2->width <= rect1->x ) { return FALSE; } } else { - if( rect1->x + rect1->w <= rect2->x ) { + if( rect1->x + rect1->width <= rect2->x ) { return FALSE; } } if( rect1->y > rect2->y ) { - if( rect2->y + rect2->h <= rect1->y ) { + if( rect2->y + rect2->height <= rect1->y ) { return FALSE; } } else { - if( rect1->y + rect1->h <= rect2->y ) { + if( rect1->y + rect1->height <= rect2->y ) { return FALSE; } } @@ -151,36 +149,36 @@ LCUI_BOOL LCUIRect_GetOverlayRect( const LCUI_Rect *a, LCUI_Rect *out ) { if( a->x > b->x ) { - if( b->x + b->w > a->x + a->w ) { - out->w = a->w; + if( b->x + b->width > a->x + a->width ) { + out->width = a->width; } else { - out->w = b->x + b->w - a->x; + out->width = b->x + b->width - a->x; } out->x = a->x; } else { - if( a->x + a->w > b->x + b->w ) { - out->w = b->w; + if( a->x + a->width > b->x + b->width ) { + out->width = b->width; } else { - out->w = a->x + a->w - b->x; + out->width = a->x + a->width - b->x; } out->x = b->x; } if( a->y > b->y ) { - if( b->y + b->h > a->y + a->h ) { - out->h = a->h; + if( b->y + b->height > a->y + a->height ) { + out->height = a->height; } else { - out->h = b->y + b->h - a->y; + out->height = b->y + b->height - a->y; } out->y = a->y; } else { - if( a->y + a->h > b->y + b->h ) { - out->h = b->h; + if( a->y + a->height > b->y + b->height ) { + out->height = b->height; } else { - out->h = a->y + a->h - b->y; + out->height = a->y + a->height - b->y; } out->y = b->y; } - if( out->w <= 0 || out->h <= 0 ) { + if( out->width <= 0 || out->height <= 0 ) { return FALSE; } return TRUE; @@ -193,20 +191,20 @@ void LCUIRect_MergeRect( LCUI_Rect *big, LCUI_Rect *a, LCUI_Rect *b ) } else { big->x = b->x; } - if( a->x + a->w < b->x + b->w ) { - big->w = b->x + b->w - big->x; + if( a->x + a->width < b->x + b->width ) { + big->width = b->x + b->width - big->x; } else { - big->w = a->x + a->w - big->x; + big->width = a->x + a->width - big->x; } if( a->y < b->y ) { big->y = a->y; } else { big->y = b->y; } - if( a->y + a->h < b->y + b->h ) { - big->h = b->y + b->h - big->y; + if( a->y + a->height < b->y + b->height ) { + big->height = b->y + b->height - big->y; } else { - big->h = a->y + a->h - big->y; + big->height = a->y + a->height - big->y; } } @@ -215,30 +213,30 @@ void LCUIRect_CutFourRect( LCUI_Rect *rect1, LCUI_Rect *rect2, { rects[0].x = rect2->x; rects[0].y = rect2->y; - rects[0].w = rect1->x - rect2->x; - rects[0].h = rect1->y + rect1->h - rect2->y; + rects[0].width = rect1->x - rect2->x; + rects[0].height = rect1->y + rect1->height - rect2->y; rects[1].x = rect2->x; - rects[1].y = rect1->y + rect1->h; - rects[1].w = rect1->x + rect1->w - rect2->x; - rects[1].h = rect2->y + rect2->h - rects[1].y; + rects[1].y = rect1->y + rect1->height; + rects[1].width = rect1->x + rect1->width - rect2->x; + rects[1].height = rect2->y + rect2->height - rects[1].y; - rects[2].x = rect1->x + rect1->w; + rects[2].x = rect1->x + rect1->width; rects[2].y = rect1->y; - rects[2].w = rect2->w - rects[1].w; - rects[2].h = rect2->y + rect2->h - rects[2].y; + rects[2].width = rect2->width - rects[1].width; + rects[2].height = rect2->y + rect2->height - rects[2].y; rects[3].x = rect1->x; rects[3].y = rect2->y; - rects[3].w = rect2->x + rect2->w - rects[3].x; - rects[3].h = rect1->y - rect2->y; + rects[3].width = rect2->x + rect2->width - rects[3].x; + rects[3].height = rect1->y - rect2->y; } int RectList_Add( LinkedList *list, LCUI_Rect *rect ) { LCUI_Rect *added_rect, union_rect; LinkedListNode *node, *prev; - if( rect->w <= 0 || rect->h <= 0 ) { + if( rect->width <= 0 || rect->height <= 0 ) { return -1; } for( LinkedList_Each( node, list ) ) { @@ -277,7 +275,7 @@ int RectList_Delete( LinkedList *list, LCUI_Rect *rect ) LinkedListNode *prev, *node; LCUI_Rect *p_rect, o_rect, tmp_rect[4]; - if( rect->w <= 0 || rect->h <= 0 ) { + if( rect->width <= 0 || rect->height <= 0 ) { return -1; } for( LinkedList_Each( node, list ) ) { @@ -298,8 +296,8 @@ int RectList_Delete( LinkedList *list, LCUI_Rect *rect ) LinkedList_DeleteNode( list, node ); node = prev; for( i = 0; i < 4; ++i ) { - if( tmp_rect[i].w <= 0 - || tmp_rect[i].h <= 0 ) { + if( tmp_rect[i].width <= 0 + || tmp_rect[i].height <= 0 ) { continue; } LinkedList_Insert( list, 0, &tmp_rect[0] ); @@ -320,7 +318,7 @@ int RectList_Delete( LinkedList *list, LCUI_Rect *rect ) LinkedList_DeleteNode( list, node ); node = prev; for( i = 0; i < 4; ++i ) { - if( tmp_rect[i].w <= 0 || tmp_rect[i].h <= 0 ) { + if( tmp_rect[i].width <= 0 || tmp_rect[i].height <= 0 ) { continue; } LinkedList_Insert( list, 0, &tmp_rect[i] );