/** 创建一个事件容器实例 */ LCUI_EventBox $(Create)(void) { LCUI_EventBox box; box = NEW_ONE(struct LCUI_EventBoxRec_); box->event_id = 100; box->handler_id = 100; box->current = 0; RBTree_Init( &box->event_slot ); RBTree_Init( &box->event_name ); RBTree_Init( &box->event_handler ); RBTree_Init( &box->used_evnet_id ); RBTree_OnJudge( &box->event_name, CompareEventName ); RBTree_OnDestroy( &box->event_handler, DestroyEventHandler ); RBTree_OnDestroy( &box->event_slot, DestroyEventSlot ); RBTree_SetDataNeedFree( &box->event_handler, 0 ); RBTree_SetDataNeedFree( &box->event_name, 0 ); RBTree_SetDataNeedFree( &box->used_evnet_id, 0 ); LinkedList_Init( &box->events[0], sizeof(LCUI_Event) ); LinkedList_Init( &box->events[1], sizeof(LCUI_Event) ); LinkedList_SetDataNeedFree( &box->events[0], 1 ); LinkedList_SetDataNeedFree( &box->events[1], 1 ); LinkedList_SetDestroyFunc( &box->events[0], DestroyEvent ); LinkedList_SetDestroyFunc( &box->events[1], DestroyEvent ); return box; }
/** 构造函数 */ static void Widget_Init(LCUI_Widget widget) { ZEROSET(widget, LCUI_Widget); widget->state = LCUI_WSTATE_CREATED; widget->trigger = EventTrigger(); widget->style = StyleSheet(); widget->custom_style = StyleSheet(); widget->inherited_style = StyleSheet(); widget->computed_style.opacity = 1.0; widget->computed_style.visible = TRUE; widget->computed_style.focusable = FALSE; widget->computed_style.display = SV_BLOCK; widget->computed_style.position = SV_STATIC; widget->computed_style.pointer_events = SV_AUTO; widget->computed_style.box_sizing = SV_CONTENT_BOX; widget->computed_style.margin.top.type = LCUI_STYPE_PX; widget->computed_style.margin.right.type = LCUI_STYPE_PX; widget->computed_style.margin.bottom.type = LCUI_STYPE_PX; widget->computed_style.margin.left.type = LCUI_STYPE_PX; widget->computed_style.padding.top.type = LCUI_STYPE_PX; widget->computed_style.padding.right.type = LCUI_STYPE_PX; widget->computed_style.padding.bottom.type = LCUI_STYPE_PX; widget->computed_style.padding.left.type = LCUI_STYPE_PX; Widget_InitBackground(widget); LinkedList_Init(&widget->children); LinkedList_Init(&widget->children_show); }
/** 初始化程序数据结构体 */ static void LCUIApp_Init(void) { LCUICond_Init( &MainApp.loop_cond ); LCUIMutex_Init( &MainApp.loop_changed ); LCUIMutex_Init( &MainApp.loop_mutex ); LinkedList_Init( &MainApp.loop_list, sizeof(LCUI_MainLoop)); LinkedList_SetDataNeedFree( &MainApp.loop_list, FALSE ); LCUIMutex_Init( &MainApp.task_run_mutex ); LCUIMutex_Init( &MainApp.task_list_mutex ); LinkedList_Init( &MainApp.task_list, sizeof(LCUI_Task) ); LinkedList_SetDestroyFunc( &MainApp.task_list, DestroyTask ); }
static int $($RegisterEvent)( LCUI_EventBox box, const char *event_name, int id ) { LCUI_RBTreeNode *node; LCUI_EventSlot *slot; /* 查找事件槽记录 */ if( node = RBTree_CustomSearch( &box->event_name, (const void*)event_name ) ) { return -1; } if( node = RBTree_Search( &box->used_evnet_id, id ) ) { return -2; } /* 新建一个事件槽 */ slot = NEW_ONE(LCUI_EventSlot); slot->name = (char*)malloc(sizeof(char)*(strlen(event_name)+1)); slot->id = id; strcpy( slot->name, event_name ); LinkedList_Init( &slot->handlers, sizeof(LCUI_EventHandler) ); /* 添加事件槽记录 */ RBTree_Insert( &box->event_slot, slot->id, slot ); /* 添加事件名记录 */ node = RBTree_CustomInsert( &box->event_name, (const void*)event_name, &slot->name ); /* 结点的 key 就是事件槽的 id */ node->key = slot->id; return 0; }
LinkedList* LinkedList_New( LinkedList_compareFunction* compareFunction, LinkedList_dataCopyFunction* dataCopyFunction, LinkedList_dataPrintFunction* dataPrintFunction, LinkedList_dataDeleteFunction* dataDeleteFunction, Order listOrder ) { /* Variables set in this function */ SizeT _sizeOfSelf = sizeof(LinkedList); const char * /*Type*/ type = LinkedList_Type; /*Stg_Class_DeleteFunction* _delete = _LinkedList_DeleteFunc; Stg_Class_PrintFunction* _print = _LinkedList_PrintFunc; Stg_Class_CopyFunction* _copy = NULL; */ LinkedList* self; /* General info */ assert ( compareFunction ); self = _LinkedList_New( /*LINKEDLIST_PASSARGS*/ ); /* List info */ self->compareFunction = compareFunction; self->dataCopyFunction = dataCopyFunction; self->dataPrintFunction = dataPrintFunction; self->dataDeleteFunction = dataDeleteFunction; self->listOrder = listOrder; /* Virtual functions */ LinkedList_Init( self ); return self; }
/** 初始化键盘输入模块 */ void LCUIModule_Keyboard_Init( void ) { LCUIMutex_Init( &record_mutex ); LinkedList_Init( &key_state_record, sizeof(key_state) ); #ifdef LCUI_KEYBOARD_DRIVER_LINUX LCUIDevice_Add( LCUIKeyboard_Init, LCUIKeyboard_Proc, LCUIKeyboard_Exit ); #endif }
void LCUIWidget_InitRenderer( void ) { RBTree_Init( &self.groups ); RBTree_OnCompare( &self.groups, OnCompareGroup ); RBTree_OnDestroy( &self.groups, OnDestroyGroup ); LinkedList_Init( &self.rects ); self.active = TRUE; }
LCUI_Worker LCUIWorker_New( void ) { LCUI_Worker worker = NEW( LCUI_WorkerRec, 1 ); LCUIMutex_Init( &worker->mutex ); LCUICond_Init( &worker->cond ); LinkedList_Init( &worker->tasks ); worker->active = FALSE; worker->thread = 0; return worker; }
/** 构造函数 */ static void $(Init)( LCUI_Widget widget ) { widget->style.z_index = 0; widget->style.x.type = SVT_NONE; widget->style.y.type = SVT_NONE; widget->style.width.type = SVT_AUTO; widget->style.height.type = SVT_AUTO; widget->style.box_sizing = CONTENT_BOX; widget->style.opacity = 1.0; widget->style.margin.top.px = 0; widget->style.margin.right.px = 0; widget->style.margin.bottom.px = 0; widget->style.margin.left.px = 0; widget->style.margin.top.type = SVT_PX; widget->style.margin.right.type = SVT_PX; widget->style.margin.bottom.type = SVT_PX; widget->style.margin.left.type = SVT_PX; widget->style.padding.top.px = 0; widget->style.padding.right.px = 0; widget->style.padding.bottom.px = 0; widget->style.padding.left.px = 0; widget->style.padding.top.type = SVT_PX; widget->style.padding.right.type = SVT_PX; widget->style.padding.bottom.type = SVT_PX; widget->style.padding.left.type = SVT_PX; widget->event = LCUIEventBox_Create(); memset( &widget->base, 0, sizeof(widget->base)); widget->parent = NULL; widget->title = NULL; widget->event = LCUIEventBox_Create(); Widget_InitTaskBox( widget ); Background_Init( &widget->style.background ); BoxShadow_Init( &widget->style.shadow ); Border_Init( &widget->style.border ); LinkedList_Init( &widget->children, sizeof(struct LCUI_WidgetFull) ); LinkedList_Init( &widget->children_show, 0 ); LinkedList_SetDestroyFunc( &widget->children, $(OnDestroy) ); LinkedList_SetDataNeedFree( &widget->children, TRUE ); LinkedList_SetDataNeedFree( &widget->children_show, FALSE ); DirtyRectList_Init( &widget->dirty_rects ); Graph_Init( &widget->graph ); }
static CSSParserContext NewCSSParserContext( size_t buffer_size, const char *space ) { CSSParserContext ctx = NEW( CSSParserContextRec, 1 ); ctx->buffer = NEW( char, buffer_size ); ctx->buffer_size = buffer_size; ctx->target = TARGET_NONE; ctx->target_bak = TARGET_NONE; ctx->space = space ? strdup( space ): NULL; LinkedList_Init( &ctx->selectors ); return ctx; }
/** 新建文本图层 */ LCUI_TextLayer TextLayer_New(void) { LCUI_TextLayer layer; layer = malloc( sizeof( LCUI_TextLayerRec ) ); layer->width = 0; layer->length = 0; layer->offset_x = 0; layer->offset_y = 0; layer->insert_x = 0; layer->insert_y = 0; layer->max_width = 0; layer->max_height = 0; layer->fixed_width = 0; layer->fixed_height = 0; layer->new_offset_x = 0; layer->new_offset_y = 0; layer->rowlist.length = 0; layer->rowlist.rows = NULL; layer->text_align = SV_LEFT; layer->is_using_buffer = FALSE; layer->is_autowrap_mode = FALSE; layer->is_mulitiline_mode = FALSE; layer->is_using_style_tags = FALSE; layer->line_height.scale = 1.428f; layer->line_height.type = SVT_SCALE; TextStyle_Init( &layer->text_style ); LinkedList_Init( &layer->style_cache ); layer->task.typeset_start_row = 0; layer->task.update_typeset = 0; layer->task.update_bitmap = 0; layer->task.redraw_all = 0; Graph_Init( &layer->graph ); LinkedList_Init( &layer->dirty_rect ); layer->graph.color_type = COLOR_TYPE_ARGB; TextRowList_InsertNewRow( &layer->rowlist, 0 ); return layer; }
/** 初始化键盘输入模块 */ int LCUI_InitKeyboard( void ) { int ret; LCUIMutex_Init( &record_mutex ); LinkedList_Init( &key_state_record, sizeof(KeyState) ); nobuff_printf("[keyboard] set event ... "); ret = LCUI_AddEvent( "keydown", LCUI_KEYDOWN ); ret |= LCUI_AddEvent( "keyup", LCUI_KEYUP ); ret |= LCUI_BindEvent( "keydown", OnKeyboardEvent, NULL, NULL ); ret |= LCUI_BindEvent( "keyup", OnKeyboardEvent, NULL, NULL ); nobuff_printf(ret < 0 ? "failed\n":"ok\n"); #ifdef LCUI_KEYBOARD_DRIVER_LINUX ret |= LCUIDevice_Add( LCUIKeyboard_Init, LCUIKeyboard_Proc, LCUIKeyboard_Exit ); #endif return ret; }
LCUI_BOOL Widget_InvalidateArea( LCUI_Widget widget, LCUI_RectF *in_rect, int box_type ) { int mode; LCUI_Rect area; LCUI_RectF rect; LCUI_Widget w = widget; LCUI_Widget root = LCUIWidget_GetRoot(); LCUI_RectGroup group; if( !w ) { w = root; } mode = LCUIDisplay_GetMode(); Widget_AdjustArea( w, in_rect, &rect, box_type ); rect.x += w->box.graph.x; rect.y += w->box.graph.y; while( w && w->parent ) { LCUIRectF_ValidateArea( &rect, w->parent->box.padding.width, w->parent->box.padding.height ); if( rect.width <= 0 || rect.height <= 0 ) { return FALSE; } if( mode != LCDM_SEAMLESS && w->parent == root ) { break; } w = w->parent; rect.x += w->box.padding.x; rect.y += w->box.padding.y; } RectFToInvalidArea( &rect, &area ); if( mode != LCDM_SEAMLESS ) { RectList_Add( &self.rects, &area ); return TRUE; } group = RBTree_CustomGetData( &self.groups, w ); if( !group ) { group = NEW( LCUI_RectGroupRec, 1 ); group->widget = w; LinkedList_Init( &group->rects ); RBTree_CustomInsert( &self.groups, w, group ); } return RectList_Add( &group->rects, &area ) == 0; }
/** 更新各种图形元素的显示 */ static void LCUIDisplay_Update(void) { LinkedList rlist; SurfaceRecord *p_sr; LinkedListNode *sn, *rn; LCUI_PaintContext paint; LinkedList_Init( &rlist ); /* 遍历当前的 surface 记录列表 */ for( LinkedList_Each( sn, &display.surfaces ) ) { p_sr = sn->data; if( !p_sr->widget || !p_sr->surface || !Surface_IsReady(p_sr->surface) ) { continue; } Surface_Update( p_sr->surface ); /* 收集无效区域记录 */ Widget_ProcInvalidArea( p_sr->widget, &rlist ); /* 在 surface 上逐个重绘无效区域 */ for( LinkedList_Each( rn, &rlist ) ) { paint = Surface_BeginPaint( p_sr->surface, rn->data ); if( !paint ) { continue; } 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 ); Widget_Render( p_sr->widget, paint ); if( display.show_rect_border ) { DrawBorder( paint ); } Surface_EndPaint( p_sr->surface, paint ); } if( rlist.length > 0 ) { Surface_Present( p_sr->surface ); } RectList_Clear( &rlist ); } RectList_Clear( &rlist ); }
/** 初始化样式标签栈 */ void StyleTagStack_Init( LCUI_StyleTagStack *tags ) { LinkedList_Init( tags, sizeof(LCUI_StyleTagData) ); }
static void SideBar_OnInit( LCUI_Widget w ) { SideBar *sb = Widget_NewPrivateData( w, SideBar ); LinkedList_Init( &sb->items ); }
void LCUIWidget_InitTask( void ) { MapTaskHandler(); self.timeout = 0; LinkedList_Init( &self.trash ); }
void LCUIWidget_InitTasks( void ) { MapTaskHandler(); LinkedList_Init( &self.trash ); }
void LCUIWidget_InitBase(void) { LinkedList_Init(&LCUIWidget.trash); LCUIWidget.root = LCUIWidget_New("root"); Widget_SetTitleW(LCUIWidget.root, L"LCUI Display"); }
/** 初始化设备处理模块 */ int LCUIModule_Device_Init(void) { LinkedList_Init( &dev_list, sizeof(DeviceData) ); LinkedList_SetDataNeedFree( &dev_list, TRUE ); return LCUIThread_Create( &dev_tid, DeviceThread, NULL ); }