/* 添加矩形区域至当前占用的队列 */ LCUI_API int RectQueue_AddToCurrent( LCUI_RectQueue *queue, LCUI_Rect rect ) { if( queue->number == 0 ) { return RectQueue_Add( &queue->queue[0], rect ); } else { return RectQueue_Add( &queue->queue[1], rect ); } }
TextLayer_Refresh( LCUI_TextLayer *layer ) /* 标记文本图层中每个字的位图,等待绘制文本图层时进行更新 */ { int i, j; int rows, len; Text_RowData *row_ptr; LCUI_CharData *char_ptr; LCUI_Rect area; rows = Queue_GetTotal( &layer->rows_data ); for(area.y=0,area.x=0,i=0; i<rows; ++i) { row_ptr = Queue_Get( &layer->rows_data, i ); len = Queue_GetTotal( &row_ptr->string ); for(j=0; j<len; ++j) { char_ptr = Queue_Get( &row_ptr->string, j ); if( !char_ptr ) { continue; } char_ptr->need_update = TRUE; } area.height = row_ptr->max_size.h; area.width = row_ptr->max_size.w; RectQueue_Add( &layer->clear_area, area ); area.y += row_ptr->max_size.h; } }
static void TextLayer_Clear( LCUI_TextLayer *layer, LCUI_Pos pos, int max_h, LCUI_CharData *char_ptr ) { static LCUI_Rect area; //printf("pos: %d,%d, max_h: %d\n", pos.x, pos.y, max_h); /* 计算区域范围 */ area.x = pos.x + char_ptr->bitmap->left; area.y = pos.y + max_h-1; area.y -= char_ptr->bitmap->top; area.width = char_ptr->bitmap->width; area.height = char_ptr->bitmap->rows; /* 记录需刷新的区域 */ RectQueue_Add( &layer->clear_area, area ); //printf("record area: %d,%d,%d,%d\n", area.x, area.y, area.width, area.height); }
void TextLayer_Merge( LCUI_TextLayer *des, LCUI_TextLayer *src ) /* 合并两个文本图层 */ { LCUI_Rect area, tmp_area; uint_t i, j, old_size, new_size; LCUI_CharData *src_ptr, *des_ptr; Text_RowData *src_row_ptr, *des_row_ptr; uint_t old_rows, new_rows, max_rows, min_rows; int32_t src_len, des_len, max_len, min_len; old_rows = Queue_Get_Total( &des->rows_data ); new_rows = Queue_Get_Total( &src->rows_data ); DEBUG_MSG("old_rows: %d, new_rows: %d\n", old_rows, new_rows); if(old_rows > new_rows) { max_rows = old_rows; min_rows = new_rows; } else { max_rows = new_rows; min_rows = old_rows; } for(area.y=0,i=0; i<min_rows; ++i) { area.x = 0; src_row_ptr = Queue_Get( &src->rows_data, i ); des_row_ptr = Queue_Get( &des->rows_data, i ); src_len = Queue_Get_Total( &src_row_ptr->string ); des_len = Queue_Get_Total( &des_row_ptr->string ); if(src_len > des_len) { max_len = src_len; min_len = des_len; } else { max_len = des_len; min_len = src_len; } for(j=0; j<min_len; ++j) { src_ptr = Queue_Get( &src_row_ptr->string, j ); des_ptr = Queue_Get( &des_row_ptr->string, j ); area.x += des_ptr->bitmap.left; /* 获取字体大小 */ if(src_ptr->data == NULL) { new_size = 12; } else { if(src_ptr->data->pixel_size > 0) { new_size = src_ptr->data->pixel_size; } else { new_size = 12; } } if(des_ptr->data == NULL) { old_size = 12; } else { if(des_ptr->data->pixel_size > 0) { old_size = des_ptr->data->pixel_size; } else { old_size = 12; } } if(src_ptr->char_code == des_ptr->char_code) { /* 转移字体位图数据 */ src_ptr->bitmap = des_ptr->bitmap; /* 指针赋值为NULL,避免被释放 */ des_ptr->bitmap.buffer = NULL; src_ptr->need_update = FALSE; } else { src_ptr->need_update = TRUE; } if(new_size != old_size) { src_ptr->need_update = TRUE; } //文本样式也要对比 //.... if(src_ptr->need_update) { tmp_area.x = area.x; tmp_area.y = area.y + old_size+2 - des_ptr->bitmap.top; tmp_area.width = des_ptr->bitmap.width; tmp_area.height = des_ptr->bitmap.rows; RectQueue_Add( &des->clear_area, tmp_area ); area.x += des_ptr->bitmap.width; FontBMP_Free(&des_ptr->bitmap); } else { area.x += des_ptr->bitmap.width; } } if( src_len < max_len ) { /* 如果这一行删减了几个字,则记录区域 */ for(j=min_len; j<max_len; ++j) { des_ptr = Queue_Get( &des_row_ptr->string, j ); if(des_ptr->data == NULL) { old_size = 12; } else { if(des_ptr->data->pixel_size > 0) { old_size = des_ptr->data->pixel_size; } else { old_size = 12; } } area.x += des_ptr->bitmap.left; area.width = area.height = old_size+2; RectQueue_Add( &des->clear_area, area ); area.x += des_ptr->bitmap.width; } } area.y += des_row_ptr->max_size.h; } area.x = 0; if(new_rows < max_rows) {/* 如果是删减几行文本,则需要记录被删文本的区域 */ for(i=min_rows; i<max_rows; ++i) { des_row_ptr = Queue_Get( &des->rows_data, min_rows ); area.width = des_row_ptr->max_size.w; area.height = des_row_ptr->max_size.h; RectQueue_Add( &des->clear_area, area ); } } /* 转移数据 */ Destroy_Queue( &des->text_source_data ); des->text_source_data = src->text_source_data; Destroy_Queue( &des->rows_data ); des->rows_data = src->rows_data; }
void TextLayer_Text_Set_Default_Style( LCUI_TextLayer *layer, LCUI_TextStyle style ) /* 设定默认的文本样式,需要调用TextLayer_Draw函数进行文本位图更新 */ { LCUI_Rect area, tmp_area; uint_t i, j; LCUI_CharData *char_ptr; LCUI_TextStyle *old_style; Text_RowData *row_ptr; int32_t rows, len, old_size; layer->default_data = style; rows = Queue_Get_Total( &layer->rows_data ); for(area.y=0,i=0; i<rows; ++i) { area.x = 0; row_ptr = Queue_Get( &layer->rows_data, i ); len = Queue_Get_Total( &row_ptr->string ); for(j=0; j<len; ++j) { char_ptr = Queue_Get( &row_ptr->string, j ); area.x += char_ptr->bitmap.left; old_style = char_ptr->data; if(old_style == NULL) { old_size = 12; char_ptr->need_update = TRUE; } else { if(old_style->pixel_size > 0) { old_size = old_style->pixel_size; } else { old_size = 12; } } /* 若有属性是缺省的 */ if(!old_style->_pixel_size) { old_style->pixel_size = style.pixel_size; char_ptr->need_update = TRUE; } if(!old_style->_style) { old_style->style = style.style; char_ptr->need_update = TRUE; } if(!old_style->_family) { strcpy(old_style->family, style.family); char_ptr->need_update = TRUE; } if(!old_style->_weight) { old_style->weight = style.weight; char_ptr->need_update = TRUE; } if(!old_style->_back_color) { old_style->back_color = style.back_color; char_ptr->need_update = TRUE; } if(!old_style->_fore_color) { old_style->fore_color = style.fore_color; char_ptr->need_update = TRUE; } if(!old_style->_decoration) { old_style->decoration = style.decoration; char_ptr->need_update = TRUE; } if(char_ptr->need_update) { tmp_area.x = area.x; tmp_area.y = area.y + old_size+2 - char_ptr->bitmap.top; tmp_area.width = char_ptr->bitmap.width; tmp_area.height = char_ptr->bitmap.rows; /* 记录之前字体位图所在区域,等待刷新 */ RectQueue_Add( &layer->clear_area, tmp_area ); area.x += char_ptr->bitmap.width; /* 重新获取字体位图 */ FontBMP_Free(&char_ptr->bitmap); TextLayer_Get_Char_BMP ( &layer->default_data, char_ptr ); } else { area.x += char_ptr->bitmap.width; } } area.y += row_ptr->max_size.h; } }
static void __TextLayer_OldArea_Erase( LCUI_TextLayer *layer, LCUI_Graph *graph ) /* * 功能:擦除文本图层的老区域 * 说明:根据记录的旧偏移坐标,刷新部件区域内的文字所在区域。 * */ { static int i, j, x, y, rows, len; static Text_RowData *row_ptr; static LCUI_CharData *char_ptr; static LCUI_Rect area; rows = Queue_GetTotal( &layer->rows_data ); /* 除去y轴偏移量,计算处于显示区域内的起始行的y轴坐标 */ for(y=layer->old_offset_pos.y,i=0; y<0 && i<rows; ++i) { row_ptr = Queue_Get( &layer->rows_data, i ); if( !row_ptr ) { continue; } if( y + row_ptr->max_size.h >= 0 ) { break; } y += row_ptr->max_size.h; } for(; i<rows; ++i) { row_ptr = Queue_Get( &layer->rows_data, i ); if( !row_ptr ) { continue; } len = Queue_GetTotal( &row_ptr->string ); /* 除去x轴偏移量,计算处于显示区域内的起始列的x轴坐标 */ for(x=layer->old_offset_pos.x,j=0; x<0 && j<len; ++j) { char_ptr = Queue_Get( &row_ptr->string, j ); if( !char_ptr ) { continue; } if( x+char_ptr->bitmap->advance.x >= 0 ) { break; } x += char_ptr->bitmap->advance.x; } /* 计算当前行的区域高度 */ area.height = layer->default_data.pixel_size+2; for( ; j<len; ++j ) { char_ptr = Queue_Get( &row_ptr->string, j ); if( !char_ptr ) { continue; } area.y = row_ptr->max_size.h-1; area.y -= char_ptr->bitmap->top; if( area.y + char_ptr->bitmap->rows > area.height ) { area.height = area.y + char_ptr->bitmap->rows; } /* 累加当前行的宽度(已减去x轴偏移量) */ x += char_ptr->bitmap->advance.x; if( x > graph->width ) { break; } } /* 计算相对于图层内的区域 */ area.x = 0-layer->offset_pos.x; area.y = y-layer->offset_pos.y; area.width = x; RectQueue_Add( &layer->clear_area, area ); //_DEBUG_MSG("area: %d,%d,%d,%d\n", area.x, area.y, area.width, area.height); y += row_ptr->max_size.h; if( y > graph->height ) { break; } } }
/* 将矩形数据追加至队列 */ static int RectQueue_Add( LCUI_Queue* queue, LCUI_Rect rect ) { int i, flag = 0; LCUI_Rect *rect_ptr, *cur_rect_ptr; LCUI_Queue rect_buff; if( rect.width <= 0 || rect.height <= 0 ) { return -1; } DEBUG_MSG("add new rect: %d,%d,%d,%d, current total: %d\n", rect.x, rect.y, rect.width, rect.height, queue->total_num); Queue_Init( &rect_buff, sizeof(LCUI_Rect), NULL ); for (i=0; i<queue->total_num; ++i) { cur_rect_ptr = (LCUI_Rect*)Queue_Get( queue, i ); if( !cur_rect_ptr ) { break; } DEBUG_MSG("[%d] rect: %d,%d,%d,%d\n", i, cur_rect_ptr->x, cur_rect_ptr->y, cur_rect_ptr->width, cur_rect_ptr->height); /* 如果矩形无效,或者被新增的矩形区域包含,则删除 */ if ( cur_rect_ptr->width <= 0 || cur_rect_ptr->height <= 0 || LCUIRect_IncludeRect( rect, *cur_rect_ptr) ) { Queue_Delete ( queue, i ); continue; } /* 如果与现有的矩形相同,或被现有的矩形包含 */ if( LCUIRect_Equal( rect, *cur_rect_ptr) || LCUIRect_IncludeRect( *cur_rect_ptr, rect ) ) { flag = 1; break; } /* 如果新增的矩形与队列中的矩形不重叠 */ if( !LCUIRect_Overlay(rect, *cur_rect_ptr) ) { continue; } continue; // 暂时不对相交的矩形进行分割 DEBUG_MSG("[%d] rect overlay, start cut\n", i); /* 根据当前区域,分割新区域 */ LCUIRect_Cut( *cur_rect_ptr, rect, &rect_buff ); for( i=0; i<rect_buff.total_num; ++i ) { rect_ptr = (LCUI_Rect*)Queue_Get( &rect_buff, i ); if( !rect_ptr ) { break; } DEBUG_MSG("[%d] add child rect: %d,%d,%d,%d\n", i, rect_ptr->x, rect_ptr->y, rect_ptr->width, rect_ptr->height); RectQueue_Add( queue, *rect_ptr ); } flag = 1; break; } /* 销毁队列 */ Queue_Destroy( &rect_buff ); if ( flag == 0 ) { return Queue_Add( queue, &rect ); } return -1; }