/* 初始化按钮部件的数据 */ static void Button_Init( LCUI_Widget *widget ) { int valid_state; LCUI_Button *button; button = WidgetPrivData_New(widget, sizeof(LCUI_Button)); /* 初始化图像数据 */ Graph_Init(&button->btn_disable); Graph_Init(&button->btn_normal); Graph_Init(&button->btn_focus); Graph_Init(&button->btn_down); Graph_Init(&button->btn_over); valid_state = (WIDGET_STATE_NORMAL | WIDGET_STATE_ACTIVE); valid_state |= (WIDGET_STATE_DISABLE | WIDGET_STATE_OVERLAY); Widget_SetValidState( widget, valid_state ); button->label = Widget_New("label");/* 创建label部件 */ /* 将按钮部件作为label部件的容器 */ Widget_Container_Add(widget, button->label); /* label部件居中显示 */ Widget_SetAlign(button->label, ALIGN_MIDDLE_CENTER, Pos(0,0)); Widget_Show(button->label); /* 显示label部件 */ /* 启用自动尺寸调整,以适应内容 */ Widget_SetAutoSize( widget, TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK); Widget_SetStyleID( widget, BUTTON_STYLE_DEFAULT ); /* 关联EVENT_FOCUSOUT事件,以在按钮失去焦点时重绘按钮 */ Widget_Event_Connect( widget, EVENT_FOCUSOUT, Button_ProcFocusOut ); }
/* 初始化复选框部件的数据 */ static void CheckBox_Init(LCUI_Widget *widget) { int valid_state; LCUI_Widget *container[2]; LCUI_CheckBox *check_box; check_box = Widget_NewPrivData(widget, sizeof(LCUI_CheckBox)); check_box->on = FALSE; /* 初始化图像数据 */ Graph_Init(&check_box->img_off_disable); Graph_Init(&check_box->img_off_normal); Graph_Init(&check_box->img_off_focus); Graph_Init(&check_box->img_off_down); Graph_Init(&check_box->img_off_over); Graph_Init(&check_box->img_on_disable); Graph_Init(&check_box->img_on_normal); Graph_Init(&check_box->img_on_focus); Graph_Init(&check_box->img_on_down); Graph_Init(&check_box->img_on_over); /* 创建所需的部件 */ check_box->label = Widget_New("label"); check_box->imgbox = Widget_New("picture_box"); /* 创建两个容器,用于调整上面两个部件的位置 */ container[0] = Widget_New(NULL); container[1] = Widget_New(NULL); /* 启用这些部件的自动尺寸调整的功能 */ Widget_SetAutoSize( widget, TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_SetAutoSize( container[0], TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_SetAutoSize( container[1], TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_Container_Add(container[0], check_box->imgbox); Widget_Container_Add(container[1], check_box->label); Widget_Container_Add(widget, container[0]); Widget_Container_Add(widget, container[1]); /* 调整尺寸 */ Widget_Resize(check_box->imgbox, Size(15, 15)); //Widget_Resize(container[0], Size(18,18)); //Widget_Resize(widget, Size(18,18)); /* 调整布局 */ Widget_SetAlign(container[0], ALIGN_MIDDLE_LEFT, Pos(0,0)); Widget_SetAlign(container[1], ALIGN_MIDDLE_LEFT, Pos(17,0)); Widget_SetAlign(check_box->imgbox, ALIGN_MIDDLE_CENTER, Pos(0,0)); Widget_SetAlign(check_box->label, ALIGN_MIDDLE_CENTER, Pos(0,0)); /* 设置图像框的尺寸模式为拉伸 */ PictureBox_SetSizeMode(check_box->imgbox, SIZE_MODE_STRETCH); /* 显示之 */ Widget_Show(check_box->label); Widget_Show(check_box->imgbox); Widget_Show(container[0]); Widget_Show(container[1]); /* 关联鼠标左键点击事件 */ Widget_Event_Connect( widget, EVENT_CLICKED, CheckBox_SwitchState ); /* 响应状态改变 */ valid_state = (WIDGET_STATE_NORMAL | WIDGET_STATE_ACTIVE); valid_state |= (WIDGET_STATE_DISABLE | WIDGET_STATE_OVERLAY); Widget_SetValidState( widget, valid_state ); }
/* 初始化单选框部件的数据 */ static void RadioButton_Init( LCUI_Widget widget ) { int valid_state; LCUI_Widget container[2]; LCUI_RadioButton *radio_button; radio_button = Widget_NewPrivData(widget, sizeof(LCUI_RadioButton)); radio_button->on = FALSE; /* 初始化图片数据 */ Graph_Init(&radio_button->img_off_disable); Graph_Init(&radio_button->img_off_normal); Graph_Init(&radio_button->img_off_focus); Graph_Init(&radio_button->img_off_down); Graph_Init(&radio_button->img_off_over); Graph_Init(&radio_button->img_on_disable); Graph_Init(&radio_button->img_on_normal); Graph_Init(&radio_button->img_on_focus); Graph_Init(&radio_button->img_on_down); Graph_Init(&radio_button->img_on_over); radio_button->mutex = NULL; radio_button->label = Widget_New("label");/* 创建label部件 */ radio_button->imgbox = Widget_New("picture_box"); /* 创建图像框部件 */ /* 创建两个容器,用于调整上面两个部件的位置 */ container[0] = Widget_New(NULL); container[1] = Widget_New(NULL); /* 启用这些部件的自动尺寸调整的功能 */ Widget_SetAutoSize( widget, TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_SetAutoSize( container[0], TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_SetAutoSize( container[1], TRUE, AUTOSIZE_MODE_GROW_AND_SHRINK ); Widget_Container_Add(container[0], radio_button->imgbox); Widget_Container_Add(container[1], radio_button->label); Widget_Container_Add(widget, container[0]); Widget_Container_Add(widget, container[1]); /* 调整尺寸 */ Widget_Resize(radio_button->imgbox, Size(15, 15)); /* 调整布局 */ Widget_SetAlign(container[0], ALIGN_MIDDLE_LEFT, Pos(0,0)); Widget_SetAlign(container[1], ALIGN_MIDDLE_LEFT, Pos(17,0)); Widget_SetAlign(radio_button->imgbox, ALIGN_MIDDLE_CENTER, Pos(0,0)); Widget_SetAlign(radio_button->label, ALIGN_MIDDLE_CENTER, Pos(0,0)); PictureBox_SetSizeMode(radio_button->imgbox, SIZE_MODE_STRETCH); /* 显示之 */ Widget_Show(radio_button->label); Widget_Show(radio_button->imgbox); Widget_Show(container[0]); Widget_Show(container[1]); Widget_ConnectEvent( widget, EVENT_CLICKED, RadioButton_Click ); valid_state = (WIDGET_STATE_NORMAL | WIDGET_STATE_ACTIVE); valid_state |= (WIDGET_STATE_DISABLE | WIDGET_STATE_OVERLAY); Widget_SetValidState( widget, valid_state); }