基于ARM开发板GEC6818的电子相册项目

项目技术简介

本项目主要是基于ARM开发板GEC6818,使用Linux平台进行代码的编写和交叉编译。
项目主要通过freambuffer帧缓存驱动来进行图片以及对应字库的显示。

项目功能

  • 实现滑动解锁界面
  • 实现对图片的检索和显示(包括正常显示和缩放)
  • 游戏的移植(五子棋小游戏)

项目实现

项目头文件

本项目通过调用Linux内核链表来实现对图片信息的储存。

#ifndef _E_ALBUM_H
    #define _E_ALBUM_H

/* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 头文件 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */

#include "list.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <linux/fb.h>
#include <unistd.h>
#include <dirent.h>
#include <pthread.h>
#include <time.h>
#include<math.h>

#define LCD_PATH     "/dev/fb0"
#define IO_PATH      "/dev/input/event0"
#define SLIDE_PATH   "./yelan.bmp"
#define DESKTOP_PATH "./desktop.bmp"
#define EXIT_PATH    "./sea.bmp"
#define LOAD_PATH    "./picture/color.bmp"
#define DZK_CHN_PATH "./kaiti.Dzk"
#define DZK_ASC_PATH "./ascii.Dzk"
#define DIR_PATH     "./photo/"
#define LENGTH       256*2
#define RATIO        4 //缩小倍数
#define NORMAL       1
#define SMALL        0


/* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 头文件 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */


/* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 结构体 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
typedef struct dev_inf // 设备初始化信息
{
    int lcd_fd;
    int touch_fd;
    int  * lcd_mmap;
    int lcd_w,lcd_h;

}DEV_INF, * P_DEV_INF;


typedef struct Chinese_character //字库结构体
{
    int fd;
    int size;
    char * mmap_p;
}CH,* P_CH;


typedef struct data_list // 链表数据
{
	int num;
    char * name;
    char * path;
	struct list_head pointer;

} DL, *DL_LINK;


struct get_coordinates // 获取坐标信息
{
    int where_x;
    int where_y;
    bool press;
}Coords;

/* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 结构体 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */



/* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 函数声明 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
P_DEV_INF Dev_inf_init();//设备信息初始化
DL_LINK Create_node();//初始化创建链表
P_CH Character_init(char * str);// 初始化字库
int Free_space(P_DEV_INF inf_d,DL_LINK head);//释放空间

int Traverse_list(DL_LINK head,P_DEV_INF inf_d); //遍历链表,显示缩略图
DL_LINK Find_node(DL_LINK head,int num);//检索节点

void * Get_instant_coordinates(P_DEV_INF inf_d); //获取坐标
int Search_save_bmp(const char * dir_name,DL_LINK head);//检索图片并保存到链表中
int Clean_lcd(P_DEV_INF inf_d);//清屏
int Show_picture(P_DEV_INF inf_d,const char * picture,int flag,int times);//展示图片
int Touch_change_picture(P_DEV_INF inf_d,DL_LINK head);//按下切换图片

int Display_Chinese(P_DEV_INF inf_d,char * string,int where_x,int where_y);//显示汉字
int Display_Ascii(P_DEV_INF inf_d,char * string,int where_x,int where_y);//显示字母

int Slidelocker(P_DEV_INF inf_d,DL_LINK head);// 滑动解锁界面
int Desktop(P_DEV_INF inf_d,DL_LINK head);//主界面显示
int Loading_UI(P_DEV_INF inf_d,char * str);//检索加载界面
int Album_UI(P_DEV_INF inf_d,DL_LINK head); //相册界面
void * Time_display(P_DEV_INF inf_d);//显示时间

/* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 函数声明 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

//游戏函数
int Go_point(int *XP,int *YP,int *mark_who,P_DEV_INF inf_d);
int  panduan(int x,int y);
void star_game(P_DEV_INF inf_d,int *XP,int *YP);
void lcd_point(int x,int y,unsigned int color,P_DEV_INF inf_d);
void yuan(int x,int y,int r,unsigned int color,P_DEV_INF inf_d);
void chessboard(P_DEV_INF inf_d);


#endif

主函数

#include "e_album.h"

int main()
{

    DL_LINK head = Create_node();
    if (head == (DL_LINK)NULL)
    {
        printf("创建头节点出错!\n");
        return -1;
    }
    P_DEV_INF inf_d = Dev_inf_init();
    if(inf_d == (P_DEV_INF)-1)
    {
        printf("初始化失败!\n");
        return -1;
    }
    
    //创建线程实时获取坐标
    pthread_t coords_id;
    if(pthread_create(&coords_id,NULL,(void *)&Get_instant_coordinates,(void *)(inf_d)) != 0)
    {
        perror("pthread_create ...");
        return -1;
    }
    pthread_t time_id;
    if(pthread_create(&time_id,NULL,(void*)&Time_display,(void *)(inf_d)) != 0)
    {
        perror("pthread_create ...");
        return -1;
    }

    struct fb_var_screeninfo var;
    memset(&var,0,sizeof(var));
    var.xoffset = 0;
    var.yoffset = 0;
    ioctl(inf_d->lcd_fd,FB_ACTIVATE_NOW,&var);
    ioctl(inf_d->lcd_fd,FBIOPAN_DISPLAY,&var);

    Search_save_bmp(DIR_PATH,head);

    Slidelocker(inf_d,head);

    pthread_cancel(time_id);
    pthread_cancel(coords_id);

    Free_space(inf_d,head);

    return 0;
}

两个线程Get_instant_coordinates(),Time_display()

void * Get_instant_coordinates(P_DEV_INF inf_d) //��ȡ����
{
    struct input_event touch;

    while(1)
    {
        if(read(inf_d->touch_fd,&touch,sizeof(touch)) == -1)
        {
            perror("read touch screen");
            return (void*)-1;
        }

        if(touch.type == EV_ABS && touch.code == ABS_X) 
        {
            Coords.where_x = touch.value*800/1024;
        }
        
        if(touch.type == EV_ABS && touch.code == ABS_Y) 
        {
            Coords.where_y = touch.value*480/600;
        }
        if(touch.type == EV_KEY && touch.code == BTN_TOUCH)
        {
            Coords.press = touch.value;
            
        }
        printf("where_x: %d where_y: %d\npress:%d\n",Coords.where_x,Coords.where_y,Coords.press);
        
    }
    
    return 0;
}

void * Time_display(P_DEV_INF inf_d)//显示时间
{
    char date[100];
    while(1)
    {
        
        time_t nowtime;
        time(&nowtime);   
        //printf("%ld\n",nowtime);

        strcpy(date,ctime(&nowtime));
        //printf("%s\n",date);
        
        Display_Ascii(inf_d,date,0,0);
        
    }

    return 0;
}

设备初始化

lcd屏幕的初始化以及触摸屏的初始化

P_DEV_INF Dev_inf_init()//设备信息初始化
{
    P_DEV_INF inf_d = (P_DEV_INF)malloc(sizeof(DEV_INF));
    if(inf_d == (P_DEV_INF)NULL)
    {
        perror("malloc dev failed");
        return (P_DEV_INF)-1;
    }
    memset(inf_d,0,sizeof(DEV_INF));
    //打开lcd,触摸屏
    inf_d->lcd_fd = open(LCD_PATH,O_RDWR);
    if(inf_d->lcd_fd == -1)
    {
        perror("open lcd failed");
        return (P_DEV_INF)-1;
    }
    inf_d->touch_fd = open(IO_PATH,O_RDWR);
    if(inf_d->touch_fd == -1)
    {
        perror("open touch screen failed");
        return (P_DEV_INF)-1;
    }

    struct fb_var_screeninfo var_inf;
    memset(&var_inf,0,sizeof(var_inf));
    if(ioctl(inf_d->lcd_fd,FBIOGET_VSCREENINFO,&var_inf) == -1)
    {
        perror("ioctl failed");
        return (P_DEV_INF)-1;
    }
    //映射lcd,触摸屏
    inf_d->lcd_w = var_inf.xres;
    inf_d->lcd_h = var_inf.yres;
    printf("lcd屏幕宽度:%d 高度:%d\n",inf_d->lcd_w,inf_d->lcd_h);

    inf_d->lcd_mmap = mmap(NULL,4*(inf_d->lcd_w)*(inf_d->lcd_h),
                            PROT_WRITE | PROT_READ,MAP_SHARED,
                            inf_d->lcd_fd,0);
    if(inf_d->lcd_mmap == MAP_FAILED)
    {
        perror("mmap lcd failed");
        return (P_DEV_INF)-1;
    }


    return inf_d;
}

字库初始化

P_CH Character_init(char * str)// 字库初始化
{
    P_CH dzk = (P_CH)malloc(sizeof(CH));
    if(dzk == (P_CH)NULL)
    {
        perror("malloc dzk failed");
        return (P_CH)-1;
    }
    dzk->fd = open(str,O_RDWR);
    if(dzk->fd == -1)
    {
        perror("open dzk failed");
        return (P_CH)-1;
    }
    struct stat file_stat;
    if(stat(str,&file_stat) == -1)
    {
        perror("stat failed ..");
        return (P_CH)-1;
    }
    dzk->size = file_stat.st_size;
    //printf("字库大小:%d\n",dzk->size);
    
    dzk->mmap_p = mmap(NULL,dzk->size,PROT_READ | PROT_WRITE,MAP_SHARED,dzk->fd,0);
    if(dzk->mmap_p == MAP_FAILED)
    {
        perror("mmap dzk failed");
        return (P_CH)-1;
    }

    return dzk;
}

创建节点

DL_LINK Create_node()//创建节点
{
    DL_LINK node = (DL_LINK)malloc(sizeof(DL));
    if(node == (DL_LINK)NULL)
    {
        perror("malloc list");
        return (DL_LINK)-1;
    }
    memset(node,0,sizeof(DL));

    node->name = malloc(LENGTH);
    node->path = malloc(LENGTH);
    if(node->name==NULL || node->path==NULL)
    {
        printf("malloc node");
        return (DL_LINK)-1;
    }
    memset(node->name,0,LENGTH);
    memset(node->path,0,LENGTH);
    node->num = 0;

    INIT_LIST_HEAD(&(node->pointer));

    return node;
}
DL_LINK Find_node(DL_LINK head,int num) //检索节点
{
    if(head == NULL)
    {
        printf("头节点异常!\n");
        return (DL_LINK)-1;
    }
    if(list_empty(&(head->pointer)))//
    {
        printf("空链表,无法检索!\n");
        return (DL_LINK)0;
    }
    DL_LINK pos = NULL;
    list_for_each_entry(pos,&(head->pointer),pointer)
    {
        if(pos->num == num)
        {
            printf("击中目标!\n");
            return pos;
        }
    }
    printf("未找到目标!\n");

    return (DL_LINK)0;
}

释放空间

int Free_space(P_DEV_INF inf_d,DL_LINK head)//释放空间
{
    if(close(inf_d->lcd_fd)==-1 || close(inf_d->touch_fd)==-1)
    {
        perror("close inf_d failed");
        return -1;
    }
    if(munmap(inf_d->lcd_mmap,4*(inf_d->lcd_w)*(inf_d->lcd_h))==-1)
    {
        perror("munmap inf_d failed");
        return -1;
    }
    free(inf_d);

    DL_LINK pos;
    DL_LINK last_node = list_entry(head->pointer.prev,DL,pointer);
    list_for_each_entry(pos,&(head->pointer),pointer)
    {
        DL_LINK free_node = list_entry(pos->pointer.prev,DL,pointer);
        free_node->pointer.next = free_node->pointer.prev = NULL;

        free(free_node->name);
        free(free_node->path);
        free(free_node);
        printf("---\n");

    }
    free(last_node->name);
    free(last_node->path);
    free(last_node);

    return 0;
}

主函数

滑动解锁

实例代码如下:
手指触碰生成50*50的方块,其余位置补色;当触碰到结尾区域时进入主界面。

int Slidelocker(P_DEV_INF inf_d,DL_LINK head)// 滑动解锁界面
{
    Show_picture(inf_d,SLIDE_PATH,NORMAL,0);
    
    while (1)
    {
        
        if(Coords.where_y>350 && Coords.where_y<450)//滑动的模块
        {
            for(int y = 363; y<438; y++)
            {
                for(int x = 0; x<800; x++)
                {
                    if(x > Coords.where_x-50 && x < Coords.where_x+50)
                    {
                        *(inf_d->lcd_mmap+inf_d->lcd_w*y+x) = 0x3A61BD;
                    }
                    else
                    {
                        *(inf_d->lcd_mmap+inf_d->lcd_w*y+x) = 0x4F4F6B;
                    }
                }
            }
            if(Coords.where_x>740 && Coords.where_x<800)
            {
                Desktop(inf_d,head);
                return 0;
            }

        }
        
    }

图片的检索和显示

图片检索

对指定路径的的图片进行检索并将图片顺序,名字和路径存入链表中。

int Search_save_bmp(const char * dir_name,DL_LINK head)//检索图片目录路径并保存到链表中
{
    DIR * dp = opendir(dir_name);
    if(dp == NULL)
    { 
        perror("opendir failed");
        return -1;
    }

    char * obj = ".bmp";
    char * name = NULL;
    char complete_path[LENGTH];
    int n = 0;
    while(1)
    {
        memset(complete_path,0,LENGTH);
        struct dirent * eq = readdir(dp);
        if(eq == NULL)
        {
            //printf("已读取到文件末尾!\n");
            break;
        }
        if(eq->d_name[0] == '.')  continue;
        
        if(dir_name[strlen(dir_name)-1] == '/')
        {
            sprintf(complete_path,"%s%s",dir_name,eq->d_name);
        }
        else
        {
            sprintf(complete_path,"%s/%s",dir_name,eq->d_name);
        }
        if(eq->d_type == DT_DIR)
        {
            if(Search_save_bmp(complete_path,head)==-1)
            {
                printf("检索失败!\n");
                return -1;
            }   
        }
        if(eq->d_type == DT_REG)
        {
            name = rindex(eq->d_name,'.');
            if(name != NULL && strcmp(name,obj)==0)
            {
                printf("找到目标文件:%s\n",complete_path);
                DL_LINK new_node = Create_node();
                if(new_node == (DL_LINK)NULL)
                {
                    printf("创建新节点失败!\n");
                    return -1;
                }
                strcpy(new_node->name,eq->d_name);
                strcpy(new_node->path,complete_path);

                list_add_tail(&(new_node->pointer),&(head->pointer));//将节点尾插进链表
                n += 1; 
                new_node->num = n;
            }
            
        }

    }
    if(closedir(dp) == -1)
    {
        perror("closedir failed");
        return -1;
    }

    return 0;
}

显示图片(缩略是SMALL,普通显示为NORMAL)

int Show_picture(P_DEV_INF inf_d,const char * picture,int flag,int times)//展示图片
{
    //Clean_lcd(inf_d);
    int bmp_w,bmp_h;
    int skip;
    int bmp_fd = open(picture,O_RDONLY);
    if(bmp_fd == -1)
    {
        perror("open bmp");
        return -1;
    }
    lseek(bmp_fd,18,SEEK_SET);
    
    if(read(bmp_fd,&bmp_w,4) == -1 || read(bmp_fd,&bmp_h,4)==-1)
    {
        perror("read failed");
        return -1;
    }
    if(bmp_w*3%4 == 0)
    {
        skip = 0;
    }
    else
    {
        skip = 4-bmp_w*3%4;
    }
    int pixel_size = 3*bmp_w*bmp_h+skip*bmp_h;
    char rgb[pixel_size];
    lseek(bmp_fd,54,SEEK_SET);
    if(read(bmp_fd,&rgb,pixel_size) == -1)
    {
        perror("read bmp");
        return -1;
    }
    
    if(flag == NORMAL)//在中心正常大小显示
    {
        int * new_mmap_p  = inf_d->lcd_mmap+ (inf_d->lcd_w \
                        * (inf_d->lcd_h/2-bmp_h/2) \
                        + (inf_d->lcd_w/2-bmp_w/2)); 
    
        for(int y=0,n=0; y<bmp_h; y++)
        {
            for(int x=0; x<bmp_w; x++,n+=3)
            {
                *(new_mmap_p+(inf_d->lcd_w)*(bmp_h-1-y)+x) \
                = rgb[n]<<0 | rgb[n+1]<<8 | rgb[n+2]<<16;
            }
            n += skip;
        }
    }
    else if(flag == SMALL)//缩略显示
    {
        int y_new,x_new;

        int m = times%3;
        int n = times/3;
        x_new = bmp_w/RATIO*m + 30*(m+1);//计算显示位置
        y_new = bmp_h/RATIO*n + 30*(n+1);
 
        int * new_mmap_p = inf_d->lcd_mmap + (inf_d->lcd_w*y_new+x_new);
        
        for(int y=0,rgb_y=0; y<bmp_h/RATIO; y++,rgb_y+=(RATIO))
        {
            for(int x=0,rgb_x=0; x<bmp_w/RATIO; x++,rgb_x+=3*RATIO)
            {
                *(new_mmap_p + (inf_d->lcd_w)*(bmp_h/RATIO-1-y)+x) = \
                rgb[(3*bmp_w+skip)*rgb_y+rgb_x] <<0 | \
                rgb[((3*bmp_w+skip)*rgb_y+rgb_x)+1] <<8 | \
                rgb[((3*bmp_w+skip)*rgb_y+rgb_x)+2] <<16;   // 200 x 120
                
            }  
        }

        printf("mmap: %p\n",new_mmap_p);
        printf("x_new:%d y_new:%d\n",x_new,y_new);
        printf("offset:%d\n",(inf_d->lcd_w*y_new+x_new));
        printf("times:%d\n",times);
    }    

    if(close(bmp_fd)==-1)
    {
        perror("close bmp");
        return -1;
    }
    return 0;
}

展示图片

int Traverse_list(DL_LINK head,P_DEV_INF inf_d) //遍历链表 显示缩略图片
{
    if(head == NULL)
    {
        printf("头节点异常!\n");
        return -1;
    }
    if(list_empty(&(head->pointer)))//
    {
        printf("空链表,无需遍历!\n");
        return 0;
    }
    DL_LINK pos = NULL;

    //调用内核链表
    int times = 0;
    // DL_LINK tmp_node  = list_entry(head->pointer.next,DL,pointer);
    // Show_picture(inf_d,tmp_node->path,NORMAL,0);
    Clean_lcd(inf_d);
    list_for_each_entry(pos,&(head->pointer),pointer)
    {
        printf("%s\n",pos->path);
        if(pos->num == 0)  break;
        if(times < 9)
        {
            Show_picture(inf_d,pos->path,SMALL,times);
            int m = times%3;
            int n = times/3;
            Display_Ascii(inf_d,pos->name,50+230*m,157+150*n);//显示图名
            times++;
        } 
        else break;           
    }
    return 0;
}

清屏函数

int Clean_lcd(P_DEV_INF inf_d)//清屏
{
     for(int y=0; y<inf_d->lcd_h; y++)
    {
        for(int x=0; x<inf_d->lcd_w; x++)
        {
            *(inf_d->lcd_mmap + (inf_d->lcd_w)*y+x) = 0xFFEEFF;
        }
    }

    return 0;
}

按下切换上下张图片,遇到头结点跳过

int Touch_change_picture(P_DEV_INF inf_d,DL_LINK head)//按下切换图片
{
    Coords.press = false;
    DL_LINK tmp_node = list_entry(head->pointer.next,DL,pointer);

    while(1)
    {
       
        //点击切换上下张
        if(Coords.press == true)
        {
            printf("坐标x:%d y:%d\n",Coords.where_x,Coords.where_y); 
            if(Coords.where_x <= 200)
            {
                tmp_node = list_entry(tmp_node->pointer.prev,DL,pointer);
            }
            else if(Coords.where_x >= 600)
            {
                tmp_node = list_entry(tmp_node->pointer.next,DL,pointer);
            }
            else
            {
                return 0;
            }
            if(tmp_node == head)
            {
                if(Coords.where_x <= 200)
                {
                    tmp_node = list_entry(tmp_node->pointer.prev,DL,pointer);
                }
                else if(Coords.where_x >= 600)
                {
                    tmp_node = list_entry(tmp_node->pointer.next,DL,pointer);
                }
            }
            Show_picture(inf_d,tmp_node->path,NORMAL,0);
            Coords.press = false;
        }

    }
        

    return 0;
}

调用字库显示汉字、字母

//汉字
int Display_Chinese(P_DEV_INF inf_d,char * string,int where_x,int where_y)
{
    P_CH dzk = Character_init(DZK_CHN_PATH);
    int len = strlen(string);
    char * fontl;
    for(int lp = 0; lp<len; lp += 2)
    {
        fontl = string+lp;
        int offset = (94*(fontl[0]-1-0xa0)+(fontl[1]-1-0xa0)) * 72;
        char * new_dzk_mmap = dzk->mmap_p + offset;
        int *  new_lcd_mmap = inf_d->lcd_mmap + (inf_d->lcd_w)*where_y+where_x;
        char datatype;
        for(int y = 0; y<24; y++)
        {
            for(int x = 0; x<24/8; x++)
            {
                datatype = *(new_dzk_mmap+(24/8)*y+x);
                for(int z = 0; z<8; z++)
                {
                    if(datatype & 0x80>>z)
                    {
                        *(new_lcd_mmap+(inf_d->lcd_w*y+8*x+z)) = 0x000000;
                    }
                    else
                    {
                        *(new_lcd_mmap+(inf_d->lcd_w*y+8*x+z)) = 0x57DDFF;
                    }
                }
            }
        }
        where_x += 24;
    } 
    if(close(dzk->fd) == -1)
    {
        perror("close failed ");
        return -1;
    }
    if(munmap(dzk->mmap_p,dzk->size) == -1)
    {
        perror("mumap failed");
        return -1;
    }
    free(dzk);

    return 0;
}

//字母
int Display_Ascii(P_DEV_INF inf_d,char * string,int where_x,int where_y)
{
    P_CH dzk = Character_init(DZK_ASC_PATH);
    int len = strlen(string);
    char character;
    for(int lp = 0; lp<len; lp ++)
    {
        character = string[lp];
        int offset = character * 32;
        char * new_dzk_mmap = dzk->mmap_p + offset;
        int *  new_lcd_mmap = inf_d->lcd_mmap + (inf_d->lcd_w)*where_y+where_x;
        char datatype;
        for(int y = 0; y<16; y++)
        {
            for(int x = 0; x<16/8; x++)
            {
                datatype = *(new_dzk_mmap+(16/8)*y+x);
                for(int z = 0; z<8; z++)
                {
                    if(datatype & 0x80>>z)
                    {
                        *(new_lcd_mmap+(inf_d->lcd_w*y+8*x+z)) = 0x000000;
                    }
                    else
                    {
                        *(new_lcd_mmap+(inf_d->lcd_w*y+8*x+z)) = 0x57DDFF;
                    }
                }
            }
        }
        where_x += 16;
    }
    if(close(dzk->fd) == -1)
    {
        perror("close failed ");
        return -1;
    }
    if(munmap(dzk->mmap_p,dzk->size) == -1)
    {
        perror("mumap failed");
        return -1;
    }
    free(dzk); 
    return 0;
}

主界面显示(Desktop)

主界面主要包括相册,游戏以及退出按钮

int Desktop(P_DEV_INF inf_d,DL_LINK head)//主界面显示
{
    
    while(1)
    {
        Coords.where_x = -1;
        Coords.where_y = -1;
        Show_picture(inf_d,DESKTOP_PATH,NORMAL,0);
        if(Coords.press == 1)
        {
            if((Coords.where_x>130 && Coords.where_x<243)&&\
            (Coords.where_y>190 && Coords.where_y<300))
            {
                Loading_UI(inf_d,LOAD_PATH);//检索加载界面
                Album_UI(inf_d,head);
                continue;                    
            }
            else if((Coords.where_x>570 && Coords.where_x<690)&&\
            (Coords.where_y>180 && Coords.where_y<300))
            {
                Clean_lcd(inf_d);
                int XP;
                int YP;
                star_game(inf_d,&XP,&YP);
                // Clean_lcd(inf_d);
                // Display_Chinese(inf_d,"开发中,敬请期待!",300,210);//游戏
                // Display_Ascii(inf_d,"Under development, stay tuned!",160,245);
                // sleep(1);
                continue;
            }
            else if((Coords.where_x>720 && Coords.where_x<790)&&\
            (Coords.where_y>10 && Coords.where_y<90))
            {
                Show_picture(inf_d,EXIT_PATH,NORMAL,0);
                Display_Chinese(inf_d,"正在退出!",350,216);
                sleep(1);
                Clean_lcd(inf_d);
                return 0;//退出
            }

        }
        
    }
    
    return 0;
}

int Album_UI(P_DEV_INF inf_d,DL_LINK head) //相册界面
{
    
    Coords.where_x = -1;
    Coords.where_y = -1;
    int flags = 0;
    Traverse_list(head,inf_d);
                
    Display_Chinese(inf_d,"退出",720,60+105*0);
    Display_Chinese(inf_d,"相册",720,60+105*1);
    Display_Chinese(inf_d,"上一页",710,60+105*2);
    Display_Chinese(inf_d,"下一页",710,60+105*3);

    struct fb_var_screeninfo var;
    memset(&var,0,sizeof(var));
    printf("1visual:%d\n",var.yoffset);

    while(1)
    {
        
        if(Coords.where_x>710 && Coords.where_x<770)//相册目录操作
        {
            if(Coords.where_y>50 && Coords.where_y<110)
            {               
                return 0;//退出
            }
            else if(Coords.where_y>155 && Coords.where_y<215)
            {
                Touch_change_picture(inf_d,head);//进入相册
                Album_UI(inf_d,head);
                continue;
            }
            else if(Coords.where_y>260 && Coords.where_y<320)//上一页
            {
                Album_UI(inf_d,head);
                continue;
                //printf("2visual:%d\n",var.yoffset); 
            }
            else if(Coords.where_y>365 && Coords.where_y<425)//下一页
            {
                // var.xoffset = 0;
                // var.yoffset = 480;
                // ioctl(inf_d->lcd_fd,FB_ACTIVATE_NOW,&var);
                // ioctl(inf_d->lcd_fd,FBIOPAN_DISPLAY,&var);
                Coords.where_x = -1;
                Coords.where_y = -1;
                DL_LINK tmp = Find_node(head,9); 
                Traverse_list(tmp,inf_d);

                Display_Chinese(inf_d,"退出",720,60+105*0);
                Display_Chinese(inf_d,"相册",720,60+105*1);
                Display_Chinese(inf_d,"上一页",710,60+105*2);
                Display_Chinese(inf_d,"下一页",710,60+105*3);
                flags = 1;
                //Coords.press = 0;

                continue;         
            }

        }
        DL_LINK tmp_node = NULL;
        if(Coords.press == 1)
        {
            if((Coords.where_y>35 && Coords.where_y<155))//第一行
            {
                if(Coords.where_x>30 && Coords.where_x<230)
                {
                    tmp_node = Find_node(head,1+flags*9);                    
                }
                else if(Coords.where_x>260 && Coords.where_x<460)
                {
                    tmp_node = Find_node(head,2+flags*9);         
                }
                else if(Coords.where_x>490 && Coords.where_x<690)
                {
                    tmp_node = Find_node(head,3+flags*9);                   
                }
            }
            else if(Coords.where_y>190 && Coords.where_y<310)//第二行
            {
                if(Coords.where_x>30 && Coords.where_x<230)
                {
                    tmp_node = Find_node(head,4+flags*9);                   
                }
                else if(Coords.where_x>260 && Coords.where_x<460)
                {
                    tmp_node = Find_node(head,5+flags*9);                   
                }
                else if(Coords.where_x>490 && Coords.where_x<690)
                {
                    tmp_node = Find_node(head,6+flags*9);                   
                }
            }
            else if(Coords.where_y>345 && Coords.where_y<465)//第三行
            {
                if(Coords.where_x>30 && Coords.where_x<230)
                {
                    tmp_node = Find_node(head,7+flags*9);                    
                }
                else if(Coords.where_x>260 && Coords.where_x<460)
                {                   
                    tmp_node = Find_node(head,8+flags*9);
                    
                }
                else if(Coords.where_x>490 && Coords.where_x<690)
                {
                    tmp_node = Find_node(head,9+flags*9);
                }
            }
            if(tmp_node != NULL)
            {
                Show_picture(inf_d,tmp_node->path,NORMAL,0);
                sleep(1);
            }
    
            if(flags == 0)
            Album_UI(inf_d,head);
            else if(flags == 1)
            {
                Coords.where_x = 720;
                Coords.where_y = 390;
            }
            continue;
        }
        
    }

    return 0;
}


int Loading_UI(P_DEV_INF inf_d,char * str)//检索加载界面
{
    Show_picture(inf_d,str,NORMAL,0);
    int load_x = 200, load_y = 200;
    int load_w = 400, load_h = 80;
    int * new_mmap = inf_d->lcd_mmap + (inf_d->lcd_w *load_y+load_x);
    Display_Chinese(inf_d,"图片检索中。。。",300,150);
    for(int x = 0; x<load_w; x++)
    {
        for(int y = 0; y<load_h; y++)
        {

            *(new_mmap+inf_d->lcd_w*y+x) = 0x57DDFF;

        }
        usleep(1000);
    }
    Display_Chinese(inf_d,"检索完成!",330,330);
    Display_Chinese(inf_d,"共有十二张图片",310,360);
    sleep(1);

    return 0;
}

以上就是项目全况。

  • 6
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值