?? t9.c
字號:
/*-----------------------------------------------------------------------------------*/
/* --- 名稱: T9拼音輸入法 --- */
/* --- 設(shè)計: 馬偉宇(puma)--- */
/* --- 版本: V1.0 --- */
/* --- Email: puma810719@yahoo.com.cn --- */
/* --- 完成時間: 2005.4.2 --- */
/* --- 改動時間:2005.4.4 增加小鍵盤輸入,增加操作提示 --- */
/* --- 版權(quán): 可以隨意使用和改動,但必需注明原作者 --- */
/*-----------------------------------------------------------------------------------*/
#include<graphics.h>
#include<io.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<e:\tt9\index.c>
/*由于個人編譯器問題,使用前,請將index.c的路徑改成你所在目錄的路徑或者改成默認路徑 */
/*>>>>>>>移植單片機中:<graphics.h><io.h><stdlib.h><conio.h>頭文件去掉<<<<<<<<<*/
/*------------------------------------------------------------------------------------*/
/* ---程序中調(diào)用到的所有子函數(shù)--- */
/*------------------------------------------------------------------------------------*/
void initial();
void st_display();
void logo_display();
void error_display();
void output_hz();
void output_other();
int check_return();
void cancel_data();
void cancel_data1();
void cancel_data2();
void blueline();
unsigned char *show_hz_clue();
void get_hz_data();
void get_hz_index();
void show_other_clue();
void get_other_data();
void enter_r();
void input_work();
/*-------------------------------------------------------------------------------------*/
/* void initial() */
/* ---初始化子函數(shù)--- */
/* ---入口:無;返回:無--- */
/* ---功能:初始化圖形和邊框--- */
/*-------------------------------------------------------------------------------------*/
void initial()
{
int i;
int driver=DETECT,mode;
/*屏幕初始化*/
initgraph(&driver,&mode,"");
setcolor(9);
/*畫顯示的框和線*/
bar(100,100,536,255);
for(i=0;i<5;i++)
{
line(100,150+i,536,150+i);
}
line(100,101,175,101);
line(100,101,100,120);
line(100,120,175,120);
line(175,101,175,120);
printf("Hello Puma! \n");
printf("please input: 5 3 5 0 2 1 3 1 5 0 4 6 r r r r w w 1\n");
for(i=0;i<20;i++)printf("\n");
printf(">>> / or Q-up; * or W-down; - or R-input change; <<<\n");
printf(">>> 7-tuv; 8-wxyz; 9-cancel or back; <<<\n");
printf(">>> 4-jkl; 5-mno; 6-pqrs; <<<\n");
printf(">>> 1-abc; 2-def; 3-ghi; <<<\n");
printf(">>> 0-enter; <<<\n");
}
/*--------------------------------------------------------------------------------------*/
/* void st_display(unsigned char (*p1)[2]) */
/* ---輸入切換顯示子函數(shù)--- */
/* ---入口:無 ;返回:無--- */
/* ---功能:顯示“拼音輸入:”--- */
/*--------------------------------------------------------------------------------------*/
void st_display(unsigned char (*p1)[2])
{
int temp_1;
for(temp_1=0;temp_1<5;temp_1++)
{
output_hz(temp_1*16+103,103,*(*(p1+temp_1)+0),*(*(p1+temp_1)+1),9); /* ==調(diào)用 漢字輸出子函數(shù)== */
}
}
/*--------------------------------------------------------------------------------------*/
/* void logo_display() */
/* ---logo顯示子函數(shù)--- */
/* ---入口:無 ;返回:無--- */
/* ---功能:顯示“拼音輸入:”--- */
/*--------------------------------------------------------------------------------------*/
void logo_display()
{
int temp_1;
char logo[4]={15,20,12,0};
for(temp_1=0;temp_1<4;temp_1++)
{
output_other(temp_1*8+280,80,logo[temp_1],9,2); /* ==調(diào)用 其它輸出子函數(shù)== */
} /* PUMA */
}
/*--------------------------------------------------------------------------------------*/
/* void error_display() */
/* ---出錯顯示子函數(shù)--- */
/* ---入口:無 ;返回:無--- */
/* ---功能:顯示“error!please enter 9!”--- */
/*--------------------------------------------------------------------------------------*/
void error_display()
{
int temp_3;
char error[5]={4,17,17,14,17};
char warn1[6]={15,11,4,0,18,4};
char warn2[5]={4,13,19,4,17};
for(temp_3=0;temp_3<5;temp_3++)
{
output_other(temp_3*8+200,50,error[temp_3],44,1); /* error */
}
output_other(240,50,16,44,4); /* ! */
for(temp_3=0;temp_3<6;temp_3++)
{
output_other(temp_3*8+250,50,warn1[temp_3],44,1); /* please */
}
output_other(298,50,0,44,4);
for(temp_3=0;temp_3<5;temp_3++)
{
output_other(temp_3*8+306,50,warn2[temp_3],44,1); /* enter */
}
output_other(352,50,9,44,3); /* 9 */
output_other(360,50,16,44,4); /* ! */
}
/*---------------------------------------------------------------------------------------*/
/* void output_hz(int x_point,int y_point,int H,int L,int color) */
/* */
/* ---漢字輸出子函數(shù)--- */
/* ---入口:x_point=屏幕X軸顯示點,y_point=屏幕Y軸顯示點,--- */
/* --- num_h=字庫X軸數(shù)字,num_l=字庫Y軸數(shù)字,color=字體顏色;返回:無--- */
/* ---功能:在屏幕上顯示出漢字,根據(jù)num_h,num_l確定字模位置,在屏幕x,y上顯示出來--- */
/*---------------------------------------------------------------------------------------*/
void output_hz(int x_point,int y_point,int H,int L,int color)
{
char buffer[32];
long int offset;
int t1,t2,t3;
FILE *fp;
if((fp=fopen("hzk16","rb"))==NULL) /*打開文件出錯提示。"hzk16" "rb"--"打開的文件" "只讀二進制數(shù)據(jù)"*/
{
printf("Can't open hzk16,please addit!");
getch();
closegraph();
exit(0);
}
offset=(94*(H-1)+(L-1))*32L; /*算偏移量,具體公式可查HZK16的定位算法*/
fseek(fp,offset,0); /*文件定位 fseek(文件類型指針,偏移量,起始點)起始點:0 文件開始;1 當前位置;2 文件末尾*/
fread(buffer,32,1,fp); /*讀文件 fread(buffer,size,count,fp) count:要讀多少個size字節(jié)數(shù)據(jù) */
/* >>>>>>>移植單片機中:需修改fseek(),fread()并添加到HZK16去取字模數(shù)據(jù)的程序,然后存到buffer[32]中<<<<<<<<*/
for(t1=0;t1<16;t1++) /*一個漢字16*16=256點,需要32個字節(jié)保存(32*8=256)*/
{
for(t2=0;t2<2;t2++) /* 1 2 */
{ /* 3 4 */
for(t3=0;t3<8;t3++) /* ... ... */
{ /* 字模內(nèi)二進制對應(yīng)的排列順序*/
if(((buffer[t1*2+t2]>>(7-t3))&0x1)!=NULL) /*判斷當前字模的二進制是否為 “1”,是,則打印出點陣*/
{
putpixel(x_point+8*t2+t3,y_point+t1,color); /* 送往打印點陣函數(shù)putpixel(x點,y點,顏色),打印順序和字模順序一樣 */
} /*==調(diào)用 在圖形上顯示點的子函數(shù)(頭文件中)==*/
}
} /* >>>>>>>移植單片機中:修改所有putpixel()子程序為LCD上顯示點的程序<<<<<<<<*/
}
fclose(fp);
}
/*-------------------------------------------------------------------------------------------*/
/* void output_other(int x_point,int y_point,int number,int color,int change) */
/* */
/* ---其它輸出子函數(shù)--- */
/* ---入口:x_point,y_point=圖形X,Y軸坐標,number=字母x軸坐標,--- */
/* --- color=字體顏色,change=選擇當前輸出類型;返回:無--- */
/* ---功能: 通過number找到字模(大寫字母,小寫字母,數(shù)字,標點符號),在圖形的XY軸上顯示--- */
/*-------------------------------------------------------------------------------------------*/
void output_other(int x_point,int y_point,int number,int color,int change)
{
int t1,t2;
for(t1=0;t1<16;t1++)
{
for(t2=0;t2<8;t2++)
{
if(change==1) /*change=1;輸出小寫字母*/
{
if(((small_en[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==調(diào)用 在圖形上顯示點的子函數(shù)(頭文件中)==*/
}
}
if(change==2) /*change=2;輸出大寫字母*/
{
if(((large_en[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==調(diào)用 在圖形上顯示點的子函數(shù)(頭文件中)==*/
}
}
if(change==3) /*change=3;輸出數(shù)字*/
{
if(((num[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==調(diào)用 在圖形上顯示點的子函數(shù)(頭文件中)==*/
}
}
if(change==4) /*change=4;輸出標點符號*/
{
if(((sign[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==調(diào)用 在圖形上顯示點的子函數(shù)(頭文件中)==*/
}
}
}
}
}
/*-------------------------------------------------------------------------------------*/
/* int check_return(char v2) */
/* */
/* ---鍵盤輸入數(shù)據(jù)判斷并返回命令字子函數(shù)--- */
/* ---入口:當前鍵盤按下的字符;返回:根據(jù)字符得到的命令字--- */
/* ---功能:判斷鍵盤按下的字符,返回一個該字符對應(yīng)的命令字--- */
/*-------------------------------------------------------------------------------------*/
int check_return(char v2)
{
int re_num;
switch(v2)
{ /*按鍵功能*/
case '1':re_num=1;break; /*abc*/
case '2':re_num=2;break; /*def*/
case '3':re_num=3;break; /*ghi*/
case '4':re_num=4;break; /*jkl*/
case '5':re_num=5;break; /*mno*/
case '6':re_num=6;break; /*pqrs*/
case '7':re_num=7;break; /*tuv*/
case '8':re_num=8;break; /*wxyz*/
case '9':re_num=9;break; /*取消退格*/
case '0':re_num=0;break; /*確認*/
case 'q':re_num=10;break; /*上翻頁*/
case '/':re_num=10;break; /*上翻頁*/
case 'w':re_num=11;break; /*下翻頁*/
case '*':re_num=11;break; /*下翻頁*/
case 'r':re_num=12;break; /*輸入狀態(tài)切換*/
case '-':re_num=12;break; /*輸入狀態(tài)切換*/
case 'x':closegraph();exit(0);
default:re_num=20;break; /*其它輸入無效*/
}
return(re_num);
}
/*------------------------------------------------------------------------------------*/
/* void cancel_data() */
/* ---退格子函數(shù)--- */
/* ---入口:無;返回:無--- */
/* ---功能:將輸入框內(nèi)的文字退格取消,一次退一個字母寬度(8*16)--- */
/*------------------------------------------------------------------------------------*/
void cancel_data()
{
m=m-8;
if(m<0)
{
m=416;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -