コード例 #1
0
ファイル: widget_msg.c プロジェクト: fshunj/LCUI
LCUI_API int WidgetMsg_Connect(	LCUI_Widget *widget,
				uint_t msg_id,
				WidgetProcFunc func )
{
	int i,n;
	LCUI_Queue *msg_func;
	LCUI_Task *task_ptr, task;

	msg_func = Widget_GetMsgFunc( widget );
	if( msg_func == NULL ) {
		return -1;
	}
	n = Queue_GetTotal( msg_func );
	for(i=0; i<n; ++i) {
		task_ptr = (LCUI_Task*)Queue_Get( msg_func, i );
		if( task_ptr == NULL ) {
			continue;
		}
		if( task_ptr->id != msg_id ) {
			continue;
		}
		task_ptr->func = (CallBackFunc)func;
		return 0;
	}
	task.id = msg_id;
	task.func = (CallBackFunc)func;
	return Queue_Add( msg_func, &task );
}
コード例 #2
0
Frames_AddFrame(	LCUI_Frames *des, LCUI_Graph *pic, 
			LCUI_Pos offset, int sleep_time )
/* 
 * 功能:为动画添加帧 
 * 说明:
 * pic指的是该帧的图像;
 * pos代表该帧图像在整个动画画面中的位置;
 * sleep_time表示该帧的显示时长(单位:毫秒)
 * */
{
	LCUI_Frame frame;
	if( !des ) {
		return -1;
	}
	if(!Graph_IsValid(pic)) {
		return -2;
	}
	
	frame.offset = offset;
	frame.sleep_time = sleep_time;
	frame.pic = pic;
	frame.current_time = frame.sleep_time;
	Queue_Add(&des->pic, &frame); 
	return 0;
}
コード例 #3
0
ファイル: textstyle.c プロジェクト: gateslu/LCUI
/** 添加样式标签 */
LCUI_API int StyleTag_Add( LCUI_Queue *tags, StyleTag_Data *data )
{
	if( Queue_Add( tags, data ) ) {
		return 0;
	}
	return 0;
}
コード例 #4
0
Create_Frames(LCUI_Size size)
/* 
 * 功能:创建一个能存放动画数据的容器
 * 说明:该容器用于记录动画的每一帧的信息,需要指定该容器的尺寸。
 *  */
{
	int pos;
	LCUI_Frames *p, frames; 
	 
	Queue_Init(&frames.pic, sizeof(LCUI_Frame), NULL);
	Queue_Init(&frames.func_data, sizeof(LCUI_Func), NULL);
	Graph_Init(&frames.slot);
	frames.slot.have_alpha = TRUE;
	frames.current = 0;
	frames.state = 0;
	frames.size = size; 
	if( !database_init ) {
		Queue_Init(&frames_database, sizeof(LCUI_Frames), NULL); 
		database_init = TRUE;
	}
	/* 记录该动画至库中 */ 
	pos = Queue_Add(&frames_database, &frames); 
	p = Queue_Get(&frames_database, pos); 
	return p;
}
コード例 #5
0
ファイル: LCUI_Work.c プロジェクト: soar-penguin/LCUI
int 
LCUI_KeyboardEvent_Connect ( void (*func) (LCUI_Key*, void*), void *arg )
/* 与键盘建立连接,当键盘中某个按键被按下/释放后,就会调用这个函数 */
{
	LCUI_Func func_data;
	if( !Get_FuncData(&func_data, func, NULL, arg) ) {
		return -2;
	}
	return Queue_Add( &LCUI_Sys.key_event, &func_data );
}
コード例 #6
0
ファイル: game_msg.c プロジェクト: fztfztfzt/PunchAndKick
/* 向消息队列中投递消息 */
int Game_PostMsg( GameMsg *msg )
{
	Queue_Lock( &game_msg_queue );
	if( !Queue_Add( &game_msg_queue, msg ) ) {
		Queue_Unlock( &game_msg_queue );
		return -1;
	}
	Queue_Unlock( &game_msg_queue );
	return LCUISleeper_BreakSleep( &msg_sleeper );
}
コード例 #7
0
ファイル: main.c プロジェクト: yydaor/LCUI
/* 
 * 功能:创建一个LCUI程序
 * 说明:此函数会将程序信息添加至程序列表
 * 返回值:成功则返回程序的ID,失败则返回-1
 **/
