更改背景绘制接口的参数

This commit is contained in:
Liu Chao
2015-04-26 14:10:48 +08:00
parent a2480c47ed
commit 06c023ac44
2 changed files with 74 additions and 64 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ LCUI_API void Background_Init( LCUI_Background *bg );
*/
LCUI_API void Graph_DrawBackground(
LCUI_PaintContext paint,
const LCUI_Size *box_size,
const LCUI_Rect *box,
LCUI_Background *bg
);
+73 -63
View File
@@ -61,14 +61,14 @@ void Background_Init( LCUI_Background *bg )
*/
void Graph_DrawBackground(
LCUI_PaintContext paint,
const LCUI_Size *box_size,
const LCUI_Rect *box,
LCUI_Background *bg
)
{
LCUI_Graph image;
LCUI_Size image_size;
LCUI_Pos image_pos = { 0, 0 };
LCUI_Rect read_rect;
LCUI_Rect read_rect, paint_rect;
Graph_FillColor( &paint->canvas, bg->color );
/* 计算背景图应有的尺寸 */
@@ -81,16 +81,16 @@ void Graph_DrawBackground(
mode = bg->image.width > bg->image.height;
case SV_COVER:
if( mode ) {
image_size.w = box_size->w;
image_size.h = bg->image.height*box_size->w;
image_size.w = box->w;
image_size.h = bg->image.height*box->w;
image_size.h = 1.0*image_size.h / bg->image.width;
image_pos.x = 0;
image_pos.y = (box_size->h - image_size.h) / 2;
image_pos.y = (box->h - image_size.h) / 2;
} else {
image_size.h = box_size->h;
image_size.w = bg->image.width*box_size->h;
image_size.h = box->h;
image_size.w = bg->image.width*box->h;
image_size.w = 1.0*image_size.w / bg->image.height;
image_pos.x = (box_size->w - image_size.w) / 2;
image_pos.x = (box->w - image_size.w) / 2;
image_pos.y = 0;
}
break;
@@ -102,7 +102,7 @@ void Graph_DrawBackground(
} else {
switch( bg->size.w.type ) {
case SVT_SCALE:
image_size.w = box_size->w * bg->size.w.scale;
image_size.w = box->w * bg->size.w.scale;
break;
case SVT_PX:
image_size.w = bg->size.w.px;
@@ -113,7 +113,7 @@ void Graph_DrawBackground(
}
switch( bg->size.h.type ) {
case SVT_SCALE:
image_size.h = box_size->h * bg->size.h.scale;
image_size.h = box->h * bg->size.h.scale;
break;
case SVT_PX:
image_size.h = bg->size.h.px;
@@ -128,37 +128,37 @@ void Graph_DrawBackground(
switch( bg->position.value ) {
case SV_TOP:
case SV_TOP_CENTER:
image_pos.x = (box_size->w - image_size.w) / 2;
image_pos.x = (box->w - image_size.w) / 2;
image_pos.y = 0;
break;
case SV_TOP_RIGHT:
image_pos.x = box_size->w - image_size.w;
image_pos.x = box->w - image_size.w;
image_pos.y = 0;
break;
case SV_CENTER_LEFT:
image_pos.x = 0;
image_pos.y = (box_size->h - image_size.h) / 2;
image_pos.y = (box->h - image_size.h) / 2;
break;
case SV_CENTER:
case SV_CENTER_CENTER:
image_pos.x = (box_size->w - image_size.w) / 2;
image_pos.y = (box_size->h - image_size.h) / 2;
image_pos.x = (box->w - image_size.w) / 2;
image_pos.y = (box->h - image_size.h) / 2;
break;
case SV_CENTER_RIGHT:
image_pos.x = box_size->w - image_size.w;
image_pos.y = (box_size->h - image_size.h) / 2;
image_pos.x = box->w - image_size.w;
image_pos.y = (box->h - image_size.h) / 2;
break;
case SV_BOTTOM_LEFT:
image_pos.x = 0;
image_pos.y = box_size->h - image_size.h;
image_pos.y = box->h - image_size.h;
break;
case SV_BOTTOM_CENTER:
image_pos.x = (box_size->w - image_size.w) / 2;
image_pos.y = box_size->h - image_size.h;
image_pos.x = (box->w - image_size.w) / 2;
image_pos.y = box->h - image_size.h;
break;
case SV_BOTTOM_RIGHT:
image_pos.x = box_size->w - image_size.w;
image_pos.y = box_size->h - image_size.h;
image_pos.x = box->w - image_size.w;
image_pos.y = box->h - image_size.h;
break;
case SV_TOP_LEFT:
default:
@@ -167,7 +167,7 @@ void Graph_DrawBackground(
} else {
switch( bg->position.x.type ) {
case SVT_SCALE:
image_pos.x = box_size->w - image_size.w;
image_pos.x = box->w - image_size.w;
image_pos.x *= bg->position.x.scale;
break;
case SVT_PX:
@@ -177,7 +177,7 @@ void Graph_DrawBackground(
}
switch( bg->position.y.type ) {
case SVT_SCALE:
image_pos.y = box_size->h - image_size.h;
image_pos.y = box->h - image_size.h;
image_pos.y *= bg->position.y.scale;
break;
case SVT_PX:
@@ -186,52 +186,62 @@ void Graph_DrawBackground(
default:break;
}
}
/* 获取当前绘制区域与背景内容框的重叠区域 */
if( !LCUIRect_GetOverlayRect( box, &paint->rect, &paint_rect ) ) {
return;
}
/* 将坐标转换为相对于背景内容框 */
paint_rect.x -= box->x;
paint_rect.y -= box->y;
/* 保存背景图像区域 */
read_rect.x = image_pos.x;
read_rect.y = image_pos.y;
read_rect.width = image_size.w;
read_rect.height = image_size.h;
/* 获取当前绘制区域与背景图像的重叠区域 */
if( LCUIRect_GetOverlayRect( &read_rect, &paint->rect, &read_rect ) ) {
/* 转换成相对于图像的坐标 */
read_rect.x -= image_pos.x;
read_rect.y -= image_pos.y;
/* 如果尺寸没有变化则直接引用 */
if( image_size.w == bg->image.w && image_size.h == bg->image.h ) {
Graph_Quote( &image, &bg->image, &read_rect );
/* 转换成相对于当前绘制区域的坐标 */
image_pos.x -= paint->rect.x;
image_pos.y -= paint->rect.y;
Graph_Mix( &paint->canvas, &image, image_pos );
} else {
float scale;
LCUI_Graph buffer;
LCUI_Rect quote_rect;
if( !LCUIRect_GetOverlayRect( &read_rect, &paint_rect, &read_rect ) ) {
return;
}
/* 转换成相对于图像的坐标 */
read_rect.x -= image_pos.x;
read_rect.y -= image_pos.y;
/* 如果尺寸没有变化则直接引用 */
if( image_size.w == bg->image.w && image_size.h == bg->image.h ) {
Graph_Quote( &image, &bg->image, &read_rect );
/* 转换成相对于当前绘制区域的坐标 */
image_pos.x = image_pos.x + box->x - paint->rect.x;
image_pos.y = image_pos.y + box->y - paint->rect.y;
Graph_Mix( &paint->canvas, &image, image_pos );
} else {
float scale;
LCUI_Graph buffer;
LCUI_Rect quote_rect;
Graph_Init( &buffer );
quote_rect = read_rect;
/* 根据宽高的缩放比例,计算实际需要引用的区域 */
if( image_size.w != bg->image.w ) {
scale = 1.0 * bg->image.width / image_size.w;
quote_rect.x *= scale;
quote_rect.width *= scale;
}
if( image_size.h != bg->image.h ) {
scale = 1.0 * bg->image.height / image_size.h;
quote_rect.y *= scale;
quote_rect.height *= scale;
}
/* 引用源背景图像的一块区域 */
Graph_Quote( &image, &bg->image, &quote_rect );
image_size.w = read_rect.width;
image_size.h = read_rect.height;
/* 计算相对于绘制区域的坐标 */
image_pos.x = read_rect.x + image_pos.x - paint->rect.x;
image_pos.y = read_rect.y + image_pos.y - paint->rect.y;
/* 按比例进行缩放 */
Graph_Zoom( &image, &buffer, FALSE, image_size );
Graph_Mix( &paint->canvas, &buffer, image_pos );
Graph_Free( &buffer );
Graph_Init( &buffer );
quote_rect = read_rect;
/* 根据宽高的缩放比例,计算实际需要引用的区域 */
if( image_size.w != bg->image.w ) {
scale = 1.0 * bg->image.width / image_size.w;
quote_rect.x *= scale;
quote_rect.width *= scale;
}
if( image_size.h != bg->image.h ) {
scale = 1.0 * bg->image.height / image_size.h;
quote_rect.y *= scale;
quote_rect.height *= scale;
}
/* 引用源背景图像的一块区域 */
Graph_Quote( &image, &bg->image, &quote_rect );
image_size.w = read_rect.width;
image_size.h = read_rect.height;
/* 计算相对于绘制区域的坐标 */
image_pos.x = read_rect.x + image_pos.x;
image_pos.x = image_pos.x + box->x - paint->rect.x;
image_pos.y = read_rect.y + image_pos.y;
image_pos.y = image_pos.y + box->y - paint->rect.y;
/* 按比例进行缩放 */
Graph_Zoom( &image, &buffer, FALSE, image_size );
Graph_Mix( &paint->canvas, &buffer, image_pos );
Graph_Free( &buffer );
}
}