FontLIB_AddFontBMP( wchar_t char_code, int font_id, int pixel_size, LCUI_FontBMP *fontbmp_buff ) { LCUI_FontCharItem *font; LCUI_FontDataItem *data; LCUI_FontBMPItem *bmp; if( !database_init ) { return NULL; } /* 获取字体数据句柄,如果获取失败,则新增 */ font = FontLIB_GetCharItem( char_code ); if( !font ) { font = malloc( sizeof(LCUI_FontCharItem) ); if( !font ) { return NULL; } FontLIB_CharInit( font ); font->char_code = char_code; /* 记录字符的编码 */ Queue_AddPointer( &fontbitmap_database, font ); } /* 但字体ID不大于0时,使用内置字体 */ if( font_id <= 0 ) { font_id = in_core_font->id; } /* 获取字体字族句柄,如果获取失败,则新增 */ data = FontLIB_GetDataItem( font, font_id ); if( !data ) { data = malloc( sizeof(LCUI_FontDataItem) ); if( !data ) { return NULL; } FontLIB_DataInit( data ); data->font_id = font_id; /* 记录该字符使用的字体ID */ Queue_AddPointer( &font->data, data ); } /* 获取字体位图句柄,如果获取失败,则新增 */ bmp = FontLIB_GetBMPItem( data, pixel_size ); if( !bmp ) { bmp = malloc( sizeof(LCUI_FontBMPItem) ); if( !bmp ) { return NULL; } bmp->pixel_size = pixel_size; /* 记录该字符的像素尺寸 */ bmp->bitmap = NULL; Queue_AddPointer( &data->font_bmp, bmp ); } /* 如果该指针为NULL,那么就申请一块空间 */ if( NULL == bmp->bitmap ) { bmp->bitmap = malloc( sizeof(LCUI_FontBMP) ); if( !bmp->bitmap ) { return NULL; } } /* 拷贝数据至该空间内 */ memcpy( bmp->bitmap, fontbmp_buff, sizeof(LCUI_FontBMP) ); return bmp->bitmap; }
LCUI_API int GraphLayer_AddChild( LCUI_GraphLayer *des_ctnr, LCUI_GraphLayer *glayer ) { int i, total; LCUI_GraphLayer *tmp_child; //_DEBUG_MSG( "des_ctnr: %p, glayer: %p\n", des_ctnr, glayer ); /* 容器图层必须有效 */ if( !des_ctnr ) { return -1; } /* 子图层必须有效,并且不能有父图层 */ if( !glayer || glayer->parent ) { //_DEBUG_MSG( "!glayer || glayer->parent\n" ); return -2; } /* 根据队列中的z值,将子图层存放在队列中适当的位置 */ total = Queue_GetTotal( &des_ctnr->child ); for( i=0; i<total; ++i ) { tmp_child = (LCUI_GraphLayer*)Queue_Get( &des_ctnr->child, i ); /* 如果比当前位置的图层的z值小,那就对比下一个位置的图层 */ if( glayer->z_index < tmp_child->z_index ) { continue; } /* 将新图层插入至该位置 */ Queue_InsertPointer( &des_ctnr->child, i, glayer ); break; } /* 如果没找到位置,则直接添加至末尾 */ if( i >= total ) { Queue_AddPointer( &des_ctnr->child, glayer ); } glayer->parent = des_ctnr; return 0; }
/* 注册一个输入法 */ LCUI_API int LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func ) { static int ime_id = 0; // 输入法的ID LCUIIME_Info *ptr_data; if( !imelist_init ) { return -1; } if( LCUIIME_FindByName( ime_name ) != NULL ) { return -2; } ptr_data = (LCUIIME_Info*)malloc( sizeof(LCUIIME_Info) ); if( !ptr_data ) { return -3; } LCUIString_Init( &ptr_data->name ); _LCUIString_Copy( &ptr_data->name, ime_name ); ime_id = ime_id + 1; ptr_data->id = ime_id; memcpy( &ptr_data->func, ime_func, sizeof(LCUIIME_Func) ); Queue_AddPointer( &imelist, ptr_data ); return ime_id; }
/* 新建一个主循环 */ LCUI_API LCUI_MainLoop* LCUI_MainLoop_New( void ) { LCUI_MainLoop *loop; if( !init_mainloop_queue ) { LCUI_MainLoopQueue_Init(); init_mainloop_queue = TRUE; } loop = LCUI_MainLoop_GetAvailable(); if( loop == NULL ) { loop = (LCUI_MainLoop*)malloc(sizeof(LCUI_MainLoop)); if( !loop ) { return NULL; } } loop->app_id = LCUIApp_GetSelfID(); loop->quit = FALSE; loop->level = Queue_GetTotal( &mainloop_queue ); loop->running = FALSE; Queue_AddPointer( &mainloop_queue, loop ); /* 重新对主循环队列进行排序 */ LCUI_MainLoopQueue_Sort(); return loop; }
/* 为样式类添加样式属性 */ LCUI_API int StyleClass_SetStyleAttr( LCUI_StyleClass *style_class, const char *pseudo_class_name, const char *attr_name, const char *attr_value ) { LCUI_StyleAttr *style_attr; if( !style_class ) { return -1; } style_attr = StyleLib_GetStyleAttr( style_class, pseudo_class_name, attr_name ); /* 如果已存在该属性,则覆盖属性值 */ if( style_attr ) { _LCUIString_Copy( &style_attr->attr_value, attr_value ); return 0; } /* 否则,就需要新增属性项了 */ style_attr = malloc( sizeof(LCUI_StyleAttr) ); if( !style_attr ) { return -2; } StyleAttr_Init( style_attr ); /* 保存属性名和属性值 */ _LCUIString_Copy( &style_attr->attr_name, attr_name ); _LCUIString_Copy( &style_attr->attr_value, attr_value ); Queue_AddPointer( &style_class->style_attr, style_attr ); return 0; }
Frames_Play(LCUI_Frames *frames) /* 功能:播放动画 */ { int i, total; LCUI_Frames *tmp_ptr; if( !frames ) { return -1; } frames->state = 1; if(__timer_id == -1){ Queue_Init( &frames_stream, sizeof(LCUI_Frames), NULL ); Queue_UsingPointer( &frames_stream ); __timer_id = set_timer( 50, Process_Frames, TRUE ); } /* 检查该动画是否已存在 */ Queue_Lock( &frames_stream ); total = Queue_GetTotal( &frames_stream ); for( i=0; i<total; ++i ) { tmp_ptr = Queue_Get( &frames_stream, i ); if( tmp_ptr == frames ) { break; } } Queue_Unlock( &frames_stream ); /* 添加至动画更新队列中 */ if( i>=total ) { return Queue_AddPointer(&frames_stream, frames); } return 1; }
static int __GraphLayer_GetLayers( LCUI_GraphLayer *root_glayer, LCUI_GraphLayer *glayer, LCUI_Rect rect, LCUI_Queue *queue ) { int i, total; LCUI_Pos pos; LCUI_Rect tmp; LCUI_GraphLayer *child; LCUI_Queue *child_list; if( !glayer ) { //_DEBUG_MSG("!glayer\n"); return -1; } if( !glayer->visible ) { //_DEBUG_MSG("!glayer_visible\n"); return 1; } child_list = &glayer->child; /* 从底到顶遍历子部件 */ total = Queue_GetTotal( child_list ); //_DEBUG_MSG( "root: %p, cur: %p, child total: %d\n", // root_glayer, glayer, total ); /* 从尾到首,从底到顶,遍历图层 */ for( i=total-1; i>=0; --i ) { child = (LCUI_GraphLayer*)Queue_Get( child_list, i ); /* 忽略无效或不可见的图层 */ if( !child || !child->visible ) { continue; } /* 获取子图层的有效区域及全局坐标 */ tmp = GraphLayer_GetValidRect( root_glayer, child ); pos = GraphLayer_GetGlobalPos( root_glayer, child ); //_DEBUG_MSG( "child: %p, pos: %d,%d, valid rect: %d,%d, %d, %d\n", // child, pos.x, pos.y, tmp.x, tmp.y, tmp.width, tmp.height); //Graph_PrintInfo( &child->graph ); /* 有效区域加上子部件的全局坐标 */ tmp.x += pos.x; tmp.y += pos.y; /* 判断区域是否有效 */ if( !LCUIRect_IsValid(tmp) ) { continue; } /* 若该有效区域与目标区域重叠,则记录子部件,并进行递归 */ if( LCUIRect_Overlay(tmp, rect) ) { Queue_AddPointer( queue, child ); __GraphLayer_GetLayers( root_glayer, child, rect, queue ); } } return 0; }
FontLIB_AddFontInfo( const char *family_name, const char *style_name, const char *filepath, FT_Face face ) { LCUI_FontInfo *info; info = malloc( sizeof(LCUI_FontInfo) ); info->id = ++font_count; strncpy( info->family_name, family_name, NAME_MAX_LEN ); strncpy( info->style_name, style_name, NAME_MAX_LEN ); strncpy( info->filepath, style_name,PATH_MAX_LEN ); info->face = face; Queue_AddPointer( &font_database, info ); return info->id; }
static Thread_TreeNode * ThreadTreeNode_AddNew( Thread_TreeNode *ttn, LCUI_Thread tid ) /* 功能:在线程树中添加新的结点 */ { Thread_TreeNode *new_ttn; new_ttn = malloc(sizeof(Thread_TreeNode)); Thread_TreeNode_Init( new_ttn ); new_ttn->tid = tid; new_ttn->parent = ttn; Queue_AddPointer(& ttn->child, new_ttn ); return new_ttn; }
/* 为两个单选框建立互斥关系 */ LCUI_API void RadioButton_CreateMutex( LCUI_Widget a, LCUI_Widget b ) { LCUI_Queue *p, queue; LCUI_RadioButton *rb_a, *rb_b; if(mutex_lib_init == 0) { Queue_Init(&mutex_lib, sizeof(LCUI_Queue), __Destroy_MutexData); mutex_lib_init = 1; } rb_a = (LCUI_RadioButton *)Widget_GetPrivData(a); rb_b = (LCUI_RadioButton *)Widget_GetPrivData(b); if( !rb_a->mutex ) { if( !rb_b->mutex ) { Queue_Init(&queue, sizeof(LCUI_Widget*), NULL); /* 将子队列添加至父队列 */ p = (LCUI_Queue*)Queue_Add(&mutex_lib, &queue); /* 添加指针至队列 */ Queue_AddPointer(p, a); Queue_AddPointer(p, b); /* 保存指向关系队列的指针 */ rb_a->mutex = p; rb_b->mutex = p; } else { Queue_AddPointer(rb_b->mutex, a); rb_a->mutex = rb_b->mutex; } } else { if( !rb_b->mutex ) { Queue_AddPointer(rb_a->mutex, b); rb_b->mutex = rb_a->mutex; } else {/* 否则,两个都和其它部件有互斥关系,需要将它们拆开,并重新建立互斥关系 */ RadioButton_DeleteMutex(a); RadioButton_DeleteMutex(b); RadioButton_CreateMutex(a, b); } } }
/* 对目标行进行断行处理,也就是将目标行指定位置后面的全部文字转移到另一行 */ static void TextLayer_Text_RowBreak ( LCUI_TextLayer *layer, Text_RowData *src, int break_point, Text_RowData *des ) { static int i, total; static LCUI_CharData *char_ptr; total = Queue_GetTotal( &src->string ); for(i=break_point; i<total; ++i ) { char_ptr = Queue_Get( &src->string, break_point ); Queue_AddPointer( &des->string, char_ptr ); char_ptr->need_update = TRUE; Queue_DeletePointer( &src->string, break_point ); } }
/* 添加指定名称的样式类到样式库中 */ LCUI_API LCUI_StyleClass* StyleLib_AddStyleClass( LCUI_StyleLibrary *lib, const char *class_name ) { LCUI_StyleClass *style_class; /* 如果已存在同名类 */ if( StyleLib_GetStyleClass( lib, class_name ) ) { return NULL; } style_class = (LCUI_StyleClass*)malloc( sizeof(LCUI_StyleClass) ); if( !style_class ) { return NULL; } StyleClass_Init( style_class ); /* 保存类名 */ _LCUIString_Copy( &style_class->class_name, class_name ); Queue_AddPointer( &lib->style_classes, style_class ); return style_class; }