static int LCUIAppList_Add( void )
{
	LCUI_App app;
	
	LCUIApp_Init (&app); /* 初始化程序数据结构体 */
	app.id	= LCUIThread_SelfID(); /* 保存ID */ 
	Queue_Add(&LCUI_Sys.app_list, &app); /* 添加至队列 */
	LCUIApp_RegisterMainThread( app.id ); /* 注册程序主线程 */
	return 0;
}
コード例 #8
0
ファイル: LCUI_Work.c プロジェクト: soar-penguin/LCUI
int 
EventQueue_Add(LCUI_EventQueue *queue, int event_id, LCUI_Func *func)
/* 功能:记录事件及对应回调函数至队列 */
{
	LCUI_Event *event;
	
	event = Find_Event(queue, event_id);
	if ( !event ) {/* 如果没有,就添加一个新事件类型 */ 
		int pos;
		LCUI_Event new_event;
		new_event.id = event_id;
		Queue_Init(&new_event.func_data, sizeof(LCUI_Func), NULL);
		pos = Queue_Add(queue, &new_event);/* 将新数据追加至队列 */
		event = Queue_Get(queue, pos);	/* 获取指向新增成员的指针 */
	}
	
	event->id = event_id; /* 保存事件ID */
	Queue_Add(&event->func_data, func);
	return 0;
}
コード例 #9
0
ファイル: LCUI_Work.c プロジェクト: soar-penguin/LCUI
void 
Send_Task_To_App(LCUI_Func *func_data)
/*
 * 功能:发送任务给程序,使这个程序进行指定任务
 * 说明:LCUI_Func结构体中的成员变量 id,保存的是目标程序的id
 */
{ 
	LCUI_App *app;
	app = Find_App( func_data->id );
	if( !app ) {
		return;
	}
	Queue_Add( &app->task_queue, func_data );
}
コード例 #10
0
ファイル: text_layer.c プロジェクト: dwdcth/LCUI
static int 
TextLayer_Text_Add_NewRow ( LCUI_TextLayer *layer )
/* 添加新行 */
{
	Text_RowData data; 
	/* 单整行最大尺寸改变时,需要移动整行,目前还未支持此功能 */
	data.pos = Pos(0,0); 
	data.max_size = Size(0,0);
	Queue_Init( &data.string, sizeof(LCUI_CharData), NULL );
	/* 使用链表模式,方便数据的插入 */
	Queue_Set_DataMode( &data.string, QUEUE_DATA_MODE_LINKED_LIST );
	/* 队列成员使用指针,主要是引用text_source_data里面的数据 */
	Queue_Using_Pointer( &data.string );
	return Queue_Add( &layer->rows_data, &data );
}
コード例 #11
0
ファイル: task.c プロジェクト: fshunj/LCUI
/*
 * 功能:发送任务给程序,使这个程序进行指定任务
 * 说明:LCUI_Task结构体中的成员变量 id,保存的是目标程序的id
 */
