Example #1
0
LCUI_API int GraphLayer_Sort( LCUI_GraphLayer *glayer )
{
	LCUI_GraphLayer *child_a, *child_b;
	int i, j, total;
	
	if( !glayer ) {
		return -1;
	}
	/* 排序前先锁上队列互斥锁 */
	Queue_Lock( &glayer->child );
	total = Queue_GetTotal( &glayer->child );
	/* 使用的是冒泡排序法 */
	for(j=0; j<total; ++j)
	for(i=total-1; i>=1; --i) {
		child_a = (LCUI_GraphLayer*)Queue_Get( &glayer->child, i );
		if( !child_a ) {
			continue;
		}
		child_b = (LCUI_GraphLayer*)Queue_Get( &glayer->child, i-1 );
		if( !child_b ) {
			continue;
		}
		if( child_a->z_index > child_b->z_index ) {
			Queue_Move( &glayer->child, i-1, i);
		}
	}
	/* 解开互斥锁 */
	Queue_Unlock( &glayer->child );
	return 0;
}
Example #2
0
File: timer.c Project: fshunj/LCUI
/** 更新定时器在定时器列表中的位置 */
static void TimerList_UpdateTimerPos(	LCUI_Queue *timer_list,
					timer_data *p_timer )
{
	int n, src_i=-1, des_i=-1;
	int64_t time_left, tmp_time_left;
	timer_data *p_tmp_timer;
	/* 计算该定时器的剩余定时时长 */
	time_left = LCUI_GetTicks( p_timer->start_time );
	time_left -= p_timer->pause_ms;
	time_left = p_timer->total_ms - time_left;
	/* 锁上定时器列表 */
	Queue_Lock( &global_timer_list );
	n = Queue_GetTotal( &global_timer_list );
	while(n--) {
		p_tmp_timer = (timer_data*)Queue_Get( &global_timer_list, n );
		if( !p_tmp_timer ) {
			continue;
		}
		/* 若找到自己的位置,则记录 */
		if( p_tmp_timer->id == p_timer->id ) {
			src_i = n;
			/* 如果已经找到目标位置,则退出循环 */
			if( des_i != -1 ) {
				break;
			}
			continue;
		}
		tmp_time_left = LCUI_GetTicks( p_tmp_timer->start_time );
		tmp_time_left -= p_tmp_timer->pause_ms;
		tmp_time_left = p_tmp_timer->total_ms - tmp_time_left;
		/* 若该定时器的剩余定时时长不大于当前定时器,则记录 */
		if( des_i == -1 && time_left >= tmp_time_left ) {
			DEBUG_MSG("src timer: %d, pos: %d, , cur_ms: %I64dms, des timer: %d, pos: %d, cur_ms: %I64dms\n",
				p_timer->id, src_i, LCUI_GetTicks(p_timer->start_time), 
				p_tmp_timer->id, des_i, LCUI_GetTicks(p_tmp_timer->start_time) );
			des_i = n;
			/* 如果已经找到源位置,则退出循环 */
			if( src_i != -1 ) {
				break;
			}
		}
	}
	/* 若目标位置无效,则将末尾作为目标位置 */
	if( des_i == -1 ) {
		DEBUG_MSG("tip\n");
		des_i = Queue_GetTotal( &global_timer_list )-1;
	}
	/* 若源位置和目标位置有效,则开始移动 */
	if( src_i != -1 ) {
		DEBUG_MSG("src: %d, des: %d\n", src_i, des_i );
		Queue_Move( &global_timer_list, des_i, src_i );
	}
	Queue_Unlock( &global_timer_list );
}
Example #3
0
LCUI_API int GraphLayer_Front( LCUI_GraphLayer *glayer )
{
	int i, total, src_pos = -1, des_pos = -1;
	LCUI_GraphLayer *tmp_child;
	LCUI_Queue *child_list;

	if( !glayer || !glayer->parent ) {
		return -1;
	}

	child_list = &glayer->parent->child;
	total = Queue_GetTotal( child_list );
	/* 先在队列中找到自己,以及z-index值小于或等于它的第一个图层 */
	for(i=0,src_pos=des_pos=-1; i<total; ++i) {
		tmp_child = (LCUI_GraphLayer*)Queue_Get( child_list, i );
		if( !tmp_child ) {
			continue;
		}
		if( tmp_child == glayer ) {
			src_pos = i;
			continue;
		}
		if( des_pos == -1 ) {
			/* 如果该位置的图层的z-index值不大于自己 */
			if( tmp_child->z_index <= glayer->z_index ) {
				/* 如果未找到自己的源位置 */
				if( src_pos == -1 ) {
					des_pos = i;
					continue;
				}
				/* 否则,退出循环,因为已经在前排了 */
				break;
			}
		} else {
			if( src_pos != -1 ) {
				break;
			}
		}
	}
	/* 没有找到就退出 */
	if( des_pos == -1 || src_pos == -1 ) {
		return -2;
	}
	/* 找到的话就移动位置 */
	Queue_Move( child_list, des_pos, src_pos );
	return 0;
}