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

📄 facectrl.c

📁 使用tc2的adaptive huffman编码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
#include <alloc.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include "Filedivi.c"

union REGS regs;


/*draw background and window*/
void drawBG()
{
    char pchtitle[]={"Doctor Cheng -- Compression Expert"};
    setbkcolor(0);
    setfillstyle(0,0);
    bar(0,0,640,480);
    setlinestyle(0, 0, 0);
    setfillstyle(1,8);
    bar(105,105,545,385);
    setfillstyle(1,7);
    bar(100,100,540,380);
    setfillstyle(1,1);
    bar(100,100,540,120);
    settextstyle(0,0,1);
    outtextxy(180,106,pchtitle);
}


/*draw the big buttons*/
void drawButtonxy(int x,int y,int icolor,char *pchbutton)
{
    setfillstyle(1,8);
    bar(x+2,y+2,x+100+2,y+35+2);
    setfillstyle(1,icolor);
    bar(x,y,x+100,y+35);
    setcolor(15);
    settextstyle(4,0,1);
    outtextxy(x,y+4,pchbutton);
}


/*draw the selection item*/
void drawselection(int x,int y,int icolor,char *pchselection)
{
    setfillstyle(1,icolor);
    bar(x,y,x+130,y+16);
    setcolor(2);
    setlinestyle(0,0,1);
    rectangle(x,y,x+130,y+16);
    setcolor(0);
    settextstyle(2,0,4);
    outtextxy(x,y+2,pchselection);
}


/*show the status on the right*/
void showstatus(status1 *s1)
{
    char strDec[10],strSign[8][10];
    setcolor(0);
    settextstyle(1,0,1);
    setusercharsize(1,3,1,3);
    switch(s1->iMode)
    {

	case 1:setfillstyle(1,7);       /*clear the zone*/
	       bar(381,141,540,380);
	       outtextxy(410,140,"Coding Mode:");
	       if(s1->iSubmode==1)
	       {
		   outtextxy(420,165,"Encode");
	       }
	       else
		   if(s1->iSubmode==2)
		   {
		       outtextxy(420,165,"Decode");
		   }

	       outtextxy(410,200,"Input Dictionary:");
	       outtextxy(420,220,s1->pchinput);
	       outtextxy(410,260,"Output Dictionary:");
	       outtextxy(420,280,s1->pchoutput);
	       break;
	case 2:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,141,540,380);
	       setusercharsize(2,5,2,5);
	       if(s1->iSuccess==1)
	       {
		   outtextxy(260 ,140,"Success!");
	       }
	       else
	       {
		   outtextxy(260 ,140,"Fail!");
	       }
	       outtextxy(260 ,190,"Original Size:");
	       ultoa(s1->lOSize,strSign[0],10);
	       outtextxy(260,215,strSign[0]);
	       outtextxy(260 ,250,"Compressed Size:");
	       ultoa(s1->lCSize,strSign[1],10);
	       outtextxy(260,275,strSign[1]);
	       outtextxy(260 ,310,"Compression Ratio:");
	       ultoa(s1->lCRatio,strSign[2],10);
	       outtextxy(260,335,strSign[2]);
	       break;
	case 3:setfillstyle(1,7);       /*clear the zone*/
	       bar(381,141,540,380);
	       outtextxy(410,140,"Input Dictionary:");
	       outtextxy(420,160,s1->pchinput);
	       outtextxy(410,190,"Output Dictionary:");
	       outtextxy(420,210,s1->pchoutput);
	       outtextxy(410,240,"Similarity,by size:(%)");
	       ultoa(s1->lRatioSize,strSign[3],10);
	       outtextxy(410,260,strSign[3]);
	       outtextxy(410,290,"Similarity,by byte:(%)");
	       ultoa(s1->lRatioByte,strSign[4],10);
	       outtextxy(410,310,strSign[4]);
	       break;
	case 4:setfillstyle(1,7);       /*clear the zone*/
	       bar(381,141,540,380);
	       switch(s1->iSubmode)
	       {
		   case 1:outtextxy(410,160,"Welcome to use");break;
		   case 2:outtextxy(410,160,"DCCE  Ver 1.0");break;
		   case 3:outtextxy(410,160,"Viky Cheng ");
			  outtextxy(410,180,"@ Hefei Univ of Tech");
			   break;
	       }
	       break;
	case 5:setfillstyle(1,7);       /*clear the zone*/
	       bar(381,141,540,380);
	       outtextxy(260,160,"Thank you for your use!");
	       outtextxy(260,190,"Please click 'confirm' to quit.");
	       break;

	}
}



