?? 2.txt
字號:
{ short i, j, k, t,l=rwidth*height,m; int off,d; char *loc=screen_ptr+(off=((sy*screen_width+sx)>>3)); //printf("drawing bmp.\n"); for(t=0,k=0,i=0;i<height;i++,k+=screen_width>>3,t+=rwidth) for(j=0;(j<rwidth)&&(j<20);j++) { m=k+j; if(m+off>=3200) // if(m+off>=4000) return; loc[m]=pixel[t+j]; } //printf("draw_bmp finished.\n");}void ShowBMP(char *filename,short x,short y){ BMPHEAD bm; int tmpi; FILE *fp=fopen(filename,"rb"); char *buf,c; int i,j,t,width; long size; //printf("showing BMP KEYBORAD.\n"); if(!fp) return; //printf("freading...\n"); fread(&bm,1,sizeof(BMPHEAD),fp); //printf("fread finished.\n"); /*buf = (char*)&bm; for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi++) printf("%02x ",buf[tmpi]); printf("\n"); for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi+=2) printf("%04x ",*((short *)(buf+tmpi)) ); printf("\n"); for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi+=4) printf("%08x ",*((long *)(buf+tmpi)) ); printf("\n");*/ buf=(char*)&bm.bits; c=buf[0]; buf[0]=buf[1]; buf[1]=c; if(bm.bits!=0x100) { fclose(fp); printf("\ngraphic: Unsupported color bitmap\n"); return; } //printf("exchange width\n"); //printf("graphic:width=%08x\n",bm.width); bm.width = 160; /*buf=(char*)&bm.width; c=buf[0]; buf[0]=buf[3]; buf[3]=c; c=buf[1]; buf[1]=buf[2]; buf[2]=c; printf("graphic:width=%08x\n",bm.width); */ //printf("exchange height\n"); bm.height = 60; /* buf=(char*)&bm.height; c=buf[0]; buf[0]=buf[3]; buf[3]=c; c=buf[1]; buf[1]=buf[2]; buf[2]=c; */ width=(bm.width+7)>>3; if(width&3) width+=(4-(width&3)); //printf("bmphead=%d",sizeof(BMPHEAD)); //printf("width=%d,bm.height=%ld,size=%ld\n",width,bm.height,width*bm.height); buf=(char*)malloc(size=(width*bm.height)); //printf("malloc ok\n"); //fread(&i,1,8,fp); //fread(buf,1,100,fp); //lyk //fread(buf,1,8,fp); //fread(buf,1,1,fp); //lseek(fp,8,1); fread(buf,1,size,fp); fclose(fp); //printf("entering loop...\n"); for(i=0;i<(bm.height>>1); i++) for(t=i*width,j=0;j<width;j++) { c=buf[t+j]^0xff; buf[t+j]=buf[size-width-t+j]^0xff; buf[size-width-t+j]=c; } //printf("loop finished.\n"); draw_bmp(x,y,width,bm.height,buf); free(buf);}void V_scroll_screen(short height) //Up/Down Scroll{ short dir=(height<0); if(dir) height=-height; if(height<screen_height) { short nBytes=(screen_width>>3)*height, nCount=(screen_width>>3)*(screen_height-height); if(dir) //Down Scroll { memmove(screen_ptr+nBytes,screen_ptr,nCount); memset(screen_ptr,0,nBytes); } else //Up Scroll { memmove(screen_ptr,screen_ptr+nBytes,nCount); memset(screen_ptr+nCount,0,nBytes); } } else clearscreen(); }void H_scroll_screen(short width) //Left Scroll{ short dir=(width<0); if(dir) width=-width; if(width<screen_width) { if(width&7) //Check whether it is byte aligned { short nCount=screen_width*screen_height>>3; static unsigned char mskr[]={0,1,3,7,0xf,0x1f,0x3f,0x7f}, mskl[]={0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe}, buf[3200]; unsigned char /*buf,*/c,flag=0,d; short start=(width>>3),length=(width&7),i,j,wid=(screen_width>>3),off; memcpy(buf,screen_ptr,nCount); if(dir) { for(off=0,j=0;j<screen_height;j++,off+=wid) { for(flag=0,i=wid-1;i>=start;i--) { d=c=*(buf+off+i); c<<=length; if(flag) c|=(flag>>(8-length)); flag=d&mskl[length]; *(buf+off+i)=c; } if(start) for(i=wid-start;i<wid;i++) { *(buf+off+i)=0; } } } else for(off=0,j=0;j<screen_height;j++,off+=wid) { for(flag=0,i=start;i<wid;i++) { d=c=*(buf+off+i); c>>=length; if(flag) c|=(flag<<(8-length)); flag=d&mskr[length]; *(buf+off+i)=c; } if(start) for(i=0;i<start;i++) { *(buf+off+i)=0; } } memcpy(screen_ptr,buf,nCount); } else { short i,j=0,wid=screen_width>>3; width>>=3; for(i=0;i<screen_height;i++,j+=wid) { memmove(screen_ptr+j+width,screen_ptr+j,wid-width); memset(screen_ptr+j,0,width); } } } else clearscreen();}void textout(short x,short y,unsigned char *buf){ int i,j,count=strlen(buf); short k,l,m=screen_width>>3; char pixel[32]; //printf("screen_height=%d\n",screen_height);#ifdef FONT if(!font) { puts("Please Init Chinese Enviroment First!"); return; }#endif for(i=0;i<count;) { // printf("gui:i=%d,count=%d\n",i,count); if(y>=screen_height) { memmove(screen_ptr,screen_ptr+320,2880); memset(screen_ptr+2880,0,320); y-=16; } if((buf[i]>=161)&&(buf[i+1]>=161)) { //int nHeadCount; //char cTmp; j=((buf[i]-161)*94+(buf[i+1]-161))<<5; fseek(C_Font,j,SEEK_SET); fread(pixel,32,1,C_Font); //Yongkui Lu changed it to fit the small head problem from Big head problem. /*for(nHeadCount=0;nHeadCount<32;nHeadCount+=2) { cTmp=pixel[nHeadCount]; pixel[nHeadCount]=pixel[nHeadCount+1]; pixel[nHeadCount+1]=cTmp; }*/ draw_bmp(x,y,2,16,pixel); x+=16; if(x>=screen_width) { y+=16; x=0; } i+=2; } else { //Yongkui Lu add it to fit the small head problem! //int iTmp=i;//backup i //printf("gui:i=%d,count=%d,buf[%d]=%c\n",i,count,i,buf[i]); /*if(i%2==0){ i++; }else{ i--; }*/ if(buf[i]=='\n') { k=(y*screen_width+x)>>3; l=(screen_width-x)>>3; for(j=0;j<16;j++,k+=m) memset(screen_ptr+k,0,l); x=0;y+=16; } else { draw_bmp(x,y,1,16,E_Font+(buf[i]<<4)); x+=8; } //i=iTmp; //load from backup i++; /*iTmp=i;//backup i if(i%2==0){ i++; }else{ i--; } if(buf[i]=='\n') { k=(y*screen_width+x)>>3; l=(screen_width-x)>>3; for(j=0;j<16;j++,k+=m) memset(screen_ptr+k,0,l); x=0;y+=16; } else { draw_bmp(x,y,1,16,E_Font+(buf[i]<<4)); x+=8; } i=iTmp; //load from backup i++;*/ } }}void setmode(CopyMode mode){ Mode=mode;}CopyMode getmode(void) { return Mode; }void setcolor(short color){ Color=color;}UINT getcolor(void){ return Color;}void setfillpattern(PatternIndex index){ P_Index=index; }PatternIndex getfillpattern(void){ return P_Index; }void moveto(short x,short y){ X=x;Y=y;}void lineto(short x,short y){ line(x,y,X,Y); X=x;Y=y;}/* * $Id: graphic.c,v 1.2 1999/11/12 13:03:26 till Exp $ * * Graphics primitive drawing functions * derived from: graphic.c Pixy Graphic Library * derived from: lissa.c: Graphics demos * * Copyright (C) 2001 Chen Yang <support@hhcn.com> * Copyright (C) 1999 Till Krech <till@snafu.de> * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The code in this file is partially based on Kenneth Albanowskis work * for the lissa graphics demo. *//******************Notice*********************************** * The Default Font size for ASCII Font is 8x16 * The Default Font size of Chinese Font is 16x16 ***********************************************************/#include <sys/types.h>#include <sys/stat.h>#include <linux/fb.h>#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <sys/mman.h>#include "mathf.h"#include "font_8x16.h"#include "gui.h"/*Define the correct Chinese Font File Path*/#define CHINESE_FONT_FILE "/font/hanzi"typedef struct { unsigned short height; unsigned char data[0];} Pattern;const Pattern _BlackPattern ={ 1, {~0}};const Pattern _WhitePattern ={ 1, { 0 }};const Pattern _DarkGreyPattern ={ 2, { (unsigned char)0x55555555, (unsigned char)0xCCCCCCCC }};const Pattern _LightGreyPattern ={ 4, { (unsigned char)0x88888888, (unsigned char)0x00000000, (unsigned char)0x22222222, (unsigned char)0x00000000, }};const Pattern _MicroPengPattern ={ 16, { 0x3c,0x7e,0x56,0xaa,0x86,0x4e,0x7b,0xc3,0x83,0x83,0xc3,0xc7,0xbd,0x99,0x99, 0xff }};static const Pattern *patterns[] = { /* This must correspond to the enum in pixy.h! */ &_BlackPattern, &_WhitePattern, &_DarkGreyPattern, &_LightGreyPattern, &_MicroPengPattern,};static short masktab[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};static int screen_fd=-1;FILE *C_Font;unsigned char * screen_ptr=(unsigned char*)(0x0400),*E_Font=(unsigned char*)(0x8500);static short screen_width=160,screen_height=160;static short WinSX,WinSY,WinEX,WinEY;static unsigned short X,Y,Color,P_Index,Mode=MODE_SRC;//CopyMode pixy_copy_mode = Mode_SRC;inline void setpixel(short x, short y, short color){ if ((x<0) || (x>=screen_width) || (y<0) || (y>=screen_height)) return; { unsigned char * loc = screen_ptr + ((y * screen_width*2 + x*2 )); if (color){ *loc =0xff;*(loc+1)=0xff; }else{ *loc = 0x0;*(loc+1)=0x0; } /* short mask = masktab[(x&7)]; unsigned char * loc = screen_ptr + ((y * screen_width + x )>>3); if (color) *loc |= mask; else *loc &= ~mask; */ }}/* Abrash's take on the simplest Bresenham line-drawing algorithm. * * This isn't especially efficient, as we aren't combining the bit-mask * logic and addresses with the line drawing code, never mind higher * level optimizations like run-length slicing, etc. * */static inline void draw_xish_line(short x, short y, short dx, short dy, short xdir){ short dyX2=dy+dy; short dyX2mdxX2=dyX2-(dx+dx); short error=dyX2-dx; setpixel(x, y, Color); while (dx--) { if (error >= 0) { y++; error += dyX2mdxX2; } else { error += dyX2; } x += xdir; setpixel(x,y,Color); }}static inline void draw_yish_line(short x, short y, short dx, short dy,short xdir){ short dxX2=dx + dx; short dxX2mdyX2=dxX2-(dy+dy); short error=dxX2-dy; setpixel(x, y, Color); while (dy--) { if (error >= 0) { x+= xdir; error += dxX2mdyX2; } else { error += dxX2; } y++; setpixel(x,y, Color); }}void line(short x1, short y1, short x2, short y2){ short dx,dy; if ( y1 > y2) { short t = y1; y1 = y2; y2 = t; t = x1; x1 = x2; x2 = t; } dx = x2-x1; dy = y2-y1; if (dx > 0) { if (dx > dy) draw_xish_line(x1, y1, dx, dy, 1); else draw_yish_line(x1, y1, dx, dy, 1); } else { dx = -dx; if (dx > dy) draw_xish_line(x1, y1, dx, dy, -1); else draw_yish_line(x1, y1, dx, dy, -1); } }/* One of Abrash's ellipse algorithms */void ellipse(short x, short y, short a, short b){ short wx, wy; short thresh; short asq = a * a; short bsq = b * b; short xa, ya; setpixel(x, y+b, Color); setpixel(x, y-b, Color); wx = 0; wy = b; xa = 0; ya = asq * 2 * b; thresh = asq / 4 - asq * b; for (;;) { thresh += xa + bsq; if (thresh >= 0) { ya -= asq * 2; thresh -= ya; wy--; } xa += bsq * 2; wx++; if (xa >= ya) break; setpixel(x+wx, y-wy, Color); setpixel(x-wx, y-wy, Color); setpixel(x+wx, y+wy, Color); setpixel(x-wx, y+wy, Color); } setpixel(x+a, y, Color); setpixel(x-a, y, Color); wx = a; wy = 0; xa = (bsq * a) << 1; ya = 0; thresh = (bsq >> 2) - bsq * a; for (;;) { thresh += ya + asq; if (thresh >= 0) { xa -= bsq + bsq; thresh = thresh - xa; wx--; } ya += asq + asq; wy++; if (ya > xa) break; setpixel(x+wx, y-wy, Color); setpixel(x-wx, y-wy, Color); setpixel(x+wx, y+wy, Color); setpixel(x-wx, y+wy, Color); }}inline void h_line(int x1,int x2,int y){ static short ftab[]={0xff,0x7f,0x3f,0x1f,0x0f,0x7,0x3,0x1}; static short btab[]={0x0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe}; short count; count=(x2-x1)>>3; if(count>1) { unsigned char *loc; loc=screen_ptr+((y*screen_width+x1)>>3); if(Color) { *(loc)|=ftab[x1&7]; memset(loc+1,0xff,count-1); *(loc+count)|= ftab[7-(x2&7)]; } else { *loc &=btab[x1&7]; memset(loc+1,0,count-1); *(loc+count)&=ftab[(x2&7)+1]; } } else line(x1, y, x2, y); }/* Composites */void rectangle(short x1, short y1, short x2, short y2){ line(x1, y1, x2, y1); line(x2, y1, x2, y2); line(x2, y2, x1, y2); line(x1, y2, x1, y1);}void bar(short x1,short y1,short x2,short y2){ for(;y1<y2;y1++) h_line(x1,x2,y1);}inline void clip_screen(short in_x, short in_y, short in_w, short in_h, short *out_x, short *out_y, short *out_w, short *out_h) { short swp; if (in_w < 0) { in_x += in_w; in_w = -in_w; } if (in_h < 0) { in_y += in_h; in_h = -in_h; } if (in_x < 0) { in_w -= in_x;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -