Пример #1
0
/**************************** 私有函数 **********************************/
static void
Move_ScrollBar( LCUI_Widget *widget, LCUI_Pos new_pos )
{
	double scale;
	int size;
	LCUI_ScrollBar *scrollbar;
	//_DEBUG_MSG("new_pos: %d,%d\n", new_pos.x, new_pos.y);
	scrollbar = Widget_GetPrivData( widget->parent );
	/* 使该坐标在限制范围内 */
	new_pos = Widget_GetValidPos( widget, new_pos );
	/* 判断滚动条的方向 */
	if( scrollbar->direction == 0 ) { /* 纵向 */
		/* 先得到容器高度 */
		size = Widget_GetContainerHeight( widget->parent );
		//_DEBUG_MSG("1,size: %d\n", size);
		/* 减去自身高度 */
		size -= _Widget_GetHeight( widget );
		//_DEBUG_MSG("2,size: %d\n", size);
		/* 再用当前坐标除以size,得到比例 */
		scale = new_pos.y * 1.0 / size;
		//_DEBUG_MSG("%.2f = %d * 1.0 / %d\n", scale, new_pos.y, size);
		/* 将max_num乘以比例,得出current_num的值 */
		scrollbar->data.current_num = scale * scrollbar->data.max_num;
		//_DEBUG_MSG("current_num: %d, scale: %.2f, max_num: %d\n", 
		//scrollbar->data.current_num, scale, scrollbar->data.max_num);
	} else { /* 横向 */
		size = Widget_GetContainerWidth( widget->parent );
		size -= _Widget_GetWidth( widget );
		scale = new_pos.x * 1.0 / size;
		scrollbar->data.current_num = scale * scrollbar->data.max_num;
	}
	//_DEBUG_MSG("widget:%p, pos: %d,%d\n", widget, new_pos.x, new_pos.y);
	Widget_Move( widget, new_pos );
}
Пример #2
0
TextBox_Cursor_Update( LCUI_Widget *widget )
/* 更新文本框的光标,返回该光标的像素坐标 */
{
	LCUI_Pos pixel_pos;
	LCUI_Widget *cursor;
	LCUI_TextLayer *layer;
	LCUI_TextBox *textbox;
	LCUI_Size size;
	
	textbox = Widget_GetPrivData( widget );
	layer = TextBox_GetTextLayer( widget );
	/* 如果显示了占位符,那么就复位光标的位置 */
	if( textbox->show_placeholder ) {
		TextLayer_Cursor_SetPos( layer, Pos(0,0) );
	}
	cursor = TextBox_GetCursor( widget );
	size.w = 1;
	size.h = TextLayer_CurRow_GetMaxHeight( layer );
	pixel_pos = TextLayer_Cursor_GetPixelPos( layer );
	Widget_Move( cursor, pixel_pos );
	Widget_Resize( cursor, size );
	/* 若当前文本框处于焦点状态,则让光标在更新时显示 */
	if( active_textbox == widget ) {
		Widget_Show( cursor );
	}
	return pixel_pos;
}
Пример #3
0
/* 处理鼠标移动事件 */
static void 
Window_ExecMove(LCUI_Widget *titlebar, LCUI_WidgetEvent *event)
{
	LCUI_Pos pos, offset;
	LCUI_Widget *window;
	
	window = titlebar->parent;
	if( !window ) {
		return;
	}
	//_DEBUG_MSG( "new:%d,%d, cursor:%d,%d\n", 
	//event->drag.new_pos.x, event->drag.new_pos.y, 
	//event->drag.cursor_pos.x, event->drag.cursor_pos.y );
	/* 将新全局坐标减去标题栏的全局坐标,得到偏移坐标 */
	pos = Widget_GetGlobalPos( titlebar );
	offset = Pos_Sub( event->drag.new_pos, pos );
	pos = Widget_GetGlobalPos( window );
	/* 将偏移坐标加在窗口全局坐标上,得出窗口的新全局坐标 */
	pos = Pos_Add( pos, offset );
	/* 转换成在容器区域内的相对坐标 */
	pos = Widget_ToRelPos( window->parent, pos );
	/* 解除之前设定的align */
	Widget_SetAlign( window, ALIGN_NONE, Pos(0,0) );
	/* 移动窗口的位置 */
	Widget_Move( window, pos );
}
Пример #4
0
/* 处理鼠标移动事件 */
static void Window_ExecMove( LCUI_Widget *window, LCUI_WidgetEvent *event )
{
	LCUI_Pos pos;
	/* 解除之前设定的align */
	Widget_SetAlign( window, ALIGN_NONE, Pos(0,0) );
	pos = Widget_ToRelPos( window->parent, event->drag.new_pos );
	/* 移动窗口的位置 */
	Widget_Move( window, pos );
}
Пример #5
0
static void test_move_widget( void *ar1, void *arg2 )
{
	float scale, x, y;
	float screen_w, screen_h;
	scale = LCUIMetrics_GetScale();
	screen_w = SCREEN_WIDTH / scale;
	screen_h = SCREEN_HEIGHT / scale;
	switch( self.step ) {
	case 0:
		x = self.x + DELTA;
		y = self.y + DELTA;
		if( x + WIDGET_WIDTH >= screen_w ||
		    y + WIDGET_HEIGHT >= screen_h ) {
			x = screen_w - WIDGET_WIDTH;
			y = screen_h - WIDGET_HEIGHT;
			self.step += 1;
		}
		break;
	case 1:
		x = self.x;
		y = self.y - DELTA;
		if( y <= 0 ) {
			y = 0;
			self.step += 1;
		}
		break;
	case 2:
		x = self.x - DELTA;
		y = self.y;
		if( x <= 0 ) {
			x = 0;
			self.step += 1;
		}
		break;
	case 3:
		x = self.x;
		y = self.y + DELTA;
		if( y + WIDGET_HEIGHT >= screen_h ) {
			y = screen_h - WIDGET_HEIGHT;
			self.step += 1;
		}
		break;
	case 4:
		x = self.x + DELTA;
		y = self.y - DELTA;
		if( x + WIDGET_WIDTH >= screen_w || y <= 0 ) {
			x = screen_w - WIDGET_WIDTH;
			y = 0;
			self.step += 1;
		}
		break;
	default:
		LCUI_Exit( self.pass - self.count );
		return;
	}
	Widget_Move( self.widget, x, y );
}
Пример #6
0
static void 
ScrollBar_Update( LCUI_Widget *widget )
{
	static int pos, max_len;
	static double scale;
	static char scale_str[256];
	LCUI_ScrollBar *scrollbar;
	
	scrollbar = Widget_GetPrivData( widget );
	/* 计算比例,之后转换成字符串 */
	scale = scrollbar->data.current_size*1.0 / scrollbar->data.max_size; 
	sprintf( scale_str, "%.2lf%%", scale*100 );
	//_DEBUG_MSG("current_num: %d, max_num: %d\n", 
	//scrollbar->data.current_num, scrollbar->data.max_num);
	/* 判断滚动条的方向 */
	if( scrollbar->direction == 0 ) { /* 纵向 */
		Widget_SetSize( scrollbar->widget, NULL, scale_str );
		max_len = Widget_GetContainerHeight( widget );
		max_len -= _Widget_GetHeight( scrollbar->widget );
		Widget_LimitPos( scrollbar->widget, Pos(0,0), Pos( 0, max_len ) );
		
		scale = scrollbar->data.current_num*1.0 / scrollbar->data.max_num;
		pos = scale * max_len;
		//_DEBUG_MSG("num: %d / %d\n", 
		//scrollbar->data.current_num, scrollbar->data.max_num);
		//_DEBUG_MSG("ScrollBar_Update(), scale: %.2f\n", scale);
		//_DEBUG_MSG("ScrollBar_Update(), y: %d\n", pos);
		/* 移动滚动条 */
		Widget_Move( scrollbar->widget, Pos(0,pos) );
	} else { /* 横向 */ 
		Widget_SetSize( scrollbar->widget, scale_str, NULL );
		max_len = Widget_GetContainerWidth( widget );
		max_len -= _Widget_GetWidth( scrollbar->widget );
		Widget_LimitPos( scrollbar->widget, Pos(0,0), Pos(max_len,0) );
		scale = scrollbar->data.current_num*1.0 / scrollbar->data.max_num;
		pos = scale * max_len;
		//printf("ScrollBar_Update(), num: %d / %d\n", 
		//scrollbar->data.current_num, scrollbar->data.max_num);
		//printf("ScrollBar_Update(), scale: %.2f\n", scale);
		//printf("ScrollBar_Update(), x: %d\n", pos);
		Widget_Move( scrollbar->widget, Pos(pos, 0) );
	}
}
Пример #7
0
int main( int argc, char **argv )
{
	LCUI_Widget w, root, text;
	LCUI_Graph desktop_image;

	InitConsoleWindow();
	LCUI_Init();
	LCUIDisplay_SetMode( LDM_WINDOWED );
	LCUIDisplay_SetSize( 960, 540 );
	w = LCUIWidget_New("debug-widget");
	text = LCUIWidget_New("textview");
	Widget_Append( w, text );
	TextView_SetTextW( text, L"测试文本内容,呵呵达!\nABCDEFG,abcdefg,[color=#ff0000]color font[/color]");
	Widget_Top( w );
	Widget_Show( w );
	Widget_Resize( w, 320, 240 );
	Widget_Move( w, 200, 200 );
	Widget_SetTitleW( w, L"测试" );
	Graph_Init( &desktop_image );
	Graph_LoadImage( "images/background-image.png", &desktop_image );
	root = LCUIWidget_GetRoot();

	Widget_PullStyle( root, WSS_BACKGROUND );
	root->style.background.color = RGB(255,242,223);
	root->style.background.image = desktop_image;
	root->style.background.size.using_value = TRUE;
	root->style.background.size.value = SV_COVER;
	Widget_PushStyle( root, WSS_BACKGROUND );

	Widget_PullStyle( w, WSS_BACKGROUND | WSS_SHADOW | WSS_BORDER );
	w->style.background.color.value = 0xccffffff;
	w->style.background.size.w.scale = 0.50; 
	w->style.background.size.h.px = 200;
	w->style.background.size.w.type = SVT_SCALE;
	w->style.background.size.h.type = SVT_PX;
	w->style.background.size.using_value = FALSE;
	w->style.background.position.using_value = TRUE;
	w->style.background.position.value = SV_BOTTOM_CENTER;
	w->style.shadow.color = ARGB(200,0,122,204);
	w->style.shadow.x = 2;
	w->style.shadow.y = 2;
	w->style.shadow.spread = 0;
	w->style.shadow.blur = 8;
	w->style.border.top.width = 1;
	w->style.border.right.width = 1;
	w->style.border.bottom.width = 1;
	w->style.border.left.width = 1;
	w->style.border.top.color = RGB(0,122,204);
	w->style.border.right.color = RGB(0,122,204);
	w->style.border.bottom.color = RGB(0,122,204);
	w->style.border.left.color = RGB(0,122,204);
	Widget_PushStyle( w, WSS_BACKGROUND | WSS_SHADOW | WSS_BORDER );
	//LCUITimer_Set( 5000, onTimer, NULL, TRUE );
	return LCUI_Main();
}
Пример #8
0
static void PicBtn_UpdatePos( void *arg )
{
	static int n = 2;
	LCUI_Pos pos;
	if( !need_move_pic_btn ) {
		n = 4;
		return;
	}
	pos = _Widget_GetPos( pic_btn );
	if( pos.x == 0 ) {
		return;
	}
	pos.x -= n;
	if( pos.x < 0 ) {
		pos.x = 0;
	}
	pos.y = 0;
	n+=2;
	Widget_Move( pic_btn, pos );
}
Пример #9
0
TextBox_Cursor_Move( LCUI_Widget *widget, LCUI_Pos new_pos )
/* 移动文本框内的光标 */
{
	LCUI_Pos pixel_pos;
	LCUI_Widget *cursor;
	LCUI_TextLayer *layer;
	LCUI_Size size;
	
	layer = TextBox_GetTextLayer( widget );
	cursor = TextBox_GetCursor( widget );
	size.w = 1;
	size.h = TextLayer_CurRow_GetMaxHeight( layer );
	pixel_pos = TextLayer_Cursor_SetPos( layer, new_pos );
	Widget_Move( cursor, pixel_pos );
	Widget_Resize( cursor, size );
	if( active_textbox == widget ) {
		Widget_Show( cursor );
	}
	/* 更新文本显示区域 */
	TextBox_ViewArea_Update( widget );
	return pixel_pos;
}
Пример #10
0
/* 移动滑块 */
void move_pic_btn(LCUI_Widget *widget, LCUI_WidgetEvent *event)
{
	LCUI_Size size;
	LCUI_Rect des, rect;
	LCUI_Pos pos, parent;

	need_move_pic_btn = FALSE;
	parent = Widget_GetGlobalPos(widget->parent);
	pos = Pos_Sub(event->drag.new_pos, parent);
	Widget_Move(widget, pos);
	if(event->drag.end_click) {/* 如果拖动已经结束 */
		rect = Widget_GetRect(widget);
		size = Widget_GetSize(widget->parent);
		des = Rect(size.w-10, 0, 30, 30);/* 目标区域 */
		 /* 如果部件区域与目标区域重叠,则退出程序 */
		if(LCUIRect_Overlay(rect, des)) {
			LCUI_MainLoop_Quit(NULL);
		} else {/* 否则,让部件回到起始位置,这个使用的是匀速移动 */
			need_move_pic_btn = TRUE;
		}
	}
}
Пример #11
0
int main(void)
{
	int  i, x, y = 3;
	
	LCUI_Init();
	
	window = Window_New( "测试MessageBox", NULL, Size(320,240) );
	label_btn = Widget_New( "label" );
	label_icon = Widget_New( "label" );
	btn = Widget_New( "button" );
	
	Window_ClientArea_Add( window, label_btn );
	Label_Text( label_btn, "请选择按钮类型:" );
	Widget_Move( label_btn, Pos(5,y) );
	Widget_Show( label_btn );
	
	for(i=0; i<6; ++i) {
		rb_btn[i] = RadioButton_New( rb_btn_text[i] );
		if( i>0 ) {
			RadioButton_CreateMutex( rb_btn[0], rb_btn[i] );
		} else {
			RadioButton_SetOn( rb_btn[0] );
		}
		Window_ClientArea_Add( window, rb_btn[i] );
		y += 16;
		Widget_Move( rb_btn[i], Pos(5,y) );
		Widget_Show( rb_btn[i] );
	}
	
	y += 16;
	Window_ClientArea_Add( window, label_icon );
	Label_Text( label_icon, "请选择图标类型:" );
	Widget_Move( label_icon, Pos(5,y) );
	Widget_Show( label_icon );
	
	for(i=0; i<5; ++i) {
		rb_icon[i] = RadioButton_New( rb_icon_text[i] );
		if( i>0 ) {
			RadioButton_CreateMutex( rb_icon[0], rb_icon[i] );
		} else {
			RadioButton_SetOn( rb_icon[0] );
		}
		Window_ClientArea_Add( window, rb_icon[i] );
		/* 计算当前单选框的坐标 */
		if(i%2 == 0) {
			y += 16;
			x = 5;
		} else {
			x = 150;
		}
		Widget_Move( rb_icon[i], Pos(x,y) );
		Widget_Show( rb_icon[i] );
	}
	
	Button_Text( btn, "显示MessageBox" );
	Widget_SetAlign( btn, ALIGN_BOTTOM_CENTER, Pos(0,-3) );
	Widget_Resize( btn, Size(80, 20) );
	Window_ClientArea_Add( window, btn );
	Widget_Show( btn );
	
	Widget_Event_Connect( btn, EVENT_CLICKED, show_msgbox );
	Widget_Event_Connect( Window_GetCloseButton(window), EVENT_CLICKED, program_quit );
	Widget_Show( window );
	return LCUI_Main();
}
Пример #12
0
/** 初始化键位设置窗口 */
void GameWindow_InitSetKeyboardWindow(void)
{
	/* 创建所需的GUI部件 */
	window = Widget_New("window");
	box = Widget_New(NULL);
	label = Widget_New("label");
	label_left = Widget_New("label");
	label_right = Widget_New("label");
	label_up = Widget_New("label");
	label_down = Widget_New("label");
	label_jump = Widget_New("label");
	label_defense = Widget_New("label");
	label_a_atk = Widget_New("label");
	label_b_atk = Widget_New("label");
	btn_left = Widget_New("button");
	btn_right = Widget_New("button");
	btn_up = Widget_New("button");
	btn_down = Widget_New("button");
	btn_a_atk = Widget_New("button");
	btn_b_atk = Widget_New("button");
	btn_jump = Widget_New("button");
	btn_defense = Widget_New("button");
	btn_ok = Widget_New("button");
	btn_reset = Widget_New("button");
	
	Widget_Container_Add( box, btn_left );
	Widget_Container_Add( box, btn_right );
	Widget_Container_Add( box, btn_up );
	Widget_Container_Add( box, btn_down );
	Widget_Container_Add( box, btn_jump );
	Widget_Container_Add( box, btn_defense );
	Widget_Container_Add( box, btn_a_atk );
	Widget_Container_Add( box, btn_b_atk );
	Widget_Container_Add( box, label_left );
	Widget_Container_Add( box, label_right );
	Widget_Container_Add( box, label_up );
	Widget_Container_Add( box, label_down );
	Widget_Container_Add( box, label_jump );
	Widget_Container_Add( box, label_defense );
	Widget_Container_Add( box, label_a_atk );
	Widget_Container_Add( box, label_b_atk );
	Window_ClientArea_Add( window, box );
	Window_ClientArea_Add( window, label );
	Window_ClientArea_Add( window, btn_ok );
	Window_ClientArea_Add( window, btn_reset );
	
	Widget_SetAutoSize( btn_left, FALSE, 0 );
	Widget_SetAutoSize( btn_right, FALSE, 0 );
	Widget_SetAutoSize( btn_up, FALSE, 0 );
	Widget_SetAutoSize( btn_down, FALSE, 0 );
	Widget_SetAutoSize( btn_jump, FALSE, 0 );
	Widget_SetAutoSize( btn_a_atk, FALSE, 0 );
	Widget_SetAutoSize( btn_b_atk, FALSE, 0 );
	Widget_SetAutoSize( btn_defense, FALSE, 0 );
	Widget_SetAutoSize( btn_ok, FALSE, 0 );

	Widget_Resize( btn_left, KEYBTN_SIZE );
	Widget_Resize( btn_right, KEYBTN_SIZE );
	Widget_Resize( btn_up, KEYBTN_SIZE );
	Widget_Resize( btn_down, KEYBTN_SIZE );
	Widget_Resize( btn_jump, KEYBTN_SIZE );
	Widget_Resize( btn_a_atk, KEYBTN_SIZE );
	Widget_Resize( btn_b_atk, KEYBTN_SIZE );
	Widget_Resize( btn_defense, KEYBTN_SIZE );
	Widget_Resize( btn_ok, BTN_SIZE );
	Widget_Resize( btn_reset, BTN_SIZE );
	
	Widget_Move( btn_left, Pos(0,50+22) );
	Widget_Move( btn_right, Pos(100,50+22) );
	Widget_Move( btn_up, Pos(50,0+22) );
	Widget_Move( btn_down, Pos(50,50+22) );
	Widget_Move( btn_jump, Pos(200,50+22) );
	Widget_Move( btn_a_atk, Pos(200,0+22) );
	Widget_Move( btn_b_atk, Pos(250,0+22) );
	Widget_Move( btn_defense, Pos(250,50+22) );
	
	Widget_Move( label_left, Pos(10,125) );
	Widget_Move( label_right, Pos(110,125) );
	Widget_Move( label_up, Pos(60,0) );
	Widget_Move( label_down, Pos(60,125) );
	Widget_Move( label_a_atk, Pos(210,0) );
	Widget_Move( label_b_atk, Pos(260,0) );
	Widget_Move( label_jump, Pos(210,125) );
	Widget_Move( label_defense, Pos(260,125) );

	UpdateKeyBtn();
	/* 设置各种文本 */
	Label_TextW( label_left, TEXT_LEFT );
	Label_TextW( label_right, TEXT_RIGHT );
	Label_TextW( label_up, TEXT_UP );
	Label_TextW( label_down, TEXT_DOWN );
	Label_TextW( label_jump, TEXT_JUMP );
	Label_TextW( label_defense, TEXT_DEFENSE );
	Label_TextW( label_a_atk, TEXT_A_ATK );
	Label_TextW( label_b_atk, TEXT_B_ATK );
	/* 设置窗口 */
	Widget_SetStyleID( window, WINDOW_STYLE_LINE );
	Widget_Resize( window, WINDOW_SIZE );
	Widget_SetPadding( Window_GetClientArea(window), Padding(10,10,10,10) );

	Label_TextW( label, TEXT_SET_KEYBOARD );
	Widget_SetBackgroundColor( label, RGB(255,255,255) );
	Widget_SetBackgroundTransparent( label, FALSE );

	Button_TextW( btn_ok, TEXT_OK );
	Button_TextW( btn_reset, TEXT_RESET );

	Widget_SetSize( box, "100%", "165px" );
	Widget_SetBorder( box, Border(1,BORDER_STYLE_SOLID,RGB(200,200,200)) );
	Widget_SetPadding( box, Padding(10,10,10,10) );

	Widget_SetAlign( box, ALIGN_TOP_CENTER, Pos(0,12) );
	Widget_SetAlign( label, ALIGN_TOP_CENTER, Pos(0,0) );
	Widget_SetAlign( btn_ok, ALIGN_BOTTOM_CENTER, Pos(-50,-5) );
	Widget_SetAlign( btn_reset, ALIGN_BOTTOM_CENTER, Pos(50,-5) );
	/* 为键位按钮连接事件 */
	Widget_ConnectEvent( btn_ok, EVENT_CLICKED, btn_ok_on_clicked );
	Widget_ConnectEvent( btn_reset, EVENT_CLICKED, btn_reset_on_clicked );
	Widget_ConnectEvent( btn_left, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_right, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_up, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_down, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_b_atk, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_a_atk, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_jump, EVENT_CLICKED, btn_key_on_clicked );
	Widget_ConnectEvent( btn_defense, EVENT_CLICKED, btn_key_on_clicked );
	
	Widget_Show( btn_left );
	Widget_Show( btn_right );
	Widget_Show( btn_up );
	Widget_Show( btn_down );
	Widget_Show( btn_jump );
	Widget_Show( btn_a_atk );
	Widget_Show( btn_b_atk );
	Widget_Show( btn_defense );
	Widget_Show( label_left );
	Widget_Show( label_right );
	Widget_Show( label_up );
	Widget_Show( label_down );
	Widget_Show( label_jump );
	Widget_Show( label_a_atk );
	Widget_Show( label_b_atk );
	Widget_Show( label_defense );
	Widget_Show( btn_ok );
	Widget_Show( btn_reset );
	Widget_Show( box );
	Widget_Show(label );
}