⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmpbkgnd.c

📁 利用MiniGUI变得简单的嵌入式图形界面程序。达到地图移动菜单操作等效果。
💻 C
📖 第 1 页 / 共 3 页
字号:
                     case 11:p->next=a11->right;a11->right=p;break;                     case 12:p->next=a12->right;a12->right=p;break;        }
	p=(struct node *)malloc(sizeof(struct node));
	}
	free(p);
	fclose(fp);        return a1;
}void init(struct prodcons * b){    b->s=0;  pthread_mutex_init(&b->lock, NULL);  pthread_cond_init(&b->notempty, NULL);}//对缓冲区写入GPS数据//int read0(struct prodcons * b,FILE *fp){         double i;       pthread_mutex_lock(&b->lock);        if(fscanf(fp,"%lf",&i)!=1)
	return 0;        b->y=i;	         fscanf(fp,"%lf",&b->x);        b->s=1;        pthread_cond_signal(&b->notempty);        pthread_mutex_unlock(&b->lock);         return 1;}int read1(struct prodcons * b,FILE *fp){         double i;        pthread_mutex_lock(&b->lock);        if(fscanf(fp,"%lf",&i)!=1)
	return 0;        b->yy=i;	         fscanf(fp,"%lf",&b->xx);                gps_yy=b->xx;gps_xx=b->yy;        pthread_mutex_unlock(&b->lock);         return 1;}int get(struct prodcons *b){       pthread_mutex_lock(&b->lock);      while(b->s==0)     {        pthread_cond_wait(&b->notempty, &b->lock);     }      gps_x=b->x;      gps_y=b->y;      if(b->x==0&&b->y==0)return 0;      b->s=0;      pthread_mutex_unlock(&b->lock);       return 1;}//对于边界的判定(很可能需要重新写)struct shuzhi *board(double a,double b,struct shuzhi *now,struct shuzhi *old,struct shuzhi *q){    int p,count;    count=0;     if(a<=q->x1+0.0004||b>=q->y2-0.035||a>=119.283606-0.0004||b<=3211.2775+0.035){printf("wrong");return NULL;}       if(b<change0(now->y1,350))count=4;        else if(b>change0(now->y2,-350))count=-4;         else if(a<change1(now->x1,400))count=-1;          else if(a>change1(now->x2,-400))count=1;            else return NULL;    p=now->number+count;    if(old->number==p)return NULL;    while(p!=1)    {q=q->next;p--;}    return q; }void search(double m,double n,int flag,struct shuzhi *d);void search0(double m,double n,struct node *l,struct node *m1,struct node *r);void search1(double m,double n,struct node *l,struct node *m1,struct node *r);void search2(double m,double n,struct node *l,struct node *m1,struct node *r);void search3(double m,double n,struct node *l,struct node *m1,struct node *r);void searcheast(double m,double n,struct node *l,struct node *m1,struct node *r);void searchnorth(double m,double n,struct node *l,struct node *m1,struct node *r);void searchsouth(double m,double n,struct node *l,struct node *m1,struct node *r);void searchwest(double m,double n,struct node *l,struct node *m1,struct node *r);//搜索函数//void search(double m,double n,int flag,struct shuzhi *d){  struct node *l,*m1,*r;  l=d->left;m1=d->mid;r=d->right;//这里需要对截面的控制作一次判断,以确定搜索的类别与范围
	  switch(flag){    case NORTH: search0(m,n ,l,m1,r);break;    case EAST:   search1(m,n ,l,m1,r);break;    case SOUTH: search2(m,n ,l,m1,r);break;    case WEST:  search3(m,n ,l,m1,r);break;    default:printf("wrong");    }  return;  }//根据按建的返回值,进行必要的分曾搜索void search0(double m,double n,struct node *l,struct node *m1,struct node *r){  switch(flt){     case 11:searchnorth(m,n,l,m1,r);break;     case 12:searchnorth(m,n ,l,NULL,NULL);break;     case 13:searchnorth(m,n ,m1,NULL,NULL);break;     case 14:searchnorth(m,n ,r,NULL,NULL);break;     default:searchnorth(m,n ,l,m1,r);      }}void search1(double m,double n ,struct node *l,struct node *m1,struct node *r){  switch(flt){     case 11:searcheast(m,n ,l,m1,r);break;     case 12:searcheast(m,n ,l,NULL,NULL);break;     case 13:searcheast(m,n ,m1,NULL,NULL);break;     case 14:searcheast(m,n ,r,NULL,NULL);break;     default:searcheast(m,n ,l,m1,r);      }}void search2(double m,double n ,struct node *l,struct node *m1,struct node *r){  switch(flt){     case 11:searchsouth(m,n ,l,m1,r);break;     case 12:searchsouth(m,n ,l,NULL,NULL);break;     case 13:searchsouth(m,n ,m1,NULL,NULL);break;     case 14:searchsouth(m,n ,r,NULL,NULL);break;     default:searchsouth(m,n ,l,m1,r);      }}void search3(double m,double n ,struct node *l,struct node *m1,struct node *r){  switch(flt){     case 11:;searchwest(m,n ,l,m1,r);break;     case 12:searchwest(m,n ,l,NULL,NULL);break;     case 13:searchwest(m,n ,m1,NULL,NULL);break;     case 14:searchwest(m,n ,r,NULL,NULL);break;     default:searchwest(m,n ,l,m1,r);      }}void searcheast(double m,double n ,struct node *l,struct node *m1,struct node *r){while(l!=NULL){   if((l->fangxiang==ALL||l->fangxiang==EAST)&&m<l->x&&l->x<change1(m,400)&&l->y<=change0(gps_y,+200)&&l->y>=change0(gps_y,-200))  {                 num=l->num;  }l=l->next;}  while(m1!=NULL){   if((m1->fangxiang==ALL||m1->fangxiang==EAST)&&m<m1->x&&m1->x<change1(m,400)&&m1->y<=change0(gps_y,+200)&&m1->y>=change0(gps_y,-200)){                num=m1->num;  }m1=m1->next;}  while(r!=NULL){   if((r->fangxiang==ALL||r->fangxiang==EAST)&&m<r->x&&r->x<change1(m,400)&&r->y<=change0(gps_y,+200)&&r->y>=change0(gps_y,-200))  {                 num=r->num;  }r=r->next;}}void searchnorth(double m,double n ,struct node *l,struct node *m1,struct node *r){  while(l!=NULL){     if((l->fangxiang==ALL||l->fangxiang==NORTH)&&l->x<=change1(gps_x,+300)&&l->x>=change1(gps_x,-300)&&gps_y<l->y&&l->y<=change0(gps_y,+400))              {            num=l->num;             }l=l->next;    }while(m1!=NULL){     if((m1->fangxiang==ALL||m1->fangxiang==NORTH)&&m1->x<=change1(gps_x,+300)&&m1->x>=change1(gps_x,-300)&&gps_y<m1->y&&m1->y<=change0(gps_y,+400))              {           num=m1->num;             }m1=m1->next;    }  while(r!=NULL){         if((r->fangxiang==ALL||r->fangxiang==NORTH)&&r->x<=change1(gps_x,+300)&&r->x>=change1(gps_x,-300)&&gps_y<r->y&&m1->y<=change0(gps_y,+400))              {            num=r->num;             }r=r->next;    }}void searchsouth(double m,double n ,struct node *l,struct node *m1,struct node *r){ while(l!=NULL){     if((l->fangxiang==ALL||l->fangxiang==SOUTH)&&l->x<=change1(gps_x,+300)&&l->x>=change1(gps_x,-300)&&change0(gps_y,-400)<l->y&&l->y<=gps_y){                 num=l->num;  }l=l->next;} while(m1!=NULL){     if((m1->fangxiang==ALL||m1->fangxiang==SOUTH)&&m1->x<=change1(gps_x,+300)&&m1->x>=change1(gps_x,-300)&&change0(gps_y,-400)<m1->y&&m1->y<=gps_y)  {                num=m1->num;    } m1=m1->next;  }  while(r!=NULL){     if((r->fangxiang==ALL||r->fangxiang==SOUTH)&&r->x<=change1(gps_x,+300)&&r->x>=change1(gps_x,-300)&&change0(gps_y,-400)<r->y&&r->y<=gps_y)           {               num=r->num;  }r=r->next;}}void searchwest(double m,double n ,struct node *l,struct node *m1,struct node *r){  while(l!=NULL){     if((l->fangxiang==ALL||l->fangxiang==WEST)&&change1(gps_x,-400)<l->x&&l->x<gps_x&&l->y<=change0(gps_y,+200)&&l->y>=change0(gps_y,-200)){                 num=l->num;  }l=l->next;}  while(m1!=NULL) {     if((m1->fangxiang==ALL||m1->fangxiang==WEST)&&change1(gps_x,-400)<m1->x&&m1->x<gps_x&&m1->y<=change0(gps_y,+200)&&m1->y>=change0(gps_y,-200)){                num=m1->num;   }m1=m1->next;   }  while(r!=NULL) {     if((r->fangxiang==ALL||r->fangxiang==WEST)&&change1(gps_x,-400)<r->x&&r->x<gps_x&&r->y<=change0(gps_y,+200)&&r->y>=change0(gps_y,-200)){                 num=r->num;  }r=r->next;}}int panbie(double e,double f){ int flag=0;/*以下为方向判别算发*/ if((f>e)&&(f>-e)){flag=NORTH;} else if((f<e)&&(f>-e)){flag=EAST;} else if((f<e)&&(f<-e)){flag=SOUTH;} else if((f>e)&&(f<-e)){flag=WEST;} return (flag); //printf("%d\n",flag);}int transfer_x(double x){    int a,b,c,d;     a=(x-119.25)*1000000;     b=a/10000;c=a%10000;     d=b*6000+c;     return d;}int transfer_y(double y) {    int a,b,c,d;      a=(y-3210)*10000;      b=a/10000;c=a%10000;      d=b*6000+c;      return d; }void *thread1() { FILE *fp; if((fp=fopen("lujin.txt","r"))==NULL)
	{
		printf("Can't open file .\n");
	}  while(1)  {if(single==0)continue;  read0(&buffer,fp);  sleep(1);}  return NULL; }void *thread2(){    int q,fl;     int z1,z2,v1,v2;    double x,y,e,f;    x=y=0;   while(1)  {  q=get(&buffer);    if(q==0)break;    z1=transfer_x(x);    z2=transfer_x(gps_x);    v1=transfer_y(y);    v2=transfer_y(gps_y);    e=(double)(z2-z1);f=(double)(v2-v1);    fl=panbie(e,f);    printf("Position Now  : %lf %lf\n",gps_x,gps_y);    printf("Direction Now : %d\n",fl);    x=gps_x;y=gps_y;    while(old!=NULL)//判别区域    {    if(old->x1<=x&&x<=old->x2&&old->y1<=y&&y<=old->y2)         {find=old;break;}         old=old->next;     }     printf("Area Now  :  %d\n",find->number);     old=head;     search(x,y,fl,find);     find1=board(x,y,find,j,head);     if(find1!=NULL)search(x,y,fl,find1);     j=find;}    return NULL;}void *thread3(){ while(GetMessage(&Msg,hMainWnd))    { TranslateMessage(&Msg);      DispatchMessage(&Msg);    }}void*thread4( ){    FILE *fp1;     if((fp1=fopen("path.txt","r"))==NULL)
                  printf("Can't open file .\n");     while(1)         {read1(&buffer,fp1);         sleep(1);}     printf("producer stopped!\n");     return NULL;}int MiniGUIMain (int argc, const char* argv[]){    int pid;     pthread_t th_a, th_b,th_c,th_d;     void * retval;     init(&buffer);     head=old=j=makelist();         system("./loadbmp &");      printf("PID=%d\n",pid =getpid());                  #ifdef _LITE_VERSION    SetDesktopRect(0, 0, 800, 600);#endif            InitMainWindow();    ShowWindow(hMainWnd,SW_SHOWNORMAL);    pthread_create(&th_d, NULL, thread4, NULL);    pthread_create(&th_c, NULL, thread3, NULL);    pthread_create(&th_a, NULL, thread1, NULL);    pthread_create(&th_b, NULL, thread2, NULL);  /* Wait until producer and consumer finish. */        pthread_join(th_d, &retval);             pthread_join(th_c, &retval);	        pthread_join(th_a, &retval);    	pthread_join(th_b, &retval);      MainWindowThreadCleanup(hMainWnd);    return (0);}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -