#include <graphics.h> #include <dos.h>
int InitMouse() {_AX=0;__int__(0x33);return(_AX);} void ShowMouse() {_AX=1;__int__(0x33);} void HideMouse() {_AX=2;__int__(0x33);} void SetMousePos(int x,int y) {_AX=4;_CX=x;_DX=y;__int__(0x33);}
typedef struct { int x,y,key; } MOUSESTRUCT;
void glreadmouse(MOUSESTRUCT *m) { _AX=3;__int__(0x33); m->x=_CX; m->y=_DX; m->key=_BX; }
void glfill(int x,int minx,int maxx, int y,int miny,int maxy, int color,int edgecolor) { #define SIZE 10 static int stack[SIZE][2],size=SIZE; int sp=0; #define PUSH(x,y){ if(!full()) stack[sp][0]=x,stack[sp][1]=y,sp++; } #define POP(x,y){ if(!empty()) sp--,x=stack[sp][0],y=stack[sp][1]; } #define empty() (sp<=0) #define full() (sp>=size) int xx,c,cu,cd; PUSH(x,y); while(!empty()) { char sd=1,su=1,eu=1,ed=1; POP(x,y); if(y<miny||y>maxy) continue; if(y==miny) eu=0; else if(y==maxy) ed=0; while(x>=minx) { c=getpixel(x,y); if(c==edgecolor) break; x--; } for(xx=x+1;xx<=maxx;xx++) { c=getpixel(xx,y); if(c==edgecolor) break; else putpixel(xx,y,color); cu=getpixel(xx,y-1); cd=getpixel(xx,y+1); if(cu!=color&&cu!=edgecolor&&eu){ if(su) PUSH(xx,y-1); su=0;} else su=1; if(cd!=color&&cd!=edgecolor&&ed){ if(sd) PUSH(xx,y+1); sd=0;} else sd=1; } } }
int color=9;
void gldraw(MOUSESTRUCT new) { static MOUSESTRUCT old={-1,-1,-1}; if(new.key==1) { if(old.x==-1&&old.y==-1) line(new.x,new.y,new.x,new.y); else line(old.x,old.y,new.x,new.y); old=new; } else if(new.key==2) glfill(new.x,0,639,new.y,0,479,color,color); else old.x=old.y=-1; }
main() { int gdriver=VGA,gmode=VGAHI; if(InitMouse()==0) { printf("\nmouse not install!\n");exit();} initgraph(&gdriver,&gmode,"d:\\tc"); outtextxy(270,370,"glvenlan"); while(1) { static MOUSESTRUCT now; if(kbhit()) { char c=getch(); if(c==0x1b) break; if(c==' ') cleardevice(); else if(c>='1'&&c<='9') color=c&0xf; } setcolor(color); ShowMouse(); delay(1000); HideMouse(); glreadmouse(&now); gldraw(now); } closegraph(); }