#include "iGraphics.h" #include #include #include using namespace std; #define screenwidth 1400 #define screenheight 700 char promptMsg[][200]={"prompt//PENTOOL.bmp","prompt//ERASERTOOL.bmp","prompt//CIRCLETOOL.bmp" ,"prompt//RECTTOOL.bmp","prompt//LINETOOL.bmp","prompt//GRABTOOL.bmp" ,"prompt//SAVEMSG.bmp","prompt//NOTSAVEMSG.bmp","prompt//TEXTBOXTOOL.bmp" ,"prompt//LOADMSG.bmp","prompt//SAVEINS.bmp"}; char fontarray[][200]={"GLUT_BITMAP_9_BY_15","GLUT_BITMAP_8_BY_13", "GLUT_BITMAP_TIMES_ROMAN_10","GLUT_BITMAP_TIMES_ROMAN_24", "GLUT_BITMAP_HELVETICA_10","GLUT_BITMAP_HELVETICA_12", "GLUT_BITMAP_HELVETICA_18"}; char opening[200][200]={ "OPENING\\open (1).bmp", "OPENING\\open (2).bmp", "OPENING\\open (3).bmp", "OPENING\\open (4).bmp", "OPENING\\open (5).bmp", "OPENING\\open (6).bmp", "OPENING\\open (7).bmp", "OPENING\\open (8).bmp", "OPENING\\open (9).bmp", "OPENING\\open (10).bmp", "OPENING\\open (11).bmp", "OPENING\\open (12).bmp", "OPENING\\open (13).bmp", "OPENING\\open (14).bmp", "OPENING\\open (15).bmp", "OPENING\\open (16).bmp", "OPENING\\open (17).bmp", "OPENING\\open (18).bmp", "OPENING\\open (19).bmp", "OPENING\\open (20).bmp", "OPENING\\open (21).bmp", "OPENING\\open (22).bmp", "OPENING\\open (23).bmp", "OPENING\\open (24).bmp", "OPENING\\open (25).bmp", "OPENING\\open (26).bmp", "OPENING\\open (27).bmp", "OPENING\\open (28).bmp", "OPENING\\open (29).bmp", "OPENING\\open (30).bmp", "OPENING\\open (31).bmp", "OPENING\\open (32).bmp", "OPENING\\open (33).bmp", "OPENING\\open (34).bmp", "OPENING\\open (35).bmp", "OPENING\\open (36).bmp", "OPENING\\open (37).bmp", "OPENING\\open (38).bmp", "OPENING\\open (39).bmp", "OPENING\\open (40).bmp", "OPENING\\open (41).bmp", "OPENING\\open (42).bmp", "OPENING\\open (43).bmp", "OPENING\\open (44).bmp", "OPENING\\open (45).bmp", "OPENING\\open (46).bmp", "OPENING\\open (47).bmp", "OPENING\\open (48).bmp", "OPENING\\open (49).bmp", "OPENING\\open (50).bmp", "OPENING\\open (51).bmp", "OPENING\\open (52).bmp", "OPENING\\open (53).bmp", "OPENING\\open (54).bmp", "OPENING\\open (55).bmp", "OPENING\\open (56).bmp", "OPENING\\open (57).bmp", "OPENING\\open (58).bmp", "OPENING\\open (59).bmp", "OPENING\\open (60).bmp", "OPENING\\open (61).bmp", "OPENING\\open (62).bmp", "OPENING\\open (63).bmp", "OPENING\\open (64).bmp", "OPENING\\open (65).bmp", "OPENING\\open (66).bmp", "OPENING\\open (67).bmp", "OPENING\\open (68).bmp", "OPENING\\open (69).bmp", "OPENING\\open (70).bmp", "OPENING\\open (71).bmp", "OPENING\\open (72).bmp", "OPENING\\open (73).bmp", "OPENING\\open (74).bmp", "OPENING\\open (75).bmp", "OPENING\\open (76).bmp", "OPENING\\open (77).bmp", "OPENING\\open (78).bmp", "OPENING\\open (79).bmp", "OPENING\\open (80).bmp", "OPENING\\open (81).bmp", "OPENING\\open (82).bmp", "OPENING\\open (83).bmp", "OPENING\\open (84).bmp", "OPENING\\open (85).bmp", "OPENING\\open (86).bmp", "OPENING\\open (87).bmp", "OPENING\\open (88).bmp", "OPENING\\open (89).bmp", "OPENING\\open (90).bmp", "OPENING\\open (91).bmp", "OPENING\\open (92).bmp", "OPENING\\open (93).bmp", "OPENING\\open (94).bmp", "OPENING\\open (95).bmp", "OPENING\\open (96).bmp", "OPENING\\open (97).bmp", "OPENING\\open (98).bmp", "OPENING\\open (99).bmp", "OPENING\\open (100).bmp", "OPENING\\open (101).bmp", "OPENING\\open (102).bmp", "OPENING\\open (103).bmp", "OPENING\\open (104).bmp", "OPENING\\open (105).bmp", "OPENING\\open (106).bmp", "OPENING\\open (107).bmp", "OPENING\\open (108).bmp", "OPENING\\open (109).bmp", "OPENING\\open (110).bmp", "OPENING\\open (111).bmp", "OPENING\\open (112).bmp", "OPENING\\open (113).bmp", "OPENING\\open (114).bmp", "OPENING\\open (115).bmp", "OPENING\\open (116).bmp", "OPENING\\open (117).bmp", "OPENING\\open (118).bmp", "OPENING\\open (119).bmp", "OPENING\\open (120).bmp", "OPENING\\open (121).bmp", "OPENING\\open (122).bmp", "OPENING\\open (123).bmp", "OPENING\\open (124).bmp", "OPENING\\open (125).bmp", "OPENING\\open (126).bmp", "OPENING\\open (127).bmp", "OPENING\\open (128).bmp", "OPENING\\open (129).bmp", "OPENING\\open (130).bmp", "OPENING\\open (131).bmp", "OPENING\\open (132).bmp", "OPENING\\open (133).bmp", "OPENING\\open (134).bmp", "OPENING\\open (135).bmp", "OPENING\\open (136).bmp", "OPENING\\open (137).bmp", "OPENING\\open (138).bmp", "OPENING\\open (139).bmp", "OPENING\\open (140).bmp", "OPENING\\open (141).bmp", "OPENING\\open (142).bmp", "OPENING\\open (143).bmp", "OPENING\\open (144).bmp", "OPENING\\open (145).bmp", "OPENING\\open (146).bmp", "OPENING\\open (147).bmp", "OPENING\\open (148).bmp", "OPENING\\open (149).bmp", "OPENING\\open (150).bmp" } ; char HOMEPAGE[200][200]={ "HOMEPAGE\\H (1).bmp", "HOMEPAGE\\H (2).bmp", "HOMEPAGE\\H (3).bmp", "HOMEPAGE\\H (4).bmp", "HOMEPAGE\\H (5).bmp", "HOMEPAGE\\H (6).bmp", "HOMEPAGE\\H (7).bmp", "HOMEPAGE\\H (8).bmp", "HOMEPAGE\\H (9).bmp", "HOMEPAGE\\H (10).bmp", "HOMEPAGE\\H (11).bmp", "HOMEPAGE\\H (12).bmp", "HOMEPAGE\\H (13).bmp", "HOMEPAGE\\H (14).bmp", "HOMEPAGE\\H (15).bmp", "HOMEPAGE\\H (16).bmp", "HOMEPAGE\\H (17).bmp", "HOMEPAGE\\H (18).bmp", "HOMEPAGE\\H (19).bmp", "HOMEPAGE\\H (20).bmp", "HOMEPAGE\\H (21).bmp", "HOMEPAGE\\H (22).bmp", "HOMEPAGE\\H (23).bmp", "HOMEPAGE\\H (24).bmp", "HOMEPAGE\\H (25).bmp", "HOMEPAGE\\H (26).bmp", "HOMEPAGE\\H (27).bmp", "HOMEPAGE\\H (28).bmp", "HOMEPAGE\\H (29).bmp", "HOMEPAGE\\H (30).bmp", "HOMEPAGE\\H (31).bmp", "HOMEPAGE\\H (32).bmp", "HOMEPAGE\\H (33).bmp", "HOMEPAGE\\H (34).bmp", "HOMEPAGE\\H (35).bmp", "HOMEPAGE\\H (36).bmp", "HOMEPAGE\\H (37).bmp", "HOMEPAGE\\H (38).bmp", "HOMEPAGE\\H (39).bmp", "HOMEPAGE\\H (40).bmp", "HOMEPAGE\\H (41).bmp", "HOMEPAGE\\H (42).bmp", "HOMEPAGE\\H (43).bmp", "HOMEPAGE\\H (44).bmp", "HOMEPAGE\\H (45).bmp", "HOMEPAGE\\H (46).bmp", "HOMEPAGE\\H (47).bmp", "HOMEPAGE\\H (48).bmp", "HOMEPAGE\\H (49).bmp", "HOMEPAGE\\H (50).bmp", "HOMEPAGE\\H (51).bmp", "HOMEPAGE\\H (52).bmp", "HOMEPAGE\\H (53).bmp", "HOMEPAGE\\H (54).bmp", "HOMEPAGE\\H (55).bmp", "HOMEPAGE\\H (56).bmp", "HOMEPAGE\\H (57).bmp", "HOMEPAGE\\H (58).bmp", "HOMEPAGE\\H (59).bmp", "HOMEPAGE\\H (60).bmp", "HOMEPAGE\\H (61).bmp", "HOMEPAGE\\H (62).bmp", "HOMEPAGE\\H (63).bmp", "HOMEPAGE\\H (64).bmp", "HOMEPAGE\\H (65).bmp", "HOMEPAGE\\H (66).bmp", "HOMEPAGE\\H (67).bmp", "HOMEPAGE\\H (68).bmp", "HOMEPAGE\\H (69).bmp", "HOMEPAGE\\H (70).bmp", "HOMEPAGE\\H (71).bmp", "HOMEPAGE\\H (72).bmp", "HOMEPAGE\\H (73).bmp", "HOMEPAGE\\H (74).bmp", "HOMEPAGE\\H (75).bmp", "HOMEPAGE\\H (76).bmp", "HOMEPAGE\\H (77).bmp", "HOMEPAGE\\H (78).bmp", "HOMEPAGE\\H (79).bmp", "HOMEPAGE\\H (80).bmp", "HOMEPAGE\\H (81).bmp", "HOMEPAGE\\H (82).bmp", "HOMEPAGE\\H (83).bmp", "HOMEPAGE\\H (84).bmp", "HOMEPAGE\\H (85).bmp", "HOMEPAGE\\H (86).bmp", "HOMEPAGE\\H (87).bmp", "HOMEPAGE\\H (88).bmp", "HOMEPAGE\\H (89).bmp", "HOMEPAGE\\H (90).bmp", "HOMEPAGE\\H (91).bmp", "HOMEPAGE\\H (92).bmp", "HOMEPAGE\\H (93).bmp", "HOMEPAGE\\H (94).bmp", "HOMEPAGE\\H (95).bmp", "HOMEPAGE\\H (96).bmp", "HOMEPAGE\\H (97).bmp", "HOMEPAGE\\H (98).bmp", "HOMEPAGE\\H (99).bmp", "HOMEPAGE\\H (100).bmp", "HOMEPAGE\\H (101).bmp", "HOMEPAGE\\H (102).bmp", "HOMEPAGE\\H (103).bmp", "HOMEPAGE\\H (104).bmp", "HOMEPAGE\\H (105).bmp", "HOMEPAGE\\H (106).bmp", "HOMEPAGE\\H (107).bmp", "HOMEPAGE\\H (108).bmp", "HOMEPAGE\\H (109).bmp", "HOMEPAGE\\H (110).bmp", "HOMEPAGE\\H (111).bmp", "HOMEPAGE\\H (112).bmp", "HOMEPAGE\\H (113).bmp", "HOMEPAGE\\H (114).bmp", "HOMEPAGE\\H (115).bmp", "HOMEPAGE\\H (116).bmp", "HOMEPAGE\\H (117).bmp", "HOMEPAGE\\H (118).bmp", "HOMEPAGE\\H (119).bmp", "HOMEPAGE\\H (120).bmp", "HOMEPAGE\\H (121).bmp", "HOMEPAGE\\H (122).bmp", "HOMEPAGE\\H (123).bmp", "HOMEPAGE\\H (124).bmp", "HOMEPAGE\\H (125).bmp", "HOMEPAGE\\H (126).bmp", "HOMEPAGE\\H (127).bmp", "HOMEPAGE\\H (128).bmp", "HOMEPAGE\\H (129).bmp", "HOMEPAGE\\H (130).bmp", "HOMEPAGE\\H (131).bmp", "HOMEPAGE\\H (132).bmp", "HOMEPAGE\\H (133).bmp", "HOMEPAGE\\H (134).bmp", "HOMEPAGE\\H (135).bmp", "HOMEPAGE\\H (136).bmp", "HOMEPAGE\\H (137).bmp", "HOMEPAGE\\H (138).bmp", "HOMEPAGE\\H (139).bmp", "HOMEPAGE\\H (140).bmp", "HOMEPAGE\\H (141).bmp", "HOMEPAGE\\H (142).bmp", "HOMEPAGE\\H (143).bmp", "HOMEPAGE\\H (144).bmp", "HOMEPAGE\\H (145).bmp", "HOMEPAGE\\H (146).bmp", "HOMEPAGE\\H (147).bmp", "HOMEPAGE\\H (148).bmp", "HOMEPAGE\\H (149).bmp", "HOMEPAGE\\H (150).bmp" }; double ofsett_x=0.0,ofsett_y=0.0; int startpanx=0, startpany=0; double scalex=1,scaley=1; int moving =0; int curr_c_filled=0; int curr_r_filled=0; int filledrectcnt=0; int slider_y=800; int modes=6; int border=100; int promptMsgNo; int showPrompt=0; int save_cnt=0; int showcircleoptn=0; int showsaveins=0; int showrectoptn=0; int opnindx=0; int hmindx=0; char save_filename[100],save_names[100][100]; int intermidiate; int entrydone; int total_pts = 0; int curr_pts_size =10; int curr_r, curr_b, curr_g; int tools=0; int circleCnt = 0; int x_cir1,y_cir1; int circle_tool=0; int tempcount=0; int textcnt=0; int len=0; int linecnt=0; int box_len=10; int t_x,t_y,t_r,t_g,t_b,t_size; int r_x,r_y,r_dx,r_dy,r_r,r_g,r_b; int txt_x,txt_y,txt_r,txt_g,txt_b,txt_text; int l_x,l_y,l_x1,l_y1,l_r,l_g,l_b; typedef struct { int x, y, r, g, b, size; } pts; typedef struct { int x, y, r, g, b,size,isfilled; } circle; typedef struct { int x,y,r,g,b,dx,dy,isfilled; }filledRect; typedef struct { int r,g,b,x,y; char text[100]; }textBox; typedef struct { int x,y,r,g,b,size; }circletemp; typedef struct { int x1,y1,x2,y2,r,g,b; }line ; pts *PointsArr = (pts *)malloc(9999999 * sizeof(pts)); line * lineArr = (line *) malloc (100 * sizeof(line)); int * linesAt = (int *) malloc (100 * sizeof(int)); circle *CircleArr = (circle *)malloc(1000 * sizeof(circle)); int *CirclesAt = (int *)malloc(100 * sizeof(int)); filledRect * filledRectArr = (filledRect *) malloc (1000 * sizeof(filledRect)); int * filledRectsAt = (int *) malloc (100* sizeof(int)); textBox * textBoxArr= (textBox *) malloc (20 * sizeof (textBox)); int * textsAt = (int *) malloc (20* sizeof (int)); // filledcircle * filledcircleArr=(pts *)malloc(1000 * sizeof(filledcircle)); // int *filledcircleAt=(int *)malloc(100 *sizeof(int)); void init(); void undo(); void erase(); void worldtoscreen(double fworldx, double fworldy,int &nscreenx;, int &nscreeny;){ nscreenx=(int)(fworldx-ofsett_x)*scalex; nscreeny=(int)(fworldy-ofsett_y)*scaley; } void screentoworld(int nscreenx ,int nscreeny,double &fworldx;, double &fworldy;){ fworldx=(double)(nscreenx)/scalex+ofsett_x; fworldy=(double)(nscreeny)/scaley+ofsett_y; } void savefile(const char save_filename[]) { FILE *to_write = fopen(save_filename, "wb"); if (to_write == NULL) { promptMsgNo = 2; return; // Exit function if unable to open file } if (fwrite(&total;_pts, sizeof(int), 1, to_write) != 1 || fwrite(&textcnt;, sizeof(int), 1, to_write) != 1 || fwrite(&circleCnt;, sizeof(int), 1, to_write) != 1 || fwrite(&linecnt;, sizeof(int), 1, to_write) != 1 || fwrite(&filledrectcnt;, sizeof(int), 1, to_write) != 1 || fwrite(textsAt, sizeof(int), textcnt, to_write) != textcnt || fwrite(CirclesAt, sizeof(int), circleCnt, to_write) != circleCnt || fwrite(filledRectsAt, sizeof(int), filledrectcnt, to_write) != filledrectcnt || fwrite(PointsArr, sizeof(pts), total_pts, to_write) != total_pts || fwrite(lineArr, sizeof(line), linecnt, to_write) != linecnt || fwrite(filledRectArr, sizeof(filledRect), filledrectcnt, to_write) != filledrectcnt || fwrite(CircleArr, sizeof(circle), circleCnt, to_write) != circleCnt) { promptMsgNo = 2; fclose(to_write); // Close file before exiting return; } fclose(to_write); // Close file after writing // Open the save list file FILE *save_list = fopen("saves", "a+"); if (save_list == NULL) { promptMsgNo = 2; return; } // Check if the save filename already exists in the saves file bool exists = false; char read[100]; while (fgets(read, 100, save_list)) { if (strcmp(read, save_filename) == 0) { exists = true; break; } } if (!exists) { fwrite(save_filename, sizeof(char), strlen(save_filename), save_list); fwrite("\n", sizeof(char), 1, save_list); } fclose(save_list); tools=21; // Close the saves file showPrompt = 1; } void loadFile(char save_name[]) { promptMsgNo = 9; FILE *from_save = fopen(save_name, "rb"); if (from_save == NULL) { showPrompt = 1; promptMsgNo = 10; modes = 1; return; } if (fread(&total;_pts, sizeof(int), 1, from_save) != 1 || fread(&textcnt;, sizeof(int), 1, from_save) != 1 || fread(&circleCnt;, sizeof(int), 1, from_save) != 1 || fread(&linecnt;, sizeof(int), 1, from_save) != 1 || fread(&filledrectcnt;, sizeof(int), 1, from_save) != 1 || fread(textsAt, sizeof(int), textcnt, from_save) != textcnt || fread(CirclesAt, sizeof(int), circleCnt, from_save) != circleCnt || fread(filledRectsAt, sizeof(int), filledrectcnt, from_save) != filledrectcnt || fread(PointsArr, sizeof(pts), total_pts, from_save) != total_pts || fread(lineArr, sizeof(line), linecnt, from_save) != linecnt || fread(filledRectArr, sizeof(filledRect), filledrectcnt, from_save) != filledrectcnt || fread(CircleArr, sizeof(circle), circleCnt, from_save) != circleCnt) { modes = 1; fclose(from_save); return; } fclose(from_save); } void readList() { FILE *save_list = fopen("saves", "r"); if (save_list == NULL) { modes = 1; showPrompt = 1; promptMsgNo = 11; return; } // Count the number of lines (saved files) while (!feof(save_list)) { char c = fgetc(save_list); if (c == '\n') { save_cnt++; } } rewind(save_list); for (int i = 0; i < save_cnt; i++) { fgets(save_names[i], 200, save_list); size_t len = strlen(save_names[i]); if (len > 0 && save_names[i][len - 1] == '\n') { save_names[i][len - 1] = '\0'; } } fclose(save_list); } void drawobjs() { for (int i = 0, q = 0, p=0, t=0, w=0; i < total_pts; i++) { if(i==textsAt[t]){ int pixel_x,pixel_y; iSetColor(textBoxArr[t].r,textBoxArr[t].g,textBoxArr[t].b); worldtoscreen(textBoxArr[t].x,textBoxArr[t].y,pixel_x,pixel_y); iText(pixel_x,pixel_y,textBoxArr[t].text,GLUT_BITMAP_TIMES_ROMAN_24); t++; } else if (i == CirclesAt[q]) { int pixel_x,pixel_y,pixel_r; worldtoscreen(CircleArr[q].x, CircleArr[q].y,pixel_x,pixel_y); iSetColor(CircleArr[q].r, CircleArr[q].g, CircleArr[q].b); pixel_r=(int)(CircleArr[q].size*scalex)00; if(CircleArr[q].isfilled) iFilledCircle(pixel_x,pixel_y, CircleArr[q].size, 1000); else iCircle(pixel_x,pixel_y, pixel_r, 1000); q++; printf("%d %d %d\n",pixel_x,pixel_y,pixel_r); } else if(i == filledRectsAt[p]){ int pixel_x,pixel_y; int pixel_dx,pixel_dy; worldtoscreen(filledRectArr[p].x, filledRectArr[p].y,pixel_x,pixel_y); //worldtoscreen(filledRectArr[p].dx, filledRectArr[p].dy,pixel_dx,pixel_dy); pixel_dx=filledRectArr[p].dx*scalex; pixel_dy=filledRectArr[p].dy*scaley; iSetColor(filledRectArr[p].r,filledRectArr[p].g,filledRectArr[p].b); //rintf(" %d %d %d %d\n",filledRectArr[].x,CircleArr[q].y,CircleArr[q].size); if(filledRectArr[p].isfilled) iFilledRectangle(pixel_x,pixel_y,pixel_dx,pixel_dy); else iRectangle(pixel_x,pixel_y,pixel_dx,pixel_dy); p++; //printf("%d %d %d %d \n",pixel_x,pixel_y,filledRectArr[p].dx, filledRectArr[p].dy); } else if(i==linesAt[w]){ int pixel_x1,pixel_y1,pixel_x2,pixel_y2; worldtoscreen(lineArr[w].x1, lineArr[w].y1,pixel_x1,pixel_y1); worldtoscreen( lineArr[w].x2, lineArr[w].y2,pixel_x2,pixel_y2); iSetColor(lineArr[w].r, lineArr[w].g, lineArr[w].b); iLine(pixel_x1,pixel_y1,pixel_x2,pixel_y2); w++; // printf("%d %d %d %d\n",lineArr[w].x1, lineArr[w].y1, lineArr[w].x2, lineArr[w].y2); //printf("%d %d %d %d \n",pixel_x,pixel_y,pixel_x1,pixel_y1); } else { int pixel_x,pixel_y; worldtoscreen(PointsArr[i].x, PointsArr[i].y,pixel_x,pixel_y); iSetColor(PointsArr[i].r, PointsArr[i].g, PointsArr[i].b); iFilledCircle(pixel_x,pixel_y, PointsArr[i].size); } } } void iDraw() { if(modes==1){ iShowBMP(0,0,HOMEPAGE[hmindx]); } if(modes==2){ iClear(); iSetColor(255, 255, 255); iFilledRectangle(0, 0, 1400, 700); drawobjs(); if (tools ==2){ int pixel_x,pixel_y; worldtoscreen(t_x, t_y,pixel_x,pixel_y); iSetColor(t_r,t_g, t_b); iCircle(pixel_x,pixel_y, t_size, 1000); } if(tools==3){ int pixel_x,pixel_y,pixel_dx=0,pixel_dy=0; worldtoscreen(r_x,r_y,pixel_x,pixel_y); worldtoscreen(r_dx,r_dy,pixel_dx,pixel_dy); iSetColor(r_r, r_g, r_b); //iFilledRectangle(pixel_x,pixel_y,r_dx,r_dy); } if(tools==13 || tools==14){ int pixel_x,pixel_y; worldtoscreen(txt_x,txt_y,pixel_x,pixel_y); iSetColor(0,0,0); iRectangle(pixel_x,pixel_y-5,box_len,25); } iSetColor(255, 255, 255); iFilledRectangle(0, 0, 130, 700); iShowBMP(10, 20, "image//4.bmp"); iShowBMP(60+15, 35, "image//eraser.bmp"); iShowBMP(67+10, 180, "image//pen.bmp"); if(tools==1) iShowBMP(105+10, 100, "image//size.bmp"); iShowBMP(67+10, 230, "image//textbox.bmp"); iShowBMP(67+10, 285, "image//grab tool.bmp"); iShowBMP(80,325,"image//line.bmp"); iShowBMP(1224,621,"image//savelogo2.bmp"); iShowBMP(1285,626,"image//back.bmp"); iShowBMP(80,370,"image\\deselect.bmp"); iSetColor(0, 0, 0); //iFilledCircle(87, 100, 15, 1000); iShowBMP(66+10, 130, "image//rectangle image.bmp"); iShowBMP(67+10, 85, "image//circle.bmp"); if(tools==1)iShowBMP(67, 180, "image//slider.bmp"); if(tools==6)iShowBMP(67, 280, "image//slider.bmp"); if(tools==100)iShowBMP(67, 230, "image//slider.bmp"); if(tools==3)iShowBMP(67, 130, "image//slider.bmp"); if(tools==2)iShowBMP(67, 87, "image//slider.bmp"); if(showcircleoptn==1)iShowBMP(126,36,"image\\circleoptn.bmp"); if(tools==7)iShowBMP(67, 35, "image//slider.bmp"); if(tools==20)iShowBMP(470, 206, "image//savelogo.bmp"); if(tools==20)iText(501,375,save_filename,GLUT_BITMAP_TIMES_ROMAN_24); if(tools==20)iShowBMP(485,580,promptMsg[10]); if(tools==13 || tools==14)iShowBMP(67, 230, "image//slider.bmp"); if(tools==16 || tools==17)iShowBMP(67, 320, "image//slider.bmp"); iShowBMP(1157,621,"image\\undo.bmp"); if(showrectoptn==1)iShowBMP(126,75,"image\\rectoptn.bmp"); if(tools==0)iShowBMP(67,375,"image//slider.bmp"); iSetColor(0,0,0); iFilledCircle(35,650,25,100000); iSetColor(curr_r,curr_g,curr_b); iFilledCircle(35,650,20,100000); if(showPrompt){ iSetColor(0,0,0); if(tools==1)iShowBMP(485,590,promptMsg[0]); if(tools==7)iShowBMP(485,590,promptMsg[1]); if(tools==2)iShowBMP(485,590,promptMsg[2]); if(tools==3)iShowBMP(485,590,promptMsg[3]); if(tools==16 || tools==17)iShowBMP(485,590,promptMsg[4]); if(tools==6 || tools==10)iShowBMP(485,590,promptMsg[5]); if(tools==13 || tools==14)iShowBMP(480,572,promptMsg[8]); if(tools==21)iShowBMP(485,590,promptMsg[6]); } // iRectangle(66, 130, 40, 40); } if(modes==3){ iClear(); // iSetColor(255, 255, 255); // iFilledRectangle(0, 0, 1400, 700); // iShowBMP(800,0,"image//logo.bmp"); // iShowBMP(70,90,"image//savelist.bmp"); iShowBMP(0,0,"image\\LOADPAGE.bmp"); iShowBMP(1260,630,"image\\back.bmp"); for(int i=0;i>border_x) { iMouseMove(mx, my); } if (tools != 1 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if ((mx >= 67 && mx <= 67 + 50) && (my >= 180 && my <= 180 + 50)) { tools = 1,showPrompt=1; } } if (tools != 2 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if ((mx >= 67 && mx <= 67 + 40) && (my >= 85 && my <= 85 + 40)) {tools = 22,showcircleoptn=1;return;} } if (tools != 3 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN){ if((mx>=66 && mx<=66+40) && (my>=130 && my<=130+40)) { tools=33,showrectoptn=1;return;} } if(tools!=0 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN){ if((mx>=80&& mx<=123) && (my>=372 && my<=409)){ tools=0;return; } } if (butt GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 && my <= 10 + 56)) { curr_r = 0, curr_b = 0, curr_g = 255; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 56 && my <= 10 + 2 * 56)) { curr_r = 0, curr_b = 255, curr_g = 0; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 2 * 56 && my <= 10 + 3 * 56)) { curr_r = 102, curr_b = 204, curr_g = 0; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 3 * 56 && my <= 10 + 4 * 56)) { curr_r = 255, curr_b =255, curr_g = 0; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 4 * 56 && my <= 10 + 5 * 56)) { curr_r = 255, curr_b = 0, curr_g = 0; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 5 * 56 && my <= 10 + 6 * 56)) { curr_r = 255, curr_b = 3, curr_g = 45; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 6 * 56 && my <= 10 + 7 * 56)) { curr_r = 255, curr_b = 0, curr_g = 100; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 7 * 56 && my <= 10 + 8 * 56)) { curr_r = 255, curr_b = 0, curr_g = 168; } if ((mx >= 10 && mx <= 10 + 50) && (my >= 10 + 8 * 56 && my <= 10 + 9 * 56)) { curr_r = 255, curr_b = 0, curr_g = 255; } if ((mx >= 67 && mx <= 67+40) && (my >= 280 && my <= 280+40)&&tools;!=6) { tools=6,showPrompt=1;return; } if ((mx >= 60 && mx <= 110) && (my >= 20 && my <= 70)&&tools;!=7) { tools=7,showPrompt=1;return; }if ((mx >= 120 && mx <=(522)) && (my >= 417 && my <= 481)&& modes==1) { modes=2,showPrompt=1;return; }if ((mx >= 83 && mx <=(117)) && (my >= 237 && my <= 264)&& tools!=13) { tools=13,showPrompt=1;return; } if ((mx >= 163 && mx <=(189)) && (my >= 260 && my <= 282)&& tools==1) { curr_pts_size=20;return; }if ((mx >= 167 && mx <=(189)) && (my >= 193 && my <= 213)&& tools==1) { curr_pts_size=10;return; }if ((mx >= 81 && mx <=(114)) && (my >= 329 && my <= 357)) { tools=16,showPrompt=1;return; } }if ((mx >= 172 && mx <=(187)) && (my >= 138 && my <= 149)&& tools==1) { curr_pts_size=5;return; } if ((mx >= 1224 && mx <=(1276)) && (my >= 624 && my <= 675)&& modes==2) { tools=20,showPrompt=1;return; } if ((mx >= 668 && mx <=(749)) && (my >= 278 && my <= 301)&& modes==2 && tools==20 && moving%2==0) { savefile(save_filename);return; } if ((mx >= 120 && mx <=(521)) && (my >= 260 && my <=338 )&& modes==1) { readList(); modes=3; return; }if ((mx >= 1287 && mx <=(1376)) && (my >= 635 && my <= 662)&& modes==2 ) { modes=1; freemem(); init(); erase(); return; } if((mx >= 168 && mx <=(214)) && (my >= 124 && my <= 149)&& showcircleoptn==1 ){ curr_c_filled=0; showcircleoptn=0; tools=2; showPrompt=1; } if((mx >= 173 && mx <=(209)) && (my >= 57 && my <= 93)&& showcircleoptn==1 ){ curr_c_filled=1; showcircleoptn=0; showPrompt=1; tools=2; } if((mx >= 171 && mx <=(211)) && (my >= 166 && my <= 209)&& showrectoptn==1 ){ curr_r_filled=0; showrectoptn=0; showPrompt=1; tools=3; } if((mx >= 171 && mx <=(212)) && (my >= 94 && my <= 133)&& showrectoptn==1 ){ curr_r_filled=1; showrectoptn=0; showPrompt=1; tools=3; } if((mx >= 1156 && mx <=(1200)) && (my >= 635 && my <= 665)&& modes==2 && moving%2==0){ undo(); } if(modes==3){ if ((mx >= 1260 && mx <=(1356)) && (my >= 637 && my <= 669) ) { modes=1; init(); hmindx=0; return; } } if (tools == 2 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { CirclesAt[circleCnt] = total_pts++; CircleArr[circleCnt].x = world_x; CircleArr[circleCnt].y = world_y; CircleArr[circleCnt].r = curr_r; CircleArr[circleCnt].g = curr_g; CircleArr[circleCnt].b = curr_b; CircleArr[circleCnt].isfilled=curr_c_filled; t_x = CircleArr[circleCnt].x; t_y = CircleArr[circleCnt].y; t_r = curr_r; t_g = curr_g; t_b = curr_b; } if (tools == 2 && butt GLUT_LEFT_BUTTON && state == GLUT_UP ) { CircleArr[circleCnt].size=sqrt((mx-CircleArr[circleCnt].x)*(mx-CircleArr[circleCnt].x)-(my-CircleArr[circleCnt].y)*(my-CircleArr[circleCnt].y)); circleCnt++; t_size=0; t_x=0; t_y=0; t_r=255; t_g=255; t_b=255; } if (tools == 3 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN && mx>border_x ) { filledRectsAt[filledrectcnt]=total_pts++; filledRectArr[filledrectcnt].x=world_x; filledRectArr[filledrectcnt].y=world_y; filledRectArr[filledrectcnt].r=curr_r; filledRectArr[filledrectcnt].g=curr_g; filledRectArr[filledrectcnt].b=curr_b; filledRectArr[filledrectcnt].isfilled=curr_r_filled; r_x=world_x; r_y=world_y; r_r=curr_r; r_b=curr_b; r_g=curr_g; } if (tools == 3 && button == GLUT_LEFT_BUTTON && state == GLUT_UP && mx>border_x) { double world_x, world_y; screentoworld(mx,my,world_x,world_y); filledRectArr[filledrectcnt].dx=abs(world_x-filledRectArr[filledrectcnt].x); filledRectArr[filledrectcnt].dy=abs(world_y-filledRectArr[filledrectcnt].y); filledrectcnt++; } if(tools==6){ double prev_mx,prev_my; screentoworld(mx,my,prev_mx,prev_my); if(tools==10){ double after_mx,after_my; screentoworld(mx,my,after_mx,after_my); printf("%d %d \n",ofsett_x,ofsett_y); ofsett_x +=(prev_mx-after_mx); ofsett_y +=(prev_my-after_my); printf("%d %d \n",ofsett_x,ofsett_y); }} if(tools==13 && button==GLUT_LEFT_BUTTON && state==GLUT_DOWN && mx>border_x ){ textsAt[textcnt]=total_pts++; textBoxArr[textcnt].x=world_x; textBoxArr[textcnt].y=world_y; textBoxArr[textcnt].r=curr_r; textBoxArr[textcnt].g=curr_g; textBoxArr[textcnt].b=curr_b; txt_x=textBoxArr[textcnt].x; txt_y=textBoxArr[textcnt].y; txt_r=curr_r; txt_g=curr_g; txt_b=curr_b; tools=14; } if(tools==16 && button==GLUT_LEFT_BUTTON && state==GLUT_DOWN && mx>border_x){ double world_x1,world_y1; screentoworld(mx,my,world_x1,world_y1); lineArr[linecnt].x1=world_x1; lineArr[linecnt].y1=world_y1; lineArr[linecnt].r=curr_r; lineArr[linecnt].g=curr_g; lineArr[linecnt].b=curr_b; tools=17; } if(tools==17 && button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN && mx>border_x){ double world_x2,world_y2; screentoworld(mx,my,world_x2,world_y2); lineArr[linecnt].x2=world_x2; lineArr[linecnt].y2=world_y2; linesAt[linecnt]=total_pts++; linecnt++; tools=16; } if(modes==3){ if(mx>=120 && mx<= 25 && butt GLUT_LEFT_BUTTON && state == GLUT_DOWN){ int indx=(537-my)/48; if(indx>= 1287 && mx <=(1376)) && (my >= 635 && my <= 662) ){ init(); freemem(); modes=1; } }} } void iKeyboard(unsigned char key) { if(modes==6){ modes=1; hmindx=0; } if(key=='q' && tools!=13 &&tools;!=14 && tools!=20){ scalex*=1.01; scaley*=1.01; tools=10; } if(key=='a' && tools!=13 &&tools;!=14 && tools!=20){ scalex*=0.9; scaley*=0.9; tools=10; } if(tools==14 && modes==2){ if (tools == 14 && modes == 2) { if (key == 13) { textBoxArr[textcnt++].text[len] = '\0'; tools = 13; len = 0; box_len=10; } else { if (key == 8 && len > 0) { textBoxArr[textcnt].text[--len] = '\0'; box_len-=10; } else { textBoxArr[textcnt].text[len++] = key; box_len+=10; } } } } if(tools==20 && modes==2){ if(key==13){ save_filename[len]='\0'; entrydone=1; } else{ if(key==8 && len>0){ save_filename[--len]='\0'; } else{ save_filename[len++]=key; } } } } void iSpecialKeyboard(unsigned char key) { } void freemem(){ free(PointsArr); free(textBoxArr); free(textsAt); free(CircleArr); free(CirclesAt); free(lineArr); free(linesAt); free(filledRectArr); free(filledRectsAt); } void undo(){ if(filledRectsAt[filledrectcnt]==total_pts){ filledRectArr[filledrectcnt].x=0; filledRectArr[filledrectcnt].y=0; filledRectArr[filledrectcnt].r=0; filledRectArr[filledrectcnt].g=0; filledRectArr[filledrectcnt].b=0; filledRectArr[filledrectcnt].isfilled=0; filledRectArr[filledrectcnt].dx=0; filledRectArr[filledrectcnt].dy=0; filledrectcnt--; total_pts--; } else if(CirclesAt[circleCnt]==total_pts){ CircleArr[circleCnt].x = 0; CircleArr[circleCnt].y = 0; CircleArr[circleCnt].r = 0; CircleArr[circleCnt].g = 0; CircleArr[circleCnt].b = 0; CircleArr[circleCnt].size=0; circleCnt--; total_pts--; } else if(linesAt[linecnt]==total_pts){ lineArr[linecnt].x1=0; lineArr[linecnt].y1=0; lineArr[linecnt].r=0; lineArr[linecnt].g=0; lineArr[linecnt].b=0; lineArr[linecnt].x2=0; lineArr[linecnt].y2=0; linecnt--; total_pts--; } else if(textsAt[textcnt]==total_pts){ textBoxArr[textcnt].x=0; textBoxArr[textcnt].y=0; textBoxArr[textcnt].r=0; textBoxArr[textcnt].g=0; textBoxArr[textcnt].b=0; textBoxArr[textcnt].text[len--]='\0'; textcnt--; total_pts--; } else{ PointsArr[total_pts].x = 0; PointsArr[total_pts].y = 0; PointsArr[total_pts].r = 255; PointsArr[total_pts].g = 255; PointsArr[total_pts].b = 255; PointsArr[total_pts].size=0; total_pts--; } } void init(){ ofsett_x=0.0,ofsett_y=0.0; startpanx=0, startpany=0; scalex=1,scaley=1; moving =0; curr_c_filled=0; curr_r_filled=0; filledrectcnt=0; // slider_y=800; promptMsgNo=0; showPrompt=0; save_cnt=0; showcircleoptn=0; showsaveins=0; showrectoptn=0; save_filename[100],save_names[100][100]; total_pts = 0; curr_pts_size =10; curr_r=0, curr_b=0, curr_g=0; tools=0; circleCnt = 0; textcnt=0; len=0; linecnt=0; box_len=0; } void animation(){ if(opnindx<149) opnindx++; else opnindx = 109; } void animation2(){ if(hmindx<149) hmindx++; } void erase(){pts *PointsArr = (pts *)malloc(9999999 * sizeof(pts)); line * lineArr = (line *) malloc (100 * sizeof(line)); int * linesAt = (int *) malloc (100 * sizeof(int)); circle *CircleArr = (circle *)malloc(1000 * sizeof(circle)); int *CirclesAt = (int *)malloc(100 * sizeof(int)); filledRect * filledRectArr = (filledRect *) malloc (1000 * sizeof(filledRect)); int * filledRectsAt = (int *) malloc (100* sizeof(int)); textBox * textBoxArr= (textBox *) malloc (20 * sizeof (textBox)); int * textsAt = (int *) malloc (20* sizeof (int)); } int main() { iSetTimer(5,animation); iSetTimer(9,animation2); iInitialize(screenwidth, screenheight, "Whitebaord"); return 0; }