示例#1
0
文件: text_layer.c 项目: dwdcth/LCUI
/*************************** 基本的处理 *********************************/
void 
TextLayer_Init( LCUI_TextLayer *layer )
/* 初始化文本图层相关数据 */
{
	layer->using_code_mode = IS_FALSE; 
	layer->using_style_tags = IS_FALSE; 
	layer->enable_word_wrap = IS_FALSE; 
	layer->enable_multiline = IS_FALSE; 
	
	layer->have_select = IS_FALSE;
	layer->start = 0;
	layer->end = 0;
	
	Queue_Init( &layer->color_keyword, sizeof(Special_KeyWord), Destroy_Special_KeyWord );
	/* 队列中使用链表储存这些数据 */
	Queue_Init( &layer->text_source_data, sizeof(LCUI_CharData), Destroy_CharData );
	Queue_Set_DataMode( &layer->text_source_data, QUEUE_DATA_MODE_LINKED_LIST ); 
	Queue_Init( &layer->rows_data, sizeof(Text_RowData), Destroy_Text_RowData ); 
	Queue_Init( &layer->tag_buff, sizeof(tag_style_data), destroy_tag_style_data );
	Queue_Init( &layer->style_data, sizeof(LCUI_TextStyle), NULL );
	RectQueue_Init( &layer->clear_area );
	layer->default_data.pixel_size = 12;
	layer->current_src_pos = 0;
	layer->current_des_pos = Pos(0,0);
	layer->max_text_len = 5000; 
	TextStyle_Init ( &layer->default_data );
	//TextLayer_Text_Add_NewRow ( layer );/* 添加新行 */
}
示例#2
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;
}
示例#3
0
文件: rect.c 项目: fshunj/LCUI
/* 初始化储存矩形数据的队列 */
LCUI_API void
RectQueue_Init( LCUI_RectQueue *queue )
{
	queue->number = 0;
	Queue_Init( &queue->queue[0], sizeof(LCUI_Rect), NULL );
	Queue_Init( &queue->queue[1], sizeof(LCUI_Rect), NULL );
	/* 采用链表来记录数据 */
	Queue_SetDataMode( &queue->queue[0], QUEUE_DATA_MODE_LINKED_LIST );
	Queue_SetDataMode( &queue->queue[1], QUEUE_DATA_MODE_LINKED_LIST );
}
示例#4
0
LCUI_API void
StyleClass_Init( LCUI_StyleClass *style_class )
{
	LCUIString_Init( &style_class->class_name );
	Queue_Init(	&style_class->style_attr,
			sizeof(LCUI_StyleAttr),
			NULL );
	Queue_Init(	&style_class->pseudo_classes, 
			sizeof(LCUI_StyleClass), 
			NULL );
}
示例#5
0
void ExecutorInit() {
	g_executor.clients = Map_Init(
									Map_DefaultIntCmpFunc,
									Map_DefaultIntDupFunc,
									Map_DefaultFreeFunc,
									_client_dup_func,
									Map_DefaultFreeFunc
									);
	g_executor.cur_recv_buffer_ = 0;
	g_executor.conf_lock_ = WRLock_Init();
	for(int i = 0; i != CLIENT_RECV_QUEUES; ++i) {
		g_executor.recv_buffer_[i] = Queue_Init(sizeof(Message_t));
		sem_init(&g_executor.recv_buffer_num_[i] , 0 , 0);
	}
	g_executor.cur_send_buffer_ = 0;
	for(int i = 0; i != CLIENT_SEND_QUEUES; ++i) {
		g_executor.send_buffer_[i] = Queue_Init(sizeof(Message_t));
		sem_init(&g_executor.send_buffer_num_[i] , 0, 0);
	}
	g_executor.evloop = Event_CreateLoop(MAX_CLIENTS);
	if (g_executor.evloop == NULL) {
		fprintf(stderr, "[ERROR]Create server loop error.\n");
		exit(2);
	}
	g_executor.core_fd = netListenAndBind(NULL, g_executor.port_);
	if (g_executor.core_fd == ERR_NETWORK_EXCEPTION) {
		fprintf(stderr , "[ERROR]Create server error. Server quit. Specific binding port is [%d]\n" , g_executor.port_);
		exit(2);
	}
	if (netSetNonBlock(NULL, g_executor.core_fd) != NET_OK) {
		fprintf(stderr , "[ERROR]Set server main fd to non block failed\n");
		exit(2);
	}
	if ( EV_ERR == Event_CreateFileEvent(g_executor.evloop , g_executor.core_fd , EV_READABLE , _request_accept_func , NULL ) ) {
		fprintf(stderr, "[ERROR]Create server main event failed\n");
		exit(2);
	}
	InitPBAllocator();
	_executor_start_printscreen();
	Log(LOG_FORCE,"Executor Running at 0.0.0.0:%d",g_executor.port_);
	Log(LOG_FORCE,"Logs will save to \"%s\"" , g_executor.log_path_);
	Log(LOG_FORCE,"Task result will save to \"%s:%d\"" , g_executor.store_server_addr_ , g_executor.store_server_port_);
	Log(LOG_FORCE,"The CallBack URL for a finish task is [%s]" , g_executor.save_result_to);
	if (InitAndStartTaskMonitor(DefaultFuncOnTaskFinish)) {
		exit(2);
	}
	Log(LOG_FORCE,"Task Executor Start...");
}
示例#6
0
文件: graphlayer.c 项目: aem3372/LCUI
LCUI_API LCUI_GraphLayer* GraphLayer_New( void )
{
	LCUI_GraphLayer * glayer;
	
	glayer = (LCUI_GraphLayer*)malloc( sizeof( LCUI_GraphLayer ) );
	if( glayer == NULL ) {
		return NULL;
	}
	/* 赋初始值 */
	glayer->visible = FALSE;
	glayer->inherit_alpha = TRUE;
	glayer->pos.x = glayer->pos.y = glayer->z_index = 0;
	glayer->padding.left = 0;
	glayer->padding.top = 0;
	glayer->padding.bottom = 0;
	glayer->padding.right = 0;
	glayer->parent = NULL;
	/* 初始化图像数据 */
	Graph_Init( &glayer->graph );
	/* 初始化子图层列表 */
	Queue_Init( &glayer->child, 0, NULL );
	/* 标记该队列用于存储指针,即使销毁队列后,也不自动释放指针指向的内存空间 */ 
	Queue_UsingPointer( &glayer->child ); 
	return glayer;
}
示例#7
0
/* 初始化样式库 */
LCUI_API void
StyleLib_Init( LCUI_StyleLibrary *lib )
{
	Queue_Init(	&lib->style_classes, 
			sizeof(LCUI_StyleClass), 
			NULL );
}
示例#8
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;
}
示例#9
0
/* 初始化LCUI输入法模块 */
LCUI_API void
LCUIModule_IME_Init(void)
{
	int ime_id;
	Queue_Init( &imelist, sizeof(LCUIIME_Info), LCUIIME_DestroyInfo );
	imelist_init = TRUE;
	ime_id = LCUI_DefaultIMERegister();
	LCUIIME_Select( ime_id );
}
示例#10
0
/** 初始化部件事件处理 */
void LCUIWidgetEvent_Init(void)
{
	Queue_Init( &widget_proc_record, sizeof(WidgetRecordItem), NULL );
	LCUISysEvent_Connect( LCUI_MOUSEBUTTONDOWN, LCUI_HandleMouseButton, NULL );
	LCUISysEvent_Connect( LCUI_MOUSEBUTTONUP, LCUI_HandleMouseButton, NULL );
	LCUISysEvent_Connect( LCUI_MOUSEMOTION, LCUI_HandleMouseMotion, NULL );
	LCUISysEvent_Connect( LCUI_KEYDOWN, WidgetFocusProc, NULL );
	LCUISysEvent_Connect( LCUI_KEYUP, WidgetFocusProc, NULL );
}
示例#11
0
int GameMsgLoopStart( void )
{
	if( msg_thread_id != 0 ) {
		return -1;
	}
	LCUISleeper_Create( &msg_sleeper );
	Queue_Init( &game_msg_queue, sizeof(GameMsg), NULL );
	return LCUIThread_Create( &msg_thread_id, GameMsgProcThread, NULL );
}
示例#12
0
void 
EventQueue_Init(LCUI_EventQueue * queue)
/* 功能:初始化事件队列 */
{
	/* 
	 * 由于LCUI_Event结构体的成员中有函数队列,销毁事件时需要把该队列销毁,所以需
	 * 要Destroy_Event()作为析构函数 
	 * */
	Queue_Init(queue, sizeof(LCUI_Event), Destroy_Event);
}
示例#13
0
void 
TextLayer_Init( LCUI_TextLayer *layer )
/* 初始化文本图层相关数据 */
{
	layer->read_only = FALSE;
	layer->using_code_mode = FALSE; 
	layer->using_style_tags = FALSE; 
	layer->enable_word_wrap = FALSE; 
	layer->enable_multiline = FALSE;
	layer->need_proc_buff = FALSE;
	layer->need_scroll_layer = FALSE;
	layer->have_select = FALSE;
	layer->start = 0;
	layer->end = 0;
	layer->offset_pos = Pos(0,0);
	layer->old_offset_pos = Pos(0,0);
	
	Queue_Init( &layer->color_keyword, sizeof(Special_KeyWord), Destroy_Special_KeyWord );
	/* 队列中使用链表储存这些数据 */
	Queue_Init( &layer->text_source_data, sizeof(LCUI_CharData), Destroy_CharData );
	Queue_Set_DataMode( &layer->text_source_data, QUEUE_DATA_MODE_LINKED_LIST ); 
	Queue_Init( &layer->rows_data, sizeof(Text_RowData), Destroy_Text_RowData ); 
	Queue_Init( &layer->tag_buff, sizeof(tag_style_data), destroy_tag_style_data );
	Queue_Init( &layer->style_data, sizeof(LCUI_TextStyle), NULL );
	RectQueue_Init( &layer->clear_area );
	/* 初始化屏蔽符的数据 */
	layer->password_char.display = TRUE;
	layer->password_char.need_update = FALSE;
	layer->password_char.data = NULL;
	layer->password_char.char_code = 0;
	FontBMP_Init( &layer->password_char.bitmap );
	
	layer->default_data.pixel_size = 12;
	layer->current_src_pos = 0;
	layer->current_des_pos = Pos(0,0);
	layer->max_text_len = 5000; 
	TextStyle_Init ( &layer->default_data );
	
	String_Init( &layer->text_buff );
	//TextLayer_Text_Add_NewRow ( layer );/* 添加新行 */
}
示例#14
0
文件: main.c 项目: leolimabh/qwoma
void queueInit()
{
#define LNS 20
#define COLS 64

    static char rawData[LNS][COLS];
    static char * linePtrs[LNS];
    int i = 0;
    for (i = 0; i < LNS; i++)
        linePtrs[i] = &rawData[i][0];

    Queue_Init(&queue, LNS, COLS, linePtrs);

    printf("First queue created...\n");
    printf("Size of the raw data: %d bytes\n", (int) sizeof(rawData));
    printf("Size of the array of pointers: %d bytes\n", (int) sizeof(linePtrs));
    printf("Size of queue struct: %d bytes\n", (int) sizeof(queue));
    printf("Overhead of %f per cent.\n", (float)(sizeof(linePtrs) + sizeof(queue))*100/sizeof(rawData));

#undef LNS
#undef COLS

#define LNS 5
#define COLS 1024

    static char rawData2[LNS][COLS];
    static char * linePtrs2[LNS];
    for (i = 0; i < LNS; i++)
        linePtrs2[i] = &rawData2[i][0];

    Queue_Init(&queue2, LNS, COLS, linePtrs2);

    printf("Second queue created...\n");
    printf("Size of the raw data: %d bytes\n", (int) sizeof(rawData2));
    printf("Size of the array of pointers: %d bytes\n", (int) sizeof(linePtrs2));
    printf("Size of queue struct: %d bytes\n", (int) sizeof(queue2));
    printf("Overhead of %f per cent.\n", (float)(sizeof(linePtrs2) + sizeof(queue2))*100/sizeof(rawData2));

#undef LNS
#undef COLS
}
示例#15
0
FontLIB_Init( void )
{
	if( database_init ) {
		return;
	}
	Queue_Init(	&fontbitmap_database, 
			sizeof(LCUI_FontCharItem), 
			FontLIB_Destroy );
	Queue_Init(	&font_database, 
			sizeof(LCUI_FontInfo), 
			FontLIB_DestroyFontInfo );
#ifdef LCUI_FONT_ENGINE_FREETYPE
	/* 当初始化库时发生了一个错误 */
	if ( FT_Init_FreeType( &library ) ) {
		printf("%s: %s", __FUNCTION__, FT_INIT_ERROR);
		return;
	}
#else
	library = NULL;
#endif
	database_init = TRUE;
}
示例#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
static int
TextLayer_Text_Insert_NewRow ( LCUI_TextLayer *layer, int row )
/* 在插入新行至指定位置 */
{
	Text_RowData data;
	
	data.pos = Pos(0,0); 
	data.max_size = Size(0,0);
	data.last_char = NULL;
	Queue_Init( &data.string, sizeof(LCUI_CharData), NULL ); 
	Queue_SetDataMode( &data.string, QUEUE_DATA_MODE_LINKED_LIST ); 
	Queue_UsingPointer( &data.string );
	return Queue_Insert( &layer->rows_data, row, &data );
}
示例#18
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 );
}
示例#19
0
int main() {
    queue_t *q = (queue_t*)malloc(sizeof(queue_t));
    Queue_Init(q);

    int i, t;
    for (i = 0; i < 20; i++) {
        Queue_Enqueue(q, i);
        printf("Enqueue: %d\n", i);
    }
    for (i = 0; i < 10; i++) {
        Queue_Dequeue(q, &t);
        printf("Dequeue: %d\n", t);
    }

    return 0;
}
示例#20
0
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;
}
示例#21
0
void* _client_monitor(void* arg) {
	AVOID_NOUSED(arg);
	client_iterator_t iterator;
	iterator.clients_tobe_clear = Queue_Init(sizeof(int));
	for(;;) {
		int interval = 0;
		WRLock_LockR(g_executor.conf_lock_);
		interval = g_executor.pluse_interval_;
		WRLock_UnlockR(g_executor.conf_lock_);
		iterator.pluse_interval = interval;
		iterator.check_time = time(NULL);
		Map_Foreach(g_executor.clients , _foreach_client_ , &iterator);
		int cfd;
		while(Queue_Pop(iterator.clients_tobe_clear , &cfd) == QUEUE_OK) {
			_release_client(cfd , RELEASE_BY_PLUSE);
		}
		sleep(interval);
	}
	return NULL;
}
示例#22
0
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;
}
示例#23
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;
}
示例#24
0
static void 
TextBox_Init( LCUI_Widget *widget )
/* 初始化文本框相关数据 */
{
	LCUI_TextBox *textbox;
	
	widget->valid_state = WIDGET_STATE_ACTIVE | WIDGET_STATE_OVERLAY;
	widget->valid_state |= (WIDGET_STATE_NORMAL | WIDGET_STATE_DISABLE);
	textbox = WidgetPrivData_New(widget, sizeof(LCUI_TextBox));
	textbox->text = Widget_New( "label" );
	textbox->cursor = Widget_New( NULL );
	textbox->scrollbar[0] = Widget_New( "scrollbar" );
	textbox->scrollbar[1] = Widget_New( "scrollbar" );
	/* 不可获得焦点 */
	textbox->text->focus = FALSE;
	textbox->cursor->focus = FALSE;
	textbox->scrollbar[0]->focus = FALSE;
	textbox->scrollbar[1]->focus = FALSE;
	textbox->limit_mode = 0;
	textbox->block_size = 256;
	textbox->show_placeholder = FALSE;
	LCUIWString_Init( &textbox->placeholder );
	TextStyle_Init( &textbox->placeholder_style );
	TextStyle_FontColor( &textbox->placeholder_style, RGB(100,100,100) );
	Label_AutoSize( textbox->text, FALSE, 0 );
	Widget_SetSize( textbox->text, "100%", "100%" );
	
	/* 添加至相应的容器 */
	Widget_Container_Add( textbox->text, textbox->cursor ); 
	Widget_Container_Add( widget, textbox->text ); 
	Widget_Container_Add( widget, textbox->scrollbar[0] );
	Widget_Container_Add( widget, textbox->scrollbar[1] );
	/* 设置滚动条的尺寸 */
	Widget_SetSize( textbox->scrollbar[0], "10px", NULL );
	Widget_SetSize( textbox->scrollbar[1], NULL, "10px" );
	Widget_SetAlign( textbox->scrollbar[0], ALIGN_TOP_RIGHT, Pos(0,0) );
	Widget_SetAlign( textbox->scrollbar[1], ALIGN_BOTTOM_LEFT, Pos(0,0) );
	/* 滚动条设为横向 */
	ScrollBar_SetDirection( textbox->scrollbar[1], 1 );
	/* 将回调函数与滚动条连接 */
	ScrollBar_Connect( textbox->scrollbar[0], TextBox_TextLayer_VertScroll, widget );
	ScrollBar_Connect( textbox->scrollbar[1], TextBox_HoriScroll_TextLayer, widget );
	Widget_Show( textbox->text );
	
	Queue_Init( &textbox->text_block_buff, sizeof(LCUI_TextBlock), destroy_textblock );
	
	TextLayer_UsingStyleTags( Label_GetTextLayer(textbox->text), FALSE );
	Widget_SetPadding( widget, Padding(2,2,2,2) );
	Widget_SetBackgroundColor( textbox->cursor, RGB(0,0,0) );
	Widget_SetBackgroundTransparent( textbox->cursor, FALSE );
	Widget_SetBackgroundTransparent( widget, FALSE );
	
	Widget_Resize( textbox->cursor, Size(1, 14) );
	/* 设置可点击区域的alpha值要满足的条件 */
	Set_Widget_ClickableAlpha( textbox->cursor, 0, 1 );
	Set_Widget_ClickableAlpha( textbox->text, 0, 1 );
	
	/* 设定定时器,每1秒闪烁一次 */
	if( __timer_id == -1 ) {
		__timer_id = set_timer( 500, blink_cursor, TRUE );
	}
	Widget_Event_Connect( widget, EVENT_DRAG, TextBox_TextLayer_Click );
	/* 关联 FOCUS_OUT 和 FOCUS_IN 事件 */
	Widget_Event_Connect( widget, EVENT_FOCUSOUT, _putout_textbox_cursor );
	Widget_Event_Connect( widget, EVENT_FOCUSIN, _putin_textbox_cursor );
	/* 关联按键输入事件 */
	Widget_Event_Connect( widget, EVENT_KEYBOARD, TextBox_Input );
	/* 默认不启用多行文本模式 */
	TextBox_Multiline( widget, FALSE );
}
int main()
{
	system("COLOR 1A");
	Queue *snake = Queue_Init();

	COORD screenResolution = {WIDTH, HEIGHT};
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), screenResolution);

	SetConsoleTitle("TU-Snake");

	COORD directions[4] = {
		{0, -1},
		{0, 1},
		{1, 0},
		{-1, 0},
	};

	Direction direction = LEFT;

	unsigned int keyboardInput = 0;
	double snakeSpeed = SnakeSpeed;

	COORD food = {RandomNumber(0, WIDTH), RandomNumber(0, HEIGHT)};
	int centerX = WIDTH / 2;
	int centerY = HEIGHT / 2;

	//InitSnake
	for (int i = 0; i < SnakeInitializeSize; i++)
	{
		COORD position = { centerX - i , centerY};
		Queue_Push(snake, position);
	}

	PrintSnake(snake);

	while (1)
	{
		if (_kbhit() == 1)
		{
			keyboardInput = _getch();

			switch (keyboardInput)
			{
			case 119 : //up
				if (direction != DOWN)
					direction = UP;
				break;
			case 115 : //down
				if (direction != UP)
					direction = DOWN;
				break;
			case 97 : //left
				if (direction != RIGHT)
					direction = LEFT;
				break;
			case 100 : //right
				if (direction != LEFT)
					direction = RIGHT;
				break;
			default:
				break;
			}
		}
		
		COORD snakeHead = Queue_Back(snake);
		COORD nextDirection = directions[direction];
		COORD snakeNewHead = {snakeHead.X + nextDirection.X, snakeHead.Y + nextDirection.Y};

		//check for collisions
		if (snakeNewHead.X < 0 || snakeNewHead.Y < 0 || 
			snakeNewHead.X > WIDTH || snakeNewHead.Y > HEIGHT || Queue_Contains (snake, snakeNewHead))
		{
			char text[] = "!!!Game is over!!!";
			COORD startPoint = {centerX - strlen(text)/2, centerY};
			GoToPosition(startPoint);
			system("COLOR CF");
			printf("%s", text);
			PlaySong();
			break;
		}

		//add new head to snake
		Queue_Push(snake, snakeNewHead);

		//check for grow
		if (snakeNewHead.X == food.X && snakeNewHead.Y == food.Y)
		{
			food.X = RandomNumber(0, WIDTH);
			food.Y = RandomNumber(0, HEIGHT);
			if (snakeSpeed - 1 > 1)
				snakeSpeed--;
		}
		else
		{
			Queue_Pop(snake);	
		}

		PrintSnake(snake);

		GoToPosition(food);
		printf("%c", SnakeFood);


		if (snakeSpeed - 0.1 > 1)
			snakeSpeed -= 0.1;
		Sleep((int)snakeSpeed);
		ClearScreen;
	}

	system("pause > ''");
	return 0;
}
示例#26
0
文件: device.c 项目: FrankHB/LCUI
/** 设备列表初始化 */
static void dev_list_init( LCUI_Queue *dev_list )
{
	Queue_Init( dev_list, sizeof(dev_func_data), NULL );
}
示例#27
0
文件: graphlayer.c 项目: aem3372/LCUI
LCUI_API int GraphLayer_GetGraph( LCUI_GraphLayer *ctnr, 
				LCUI_Graph *graph_buff, LCUI_Rect rect )
{
	int i, total; 
	uchar_t tmp_alpha, alpha;
	LCUI_Pos pos, glayer_pos;
	LCUI_GraphLayer *glayer;
	LCUI_Queue glayerQ;
	LCUI_Rect valid_area;
	LCUI_Graph tmp_graph;
	
	/* 检测这个区域是否有效 */
	if (rect.x < 0 || rect.y < 0) {
		return -1; 
	}
	if (rect.x + rect.width > ctnr->graph.w
	 || rect.y + rect.height > ctnr->graph.h ) {
		 return -1;
	}
	if (rect.width <= 0 || rect.height <= 0) {
		return -2;
	}
	if( !Graph_IsValid(graph_buff) ) {
	graph_buff->color_type = COLOR_TYPE_ARGB;
		Graph_Create( graph_buff, rect.width, rect.height );
	}

	Graph_Init( &tmp_graph );
	Queue_Init( &glayerQ, 0, NULL);
	Queue_UsingPointer( &glayerQ );
	
	/* 获取rect区域内的图层列表 */
	GraphLayer_GetLayers( ctnr, rect, &glayerQ ); 
	total = Queue_GetTotal( &glayerQ ); 
	DEBUG_MSG( "total: %d\n", total );
	/* 若记录数为零,则表明该区域没有图层 */
	if( total <= 0 ) {
		/* 若没有父图层,则填充白色 */
		if( ctnr == NULL ) {
			Graph_FillColor( graph_buff, RGB(255,255,255) );
		} else { /* 否则使用父图层的图形 */
			Graph_Cut( &ctnr->graph, rect, graph_buff );
		}
		/* 销毁记录 */
		Queue_Destroy( &glayerQ );
		return 0;
	}
	/* 从顶层到底层遍历图层,排除被其它图层完全遮挡或者自身完全透明的图层 */
	for(i=total-1; i>=0; --i) {
		glayer = (LCUI_GraphLayer*)Queue_Get( &glayerQ, i );
		valid_area = GraphLayer_GetValidRect( ctnr, glayer );
		glayer_pos = GraphLayer_GetGlobalPos( ctnr, glayer );
		valid_area.x += glayer_pos.x;
		valid_area.y += glayer_pos.y;
		alpha = GraphLayer_GetRealAlpha( glayer );
		/* 当前图层的透明度小于255的话,就跳过 */
		if( alpha < 255 ) {
			continue;
		}
		/* 跳过有alpha通道的图层 */
		if( glayer->graph.color_type == COLOR_TYPE_ARGB ) {
			continue;
		}
		/* 如果该图层的有效区域包含目标区域 */
		if( rect.x >= valid_area.x && rect.y >= valid_area.y
		 && rect.x + rect.w <= valid_area.x + valid_area.w
		 && rect.y + rect.h <= valid_area.y + valid_area.h ) {
			/* 移除底层的图层,因为已经被完全遮挡 */
			for(total=i-1;total>=0; --total) {
				Queue_DeletePointer( &glayerQ, 0 );
			}
			goto skip_loop;
		}
	}
skip_loop:
	total = Queue_GetTotal( &glayerQ );
	DEBUG_MSG( "total: %d\n", total );
	if(i <= 0 && ctnr ) {
			Graph_Cut( &ctnr->graph, rect, graph_buff );
	}
	/* 获取图层列表中的图层 */
	for(i=0; i<total; ++i) {
		glayer = (LCUI_GraphLayer*)Queue_Get( &glayerQ, i );
		//_DEBUG_MSG("%p = Queue_Get( %p, %d )\n", glayer, &glayerQ, i);
		if( !glayer ) {
			continue;
		}
		DEBUG_MSG("%d,%d,%d,%d\n", glayer->pos.x, glayer->pos.y, glayer->graph.w, glayer->graph.h);
		/* 获取该图层的有效区域及全局坐标 */
		pos = GraphLayer_GetGlobalPos( ctnr, glayer );
		valid_area = GraphLayer_GetValidRect( ctnr, glayer );
		/* 引用该图层的有效区域内的图像 */
		Graph_Quote( &tmp_graph, &glayer->graph, valid_area ); 
		//_DEBUG_MSG("valid area: %d,%d,%d,%d, pos: %d,%d, size: %d,%d\n", 
		//	valid_area.x, valid_area.y, valid_area.width, valid_area.height,
		//	pos.x, pos.y, glayer->graph.w, glayer->graph.h
		//	);
		/* 获取相对坐标 */
		pos.x = pos.x - rect.x + valid_area.x;
		pos.y = pos.y - rect.y + valid_area.y;
		//_DEBUG_MSG("mix pos: %d,%d\n", pos.x, pos.y);
		/* 如果该图层没有继承父图层的透明度 */
		if( !glayer->inherit_alpha ) {
			/* 直接叠加至graph_buff */
			Graph_Mix( graph_buff, &tmp_graph, pos );
		} else {
			/* 否则,计算该图层应有的透明度 */
			alpha = GraphLayer_GetRealAlpha( glayer );
			/* 备份该图层的全局透明度 */
			tmp_alpha = glayer->graph.alpha;
			/* 将实际透明度作为全局透明度,参与图像叠加 */
			glayer->graph.alpha = alpha;
			Graph_Mix( graph_buff, &tmp_graph, pos );
			/* 还原全局透明度 */
			glayer->graph.alpha = tmp_alpha;
		}
	}
	Queue_Destroy( &glayerQ );
	return 0;
}
示例#28
0
static void 
TextBox_Init( LCUI_Widget *widget )
/* 初始化文本框相关数据 */
{
	LCUI_TextBox *textbox;
	
	textbox = Widget_Create_PrivData(widget, sizeof(LCUI_TextBox));
	
	textbox->text = Create_Widget( "label" );
	textbox->cursor = Create_Widget( NULL );
	textbox->scrollbar[0] = Create_Widget( "scrollbar" );
	textbox->scrollbar[1] = Create_Widget( "scrollbar" );
	/* 不可获得焦点 */
	textbox->text->focus = FALSE;
	textbox->cursor->focus = FALSE;
	textbox->scrollbar[0]->focus = FALSE;
	textbox->scrollbar[1]->focus = FALSE;
	textbox->limit_mode = 0;
	textbox->block_size = 256;
	
	Label_AutoSize( textbox->text, FALSE, 0 );
	Set_Widget_Size( textbox->text, "100%", "100%" );
	
	/* 添加至相应的容器 */
	Widget_Container_Add( textbox->text, textbox->cursor ); 
	Widget_Container_Add( widget, textbox->text ); 
	Widget_Container_Add( widget, textbox->scrollbar[0] );
	Widget_Container_Add( widget, textbox->scrollbar[1] );
	/* 设置滚动条的尺寸 */
	Set_Widget_Size( textbox->scrollbar[0], "10px", NULL );
	Set_Widget_Size( textbox->scrollbar[1], NULL, "10px" );
	Set_Widget_Align( textbox->scrollbar[0], ALIGN_TOP_RIGHT, Pos(0,0) );
	Set_Widget_Align( textbox->scrollbar[1], ALIGN_BOTTOM_LEFT, Pos(0,0) );
	/* 滚动条设为横向 */
	ScrollBar_Set_Direction( textbox->scrollbar[1], 1 );
	/* 将回调函数与滚动条连接 */
	ScrollBar_Connect( textbox->scrollbar[0], TextBox_VertScroll_TextLayer, widget );
	ScrollBar_Connect( textbox->scrollbar[1], TextBox_HoriScroll_TextLayer, widget );
	Show_Widget( textbox->text );
	
	Queue_Init( &textbox->text_block_buff, sizeof(LCUI_TextBlock), destroy_textblock );
	
	TextLayer_Using_StyleTags( Label_Get_TextLayer(textbox->text), FALSE );
	Set_Widget_Padding( widget, Padding(2,2,2,2) );
	Set_Widget_Backcolor( textbox->cursor, RGB(0,0,0) );
	Set_Widget_BG_Mode( textbox->cursor, BG_MODE_FILL_BACKCOLOR );
	
	Resize_Widget( textbox->cursor, Size(1, 14) );
	/* 设置可点击区域的alpha值要满足的条件 */
	Set_Widget_ClickableAlpha( textbox->cursor, 0, 1 );
	Set_Widget_ClickableAlpha( textbox->text, 0, 1 );
	/* 设定定时器,每1秒闪烁一次 */
	if( __timer_id == -1 ) {
		__timer_id = set_timer( 500, blink_cursor, TRUE );
	}
	Widget_Drag_Event_Connect( widget, TextBox_TextLayer_Click );
	/* 关联 FOCUS_OUT 和 FOCUS_IN 事件 */
	Widget_FocusOut_Event_Connect( widget, hide_textbox_cursor, NULL );
	Widget_FocusIn_Event_Connect( widget, _put_textbox_cursor, NULL );
	/* 关联按键输入事件 */
	Widget_Keyboard_Event_Connect( widget, TextBox_Input );
	/* 默认不启用多行文本模式 */
	TextBox_Multiline( widget, FALSE );
}
示例#29
0
文件: timer.c 项目: fshunj/LCUI
/** 初始化定时器列表 */
static void TimerList_Init( LCUI_Queue *timer_list )
{
	Queue_Init( timer_list, sizeof(timer_data), NULL );
	/* 使用链表 */
	Queue_SetDataMode( timer_list, QUEUE_DATA_MODE_LINKED_LIST );
}
示例#30
0
void 
FuncQueue_Init(LCUI_Queue *queue)
/* 功能:初始化函数指针队列 */
{
	Queue_Init(queue, sizeof(LCUI_Func), NULL);
}