返回顶部

收藏

使用 LCUI 实现滑动解锁程序

更多

使用 LCUI 实现的一个锁屏的程序,拖动滑块至解锁区域,即可进行解锁。 下面的截图仅供参考。

slideunlock

// 一个屏幕滑动解锁的程序
#include <LCUI_Build.h>
#include LC_LCUI_H
#include LC_WIDGET_H 
#include LC_WINDOW_H
#include LC_LABEL_H
#include LC_MISC_H
#include LC_GRAPHICS_H
#include LC_PICBOX_H
#include LC_THREAD_H
#include <unistd.h>
#include <pthread.h>
#include <time.h>

void move_pic_btn(LCUI_Widget *widget, LCUI_DragEvent *event)
/* 功能:移动滑块 */
{
    LCUI_Pos pos, parent;

    parent = Get_Widget_Global_Pos(widget->parent);
    pos = Pos_Sub(event->new_pos, parent);
    Move_Widget(widget, pos);
    if(event->end_click)
    {/* 如果拖动已经结束 */
        LCUI_Size size;
        LCUI_Rect des, rect;
        usleep(10000);
        rect = Get_Widget_Rect(widget);
        size = Get_Widget_Size(widget->parent);
        des = Rect(size.w-10, 0, 30, 30);/* 目标区域 */
        if(Rect_Is_Overlay(rect, des)) /* 如果部件区域与目标区域重叠,则退出程序 */
            Main_Loop_Quit(); 
        else/* 否则,让部件回到起始位置,这个使用的是匀速移动 */
            Move_Widget_To_Pos(widget, Pos(0,0), 500);
    }
}