/*draw the selecting interface 1   */
/*codingmode denote the coding mode:0-encode,1-decode*/
void drawFace1(status1* s1)
{
    switch(s1->iMode)
    {
	case 1:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,140,405,380);
	      drawselection(250,142,14,"       Encode       ");
	      drawselection(250,187,14,"       Decode       ");
	      drawselection(250,232,14,"   Input Dictionary ");
	      drawselection(250,277,14,"  Output Dictionary ");
	      drawselection(250,322,14,"       Go Now!      ");

	      if(s1->iSubmode==1)
	      {
		  drawselection(250,142,10,   "       Encode       ");
	      }
	      else
	      {
		  if(s1->iSubmode==2)
		  {
		      drawselection(250,187,10,   "       Decode       ");
		  }
	      }
	      break;
	case 2:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,140,405,380);
	       break;
	case 3:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,140,405,380);
	      drawselection(250,142,14,"   Input Dictionary ");
	      drawselection(250,187,14,"  Output Dictionary ");
	      drawselection(250,322,14,"       Compare      ");
	      break;
	case 4:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,140,405,380);
	      drawselection(250,142,14,"       To Users     ");
	      drawselection(250,187,14,"        About       ");
	      drawselection(250,232,14,"     The Author     ");
	      break;
	case 5:setfillstyle(1,7);       /*clear the zone*/
	       bar(250,140,405,380);
	      drawselection(250,322,14,"       Confirm      ");
	      break;
	}
}



/*initialize background*/
void InitBG(status1 *s1)
{
    drawBG();
    drawButtonxy(120,132,4,"   Coding  ");
    drawButtonxy(120,177,4,"   Result  ");
    drawButtonxy(120,222,4,"   Differ  ");
    drawButtonxy(120,267,4,"    Help   ");
    drawButtonxy(120,312,4,"    Exit   ");
    drawFace1(s1);
    showstatus(s1);
}

/*mouse initialize*/
int Msinit(int Xlo,int Xhi,int Ylo,int Yhi)
{
    int retcode;
    regs.x.ax=0;
    int86(0x33,&regs,&regs);
    retcode=regs.x.ax;
    if(retcode==0)
    {
	return 0;
    }
    /*set x */
    regs.x.ax=7;
    regs.x.cx=Xlo;
    regs.x.dx=Xhi;
    int86(0x33,&regs,&regs);
    /*set y */
    regs.x.ax=8;
    regs.x.cx=Ylo;
    regs.x.dx=Yhi;
    int86(0x33,&regs,&regs);
    /*set the pix ratio*/
    regs.x.ax=15;
    regs.x.cx=4;
    regs.x.dx=4;
    int86(0x33,&regs,&regs);
    return retcode;
}


/*get the mouse status*/
void Msget( int *px,int *py,int *button)
{
    regs.x.ax=3;
    int86(0x33,&regs,&regs);
    *px=regs.x.cx;
    *py=regs.x.dx;
    *button=regs.x.bx;
}


/*draw the cursor*/
void cursor(int x,int y)
{
    setcolor(15);
    setlinestyle(0,0,2);
    line(x,y,x+10,y+10);
    line(x,y,x+6,y+1);
    line(x,y,x+1,y+6);
}


/*read the mouse status*/
void Msread(int *x,int *y,int *button)
{
    static int but0=-1;
    static int x0=-1,y0=-1;
    do
    {
	 Msget(x,y,button);
    }while(*x==x0&&*y==y0&&*button==but0);
    x0=*x;y0=*y;but0=*button;
}


/*Universal Function to determine whether the mouse is on button*/
int isButton(int x,int y)
{
    int i;
    for(i=1;i<=5;i++)
    {
	if(x>120&&x<225&&y>132+(i-1)*45&&y<132+(i-1)*45+35)
	{
	    return i;
	}
    }
    return 0;
}


/*draw figure when moving on a button*/
void DrawOnMove(int iButton)
{
    char chButton[12];
    switch(iButton)
    {
	case 1:strcpy(chButton,"   Coding  ");break;
	case 2:strcpy(chButton,"   Result  ");break;
	case 3:strcpy(chButton,"   Differ  ");break;
	case 4:strcpy(chButton,"    Help   ");break;
	case 5:strcpy(chButton,"    Exit   ");break;
    }
    drawButtonxy(120,132+(iButton-1)*45,12,chButton);
}


/*draw pic when clicking a button*/
void DrawOnClick(int iButton)
{
    char chButton[12];
    switch(iButton)
    {
	case 1:strcpy(chButton,"   Coding  ");break;
	case 2:strcpy(chButton,"   Result  ");break;
	case 3:strcpy(chButton,"   Differ  ");break;
	case 4:strcpy(chButton,"    Help   ");break;
	case 5:strcpy(chButton,"    Exit   ");break;
    }

    setfillstyle(1,7);
    bar(120,132+(iButton-1)*45,220+2,132+(iButton-1)*45+35+2);
    setfillstyle(1,12);
    bar(120+2,132+(iButton-1)*45+2,220+2,132+(iButton-1)*45+35+2);
    setcolor(15);
    settextstyle(4,0,1);
    outtextxy(120,132+(iButton-1)*45+2+4,chButton);
}


/*Universal Function to determine whether the mouse is on selection*/
int isSel(int x,int y)
{

    int i;
    for(i=1;i<=5;i++)
    {
	if(x>250&&x<385&&y>142+(i-1)*45&&y<142+(i-1)*45+16)
	{
	    return i;
	}
    }
    return 0;
}


/*draw figure when moving on a button*/
void DrawOnSel(int iMode,int iButton)
{
    switch(iMode)
    {
	case 1:
	       switch(iButton)
	       {
		   case 1:drawselection(250,142,10,"       Encode       ");break;
		   case 2:drawselection(250,187,10,"       Decode       ");break;

⌨️ 快捷键说明

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