static void Window_TitleBar_Init(LCUI_Widget *titlebar) /* 功能:初始化窗口标题栏 */ { LCUI_Graph img; LCUI_TitleBar *t; Graph_Init(&img); t = Widget_Create_PrivData(titlebar, sizeof(LCUI_TitleBar)); t->icon_box = Create_Widget("picture_box"); t->label = Create_Widget("label"); Widget_Container_Add(titlebar, t->icon_box); Widget_Container_Add(titlebar, t->label); Resize_Widget(t->icon_box, Size(18,18)); Set_PictureBox_Size_Mode(t->icon_box, SIZE_MODE_CENTER); Show_Widget(t->icon_box); Show_Widget(t->label); Set_Widget_Align(t->icon_box, ALIGN_MIDDLE_LEFT, Pos(0,0)); Set_Widget_Align(t->label, ALIGN_MIDDLE_LEFT, Pos(2,-2)); Load_Graph_Default_TitleBar_BG(&img); Set_Widget_Background_Image(titlebar, &img, LAYOUT_STRETCH); }
int main(int argc, char*argv[]) { LCUI_Init(argc, argv); window = Create_Widget("window"); scrollbar = Create_Widget("scrollbar"); label = Create_Widget("label"); /* 设定窗口标题的文本 */ Set_Window_Title_Text(window, "测试滚动条"); /* 改变窗口的尺寸 */ window->resize(window, Size(320, 240)); Resize_Widget( scrollbar, Size(10, 100) ); ScrollBar_Set_MaxSize( scrollbar, 400 ); /* 设置部件布局 */ Set_Widget_Align( label, ALIGN_MIDDLE_CENTER, Pos(-20,0) ); Set_Widget_Align( scrollbar, ALIGN_MIDDLE_CENTER, Pos(0,0) ); Label_Text( label, "0" ); /* 将窗口客户区作为部件的容器添加进去 */ Window_Client_Area_Add(window, label); Window_Client_Area_Add(window, scrollbar); /* 将回调函数与滚动条部件连接 */ ScrollBar_Connect( scrollbar, callback_func, NULL ); /* 显示部件 */ scrollbar->show(scrollbar); window->show(window); label->show(label); return LCUI_Main(); /* 进入主循环 */ }
int main(int argc,char*argv[]) { /* 声明几个部件 */ LCUI_Widget *window, *label, *logo, *img; int width, height; /* 自定义默认字体文件位置 */ //Set_Default_Font("msyh.ttf"); /* 初始化LCUI */ LCUI_Init(argc, argv); /* 创建一个LCUI程序窗口 */ width = 320;//Get_Screen_Width(); /* 窗口的宽度 */ height = 240;//Get_Screen_Height();; /* 窗口的高度 */ /* 创建部件 */ window = Create_Widget("window"); label = Create_Widget("label"); logo = Create_Widget("picture_box"); img = Create_Widget("picture_box"); //Set_Widget_Border_Style(window, BORDER_STYLE_NONE); Resize_Widget(img, Size(180, 180)); Resize_Widget(logo, Size(128,128)); Resize_Widget(window, Size(width, height)); Set_Window_Title_Text(window, "LCUI"); Set_Widget_Backcolor(window, RGB(94,200,255)); Set_PictureBox_Size_Mode(logo, SIZE_MODE_CENTER); Set_PictureBox_Image_From_File(logo, "logo_128x128.png"); Set_Label_Text(label, "LCUI 正在载入..."); Set_Label_Font(label, 15, NULL); Set_Widget_Align(logo, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Set_Widget_Align(label, ALIGN_MIDDLE_CENTER, Pos(0, +70)); /* 将这三个部件放入窗口客户区中 */ Window_Client_Area_Add(window, label); Window_Client_Area_Add(window, img); Window_Client_Area_Add(window, logo); pthread_t t; LCUI_Thread_Create(&t, NULL, change_graph, (void*)img); /* 显示部件以及窗口 */ Show_Widget(label); Show_Widget(logo); Show_Widget(window); LCUI_Main(); /* 进入主循环 */ return 0; }
int main(int argc,char*argv[]) /* 主函数,程序的入口 */ { LCUI_Widget *window, *label, *pic_box, *fore_box; /* 使用指向widget部件的指针 */ int width, height; /* 自定义默认字体文件位置 */ //Set_Default_Font("msyh.ttf"); /* 初始化LCUI */ LCUI_Init(argc, argv); /* 创建一个LCUI程序窗口 */ width = 320; /* 窗口的宽度 */ height = 240; /* 窗口的高度 */ /* 创建部件 */ window = Create_Widget("window"); label = Create_Widget("label"); pic_box = Create_Widget("picture_box"); fore_box = Create_Widget("picture_box"); Resize_Widget(fore_box, Size(190, 190)); Resize_Widget(pic_box, Size(135,135)); Resize_Widget(window, Size(width, height)); Set_Window_Title_Text(window, "头像"); LCUI_Graph pic; Graph_Init(&pic); Set_PictureBox_Size_Mode(pic_box, SIZE_MODE_STRETCH); Set_PictureBox_Image_From_File(pic_box, "image.jpg"); Set_PictureBox_Image_From_File(fore_box, "border.png"); Set_Label_Text(label, "蛋疼的头像"); Set_Label_Font(label, 16, NULL); Set_Widget_Align(pic_box, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Set_Widget_Align(fore_box, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Set_Widget_Align(label, ALIGN_MIDDLE_CENTER, Pos(0, +75)); Window_Client_Area_Add(window, label); Window_Client_Area_Add(window, pic_box); Window_Client_Area_Add(window, fore_box); Show_Widget(label); Show_Widget(pic_box); Show_Widget(fore_box); Show_Widget(window); return LCUI_Main(); }
int main(int argc, char *argv[]) { int i; LCUI_Init( argc, argv ); LCUI_RGB color[6]={{255,255,255},{127,127,127}, {255,0,0}, {255,165,0}, {30,144,255}, {65,200,65} }; LCUI_Widget *window, *widget[6], *label[6]; window = Create_Widget( "window" ); for(i=0; i<6; ++i) { widget[i] = Create_Widget( NULL ); label[i] = Create_Widget( "label" ); Label_Text( label[i], "Area %d" , i); Widget_Container_Add( widget[i], label[i] ); Window_Client_Area_Add( window, widget[i] ); Resize_Widget( widget[i], Size(80,80) ); Set_Widget_PosType( widget[i], POS_TYPE_STATIC ); Set_Widget_Align( label[i], ALIGN_MIDDLE_CENTER, Pos(0,0) ); Set_Widget_Border( widget[i], RGB(0,0,0), Border(1,1,1,1) ); Set_Widget_BG_Mode( widget[i], BG_MODE_FILL_BACKCOLOR ); Set_Widget_Backcolor( widget[i], color[i] ); Show_Widget( label[i] ); Show_Widget( widget[i] ); } Set_Window_Title_Text( window, "测试部件布局-2" ); Resize_Widget( window, Size(320, 240) ); Show_Widget( window ); return LCUI_Main(); }
static void Window_Init(LCUI_Widget *win_p) /* * 功能:初始化窗口 * 说明:类似于构造函数 **/ { LCUI_Widget *titlebar; LCUI_Widget *client_area; LCUI_Widget *btn_close; LCUI_Window *win; win = (LCUI_Window*)Widget_Create_PrivData(win_p, sizeof(LCUI_Window)); win->hide_style = NONE; win->show_style = NONE; win->count = 0; win->init_align = ALIGN_MIDDLE_CENTER; /* 创建一个标题栏部件 */ titlebar = Create_Widget("titlebar"); /* 再创建一个客户区部件 */ client_area = Create_Widget(NULL); btn_close = Create_Widget("button"); static LCUI_Graph btn_highlight, btn_normal, btn_down; Graph_Init(&btn_down); Graph_Init(&btn_highlight); Graph_Init(&btn_normal); /* 载入默认图形 */ Load_Graph_Default_TitleBar_CloseBox_Normal(&btn_normal); Load_Graph_Default_TitleBar_CloseBox_Down(&btn_down); Load_Graph_Default_TitleBar_CloseBox_HighLight(&btn_highlight); /* 显示在左上角 */ Set_Widget_Align(btn_close, ALIGN_TOP_RIGHT, Pos(0, -2)); /* 将尺寸改成和图片一样 */ Resize_Widget(btn_close, Size(btn_normal.width, btn_normal.height)); Custom_Button_Style(btn_close, &btn_normal, &btn_highlight, &btn_down, NULL, NULL); /* 关联按钮的点击事件,当按钮被点击后,调用Quit_Window函数 */ Widget_Clicked_Event_Connect(btn_close, Quit_Parent_Window, NULL); Graph_Free(&btn_highlight); Graph_Free(&btn_down); Graph_Free(&btn_normal); win->client_area = client_area; win->titlebar = titlebar; win->btn_close = btn_close; /* 没有背景图就填充背景色 */ Set_Widget_BG_Mode(win_p, BG_MODE_FILL_BACKCOLOR); Set_Widget_Border_Style(win_p, BORDER_STYLE_STANDARD); /* 放入至容器 */ Widget_Container_Add(titlebar, btn_close); Widget_Container_Add(win_p, titlebar); Widget_Container_Add(win_p, client_area); Resize_Widget(win_p, Size(50, 50)); Show_Widget(btn_close); Widget_Drag_Event_Connect(titlebar, Move_Window); }
void Set_Window_Title_Icon(LCUI_Widget *window, LCUI_Graph *icon) /* 功能:自定义指定窗口的标题栏图标 */ { LCUI_Graph *image; LCUI_Widget *title_widget; LCUI_TitleBar *title_data; title_widget = Get_Window_TitleBar(window); title_data = (LCUI_TitleBar *)Get_Widget_PrivData(title_widget); image = Get_PictureBox_Graph(title_data->icon_box); Graph_Free(image);/* 释放PictureBox部件内的图像占用的资源 */ if(icon == NULL) { return; } /* 设置新图标 */ Set_PictureBox_Image_From_Graph(title_data->icon_box, icon); Set_Widget_Align(title_data->icon_box, ALIGN_MIDDLE_LEFT, Pos(3,0)); Set_Widget_Align(title_data->label, ALIGN_MIDDLE_LEFT, Pos(23,0)); }
void *change_graph(void *arg) /* 功能:改变显示的图形 */ { LCUI_Widget *widget = (LCUI_Widget *)arg; int i; LCUI_Graph frame, temp; Graph_Init(&frame);/* 初始化 */ Load_Image("ring.png", &frame);/* 载入之 */ /* 居中显示图形 */ Set_Widget_Align(widget, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Set_PictureBox_Size_Mode(widget, SIZE_MODE_CENTER); Show_Widget(widget); while(1) { Set_PictureBox_Image_From_Graph(widget, &frame); for(i=10; i<=360; i+=10) { Rotate_Graph(&frame, i, &temp); Set_PictureBox_Image_From_Graph(widget, &temp); usleep(20000); } } LCUI_Thread_Exit(NULL); }
void Window_Widget_Auto_Size(LCUI_Widget *win_p) /* 功能:在窗口尺寸改变时自动改变标题栏和客户区的尺寸 */ { int x, y, width, height; LCUI_Widget *titlebar; LCUI_Widget *client_area; titlebar = Get_Window_TitleBar(win_p); client_area = Get_Window_Client_Area(win_p); /* 按不同的风格来处理 */ switch(Get_Widget_Border_Style(win_p)) { case BORDER_STYLE_NONE: /* 没有边框 */ /* 先计算坐标和尺寸 */ x = win_p->border.left; y = win_p->border.top; width = win_p->size.w - x - win_p->border.right; height = win_p->size.h - y - win_p->border.bottom; Move_Widget( client_area, Pos(x, y) );/* 调整位置 */ Resize_Widget( client_area, Size(width, height) );/* 调整大小 */ Hide_Widget( titlebar );/* 隐藏标题栏 */ Show_Widget( client_area );/* 客户区需要显示 */ break; case BORDER_STYLE_LINE_BORDER: /* 线条边框 */ Move_Widget( client_area, Pos(0, 0) ); Resize_Widget( client_area, Size(win_p->size.w, win_p->size.h) ); Hide_Widget( titlebar); Show_Widget( client_area); break; case BORDER_STYLE_STANDARD: /* 标准边框 */ /* * 说明:由于用户区的尺寸和位置的调整,需要确定标题栏的尺寸,因此, * 调用Exec_Resize_Widget()函数立刻调整标题栏尺寸,如果是调用 * Resize_Widget()函数,那么,确定的尺寸会有误,因为标题栏的尺 * 寸还是以前的尺寸。 * */ Set_Widget_Border(win_p, RGB(50,50,50), Border(1,1,1,1)); /* 先计算坐标和尺寸 */ x = win_p->border.left; y = win_p->border.top; width = win_p->size.w - x - win_p->border.right; height = win_p->size.h - y - win_p->border.bottom; Move_Widget(titlebar, Pos(x, y) ); Resize_Widget(titlebar, Size(width, 25)); Set_Widget_Align(client_area, ALIGN_BOTTOM_CENTER, Pos(0, y)); Resize_Widget(client_area, Size(width, height - 23)); /* 标题栏和客户区都需要显示 */ Show_Widget(titlebar); Show_Widget(client_area); break; default: // break; } }
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 ); }