/** 构造函数 */ static void $(Init)( LCUI_Widget widget ) { widget->style.z_index = 0; widget->style.x.type = SVT_NONE; widget->style.y.type = SVT_NONE; widget->style.width.type = SVT_AUTO; widget->style.height.type = SVT_AUTO; widget->style.box_sizing = CONTENT_BOX; widget->style.opacity = 1.0; widget->style.margin.top.px = 0; widget->style.margin.right.px = 0; widget->style.margin.bottom.px = 0; widget->style.margin.left.px = 0; widget->style.margin.top.type = SVT_PX; widget->style.margin.right.type = SVT_PX; widget->style.margin.bottom.type = SVT_PX; widget->style.margin.left.type = SVT_PX; widget->style.padding.top.px = 0; widget->style.padding.right.px = 0; widget->style.padding.bottom.px = 0; widget->style.padding.left.px = 0; widget->style.padding.top.type = SVT_PX; widget->style.padding.right.type = SVT_PX; widget->style.padding.bottom.type = SVT_PX; widget->style.padding.left.type = SVT_PX; widget->event = LCUIEventBox_Create(); memset( &widget->base, 0, sizeof(widget->base)); widget->parent = NULL; widget->title = NULL; widget->event = LCUIEventBox_Create(); Widget_InitTaskBox( widget ); Background_Init( &widget->style.background ); BoxShadow_Init( &widget->style.shadow ); Border_Init( &widget->style.border ); LinkedList_Init( &widget->children, sizeof(struct LCUI_WidgetFull) ); LinkedList_Init( &widget->children_show, 0 ); LinkedList_SetDestroyFunc( &widget->children, $(OnDestroy) ); LinkedList_SetDataNeedFree( &widget->children, TRUE ); LinkedList_SetDataNeedFree( &widget->children_show, FALSE ); DirtyRectList_Init( &widget->dirty_rects ); Graph_Init( &widget->graph ); }
/** 初始化window部件相关数据 */ static void Window_OnInit( LCUI_Widget *window ) { LCUI_Window *wnd; LCUI_Graph btn_bg; LCUI_TextStyle style; LCUI_Border border; wnd = Widget_NewPrivateData( window, LCUI_Window ); wnd->theme_color = COLOR_EMERALD; wnd->theme_color.a = 128; wnd->titlebar = Widget_New(NULL); wnd->client_area = Widget_New(NULL); wnd->btn_close = Widget_New(WIDGET_CLOSE_BUTTON); wnd->icon = Widget_New(NULL); wnd->text = Label_New(); wnd->titlebar->focus = FALSE; wnd->icon->focus = FALSE; wnd->text->focus = FALSE; Widget_SetFocus( wnd->client_area ); Widget_SetClickable( wnd->icon, FALSE ); Widget_SetClickable( wnd->text, FALSE ); Widget_SetClickable( wnd->titlebar, FALSE ); Widget_SetClickable( wnd->client_area, FALSE ); Graph_Init( &btn_bg ); /* 载入按钮背景 */ LoadCloseButtonIMG( &btn_bg ); /* close按钮显示在左上角 */ Widget_SetAlign( wnd->btn_close, ALIGN_TOP_RIGHT, Pos(0,0) ); Widget_Resize( wnd->btn_close, Size(30, 30) ); Widget_SetBackgroundImage( wnd->btn_close, &btn_bg ); Widget_SetBackgroundLayout( wnd->btn_close, LAYOUT_CENTER ); Widget_SetBackgroundTransparent( wnd->icon, TRUE ); Widget_SetBackgroundTransparent( wnd->titlebar, TRUE ); Widget_SetBackgroundTransparent( wnd->client_area, FALSE ); Widget_SetBackgroundTransparent( window, FALSE ); Widget_SetBackgroundColor( window, RGB(255,255,255) ); Widget_SetBackgroundLayout( wnd->icon, LAYOUT_ZOOM ); Widget_SetDock( wnd->titlebar, DOCK_TYPE_TOP ); Widget_SetDock( wnd->client_area, DOCK_TYPE_BOTTOM ); Widget_SetPadding( window, Padding(TOP_PANDDING,1,1,1) ); Widget_SetPadding( wnd->client_area, Padding(1,1,1,1) ); Widget_SetSize( wnd->titlebar, "100%", "35px" ); Border_Init( &border ); border.top_width = 0; border.bottom_width = 1; border.left_width = 1; border.right_width = 1; border.bottom_color = RGB(200,200,200); border.left_color = RGB(255,255,255); border.right_color = RGB(255,255,255); Widget_SetBorder( wnd->titlebar, border ); TextStyle_Init( &style ); TextStyle_FontSize( &style, 18 ); Label_SetTextStyle( wnd->text, style ); /* 放入至容器 */ Widget_Container_Add( wnd->titlebar, wnd->icon ); Widget_Container_Add( wnd->titlebar, wnd->text ); Widget_Container_Add( wnd->titlebar, wnd->btn_close ); Widget_Container_Add( window, wnd->titlebar ); Widget_Container_Add( window, wnd->client_area ); Widget_Resize( window, Size(100, 50) ); Widget_Resize( wnd->icon, Size(24,24) ); Widget_SetAlign( window, ALIGN_MIDDLE_CENTER, Pos(0,0) ); Widget_SetAlign( wnd->icon, ALIGN_MIDDLE_LEFT, Pos(6,0) ); Widget_SetAlign( wnd->text, ALIGN_MIDDLE_LEFT, Pos(6,0) ); /* 关联拖动事件,让鼠标能够拖动标题栏并使窗口移动 */ Widget_ConnectEvent( window, EVENT_DRAG, Window_ExecMove ); /* * 由于需要在窗口获得/失去焦点时进行相关处理,因此需要将回调函数 与部件 * 的FOCUS_IN和FOCUS_OUT事件 进行关联 * */ Widget_ConnectEvent( window, EVENT_FOCUSOUT, Window_OnFocusOut ); Widget_ConnectEvent( window, EVENT_FOCUSIN, Window_OnFocusIn ); Widget_Show( wnd->btn_close ); Widget_Show( wnd->icon ); Widget_Show( wnd->text ); Widget_Show( wnd->titlebar ); Widget_Show( wnd->client_area ); }