Ejemplo n.º 1
0
LCUI_API LCUI_FontBMP*
FontLIB_AddFontBMP(	wchar_t char_code, int font_id,
			int pixel_size, LCUI_FontBMP *fontbmp )
{
	LCUI_FontBMP *bmp_cache;
	LCUI_RBTree *tree_font, *tree_bmp;

	if( !fontlib.is_inited ) {
		return NULL;
	}
	/* 获取字符的字体信息集 */
	tree_font = (LCUI_RBTree*)
	RBTree_GetData( &fontlib.bitmap_cache, char_code );
	if( !tree_font ) {
		tree_font = (LCUI_RBTree*)malloc( sizeof(LCUI_RBTree) );
		if( !tree_font ) {
			return NULL;
		}
		RBTree_Init( tree_font );
		RBTree_SetDataNeedFree( tree_font, TRUE );
		RBTree_OnDestroy( tree_font, FontLIB_DestroyTreeNode );
		RBTree_Insert( &fontlib.bitmap_cache, char_code, tree_font );
	}
	/* 当字体ID不大于0时,使用内置字体 */
	if( font_id <= 0 ) {
		font_id = fontlib.incore_font->id;
	}
	/* 获取相应字体样式标识号的字体位图库 */
	tree_bmp = (LCUI_RBTree*)RBTree_GetData( tree_font, font_id );
	if( !tree_bmp ) {
		tree_bmp = (LCUI_RBTree*)malloc( sizeof(LCUI_RBTree) );
		if( !tree_bmp ) {
			return NULL;
		}
		RBTree_Init( tree_bmp );
		RBTree_OnDestroy( tree_bmp, FontLIB_DestroyFontBitmap );
		RBTree_SetDataNeedFree( tree_bmp, TRUE );
		RBTree_Insert( tree_font, font_id, tree_bmp );
	}
	/* 在字体位图库中获取指定像素大小的字体位图 */
	bmp_cache = (LCUI_FontBMP*)RBTree_GetData( tree_bmp, pixel_size );
	if( !bmp_cache ) {
		bmp_cache = (LCUI_FontBMP*)malloc( sizeof(LCUI_FontBMP) );
		if( !bmp_cache ) {
			return NULL;
		}
		RBTree_Insert( tree_bmp, pixel_size, bmp_cache );
	}
	/* 拷贝数据至该空间内 */
	memcpy( bmp_cache, fontbmp, sizeof(LCUI_FontBMP) );
	return bmp_cache;
}
Ejemplo n.º 2
0
/** 添加已被按下的按键 */
void LCUIKeyboard_HitKey(int key_code)
{
	clock_t ct;
	KeyStateNode node;
	LCUIMutex_Lock(&self.mutex);
	ct = clock() * 1000 / CLOCKS_PER_SEC;
	node = RBTree_GetData(&self.state_tree, key_code);
	if (!node) {
		node = NEW(KeyStateNodeRec, 1);
		node->interval_time = -1;
		node->hit_time = ct;
		node->state = LCUI_KSTATE_PRESSED;
		RBTree_Insert(&self.state_tree, key_code, node);
		LCUIMutex_Unlock(&self.mutex);
		return;
	}
	if (node->state == LCUI_KSTATE_RELEASE) {
		node->state = LCUI_KSTATE_PRESSED;
		/* 记录与上次此键被按下时的时间间隔 */
		node->interval_time = ct - node->hit_time;
		/* 记录本次此键被按下时的时间 */
		node->hit_time = ct;
	}
	LCUIMutex_Unlock(&self.mutex);
}
Ejemplo n.º 3
0
Archivo: event.c Proyecto: aem3372/LCUI
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;
}
Ejemplo n.º 4
0
/** 绑定指定ID的事件 */
int $(BindById)( LCUI_EventBox box, int event_id, EventCallBack func,
		 void *func_data, void (*destroy_data)(void*) )
{
	LCUI_RBTreeNode *node;
	LCUI_EventSlot *slot;
	LCUI_EventHandler *handler;
	void *data;

	node = RBTree_Search( &box->event_slot, event_id );
	if( !node ) {
		return -1;
	}
	slot = (LCUI_EventSlot*)node->data;
	handler = NEW_ONE(LCUI_EventHandler);
	DEBUG_MSG("eventbox: %p, handler_id: %d\n", box, box->handler_id);
	handler->id = ++box->handler_id;
	handler->func = func;
	handler->func_data = func_data;
	handler->destroy_data = destroy_data;
	LinkedList_Append( &slot->handlers, handler );
	/* 将int类型的值转换成void×类型的值 */
	data = &slot->id;
	data = *(void**)data;
	RBTree_Insert( &box->event_handler, handler->id, data );
	return handler->id;
}
Ejemplo n.º 5
0
Archivo: event.c Proyecto: aem3372/LCUI
/** 注册事件,指定事件名称和ID */
int $(RegisterEventWithId)( LCUI_EventBox box, const char *event_name, int id )
{
	/** 如果该ID已经被使用 */
	if( RBTree_Search( &box->used_evnet_id, id ) ) {
		return -1;
	}
	RBTree_Insert( &box->used_evnet_id, id, NULL );
	return $($RegisterEvent)( box, event_name, id );
}
Ejemplo n.º 6
0
/** 添加字体族,并返回该字族的ID */
static int FontLIB_AddFontInfo(	const char *family_name,
				const char *style_name,
				const char *filepath,
				FT_Face face )
{
	LCUI_FontInfo *info;
	info = (LCUI_FontInfo*)malloc( sizeof(LCUI_FontInfo) );
	info->id = ++fontlib.count;
	strncpy( info->family_name, family_name, NAME_MAX_LEN );
	strncpy( info->style_name, style_name, NAME_MAX_LEN );
	strncpy( info->filepath, filepath, PATH_MAX_LEN );
	info->face = face;
	RBTree_Insert( &fontlib.info_cache, info->id, info );
	return info->id;
}
Ejemplo n.º 7
0
Archivo: event.c Proyecto: aem3372/LCUI
/** 绑定指定ID的事件 */
int $(BindById)( LCUI_EventBox box, int event_id, EventCallBack func,
		 void *func_data, void (*destroy_data)(void*) )
{
	LCUI_RBTreeNode *node;
	LCUI_EventSlot *slot;
	LCUI_EventHandler *handler;
	
	node = RBTree_Search( &box->event_slot, event_id );
	if( !node ) {
		return -1;
	}
	slot = (LCUI_EventSlot*)node->data;
	handler = NEW_ONE(LCUI_EventHandler);
	handler->id = ++box->handler_id;
	handler->func = func;
	handler->func_data = func_data;
	handler->destroy_data = destroy_data;
	LinkedList_AddData( &slot->handlers, handler );
	RBTree_Insert( 
		&box->event_handler, handler->id, (void*)(slot->id)
	);
	return handler->id;
}