| 网站首页 | 文秘范文 | 论文中心 | 小品剧本 | 小说 | 藏金阁 | 留言簿 | 汇款帮助 | 客服中心 | FAQ | 电视 | 免费文秘 | 代写 | 
您现在的位置: 中国文秘网 >> 论文中心 >> 计算机类论文 >> 正文 用户登录 新用户注册
→中国文秘网温馨提示:为方便你访问本站,请将本站设为首页或加入收藏夹中(点击加入收藏)。
紧急公告:近来发现有些不法网站复制本站版面进行欺骗,为防止上当,敬请会员记好本站网址或把本站加入收藏夹中。
轻松入会,年卡、点卡任君选择,QQ及电话24小时服务,付款后5分钟开通,在线QQ:87651921 ,客服电话:013923833528,详情见"汇款须知"
DOS界面下通用图形编辑软件的设计          【字体:
DOS界面下通用图形编辑软件的设计
作者:佚名    论文来源:中国文秘网    点击数:2453    更新时间:2006-4-5
将此页收藏到: 网摘中国 | 新浪 | 热门 | Hao6 | 和讯 | 天极 | YouNote | 5Seek | 365Fav | 365key |博采 | 亿友响享 | 狐摘
3万篇免费论文,近200个详细分类,为你的论文写作排忧解难。点击进入  摘 要 该文介绍了一种建立在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)功能:不建立链表,边读图形文件,边显示。该函数不占用内存,适用于图素多、数据文件较大,而又不需动态刷新的图形画面显示。  

作者:汪建平 陆志才 转贴于 中国文秘网 http://www.zgwmw.com
《DOS界面下通用图形编辑软件的设计》来源于中国文秘网,中国最专业的文秘网站,欢迎阅读DOS界面下通用图形编辑软件的设计。
论文录入:中国文秘网    责任编辑:中国文秘网 
  • 上一篇论文:

  • 下一篇论文:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关论文
    在Windows中显示多幅彩色图像…
    Windows NT/2000系统下进程的…
    展OSH体系认证提高安全生产科…
    关于质量(Q)、环境(E)和…
    浅论我国推行OSHMS存在的主要…
    在Windows中显示多幅彩色图像…
    用FDISK重建DOS硬盘主引导记…
    DOS界面下通用图形编辑软件的…
    基于Windows NT平台网站的结…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    sitemap:1 2 3 4 5 6 7 8 9 10 [11] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
    352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480