LCUI_API int AppTasks_Add( LCUI_Task *task )
{
	LCUI_App *app;
	app = LCUIApp_Find( task->id );
	if( !app ) {
		return -1;
	}
	Queue_Lock( &app->tasks );
	if(Queue_Add( &app->tasks, task ) < 0 ) {
		Queue_Unlock( &app->tasks );
		return -2;
	}
	LCUISleeper_BreakSleep( &app->mainloop_sleeper );
	Queue_Unlock( &app->tasks );
	return 0;
}
コード例 #12
0
/* 将文本添加至缓冲区内 */
static int
TextBox_TextBuff_Add( LCUI_Widget *widget, wchar_t *text, int pos_type )
{
	LCUI_TextBox *textbox;
	int i, j, len, size;
	wchar_t *text_buff;
	LCUI_TextBlock text_block;
	
	textbox = Widget_GetPrivData( widget );
	len = wcslen( text );
	//_DEBUG_MSG("len = %d\n", len);
	switch( pos_type ) {
		case AT_TEXT_LAST: 
		case AT_CURSOR_POS:
		text_block.pos_type = pos_type;
		break;
		default: return -1;
	}
	for(i=0; i<len; ++i) {
		if( len-i > textbox->block_size ) {
			size = textbox->block_size;
		} else {
			size = len-i +1;
		}
		text_buff = malloc( sizeof(wchar_t) * size );
		if( !text_buff ) {
			return -2;
		}
		for( j=0; j<len; ++j,++i ) {
			/* 如果大于当前块大小 */
			if( j >= textbox->block_size ) {
					break;
			}
			text_buff[j] = text[i];
			//_DEBUG_MSG("char: %d, count: %d\n", new_text[i], count);
		}
		--i;
		text_buff[j] = 0;
		text_block.text = text_buff;
		/* 添加文本块至缓冲区 */
		Queue_Add( &textbox->text_block_buff, &text_block );
	}
	return 0;
}
コード例 #13
0
ファイル: device.c プロジェクト: FrankHB/LCUI
/** 
 * 功能:注册设备
 * 说明:为指定设备添加处理函数
 * */
LCUI_API int LCUIDevice_Add(	LCUI_BOOL (*init_func)(void), 
				LCUI_BOOL (*proc_func)(void), 
				LCUI_BOOL (*destroy_func)(void) )
{
	dev_func_data data;
	
	if( init_func ) {
		init_func();
	}
	data.init_func = init_func;
	data.proc_func = proc_func;
	data.destroy_func = destroy_func;
	Queue_Lock( &dev_list );
	if( Queue_Add( &dev_list, &data ) ) {
		Queue_Unlock( &dev_list );
		return 0;
	}
	Queue_Unlock( &dev_list );
	return -1;
}
コード例 #14
0
ファイル: LCUI_PictureBox.c プロジェクト: dwdcth/LCUI
int Set_PictureBox_Image_From_File(LCUI_Widget *widget, char *image_file)
/* 功能:添加一个图片文件,并载入至图片盒子 */
{
    int value;
    graph_data data;
    LCUI_PictureBox *pic_box = (LCUI_PictureBox*)
                               Get_Widget_PrivData(widget);
    LCUI_Graph *graph;

    if(init == IS_FALSE) {
        Queue_Init( &picbox_graph_mem,
                    sizeof(graph_data), destroy_graph_data);
        init = IS_TRUE;
    }
    /* 如果在记录中没找到该部件,那么就分配内存,否则,直接使用那块内存 */
    value = find_widget_data(widget);
    if(value == -1) {
        data.image = (LCUI_Graph*) calloc(1, sizeof(LCUI_Graph));
        data.widget = widget;
        Queue_Add(&picbox_graph_mem, &data);
    } else {
        data = *(graph_data*)Queue_Get(&picbox_graph_mem, value);
    }
    graph = data.image;

    pic_box->image_status = IMAGE_STATUS_LOADING; /* 图片状态为正在载入 */
    Set_PictureBox_Image_From_Graph(widget, NULL);
    value = Load_Image(image_file, graph);/* 载入图片文件 */
    if(value != 0) {
        /* 载入失败 */
        pic_box->image_status = IMAGE_STATUS_FAIL;
        Set_PictureBox_Image_From_Graph(widget, NULL);
    } else {
        /* 载入成功 */
        pic_box->image_status = IMAGE_STATUS_SUCCESS;
        Set_PictureBox_Image_From_Graph(widget, graph);
    }

    return value;
}
コード例 #15
0
ファイル: picturebox.c プロジェクト: fshunj/LCUI
/* 设定图片文件中的图像为PictureBox部件显示的图像 */
LCUI_API int
PictureBox_SetImageFile( LCUI_Widget *widget, char *image_file )
{
	int ret;
	graph_data data;
	LCUI_PictureBox *pic_box;
	LCUI_Graph *graph;
	
	pic_box = Widget_GetPrivData(widget);
	if( !graph_mem_init ) {
		Queue_Init( &picbox_graph_mem, 
			sizeof(graph_data), destroy_graph_data);
		graph_mem_init = TRUE;
	}
	/* 如果在记录中没找到该部件,那么就分配内存,否则,直接使用那块内存 */
	ret = find_widget_data(widget);
	if(ret == -1) {
		data.image = (LCUI_Graph*) calloc(1, sizeof(LCUI_Graph));
		data.widget = widget;
		Queue_Add(&picbox_graph_mem, &data); 
	} else {
		data = *(graph_data*)Queue_Get(&picbox_graph_mem, ret); 
	}
	graph = data.image;
	
	pic_box->image_state = IMAGE_STATE_LOADING; /* 图片状态为正在载入 */
	PictureBox_SetImage(widget, NULL);
	ret = Graph_LoadImage( image_file, graph );/* 载入图片文件 */
	if( ret == 0 ) {
		/* 载入成功 */
		pic_box->image_state = IMAGE_STATE_SUCCESS; 
		PictureBox_SetImage(widget, graph);
	} else {
		/* 载入失败 */
		pic_box->image_state = IMAGE_STATE_FAIL;
		PictureBox_SetImage(widget, NULL);
	}
	return ret;
}
コード例 #16
0
ファイル: radiobutton.c プロジェクト: hbao/LCUI
/* 为两个单选框建立互斥关系 */
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);
		}
	}
}
コード例 #17
0
ファイル: widget_event.c プロジェクト: FrankHB/LCUI
/** 添加部件至列表里,如果已存在,则标记该部件不需要删除 */
static int WidgetRecord_Add( LCUI_Widget *widget )
{
	int i, n;
	WidgetRecordItem new_item, *item;

	Queue_Lock( &widget_proc_record );
	n = Queue_GetTotal( &widget_proc_record );
	for(i=0; i<n; ++i) {
		item = (WidgetRecordItem*)
		Queue_Get( &widget_proc_record, i );
		if( item->widget == widget ) {
			Queue_Unlock( &widget_proc_record );
			item->need_delete = FALSE;
			return 1;
		}
	}
	new_item.need_delete = FALSE;
	new_item.widget = widget;
	Queue_Add( &widget_proc_record, &new_item );
	Queue_Unlock( &widget_proc_record );
	return 0;
}
コード例 #18
0
Frames_AddFunc(	LCUI_Frames *des, 
		void (*func)(LCUI_Graph*, void*), 
		void *arg )
