void DrawList(List thelist) { // traverse the list from last to first.. drawing each object NodeLink currnode; int color; thelist->cursor = thelist->last; scare_mouse(); while (thelist->cursor != NULL) { currnode = thelist->cursor; if (currnode->Object == LINE) { linebres(currnode->obj_data.line.p1.x, currnode->obj_data.line.p1.y, currnode->obj_data.line.p2.x, currnode->obj_data.line.p2.y, currnode->obj_data.line.color); } else { if (currnode->Object == CIRCLE) { circlebres(screen, currnode->obj_data.circle.p1.x, currnode->obj_data.circle.p1.y, currnode->obj_data.circle.radius, currnode->obj_data.circle.color); } else { if (currnode->Object == POLYGON) { color = currnode->obj_data.polygon.color; drawpoly(currnode,color); } else { if (currnode->Object == TEXT) { textout(screen,font,currnode->obj_data.text.data, currnode->obj_data.text.p1.x, currnode->obj_data.text.p1.y, currnode->obj_data.text.color); } } } } thelist->cursor = thelist->cursor->prev; //mode cursor back a node } unscare_mouse(); }
void drawpoly(NodeLink currnode, int color) { PList polylist; polylist = currnode->obj_data.polygon.theplist; polylist->cursor = polylist->first; while (polylist->cursor->next != NULL) { linebres(polylist->cursor->ppoint.x, polylist->cursor->ppoint.y, polylist->cursor->next->ppoint.x, polylist->cursor->next->ppoint.y, color); polylist->cursor = polylist->cursor->next; } linebres(polylist->last->ppoint.x, polylist->last->ppoint.y, polylist->first->ppoint.x, polylist->first->ppoint.y, color); }
void rubberline(List thelist, int color) { int x1, x2, y1, y2; int x3, y3; Line_Type linedata; while (!(mouse_b & 2)) { //quick addin if (mouse_b & 1) { x3 = x1 = mouse_x; y3 = y1 = mouse_y; scare_mouse(); /* draw circle while waiting for mouse release */ while (mouse_b & 1) { x2 = mouse_x; y2 = mouse_y; if (x2 != x3 || y2 != y3) { rrestore(screen);//first time through ii=0 do_line(screen,x1,y1,x2,y2, color, rsave); x3 = x2; y3 = y2; } } rrestore(screen); x2 = mouse_x; y2 = mouse_y; linebres(x1,y1,x2,y2,color); linedata.p1.x = x1; linedata.p1.y = y1; linedata.p2.x = x2; linedata.p2.y = y2; linedata.color = color; linedata.width = 1; AddLine(thelist,linedata); unscare_mouse(); } }// end whileaddin }
int main() { int x1,x2,y1,y2; char clr; int gd=DETECT,gm; void linebres(int,int,int,int,int); printf("Enter the initial coordinate points:"); scanf("%d%d",&x1,&x2); printf("Enter the end coordinate points:"); scanf("%d%d",&y1,&y2); printf("Choose the colour ...valuse from (0-15)"); scanf("%d",&clr); initgraph(&gd,&gm,""); cleardevice(); linebres(x1,y1,x2,y2,clr); getch(); closegraph(); }
void rubberrectangle(List thelist, int color) { int x1, x2, y1, y2; int x3, y3; Poly_Type polydata; PList polylist; polylist = PCreateList(); while (!(mouse_b & 2)) { //quick addin if (mouse_b & 1) { x3 = x1 = mouse_x; y3 = y1 = mouse_y; scare_mouse(); /* draw box while waiting for mouse release */ while (mouse_b & 1) { x2 = mouse_x; y2 = mouse_y; if (x2 != x3 || y2 != y3) { rrestore(screen);//first time through ii=0 if (x1 < x2) { do_line(screen,x1+1,y1,x2-1,y1, color, rsave); do_line(screen,x2,y1+1,x2,y2-1, color, rsave); do_line(screen,x2-1,y2,x1+1,y2, color, rsave); do_line(screen,x1,y2-1,x1,y1+1, color, rsave); } if (x2 < x1) { do_line(screen,x1-1,y1,x2+1,y1, color, rsave); do_line(screen,x2,y1-1,x2,y2+1, color, rsave); do_line(screen,x2+1,y2,x1-1,y2, color, rsave); do_line(screen,x1,y2+1,x1,y1-1, color, rsave); } x3 = x2; y3 = y2; } }/* end while */ rrestore(screen); x2 = mouse_x; y2 = mouse_y; //draw final points linebres(x1,y1,x2,y1,color); linebres(x2,y1,x2,y2,color); linebres(x2,y2,x1,y2,color); linebres(x1,y2,x1,y1,color); //add points to plist PAddNode(polylist,x1,y1); PAddNode(polylist,x2,y1); PAddNode(polylist,x2,y2); PAddNode(polylist,x1,y2); polydata.theplist = polylist; polydata.color = color; polydata.filled = FALSE; polydata.fill_color = 0; polydata.width = 1; AddPolygon(thelist, polydata); polylist = PCreateList(); //leak? unscare_mouse(); } }// end whileaddin }
int rubberpolygon(List thelist, int color) { int x1, x2, y1, y2; int x3, y3; bool firstrun = TRUE; PList polylist; Poly_Type polydata; polylist = PCreateList(); //make a point list while (!(mouse_b & 2)) { if (mouse_b & 1) { if (firstrun){ x3 = x1 = mouse_x; y3 = y1 = mouse_y; PAddNode(polylist,x1,y1); scare_mouse(); } else { x3 = x1 = x2; y3 = y1 = y2; } /* draw line while waiting for mouse release */ while (mouse_b & 1) { x2 = mouse_x; y2 = mouse_y; if (x2 != x3 || y2 != y3) { rrestore(screen);//first time through ii=0 do_line(screen,x1,y1,x2,y2,color, rsave); x3 = x2; y3 = y2; } } /* on m1 release */ rrestore(screen); x2 = mouse_x; // get current xy y2 = mouse_y; linebres(x1,y1,x2,y2,color); PAddNode(polylist,x2,y2); //add second point firstrun = FALSE; } }//while !mouse 2 linebres(polylist->last->ppoint.x,polylist->last->ppoint.y, polylist->first->ppoint.x,polylist->first->ppoint.y,color); //textprintf(screen,font,1,1,color,"%d",polylist->length); polydata.theplist = polylist; polydata.color = color; polydata.filled = FALSE; polydata.fill_color = 0; polydata.width = 1; AddPolygon(thelist, polydata); //DisposePList(polylist);//oops ;) unscare_mouse(); return 0; }