void *update_time(void *arg)
/* 功能:动态改变label部件的文本内容 */
{
    time_t rawtime;
    struct tm * timeinfo;
    char filename[100];
    LCUI_Widget *wday_label, *date_label;
    int l1=0,l2=0,r1=0,r2=0,old_l1=0, old_l2=0, old_r1=0,old_r2=0;
    char day[][20] = {"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
    LCUI_Widget *pic_bg, *time_box, *pic_btn_line, *pic_btn,
                    *win, *pic_l1, *pic_l2,
                     *pic_c, *pic_r1, *pic_r2;

    win = (LCUI_Widget *)arg; /* 转换类型 */
    /* 创建部件 */
    time_box        = Create_Widget(NULL);
    pic_bg          = Create_Widget("picture_box");
    pic_l1          = Create_Widget("picture_box");
    pic_l2          = Create_Widget("picture_box");
    pic_c           = Create_Widget("picture_box");
    pic_btn         = Create_Widget("picture_box");
    pic_btn_line    = Create_Widget("picture_box");
    pic_btn         = Create_Widget("picture_box");
    pic_r1          = Create_Widget("picture_box");
    pic_r2          = Create_Widget("picture_box");
    date_label      = Create_Widget("label");
    wday_label      = Create_Widget("label");

    /* 生成文件路径 */
    strcpy(filename, "drawable/time_0.png");
    /* 载入图片 */
    Set_PictureBox_Image_From_File(pic_bg, "drawable/bg.png"); 
    Set_PictureBox_Image_From_File(pic_btn_line, "drawable/btn_bg.png"); 
    Set_PictureBox_Image_From_File(pic_btn, "drawable/btn.png"); 
    Set_PictureBox_Image_From_File(pic_l1, filename); 
    Set_PictureBox_Image_From_File(pic_l2, filename); 
    Set_PictureBox_Image_From_File(pic_c,  "drawable/time_dot.png"); 
    Set_PictureBox_Image_From_File(pic_r1, filename); 
    Set_PictureBox_Image_From_File(pic_r2, filename); 

    Set_PictureBox_Size_Mode(pic_btn_line, SIZE_MODE_CENTER);

    /* 调整尺寸 */
    Resize_Widget(time_box,     Size(162, 38));
    Resize_Widget(pic_bg,       Size(300, 90));
    Resize_Widget(pic_btn_line, Size(245, 66));
    Resize_Widget(pic_btn,      Size(46, 66));
    Resize_Widget(pic_l1,       Size(33, 36));
    Resize_Widget(pic_l2,       Size(33, 36));
    Resize_Widget(pic_c,        Size(30, 38));
    Resize_Widget(pic_r1,       Size(33, 36));
    Resize_Widget(pic_r2,       Size(33, 36));
    /* 调整布局 */
    Set_Widget_Align(pic_l1, ALIGN_MIDDLE_CENTER, Pos(-66,0));
    Set_Widget_Align(pic_l2, ALIGN_MIDDLE_CENTER, Pos(-33,0));
    Set_Widget_Align(pic_c, ALIGN_MIDDLE_CENTER, Pos(0,0));
    Set_Widget_Align(pic_r1, ALIGN_MIDDLE_CENTER, Pos(33,0));
    Set_Widget_Align(pic_r2, ALIGN_MIDDLE_CENTER, Pos(66,0));
    Set_Widget_Align(time_box, ALIGN_MIDDLE_CENTER, Pos(0,-50));
    Set_Widget_Align(pic_bg, ALIGN_MIDDLE_CENTER, Pos(0,5));
    Set_Widget_Align(date_label, ALIGN_MIDDLE_CENTER, Pos(0,35-50));
    Set_Widget_Align(wday_label, ALIGN_TOP_CENTER, Pos(0,5));
    Set_Widget_Align(pic_btn_line, ALIGN_BOTTOM_CENTER, Pos(0,-10));
    /* 放入容器 */
    Widget_Container_Add(time_box, pic_l1);
    Widget_Container_Add(time_box, pic_l2);
    Widget_Container_Add(time_box, pic_c);
    Widget_Container_Add(time_box, pic_r1);
    Widget_Container_Add(time_box, pic_r2);
    Widget_Container_Add(pic_btn_line, pic_btn);

    Window_Client_Area_Add(win, pic_bg);
    Window_Client_Area_Add(win, time_box);
    Window_Client_Area_Add(win, date_label);
    Window_Client_Area_Add(win, wday_label);
    Window_Client_Area_Add(win, pic_btn_line);
    /* 限制移动范围 */
    Limit_Widget_Pos(pic_btn, Pos(0,0), Pos(195,0));
    Widget_Drag_Event_Connect(pic_btn, move_pic_btn);

    Show_Widget(pic_bg);
    Show_Widget(pic_l1);
    Show_Widget(pic_l2);
    Show_Widget(pic_c);
    Show_Widget(pic_r1);
    Show_Widget(pic_r2);
    Show_Widget(time_box);  
    Show_Widget(wday_label);
    Show_Widget(date_label);
    Show_Widget(pic_btn);
    Show_Widget(pic_btn_line);

    while(1)
    {
        time ( &rawtime );
        timeinfo = localtime ( &rawtime ); /* 获取系统当前时间 */
        /* 更改文本内容 */
        Set_Label_Text(
            date_label, "<color=40,165,45>%4d年%02d月%02d日</color>",
            timeinfo->tm_year+1900, timeinfo->tm_mon+1, timeinfo->tm_mday
        );
        Set_Label_Text(
            wday_label, 
            "<color=40,165,45>%s</color>", 
            day[(int) (timeinfo->tm_wday)]
        );
        l1 = timeinfo->tm_hour/10;
        l2 = timeinfo->tm_hour%10;
        r1 = timeinfo->tm_min/10;
        r2 = timeinfo->tm_min%10;
        if(l1 != old_l1) 
        {
            sprintf(filename, "drawable/time_%d.png", l1);
            Set_PictureBox_Image_From_File(pic_l1, filename); 
            old_l1 = l1;
        }
        if(l2 != old_l2) 
        {
            sprintf(filename, "drawable/time_%d.png", l2);
            Set_PictureBox_Image_From_File(pic_l2, filename); 
            old_l2 = l2;
        }
        if(l1 != old_r1) 
        {
            sprintf(filename, "drawable/time_%d.png", r1);
            Set_PictureBox_Image_From_File(pic_r1, filename); 
            old_r1 = r1;
        }
        if(r2 != old_r2) 
        {
            sprintf(filename, "drawable/time_%d.png", r2);
            Set_PictureBox_Image_From_File(pic_r2, filename); 
            old_r2 = r2;
        }
        sleep(1);/* 暂停1秒 */
    } 
    LCUI_Thread_Exit(NULL);
}

int main(int argc, char*argv[]) 
{
    pthread_t t;
    LCUI_Widget *window; 
    /* 设置默认字体文件所在位置 */
    Set_Default_Font("../../fonts/msyh.ttf");
    LCUI_Init(argc, argv);

    window = Create_Widget("window"); 
    LCUI_Thread_Create(&t, NULL, update_time, (void*)window);
    Set_Window_Title_Text(window, "LC 锁屏程序");
    Set_Widget_Backcolor(window, RGB(255,255,255));
    Resize_Widget(window, Size(320, 240)); 
    Set_Widget_Border_Style(window, BORDER_STYLE_LINE_BORDER);
    Show_Widget(window); 
    return LCUI_Main(); 
}
//该片段来自于http://outofmemory.cn

标签:c++,基础

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2012-11-05 21:59:42java获得随机数代码 by 怪兽狂殴奥特曼
  2. 2014-05-09 15:38:47内核定时器 by 灵剑子
  3. 2014-05-10 17:17:07万年历查询系统C++ by 灵剑子
  4. 2014-05-11 19:21:15list 函数 by 跳跳虎
  5. 2014-05-14 15:02:52C++解决易语言难题 by 跳跳虎
  6. 2014-05-16 19:41:15一个找出指定分隔符左侧的子字符串的函数 by 小项
  7. 2014-05-17 18:01:40ACM poj 2447 RSA by 跳跳虎
  8. 2014-05-18 15:04:45linux下串口编程 by walker30
  9. 2014-05-20 11:19:52简单程序包括各种邻接矩阵操作 by niutao.linux
  10. 2014-05-20 15:26:23Reading UTF-8 with C++ streams by 千万不要郁闷
  11. 2014-05-21 18:41:15指针运算 by 童学芬
相关聚客文章
  1. 博主 发表 2011-11-03 16:00:00 C++ 语言基础
  2. thinkpc 发表 2016-03-04 13:55:30 c++&nbsp;11 map基础value排序
  3. pansunyou 发表 2014-11-30 02:51:00 C++通用跨数据库访问方案之一: 基础组件cdbc
  4. linux@linux.cn (linu 发表 2016-11-04 02:37:00 C++ 程序员 Protocol Buffers 基础指南
  5. tanglei 发表 2014-05-28 15:08:01 struct与class区别联系
  6. 博主 发表 2016-06-28 05:17:59 Bazel C++ 基础[翻译]
  7. Herb Sutter 发表 2013-03-14 15:50:07 Words of wisdom: Bjarne Stroustrup
  8. SumitMSFT 发表 2013-03-22 22:12:00 Visual C++ Developer Survey
  9. bystander 发表 2013-04-11 10:50:25 模板栈以及中缀表达式求值(C++实现)
  10. mortoray 发表 2013-05-09 10:22:13 How to catch a “return” statement
  11. Qiang 发表 2011-09-08 14:06:00 Lexing Python Indentation using Spirit.Lex
  12. 博主 发表 2013-06-15 20:33:32 CloudStack云基础架构的一些概念