/* 
 * 功能:为动画关联回调函数 
 * 说明:关联回调函数后,动画每更新一帧都会调用这个函数
 * */
{
	LCUI_Func func_data;
	if( !des ) {
		return -1;
	}
	
	func_data.func = func;
	func_data.id = LCUIApp_GetSelfID();
	func_data.arg[0] = NULL;
	func_data.arg[1] = arg;
	/* 如果不将该标志置为FALSE,会是确定的值,导致在执行任务后的销毁参数时出现段错误 */
	func_data.destroy_arg[0] = FALSE;
	func_data.destroy_arg[1] = FALSE;
	Queue_Add(&des->func_data, &func_data);
	return 0;
} 
コード例 #19
0
ファイル: task.c プロジェクト: fshunj/LCUI
static int Tasks_CustomAdd( LCUI_Queue *tasks, int mode, LCUI_Task *task )
{
	int total, i;
	LCUI_Task *tmp_task;
	
	Queue_Lock( tasks );
	total = Queue_GetTotal(tasks);
	/* 如果模式是“添加新的”模式 */
	if( mode == ADD_MODE_ADD_NEW ) {
		Queue_Add(tasks, task); 
		Queue_Unlock( tasks );
		return 0;
	}
	for (i=0; i < total; ++i) { 
		tmp_task = Queue_Get(tasks, i);
		/* 如果指针无效,或者函数指针已有记录 */
		if( !tmp_task || tmp_task->func != task->func ) {
			continue;
		}
		/* 如果要求的是不重复模式 */ 
		if(Check_Option(mode, ADD_MODE_NOT_REPEAT)) {
			/* 如果要求是第1个参数不能重复 */
			if(Check_Option(mode, AND_ARG_F)) {
				/* 如果要求是第2个参数也不能重复 */
				if(Check_Option(mode, AND_ARG_S)) {
					/* 如果函数以及参数1和2都一样 */ 
					if(tmp_task->arg[0] == task->arg[0] 
					&& tmp_task->arg[1] == task->arg[1]) {
						Destroy_Task( task );
						Queue_Unlock( tasks );
						return -1; 
					}
				} else {/* 否则,只是要求函数以及第1个参数不能全部重复 */
					if(tmp_task->arg[0] == task->arg[0]) { 
						Destroy_Task( task );
						Queue_Unlock( tasks );
						return -1; 
					}
				}
			}/* 否则,如果只是要求是第2个参数不能重复 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(tmp_task->arg[1] == task->arg[1] ) {
					Destroy_Task( task );
					Queue_Unlock( tasks );
					return -1; 
				}
			} else {/* 否则,只是要求函数不同 */ 
				Destroy_Task( task );
				Queue_Unlock( tasks );
				return -1; 
			}
		}/* 如果要求的是替换模式 */
		else if(Check_Option(mode, ADD_MODE_REPLACE)) {
			/* 如果要求是第1个参数相同 */
			if( Check_Option(mode, AND_ARG_F) ) {
				/* 如果要求是第2个参数也相同 */
				if( Check_Option(mode, AND_ARG_S) ) {
					if(tmp_task->arg[0] == task->arg[0] 
					&& tmp_task->arg[1] == task->arg[1]
					) {
						break; 
					}
				} else {/* 否则,只是要求函数以及第1个参数全部相同 */
					if(tmp_task->arg[0] == task->arg[0]) {
						break; 
					}
				}
			}/* 否则,如果只是要求第2个参数不能相同 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(tmp_task->arg[1] == task->arg[1]) {
					break; 
				}
			} else { 
				break; 
			}
		}
	}
	
	if(i == total) {
		Queue_Add(tasks, task); 
	} else {
		Queue_Replace( tasks, i, task ); 
	}
	Queue_Unlock( tasks );
	return 0;
}
コード例 #20
0
ファイル: widget_msg.c プロジェクト: fshunj/LCUI
LCUI_API int WidgetMsg_Post(	LCUI_Widget *widget,
				uint_t msg_id,
				void *data,
				LCUI_BOOL only_one,
				LCUI_BOOL need_free )
{
	int i, total, n_found, ret = 0;
	WidgetMsgData tmp_msg, *tmp_msg_ptr;
	LCUI_Queue *des_queue;

	if( !widget ) {
		return -1;
	}
	tmp_msg.msg_id = msg_id;
	tmp_msg.need_free = need_free;
	tmp_msg.target = widget;
	if( data ) {
		tmp_msg.valid = TRUE;
	} else {
		tmp_msg.valid = FALSE;
	}
	switch(tmp_msg.msg_id) {
	    case WIDGET_MOVE:
		if(tmp_msg.valid) {
			tmp_msg.data.pos = *((LCUI_Pos*)data);
		}
		break;
	    case WIDGET_RESIZE:
		if(tmp_msg.valid) {
			tmp_msg.data.size = *((LCUI_Size*)data);
		}
		break;
	    case WIDGET_CHGSTATE:
		if(tmp_msg.valid) {
			tmp_msg.data.state = *((int*)data);
		}
		break;
	    case WIDGET_PAINT:
	    case WIDGET_REFRESH:
	    case WIDGET_UPDATE:
	    case WIDGET_SORT:
		tmp_msg.valid = FALSE;
		break;
		/* 部件的显示、隐藏和销毁消息,需要发送到父部件 */
	    case WIDGET_SHOW:
	    case WIDGET_HIDE:
	    case WIDGET_DESTROY:
		/* 如果不是根部件 */
		if( widget != RootWidget_GetSelf() ) {
			widget = widget->parent;
		} 
		tmp_msg.valid = FALSE;
		break;
	    default:
		tmp_msg.data.ptr = data;
		break;
	}
	des_queue = Widget_GetMsgBuff( widget );
	total = Queue_GetTotal( des_queue );
	for(n_found=0,i=0; i<total; ++i) {
		tmp_msg_ptr = (WidgetMsgData*)Queue_Get( des_queue, i );
		if( !tmp_msg_ptr ) {
			continue;
		}
		if(tmp_msg_ptr->valid != tmp_msg.valid
		|| tmp_msg_ptr->msg_id != tmp_msg.msg_id
		|| tmp_msg_ptr->target != tmp_msg.target ) {
			continue;
		}
		++n_found;
		/* 如果已存在的数量少于2 */
		if( !only_one && n_found < 2 ) {
			continue;
		}
		/* 否则,需要进行替换 */
		switch(tmp_msg.msg_id) {
		    case WIDGET_MOVE:
			if(tmp_msg.valid) {
				tmp_msg_ptr->data.pos = tmp_msg.data.pos;
				tmp_msg_ptr->valid = TRUE;
			} else {
				tmp_msg_ptr->valid = FALSE;
			}
			break;
		    case WIDGET_RESIZE:
			if(tmp_msg.valid) {
				tmp_msg_ptr->data.size = tmp_msg.data.size;
				tmp_msg_ptr->valid = TRUE;
			} else {
				tmp_msg_ptr->valid = FALSE;
			}
			break;
		    case WIDGET_CHGSTATE:
			if(tmp_msg.valid) {
				tmp_msg_ptr->data.state = tmp_msg.data.state;
			} else {
				tmp_msg_ptr->valid = FALSE;
			}
			break;
		    case WIDGET_PAINT:
		    case WIDGET_REFRESH:
		    case WIDGET_HIDE:
		    case WIDGET_UPDATE:
		    case WIDGET_SHOW:
		    case WIDGET_SORT:
			tmp_msg.valid = FALSE;
			break;
		    default:
			if( tmp_msg_ptr->need_free ) {
				free( tmp_msg_ptr->data.ptr );
			}
			tmp_msg_ptr->need_free = tmp_msg.need_free;
			tmp_msg_ptr->data.ptr = tmp_msg.data.ptr;
			break;
		}
		break;
	}
	/* 未找到,则添加新的 */
	if( i>= total ) {
		ret = Queue_Add( des_queue, &tmp_msg );
	}
	return ret;
}
コード例 #21
0
ファイル: LCUI_Work.c プロジェクト: soar-penguin/LCUI
int 
AppTask_Custom_Add(int mode, LCUI_Func *func_data)
/*
 * 功能:使用自定义方式添加程序任务
 * 用法示例:
 * 在函数的各参数与队列中的函数及各参数不重复时,添加它
 * AppTask_Custom_Add(ADD_MODE_NOT_REPEAT | AND_ARG_F | AND_ARG_S, func_data);
 * 只要函数和参数1不重复则添加
 * AppTask_Custom_Add(ADD_MODE_NOT_REPEAT | AND_ARG_F, func_data);
 * 要函数不重复则添加
 * AppTask_Custom_Add(ADD_MODE_NOT_REPEAT, func_data);
 * 添加新的,不管是否有重复的
 * AppTask_Custom_Add(ADD_MODE_ADD_NEW, func_data);
 * 有相同函数则覆盖,没有则新增
 * AppTask_Custom_Add(ADD_MODE_REPLACE, func_data);
 * */
{
	int total, i;
	/* 先获取程序数据结构体指针 */
	LCUI_App *app;
	LCUI_FuncQueue *queue;
	LCUI_Func *temp = NULL;
	
	if( func_data->id == (LCUI_ID)0 ) {
		app = Get_Self_AppPointer();
	} else {
		app = Find_App( func_data->id );
	}
	if( !app ) {
		return -1;
	}
	queue = &app->task_queue;
	total = Queue_Get_Total(queue);
	/* 如果模式是“添加新的”模式 */
	if( mode == ADD_MODE_ADD_NEW ) {
		Queue_Add(queue, func_data); 
		return 0;
	}
	
	//printf("mode: %d\n", mode);
	for (i = 0; i < total; ++i) {
		//printf("1\n");
		temp = Queue_Get(queue, i);
		/* 如果指针无效,或者函数指针已有记录 */
		if( !temp || temp->func != func_data->func ) {
			continue;
		}
		/* 如果要求的是不重复模式 */ 
		if(Check_Option(mode, ADD_MODE_NOT_REPEAT)) {
			/* 如果要求是第1个参数不能重复 */
			if(Check_Option(mode, AND_ARG_F)) {
				//printf("ADD_MODE_NOT_REPEAT, AND_ARG_F\n");
				//printf("old:%p, new:%p\n", queue->queue[i].arg_f, arg_f);
				/* 如果要求是第2个参数也不能重复 */
				if(Check_Option(mode, AND_ARG_S)) {
					/* 如果函数以及参数1和2都一样 */ 
					if(temp->arg[0] == func_data->arg[0] 
					&& temp->arg[1] == func_data->arg[1]) {
						__destroy_apptask( func_data );
						return -1; 
					}
				} else {/* 否则,只是要求函数以及第1个参数不能全部重复 */
					if(temp->arg[0] == func_data->arg[0]) { 
						__destroy_apptask( func_data );
						return -1; 
					}
				}
			}/* 否则,如果只是要求是第2个参数不能重复 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(temp->arg[1] == func_data->arg[1] ) {
					__destroy_apptask( func_data );
					return -1; 
				}
			} else {/* 否则,只是要求函数不同 */ 
				__destroy_apptask( func_data );
				return -1; 
			}
		}/* 如果要求的是替换模式 */
		else if(Check_Option(mode, ADD_MODE_REPLACE)) {
			//printf("ADD_MODE_REPLACE\n");
			/* 如果要求是第1个参数相同 */
			if( Check_Option(mode, AND_ARG_F) ) {
				/* 如果要求是第2个参数也相同 */
				if( Check_Option(mode, AND_ARG_S) ) {
					if(temp->arg[0] == func_data->arg[0] 
					&& temp->arg[1] == func_data->arg[1]
					) {
						break; 
					}
				} else {/* 否则,只是要求函数以及第1个参数全部相同 */
					if(temp->arg[0] == func_data->arg[0]) {
				//		printf("ARG_F\n");
						break; 
					}
				}
			}/* 否则,如果只是要求第2个参数不能相同 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(temp->arg[1] == func_data->arg[1]) {
					break; 
				}
			} else { 
				break; 
			}
		}
	}
	
	if(i == total) {
		Queue_Add(queue, func_data); 
	} else {
		Queue_Replace( queue, i, func_data ); 
	}
	return 0;
}
コード例 #22
0
ファイル: rect.c プロジェクト: fshunj/LCUI
/*
 * 功能:将有重叠部分的两个矩形,进行分割,并得到分割后的矩形
 * 说明:主要用于局部区域刷新里,添加的需刷新的区域有可能会与已添加的区域重叠,为避免
 * 重复刷新同一块区域,需要在添加时对矩形进行分割,得到完全重叠和不重叠的矩形。
 * 参数说明:
 * old : 已存在的矩形区域
 * new : 将要添加的矩形区域
 * rq  : 指向矩形的队列的指针
 * 注意!传递参数时,请勿颠倒old和new位置。
 **/
LCUI_API int
LCUIRect_Cut(	LCUI_Rect	old_rect,
		LCUI_Rect	new_rect, 
		LCUI_Queue	*rects_buff )
{
	int i; 
	LCUI_Rect r[5];
	
	for(i=0; i<5; ++i) {
		Rect_Init(&r[i]); 
	}
	
	/* 计算各个矩形的x轴坐标和宽度 */
	r[0].x = new_rect.x;
	r[0].y = new_rect.y; 
	//printf("old,pos(%d,%d), size(%d,%d)\n", old_rect.x, old_rect.y, old_rect.width, old_rect.height);
	//printf("new,pos(%d,%d), size(%d,%d)\n", new_rect.x, new_rect.y, new_rect.width, new_rect.height);
	/* 如果前景矩形在背景矩形的左边 */  
	if(new_rect.x < old_rect.x) {
		/* 如果X轴上与背景矩形不重叠 */  
		if(new_rect.x + new_rect.width <= old_rect.x) {
			return -1;
		}
		r[0].width = old_rect.x - new_rect.x;
		r[1].x = old_rect.x;
		r[2].x = r[1].x;
		r[4].x = r[2].x;
		/* 如果前景矩形在X轴上包含背景矩形 */  
		if(new_rect.x + new_rect.width > old_rect.x + old_rect.width) {
			r[1].width = old_rect.width;
			
			r[3].x = old_rect.x + old_rect.width;
			r[3].width = new_rect.x + new_rect.width - r[3].x;
		} else { /* 得出矩形2的宽度 */ 
			r[1].width = new_rect.x + new_rect.width - old_rect.x;  
		}
		/* 得出矩形3和5的宽度 */ 
		r[2].width = r[1].width;
		r[4].width = r[2].width;
	} else {  
		if(old_rect.x + old_rect.width <= new_rect.x) { 
			return -1;
		}
		r[1].x = new_rect.x;
		r[2].x = r[1].x; 
		r[4].x = r[2].x;
		
		if(new_rect.x + new_rect.width > old_rect.x + old_rect.width) {  
			r[1].width = old_rect.x + old_rect.width - r[1].x;
			r[3].x = old_rect.x + old_rect.width;
			r[3].width = new_rect.x + new_rect.width - r[3].x;
		} else {
			r[1].width = new_rect.width; 
		}
			
		r[2].width = r[1].width;
		r[4].width = r[2].width;
	}
	 
	/* 计算各个矩形的y轴坐标和高度 */
	r[0].height = new_rect.height;
	r[3].y = new_rect.y;
	r[3].height = r[0].height;
	r[4].y = old_rect.y + old_rect.height; 
	if(new_rect.y < old_rect.y) {
		if(new_rect.y + new_rect.height <= old_rect.y) { 
			return -1;
		}
		r[1].y = new_rect.y; 
		r[1].height = old_rect.y - new_rect.y;
		r[2].y = old_rect.y; 
		/* 如果前景矩形在Y轴上包含背景矩形 */ 
		if(new_rect.y + new_rect.height > old_rect.y + old_rect.height) { 
			r[2].height = old_rect.height;
			r[4].height = new_rect.y + new_rect.height - r[4].y; 
		} else { 
			r[2].height = new_rect.y + new_rect.height - old_rect.y;  
		}
	} else {  
		if(new_rect.y >= old_rect.y + old_rect.height) { 
			return -1;
		}
		r[2].y = new_rect.y; 
		
		if(new_rect.y + new_rect.height > old_rect.y + old_rect.height) {  
			r[2].height = old_rect.y + old_rect.height - r[2].y;
			r[4].height = new_rect.y + new_rect.height - r[4].y;
		} else r[2].height = new_rect.y + new_rect.height - r[2].y;
	}
	
	//r[0].width -= 1;
	//r[1].height -= 1;
	//r[3].x += 1;
	//r[3].width -= 1;
	//r[4].y += 1;
	//r[4].height -= 1;
	  
	for(i=0; i<5; i++) { 
		//if(debug_mark)
		//	printf("slip rect[%d]: %d,%d, %d,%d\n", i, r[i].x, r[i].y, r[i].width, r[i].height);
		Queue_Add(rects_buff, &r[i]); 
	}
	return 0;
}
コード例 #23
0
ファイル: text_layer.c プロジェクト: dwdcth/LCUI
static void 
TextLayer_TagStyle_Add( LCUI_TextLayer *layer, tag_style_data *data )
/* 将字体样式数据加入队列 */
{
	Queue_Add( &layer->tag_buff, data );
}
コード例 #24
0
ファイル: rect.c プロジェクト: fshunj/LCUI
/* 将矩形数据追加至队列 */
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;
}