<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            DOS界面下通用圖形編輯軟件的設計

            時間:2024-06-26 21:17:18 計算機畢業論文 我要投稿
            • 相關推薦

            DOS界面下通用圖形編輯軟件的設計


               摘 要 該文介紹了一種建立在DOS界面下生成圖素文件的通用圖形編輯程序的設計方法。
            目前用作DDC的PC總線工控機(IPC)大部分工作在DOS界面上,而DOS不具有像Windows那樣美觀方便的圖形用戶接口(GUI)。生成工藝流程圖等復雜圖形若用程序設計語言直接編程需花費大量精力和代碼,且不易修改。設計出數據文件小,占用內存少的圖形編輯軟件是控制界的一個研究課題。這里介紹一種生成圖素數據文件的通用圖形編輯軟件的設計方法。
            一、數據結構與數據文件格式
            由于所有的操作都基本建立在圖素的基礎之上,故數據結構也以圖素為中心。以下以圓、直線、矩形、字符串為例,其它圖素類似。
            1.定義所需圖素
            struct circle /*定義圓 */
            {
            int x,y,r; /* 圓心,半徑 */
            char linecolor,linestyle; /* 圓外圍線的顏色,線型 */
            char fillcolor,fillstyle; /* 填充顏色,模式 */
            };
            struct line /* 定義直線 */
            {
            int x1,y1;
            int x2,y2;
            char linecolor,linestyle,linethick; /* 線顏色,模式,粗細 */
            };
            struct box /* 定義矩形 */
            {
            int x1,y1;
            int x2,y2;
            char linecolor,linestyle;
            char fillcolor,fillstyle;
            };
            struct string /* 定義字符串 */
            {
            int x,y;
            char str[10]
            char backcolor,dir;
            char str-color,str-style;
            };
            .
            . /* 定義其它圖素 */
            .
            2.將各圖素置于一條鏈表之中
            typedef struct tagElementList
            {
            char ElementType; /* 標識元素類別 */
            int ElementID; /* 元素標識符,在接口中用來控制其屬性 */
            union tagElement {
            struct circle circle;
            struct box box;
            struct string string;
            struct line line;
            .
            . /* 可在此說明其它元素 */
            .
            }Element;
            struct tagElementList *next;
            }ElementList;
            利用這種數據結構可在內存中形成一個圖素鏈表,所有操作都可以此鏈表為基礎。
            3.定義幾個指針,以備各種操作
            ElementList *List-head. *List-end,*List-temp, *List-here;
            4.定義一個全局變量,記錄圖素個數
            static int Elementcount=0;
            圖形文件格式為:第一字節(char),表示整個圖形的背景顏色;接下來一個字(word),對應于Elementcount,表示圖素個數;后面是內存鏈表中每個圖素的屬性值。
            二、圖形編輯功能的實現
            本軟件包含的圖形編輯功能主要有:作圖、修改、移動、刪除、復制,下面僅舉幾例說明實現的方法。
            1.作圖
            以圓為例,其它圖形類似。
            drawcircle()
            {
            int i;
            char s[20],c;
            int cx,cy,cr;
            int cls,clc,cfc,cfs;
            movecursor(); /* 移動光標,確定圓心 */
            cx=cursor-x;
            cy=cursor-y;
            movecursor(); /* 確定半徑 */
            cr=(int)sqrt((cursor-x-cx)*(cursor-x-cx)+(cursor-y-cy)*(cursor-y-cy);
            setcolor(WHITE);
            circle (cx,cy,cr); /* 畫圓 */
            cls=selectlinestyle();
            clc=selectcolor ("select-line-color");
            setcolor(clc);
            for(i=0;i<=cls;i++)
            circle(cx,cy,cr-i);
            cfs=selectfillstyle();
            cfc=selectcolor("set-fill-color");
            setfillstyle(cfs.cfc);
            floodfill(cx,cy,clc); /* 填充 */
            temp(ElementList *) malloc(sizeof(ElementList));
            temp->ElementType= 'c';
            temp->Element.circle.x=cx;
            temp->Element.circle.y=cy;
            temp->Element.circle.r=cr;
            temp->Element.circle.lcolor=clc;
            temp->Element.circle.lstyle=cls;
            temp->Element.circle.fcolor=cfc;
            temp->Element.circle.fstyle=cfs;
            addtolist(temp); /* 將圖素加入圖素鏈表 */
            }
            其中 addtolist ()可以如下實現:
            addtolist (ElementList *Etemp)
            {
            if(List-head==NULL)
            {
            List-head=Etemp;
            List-end=Etemp;
            }
            else
            { List-end->next=Etemp;
            List-end=Etemp;
            Etemp->next=NULL;
            }
            Elementcount++;
            }
            2.圖形的移動、刪除、復制功能
            以移動為例,首先用箭頭鍵或鼠標框取要移動的區域,區域矩形的左上,右下坐標分別為(block-x1,block-y1),(block-x2,block-y2),然后移動標識矩形到要到達的地方,確定。這樣標識矩形的終止位置與初始位置存在一個偏差,水平與垂直偏差分別為dl-x,dl-y。
            接下來搜索內存圖素鏈表,確定每個圖素的外接矩形,判斷外接矩形是否在初始標識矩形內,若在,則將該圖素的坐標屬性值改變dl-x,dl-y。清除圖形區,根據新的圖素鏈表作圖。
            圖形的刪除功能類似,只需將符合條件的圖素從鏈表中清除,再修改Elementcount值即可。
            拷貝圖形則只需將符合條件的圖素備份一個結點,修改結點的坐標屬性值,再將該結點加入鏈表,相應增加Elementcount的值。
            以下為移動圖形的代碼。
            fnMove ()
            {
            Rect rect; /* 定義的矩形 */
            int i;
            selectblock (); /* 選擇要移動的塊 */
            moveblock (); /* 移動塊 */
            List-temp=List-head;
            for (i=0;i<Elementcount; i++)
            {
            getrect (&rect, List-temp); /* 計算List-temp所指圖素的外接矩形 */
            if (inblock(rect.x1,rect.x2,rect.y1.rect.y2))
            /* 判斷外接矩形是否在所選塊內 */
            change (List-temp, dl-x,dl-y);
            /* 改變圖素的坐標屬性 */
            List-temp=List-temp->next;
            }
            clearscreeen (); /* 清除作圖區 */
            drawlink (); /* 依據圖素鏈表畫圖 */
            }
            其中,change ( )可以實現如下。
            change(ElementList *Ctemp, int dl-x,int dl-y)
            {
            switch (Ctemp->ElementType)
            {
            case 'c': Ctemp->Element.circle.x+=dl-x;
            Ctemp->Element.circle.y+=dl-y;
            break;
            case 'b': Ctemp->Element.box.x1+=dl-x;
            Ctemp->Element.box.x2+=dl-x;
            Ctemp->Element.box.y1+=dl-y;
            Ctemp->Element.box.y2+=dl-y;
            break;
            case 'l': Ctemp->Element.line.x1+=dl-x;
            Ctemp->Element.line.y1+=dl-y;
            Ctemp->Element.line.x2+=dl-x;
            Ctemp->Element.line.y2+=dl-y;
            break;
            case 's': Ctemp->Element.string.x+=dl-x;
            Ctemp->Element.string.y+=dl-y;
            break;
            .
            .
            .
            }
            }
            三、文件功能的實現
            存盤時,打開文件,寫入圖形的背景顏色,寫入圖素個數Elementcount,再將內存鏈表中各圖素的屬性值依次寫入文件即可。
            讀盤時,在內存中動態建立圖素鏈表,將文件中的圖素屬性值依次放入鏈表中,再根據背景顏色、圖素屬性值在屏幕上顯示圖形。
            存盤過程實現如下。
            savefile(char * filename)
            {
            FILE *fp;
            int i;
            List-temp=List-head;
            Eid=0;
            if((fp=fopen(filename,"w+b"))==NULL)
            {
            printf ("%s", "Cant't open the file ");
            exit(1);
            }
            fwrite(&back-color, sizeof(char),1,fp);
            fwrite(&Elementcount,sizeof(int),1,fp);
            for(i=0;i<Elementcount;i++)
            { List-temp->ElementID=Eid;
            fwrite(List-temp,sizeof(ElementList),1,fp);
            List-temp=List-temp->next;
            Eid++;
            }
            fclose(fp);
            }
            四、應用程序編程接口
            應用程序編程接口主要功能是讀圖形文件并顯示,對畫面圖素進行動態刷新。這些接口均以函數形式出現,供控制應用程序調用。
            1.draw-chart (char * filename)功能:讀圖形文件,在內存中建立圖素鏈表,顯示圖形。
            2.change-chart(int Element-ID, int how)功能:改變圖素Element-ID的特性,怎樣改變由how決定。該接口能方便地實現圖形的動態刷新。
            3.clear-chart( )功能:釋放圖素鏈表占用的內存。
            4.draw ( char * filename)功能:不建立鏈表,邊讀圖形文件,邊顯示。該函數不占用內存,適用于圖素多、數據文件較大,而又不需動態刷新的圖形畫面顯示。  

            作者:汪建平 陸志才 

            【DOS界面下通用圖形編輯軟件的設計】相關文章:

            DOS用戶界面的設計03-20

            Linux下的GTK圖形界面編程12-04

            淺論軟件界面設計中的色彩運用03-05

            DOS下DSP播音的編程03-03

            在 DOS 下使用Windows *.WAV 文件03-03

            淺談圖形用戶界面的文化傳播影響03-01

            基于Perl的DoS工具設計與實現03-10

            設計界面說-探討設計藝術03-20

            設計工作的界面管理03-19

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看