Graphics Editor

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Graphics Editor as PDF for free.

More details

  • Words: 5,980
  • Pages: 41
graphics editor version 1.0 authors: akshay srivatsa and shrikanteshwara s

abstract: the graphics editor gives the flexibility to the user to create and manipulate graphical objects, pictures and sophisticated 2-d objects.

version 1.0

page 1 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________

certificate name of institution: sri kumaran children’s home-cbse this is to certify that srikanteswara s has satisfactorily completed the course of project in practical computer science prescribed by the central board of secondary education , university aissce course in the laboratory of this college in the year 2002-03 date: signature of the teacher in charge of the batch

signature of the external examiner

version 1.0

page 2 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________

table of contents

INTRODUCTION................................................................................................................... SYSTEM REQUIREMENTS................................................................................................... ABOUT THE GRAPHICS EDITOR........................................................................................ FLOW CHART....................................................................................................................... FUNCTIONS USED............................................................................................................... ALGORITHM......................................................................................................................... ACKNOWLEDGEMENT........................................................................................................ PHOTOS................................................................................................................................ BIBLIOGRAPHY................................................................................................................... SOURCE CODE....................................................................................................................

version 1.0

page 3 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________

introduction the graphics editor helps you to edit pictures, 2-d objects and other graphical objects. the version of the editor is 1.0. this editor has been built in c++ which provides graphical support. so this editor uses c++ graphics libraries, which are dos compliant and are not windows compliant. this editor has been built studying the functions and the layout of microsoft windows paint® but the code for the editor is our own and genuine.

system requirements operating system: microsoft windows 3.1 and above/ dos  cpu: 486 and above memory: 32 mb and above software: borland’s turbo c++

about the graphics editor like paint, this editor template consists of the following

1. 2. 3. 4.

version 1.0

main menu drawing board colour bar tool bar

page 4 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________

main menu: this is a very important part of the editor as it is used to perform some general operations on the editor like save, new, exit, usage, credits etc.. this menu has been divided into 3 parts • • •

file help edit file: this menu consists of options to control the editor and the drawing board. the menu elements are: new: this helps us to create a new drawing board by clear all the existing graphics on the drawing board. due to limitations of c++ graphics, we have used the floodfill() function to clear the screen. we use this tool to fill the editor with all the colours except white to clear all the pictures on the editor and later fill the drawing area with white. this process turns out to be a wonderful display of colours in a matter of few seconds. save and save as:

version 1.0

page 5 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________ this helps us to save files in the form of binary files. the file name with the extension of .dat must be given during the saving of the file. the saving of the file is done using malloc() and getimage. the whole drawing board has been divided into 8 parts and each part is saved into a file by using the above functions. note: it is advised to use the save and saveas options only a few time in a single run of the editor. we find that borland c++ has problems with allocation of memory and does not deallocate them properly. this might cause problems during the running of the editor and even might hang the system. open: since a save function has been employed, we have created a function to open the files. opening of the file can be done by typing the name of the file with it’s extension (.dat). if the file exists, it will be displayed on the drawing board but, if it doesn’t exist, the drawing board will remain unchanged. again here we have employed malloc() and putimage() functions. since, saving was done by dividing the image into eight parts, putting of the image is also done by putting the 8 parts of the file onto the drawing board. exit: this function is used to exit the whole editor. help: this menu consists of tutorials for the user to use the editor. it also gives the user, a general information about the creators of the editor. the menu elements are: credits: this gives the user a general information about the creators of this editor and their contact telephone numbers for further information about the editor. about: this option enables the user to know the some general information about the editor like version, product information etc.. usage: this is a very important part of the editor. this option enables the user to know the different tools in the editor, their usage and their operation. all the options of the help menu will display their contents covering the editor. so all the pictures on the editor will be lost and a new drawing board is put up on the screen. so it is advised to save the pictures on the drawing board before viewing the help menu. edit: this menu consists of options to cut, copy and paste images. due to time constraints, we could not develop this menu.

version 1.0

page 6 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________ drawing board: the drawing board is the area where the graphical operation can be performed. the white region in the editor is the drawing board. this drawing area is surrounded by a blue coloured box so as to stop the graphical objects from crossing the drawing area. if any operation is performed on the drawing board in such a manner that the resulting graphical object goes beyond the drawing board, then the tool will automatically get unselected. the numbers on the adjacent sides of the drawing board represent the scale of the drawing board. colour bar: this bar provide the user with 15 colours to operate with. the left-most bar located on the editor is the colour bar. the selection of colours need to be done only when asked for. however many tools in the editor do not ask for colour selection and work on black colour by default. tool bar: this software can’t be called as a graphics editor if not for this bar. this can e considered to be the most important bar in the editor. this bar contains all the necessary tool to perform graphical operations on the drawing board. the options are: floodfill: this tool enables the user to fill a given region with a given colour. the user needs to click on a point which is located within the area which needs to be filled. then he needs to select the filling colour and finally the colour of the boundary. on doing so the filling colour will fill all the area bordered by the boundary colour. ellipse: this is a function used to draw ellipses of given fixed dimensions. the ellipses are black in colour by default. c++ provides the ellipse function, which we have implemented in this option. line: this function enables the user to draw lines. we have used the line function which is defined in graphic.h once the line option has been selected, the user needs to select the colour of the line. once the colour is selected, a line is drawn when the user clicks the two ends of the line on the drawing board. circle: this option is user to craw circles of fixed radius. the user needs to select the colour of the circle and the centre of the circle. but this option cannot be used to draw arcs of given angular dimensions. for this purpose, we have developed another option known as the arc function. arc: version 1.0

page 7 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________ as mentioned earlier, circle draws arcs of angle 180°. but the arc function can be used to draw arcs of user defined angle. here again, we have set the radius of the arc, which cannot be changed. on selecting this function, the user needs to enter the angle of the arc. once the entering is complete, the user needs to select the center of the circle and the arc will be drawn immediately. rectangle: this option can be used to draw rectangles and squares. like line, colour selection needs to be done. after the selection, the user needs to click the diagonal ends of the rectangle. after the click the rectangles will be drawn. x,y coor: this function is used to find the co-ordinates of a point on the drawing board. the coordinates will be displayed just above the drawing board. we have introduced this option considering that it will be of some use to the user. we have not used this tool in any of our functions. pencil: this tool is used to give some flexibility to the user to create his own drawing. this can be used just the way a pencil is used. like any other option, the colour selection must be done after which the pencil can be used on the drawing board. erase: this function was introduced with an intention of erasing graphical objects. but due to time constraints, we were unable to develop this option. to make things easier, we have used the mouse facility. but the code for the mouse operation is not ours and this code was obtained from book and net sources.

version 1.0

page 8 of 41 date: 23-Oct-08

graphics editor _____________________________________________________________ ________ flow chart this is a very basic flowchart. this flowchart just gives an idea about the foundation of the editor. for detailed understanding, refer to the algorithm.

7

version 1.0

page 9 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

graphics editor _____________________________________________________________ ________ functions used 1. int check_area(int mousex,int mousey); 2. void operations(int item); 3. int colours(int col); 4. void click_mouse(); 5. unsigned initmouse(); 6. void showmouse(); 7. void hidemouse(); 8. void restrictmouse(int x1,int y1,int x2,int y2); 9. void getmouse(int *pbutton,int *px,int *py); 10. void setmouse(int x,int y); 11. void structure(); 12. void menu(int mousex,int mousey); 13. void bullet(char arr[100],int length,int x,int y); 14. void quit(); 15. void drop_down(char *p,int q); 16. void erase_drop(); 17. void select(int mousex,int mousey); 18. void unselect(); 19. void colour_unselect(); 20. int colour_select(int mousex,int mousey);

version 1.0

page 11 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

algorithm

for graphics editor v.1.0

the following algorithm was used to develop the graphics editor. the editor is divided into three separate files, along with their respective header files. the three files were individually included in a common project file (*.prj). the header files used were: #include #include <stdlib.h> #include <stdio.h> #include #include #include <dos.h> #include #include <string.h> #include #include<stdlib.h> #include "ed_util.h" #include "oper.h" the algorithm assumes the declaration and initialisation of certain variables belonging to primary datatypes. a detailed explanation of some functions have been excluded in order to enable the reader to quickly yet comprehensively get an intelligent insight into the making of the project. 1. start the start-up screen 2. a for loop containing 3 variables is opened, which repeats itself 50 times. 2.1 with colour set to blue, a line with pre defined coordinates is drawn 2.2 with colour set to green, a circle with pre defined boundaries is drawn 2.3 with colour set to red, a circle with a set of pre defined boundaries is drawn. 3. the screen is cleared and the background colour is set to red 3.1 graphics editor is displayed on the screen. 4. upon user click, the editor proceeds to the next stage.

graphics editor _____________________________________________________________ ________ the template of the editor 5. the structure() function is called and the template of the editor is created. 5.1 a rectangle is drawn to determine the outer boundary of the editor. 5.2 repeated usage of the line() function draws lines for the editor’s toolbar and its scale. 5.3 setting the fill style to solid fill, and by repeated usage of floodfill function, colour is injected into the various items in the tool bar. 5.4 the text on the toolbar is then entered as well as the readings on the scale of the editor. 5.5 appropriate colours are then filled in other parts of the editor, and the title of the editor is displayed. 5.6 colour for the color boxes in the editor is injected, and the editor’s main menu is created using the line() function. 5.7 the editor is presented in full view. 6. mouse support is checked. if mouse support is unavailable, an error message is printed and the program returns to the compiler. mouse functions 7. the mouse functions are explained here. 7.1 void showmouse() displays the mouse cursor on the screen. 7.2 void hidemouse() hides the mouse from the user and the editor. 7.3 void restrictmouse() restricts the mouse to certain pre determined areas of the screen i.e. the editor workspace. 7.4 void getmouse() gets the coordinates of the mouse at that instant. 7.5 void setmouse() sets the coordinates of the mouse to a particular value. 7.6 void clickmouse() checks if the mouse has been clicked or not.

menu of the editor 8. this is performed by the function void menu(int mousex, int mousey); the coordinates of the mouse are found, and if the mouse is clicked . 8.1 if the mouse coordinates are within a specified range, the file menu is displayed i.e. new, open, sav, savas, exit. 8.1.1 the function file_options is called. proceed to step 9. 8.2 similarly, depending on the coordinates of the mouse, the menu for other options like help, edit etc. is displayed. 8.3 if the mouse is clicked outside the main menu bar, the program breaks from the menu function. version 1.0

page 13 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

the file menu 9. an infinite while loop is opened, such that the program breaks from the function only if the mouse coordinates are outside the main menu bar. 10. a switch case loop is opened where the value of a particular variable is changed repeatedly. 10.1 case 1: this is for creating a new file 10.1.1 the entire editor workspace is completely filled by white colour. the old geometrical shapes are erased. 10.2case 4: this is used to save the file 10.2.1. a file object is opened in output mode. 10.2.2. the screen is divided into 8 sectors. individually, using the getimage() function, each of the sectors is written onto the file with a userspecified name, using the file object. 10.2.3. using the file.write() function, the entire file is saved through 8 processes. an output message indicating that the file is saved is displayed. 10.2.4. the file object is closed. 10.3case 2: this is for opening a file that is already saved. 10.3.1. a file object is opened in input mode 10.3.2. the user enters the name of the file to be opened. 10.3.3. again, using the putimage() function, each of the 8 sectors of the work space is read and set in display mode. 10.3.4. using the file.read() function, the entire file is displayed through 8 processes. 10.3.5. the file object is closed. 10.4case 5: this is for exiting from the editor. 10.4.1. the quit() function is called and the editor is closed. the program returns to the c++ compiler.

operations performed by the editor

graphics editor _____________________________________________________________ ________ 11. this is performed by the void operations(int item) function. 11.1 case line: this draws a line, with user-specified coordinates 11.1.1. the mouse is clicked at the relevant positions to select the colour of the line to be drawn. 11.1.2. an infinite while loop is opened such that the program exits from the loop only if the mouse is clicked outside the workspace. this step proceeds only if the mouse is clicked and within the work space. the 2 end points of the line are to be clicked. the same is indicated by a message displayed on the editor. 11.1.3. a line is drawn between the 2 specified coordinates. 11.1.4. repeat the previous 2 steps as long as the mouse is clicked within the work space.

11.2. case floodfill: this is used to fill a pre-determined area of the work space with a certain colour. an indefinite while loop is begun. 11.2.1. if newbutton <- 1 and area <- 1, proceed to 11.2.2. 11.2.2. as indicated by the message on the editor, the relevant mouse positions are to be clicked in order to choose the colour by which the necessary area is to be floodfilled. 11.2.3. as in 11.2.2., click on the colour for the boundary. 11.2.4. the appropriate area is floodfilled with the colour chosen. 11.2.5. repeat the above for steps until the mouse is clicked outside the work space. on this event, break from the operations function.

11.3case ellipse: this is used to draw an ellipse and to drag it across the work space. 11.3.1. an infinite while loop is begun. the mouse coordinates are obtained. 11.3.2. if the mouse is clicked within the work space, an ellipse is drawn from the point of the mouse click. 11.3.3. else continue. 11.3.4. repeat the previous 3 steps until the mouse is clicked outside the work space. 11.4. case rectangle: this is used to draw a rectangle whose end coordinates are obtained from the user. 11.4.1.click the mouse at the relevant positions to determine the colour of the rectangle to be drawn. version 1.0

page 15 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

11.4.2.begin an infinite while loop. 11.4.3.click at 2 points on the work space, as indicated by the message on the editor. 11.4.4.on clicking again outside the area of the rectangle, the rectangle is drawn with the desired colour and within the desired coordinates. 11.4.5.repeat the above 3 steps until the mouse is clicked outside the workspace.

11.5. case pencil: this is used to draw small circles 11.5.1.as indicated by the message on the editor, click the mouse at relevant positions to determine the colour of the circles to be drawn. 11.5.2.begin an infinite while loop. 11.5.3.draw a circle with the mouse coordinates previously obtained as it’s centre. the circle has a pre-determined radius. 11.5.4.click 2 points to draw a new circle. 11.5.5.repeat the above 2 steps until the mouse is clicked outside the editor work space. 11.6. case coordinates: this is used to find out the mouse coordinates at a required position. 11.6.1.begin an infinite while loop. 11.6.2.as indicated by the message on the editor, click on any position on the work space to get the coordinates of that position. 11.6.3.display the mouse coordinates at that point using the check_area function. 11.6.4.repeat the above 2 steps until the mouse is clicked outside the work space. 11.7. case erase: this is used to erase the region between 2 points that are clicked on the work space. 11.7.1.as indicated by the message on the screen, click the mouse on 2 points on the work space, between which the portion of the screen is to be erased. 11.7.2.begin an infinite while loop 11.7.3.use the getmouse() function to get the coordinates of the point that is clicked. 11.7.4.if the mouse is clicked within the work space, draw a rectangle between the points that are clicked.

graphics editor _____________________________________________________________ ________ 11.7.5.floodfill the area enclosed by the rectangle with white colour. 11.7.6.repeat the previous 3 steps until the mouse is clicked outside the work space. quitting the editor 12.

this is performed by the function void quit(). 12.1. the screen is cleared. 12.2. using the bullet() function, certain text is displayed on the editor. 12.3. upon a keyboard hit by the user, the program exits from the editor and returns to the c++ compiler. 13.end.

version 1.0

page 17 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

acknowledgement during the course of our project titled “graphics editor”, we have had many wonderful experiences and learning opportunities. we are grateful to everyone who helped us in our work, and sincerely appreciate their help. we thank the principal of our school mrs. deepa sridhar for providing us all appropriate facilities in the computer laboratory that was useful in our building the editor. we thank our computer science lecturer mrs. kavita for enabling us develop our computer and creativity skills. we thank all the other lab teachers too. we also thank our parents and classmates for their timely support and encouragement. this is a project we will remember forever and we profoundly express our gratitude to everyone who helped us during our project. akshay srivatsa srikanteswara s

graphics editor _____________________________________________________________ ________ photos

version 1.0

page 19 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

bibliography let us c by yashwanth kanitkar let us c++ by yahwanth kanitkar websites : www.programmerheaven.com

graphics editor _____________________________________________________________ ________ source code oper.cpp /* graphics editor by akshay and srikanteshwara */ #include #include #include #include #include #include #include #include #include #include #include #include

<stdlib.h> <stdlib.h> <stdio.h> <dos.h> <string.h> "ed_util.h" "oper.h"

/**********/ int left, top,right, bottom, colour, j, k, l, c, i, a, r=50, side=50; int button,mousex,mousey,newbutton,newmousex,newmousey; extern int positionx,positiony; void *ptr_menu,*ptr_save; /*********/ //a&c are for increasing the radius of the circle and for switching between cases,respectively // side is the length of the side of the square drawn with predefined// //radius and r is the radius of the circle drawn by user int main(void) { /* request auto detection */ int gdriver = detect, gmode, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "d:\\tc\\bgi"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grok) /* an error occurred */ { printf("graphics error: %s\n", grapherrormsg(errorcode)); printf("press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /* this is for the start up screen*/ for(i=0,j=500,k=250,l=750;i<500;i+=10,j-=10,k+=10,l-=10) { setbkcolor(0); setcolor(blue); line(i,j,k,l);

version 1.0

page 21 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ delay(10); circle(100,i,i); setcolor(5); circle(j,100,j); setcolor(green); circle(k,k,100); setcolor(red); circle(100,l,l); delay(100); } cleardevice(); setbkcolor(red); setcolor(15); /*********/ int style,size ; /*********/ style=triplex_font; size=7; settextstyle(style, horiz_dir, size); outtextxy(90,180,"graphics editor"); getch(); clrscr(); settextstyle(default_font,horiz_dir,1); cleardevice(); setbkcolor(0); structure(); // to call the template of the function// /*********/ int x,y,button,temp=50; /*********/ if(initmouse()==0) { printf("mouse support unavailable"); return(1); } showmouse(); while(1) { getmouse(&button,&mousex,&mousey); // cout<
}

edutil.cpp /**********/ extern int left, top, colour, right, bottom, j, k, l, c, i, a, r, side;

graphics editor _____________________________________________________________ ________ extern int button,mousex,mousey,newbutton,newmousex,newmousey; extern int positionx,positiony; extern void *ptr_menu,*ptr_save; /*********/ //a&c are for increasing the radius of the circle and for switching between cases,respectively // side is the length of the side of the square drawn with predefined// //radius and r is the radius of the circle drawn by user unsigned initmouse() { _ax=0; geninterrupt(0x33); return _ax; }

//generate inpterrupt

void showmouse() { _ax=1; geninterrupt(0x33); }

void hidemouse() { _ax=2; geninterrupt(0x33); }

void restrictmouse(int x1,int y1,int x2,int y2) { _ax=7; _cx=x1; _dx=x2; geninterrupt(0x33); _ax=8; _cx=y1; _dx=y2; geninterrupt(0x33); }

void getmouse(int *pbutton,int *px,int *py) { _ax=3; geninterrupt(0x33); *pbutton=_bx; *px=_cx; *py=_dx; }

void setmouse(int x,int y) { _ax=4; _cx=x; _dx=y; geninterrupt(0x33); } void structure()

version 1.0

page 23 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ { left = getmaxx() / 2 - 290; top = getmaxy() / 2 - 230; right = getmaxx() / 2 + 290; bottom = getmaxy() / 2 + 230; rectangle(left,top,right,bottom); line(100,50,100,468); delay(30); line(30,50,608,50); // code for the template of the editor// delay(30); line(30,30,608,30); delay(30); line(115,65,115,468); delay(30); line(115,65,608,65); //scale of the editor// delay(30); line(100,30,100,50); // these are the lines for the toolbar// delay(30); line(170,30,170,50); delay(30); line(50,50,50,468); delay(30); line(580,30,580,50); delay(30); setfillstyle(solid_fill,8); delay(30); floodfill(40,40,15); delay(30); floodfill(120,40,15); delay(30); floodfill(190,40,15); delay(30); floodfill(250,40,15); delay(30); floodfill(310,40,15); delay(30); floodfill(390,40,15); delay(30); floodfill(590,40,15); delay(30); floodfill(350,40,15); delay(30); setcolor(12);

// to fill color for the tool bar//

// a line to separate the tools and colours

outtextxy(50,38,"f"); delay(30); outtextxy(122,38,"h"); delay(30); outtextxy(590,38,"x"); setcolor(15); outtextxy(58,38,"ile"); delay(30); // the characters for the rest of the name of the menu bar// outtextxy(133,38,"elp"); delay(30); delay(30); setfillstyle(solid_fill,15); floodfill(130,70,15);

graphics editor _____________________________________________________________ ________ setcolor(0); delay(30); outtextxy(118,68,"0"); delay(30); outtextxy(218,68,"50"); delay(30); outtextxy(318,68,"100"); delay(30); outtextxy(418,68,"150"); delay(30); outtextxy(518,68,"200"); delay(30); outtextxy(118,168,"50"); delay(30); outtextxy(118,268,"100"); delay(30); outtextxy(118,368,"150"); delay(30); outtextxy(118,460,"200"); delay(30);

//readings of the scale of the editor// //along the horizontal//

//readings of the scale of the editor // // along the verticle//

setcolor(12); delay(30); setfillstyle(solid_fill,8); delay(30); floodfill(110,70,15); // to fill color for the rest of the editor// delay(30); floodfill(90,70,15); delay(30); floodfill(70,20,15); delay(30); setfillstyle(solid_fill,8); floodfill(250,20,15); //title for the editor/ outtextxy(10,40,"g"); outtextxy(10,60,"r"); outtextxy(10,80,"a"); outtextxy(10,100,"p"); outtextxy(10,120,"h"); outtextxy(10,140,"i"); outtextxy(10,160,"c"); outtextxy(10,180,"s"); outtextxy(10,220,"e"); outtextxy(10,240,"d"); outtextxy(10,260,"i"); outtextxy(10,280,"t"); outtextxy(10,300,"o"); outtextxy(10,320,"r"); delay(30); setcolor(15); line(30,80,50,80); delay(30); line(30,110,50,110); delay(30); line(30,140,50,140); delay(30); line(30,170,50,170); delay(30); line(30,200,50,200); delay(30); line(30,230,50,230); delay(30); line(30,260,50,260); delay(30); line(30,290,50,290);

version 1.0

// code for lines for the colors//

page 25 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ delay(30); line(30,320,50,320); delay(30); line(30,350,50,350); delay(30); line(30,380,50,380); delay(30); line(30,410,50,410); delay(30); line(30,440,50,440); delay(30); setfillstyle(interleave_fill,0); bar// floodfill(40,70,15); setfillstyle(interleave_fill,1); delay(30); floodfill(40,100,15); setfillstyle(interleave_fill,2); delay(30); floodfill(40,130,15); setfillstyle(interleave_fill,3); delay(30); floodfill(40,150,15); setfillstyle(interleave_fill,4); delay(30); floodfill(40,190,15); setfillstyle(interleave_fill,5); delay(30); floodfill(40,220,15); setfillstyle(interleave_fill,6); delay(30); floodfill(40,250,15); setfillstyle(interleave_fill,7); delay(30); floodfill(40,270,15); setfillstyle(interleave_fill,8); delay(30); floodfill(40,300,15); setfillstyle(interleave_fill,9); delay(30); floodfill(40,330,15); in the color bar// setfillstyle(interleave_fill,10); delay(30); floodfill(40,360,15); setfillstyle(interleave_fill,11); delay(30); floodfill(40,390,15); setfillstyle(interleave_fill,12); delay(30); floodfill(40,420,15); setfillstyle(interleave_fill,13); delay(30); floodfill(40,450,15);

// from here we have the code for the color

//all these lines of code are for filling colors

/* these lines are for the editor's main menu*/ delay(30); line(50,95,100,95); delay(20); line(50,140,100,140); delay(30); line(50,185,100,185); delay(30); line(50,230,100,230); delay(30);

graphics editor _____________________________________________________________ ________ line(50,275,100,275); delay(30); line(50,320,100,320); delay(30); line(50,365,100,365); delay(30); line(50,410,100,410); setcolor(1); rectangle(145,80,605,465); /* these lines are to fill the tool bar*/ delay(30); setcolor(15); delay(30); rectangle(55,58,95,88); delay(30); line(75,58,75,88); delay(30); setfillstyle(solid_fill,2); delay(30); floodfill(78,60,15); delay(30); setfillstyle(interleave_fill,5); floodfill(72,60,15); delay(30); ellipse(75,118,0,360,22,12); delay(30); rectangle(65,152,85,172); delay(30); line(54,190,91,227); delay(30); arc(72,264,0,120,23); delay(30); circle(75,298,15); delay(30); rectangle(56,332,96,362); delay(30); outtextxy(60,341,"x,y"); delay(30); outtextxy(64,351,"coor"); outtextxy(57,430,"erase");

line(70,375,70,395); delay(30); line(80,375,80,395); delay(30); line(70,375,80,375); delay(30); line(70,395,80,395); delay(30); setfillstyle(solid_fill,6); floodfill(72,384,15); line(80,395,75,405); delay(30); line(70,395,75,405); size_t area_menu; area_menu=imagesize(0,0,610,31); ptr_menu=malloc(area_menu); getimage(20,5,610,31,ptr_menu); setcolor(2); outtextxy(360,55,"(x,y):"); } void unselect()

version 1.0

page 27 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ {

}

for(int box=0;box<9;box++) { setcolor(15); for(int box=0;box<9;box++) { int y1=50+box*45; int y2=y1+45; line(50,y1,100,y1); line(50,y2,100,y2); line(50,y1,50,y2); line(100,y1,100,y2); } } return;

void select(int mousex,int mousey) { setcolor(0); for(int box=0;box<9;box++) {

}

} return;

int y1=50+box*45; int y2=y1+45; if((mousex>=50 && mousex<=100) && (mousey>=y1 && mousey<=y2)) { hidemouse(); line(50,y1,100,y1); line(50,y2,100,y2); line(50,y1,50,y2); line(100,y1,100,y2); showmouse(); delay(200); operations(box); return; } else continue;

void drop_down(char *p,int q) { setcolor(15); int x1=30+70*q; line(x1,10,x1,30); setfillstyle(solid_fill,1); setcolor(11); outtextxy(x1-66,17,p); return; } void erase_drop() { hidemouse(); putimage(20,5,ptr_menu,copy_put); showmouse(); return; } int colour_select(int mousex,int mousey) { setcolor(0); for(int col=0;col<14;col++) { int y1=50+30*col;

graphics editor _____________________________________________________________ ________ int y2=y1+30; if((mousex>=30 && mousex<=50) && (mousey>=y1 && mousey<=y2)) { line(left,y1,left,y2); line(30,y1,50,y1); line(30,y2,50,y2); line(30,y1,30,y2); colour=col; return(colour); } }

}

void colour_unselect() { setcolor(15); line(30,50,30,470); line(left,50,left,470); for(int col=0;col<14;col++) { int y1=50+30*col; line(30,y1,50,y1); } return; } void file_menu() { int i,j; while(1) { getmouse(&newbutton,&newmousex,&newmousey); if(newmousex>=20 && newmousex<=610 && newmousey>=5 && newmousey<=30 && newbutton==1) { int ch; ch=((newmousex-30)/70)+1; /* this gives us the option chosen */ switch(ch) { case 1: delay(100); hidemouse(); for(int tempo=15;tempo>=0;tempo--) { setfillstyle(solid_fill,tempo); floodfill(200,400,1); } setcolor(black); rectangle(145,80,605,465); setfillstyle(solid_fill,white); floodfill(150,90,black); setcolor(1); rectangle(145,80,605,465); showmouse(); return; case 4: ofstream file; setcolor(2); erase_drop(); hidemouse(); outtextxy(210,470,"enter the file name"); outtextxy(37,15,"file name: "); showmouse(); char name_save[20]; int j=0; char temp_save[2]; while(1) {

version 1.0

page 29 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ name_save[j]=getch(); if(name_save[j]!=13) { temp_save[0]=name_save[j]; temp_save[1]='\0'; name_save[j+1]='\0'; outtextxy(117+(10*j),15,temp_save); j++; continue; } name_save[j]='\0'; break;

} erase_drop(); setcolor(0); outtextxy(210,470,"enter the file name"); file.open(name_save,ios::binary); size_t area_save; for(int k=0;k<4;k++) { area_save=imagesize(105+(128*k),57,105+(128*(k+1)),265); ptr_save=malloc(area_save); getimage(105+(128*k),57,105+(128*(k+1)),265,ptr_save); file.write((char*)ptr_save,area_save); free(ptr_save); } for(int l=0;l<4;l++) { area_save=imagesize(105+(128*l),265,105+(128*(l+1)),469); ptr_save=malloc(area_save); getimage(105+(128*l),265,105+(128*(l+1)),469,ptr_save); file.write((char*)ptr_save,area_save); free(ptr_save); } setcolor(2); file.close(); erase_drop(); outtextxy(37,15,"s a v e d"); delay(900); setcolor(0); outtextxy(37,15,"s a v e d"); setcolor(0); outtextxy(210,470,"saveas mode"); return; case 2: ifstream file1; setcolor(2); erase_drop(); hidemouse(); outtextxy(210,470,"enter the file name"); outtextxy(37,15,"file name: "); showmouse(); char name[20]; int i=0; char temp[2]; while(1) { name[i]=getch(); if(name[i]!=13) { temp[0]=name[i]; temp[1]='\0'; name[i+1]='\0';

graphics editor _____________________________________________________________ ________ outtextxy(117+(10*i),15,temp); i++; continue;

} name[i]='\0'; break;

} erase_drop(); setcolor(0); outtextxy(210,470,"enter the file name"); file1.open(name,ios::binary); size_t area_disp; for(int s=0;s<4;s++) { area_disp=imagesize(105+(128*s),57,105+(128*(s+1)),265); ptr_save=malloc(area_disp); file1.read((char*)ptr_save,area_disp); putimage(105+(128*s),57,ptr_save,copy_put); free(ptr_save); } for(int t=0;t<4;t++) { area_disp=imagesize(105+(128*l),265,105+(128*(l+1)),469); ptr_save=malloc(area_disp); file1.read((char*)ptr_save,area_disp); putimage(105+(128*t),265,ptr_save,copy_put); free(ptr_save); } file1.close(); erase_drop(); setcolor(0); outtextxy(210,470,"open mode"); return; case 5: hidemouse(); quit(); default: return; }

} else if(newbutton==1) { return; } }

}

void credits() { while(1) { getmouse(&newbutton,&newmousex,&newmousey); if(newmousex>=20 && newmousex<=610 && newmousey>=5 && newmousey<=30 && newbutton==1) { int ch; ch=((newmousex-30)/70)+1; switch(ch) { case 2: setcolor(4); hidemouse(); settextstyle(default_font,horiz_dir,1); /******/ char x; /******/

version 1.0

page 31 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ /*******/ int length1,xa=50,ya=100; /*******/ clrscr(); /*******/ char exit_1[100]="this is the graphics editor version 1.0 (beta)

developed as";

/*******/ length1= strlen(exit_1); bullet(exit_1,length1,xa,ya); /********/ int length2,length3,length4,length5; /********/ int xb=50,xc=50,xd=50,xe=50,yb=150,yc=200,yd=250,ye=300; /*********/ char exit_2[100]="a project for the xii grade by akshay and srikanteshwara.";

/*********/ length2=strlen(exit_2); bullet(exit_2,length2,xb,yb);

/*********/ char exit_3[100]="this software enables you to perform elementary drawing and painting."; /*********/ length3=strlen(exit_3); bullet(exit_3,length3,xc,yc); /*******/ char exit_4[100]="certain features have been disabled. we apologize for the inconvenience."; /*******/ length4=strlen(exit_4); bullet(exit_4,length4,xd,yd); /*******/ char exit_5[100]="press any key to return to the editor..."; /*******/ length5=strlen(exit_5); bullet(exit_5,length5,xe,ye); free(ptr_menu); getch(); cleardevice(); setcolor(0); closegraph(); int gdriver = detect, gmode, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "d:\\tc\\bgi"); structure(); showmouse(); return; case 1:

setcolor(4); hidemouse(); settextstyle(default_font,horiz_dir,1); /******/ char x2; /******/ /*******/ int length12,xa2=50,ya2=100; /*******/

graphics editor _____________________________________________________________ ________ clrscr(); /*******/ char exit_12[100]="this editor is developed by akshay srivatsa and srikanteswara s";

/*******/ length12= strlen(exit_12); bullet(exit_12,length12,xa2,ya2); /********/ int length22,length32,length42,length52; /********/ int xb2=50,xc2=50,xd2=50,xe2=50,yb2=150,yc2=200,yd2=250,ye2=300; /*********/ char exit_22[100]="students of xi std, sri kumaran children's

home-cbse.";

/*********/ length22=strlen(exit_22); bullet(exit_22,length22,xb2,yb2); /*********/ char exit_32[100]="they can be contacted at 6581662 and 6677370

respectively.";

/*********/ length32=strlen(exit_32); bullet(exit_32,length32,xc2,yc2); /*******/ char exit_42[100]="thank you for using graphics editor version

1.0";

/*******/ length42=strlen(exit_42); bullet(exit_42,length42,xd2,yd2); /*******/ char exit_52[100]="press any key to return to the editor..."; /*******/ length52=strlen(exit_52); bullet(exit_52,length52,xe2,ye2); free(ptr_menu); getch(); cleardevice(); setcolor(0); closegraph(); int gdriver2 = detect, gmode2, errorcode2; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "d:\\tc\\bgi"); structure(); showmouse(); return; default: return; }

} else if(newbutton==1) return; } } void menu(int mousex,int mousey) { void quit();

version 1.0

page 33 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ void hidemouse(); if((mousex>=30 && mousex<=100) && (mousey>=33 && mousey<=46)) { erase_drop(); drop_down("new",1); drop_down("open",2); drop_down("save",3); drop_down("savas",4); drop_down("exit",5); delay(150); file_menu(); erase_drop(); return; } if((mousex>=100 && mousex<=160 ) && (mousey>=33 && mousey<=46)) { erase_drop(); drop_down("about",1); drop_down("credits",2); delay(150); credits(); erase_drop(); return; } if((mousex>=582 && mousex<=607) && (mousey>=33 && mousey<=46)) { hidemouse(); quit(); return; } if((mousex>=50 && mousex<=100) && (mousey>=50 && mousey<=470)) { unselect(); select(mousex,mousey); return; } if((mousex>=30 && mousex<=50) && (mousey>=50 && mousey<=470)) { colour_unselect(); colour_select(mousex,mousey); return; } else return;

}

void bullet(char arr[100],int length,int x,int y) { /***********/ char outstr[2]; outstr[1]=0; /**********/ for(i=0;i
graphics editor _____________________________________________________________ ________ {

setcolor(4); settextstyle(default_font,horiz_dir,1); /******/ char x; /******/ /*******/ int length1,xa=50,ya=100; /*******/ clrscr(); /*******/ char exit_1[100]="this editor is developed by akshay srivatsa and srikanteswara s"; /*******/ length1= strlen(exit_1); bullet(exit_1,length1,xa,ya); /********/ int length2,length3,length4,length5; /********/ int xb=50,xc=50,xd=50,xe=50,yb=150,yc=200,yd=250,ye=300; /*********/ char exit_2[100]="students of xi std, sri kumaran children's home-cbse."; /*********/ length2=strlen(exit_2); bullet(exit_2,length2,xb,yb); /*********/ char exit_3[100]="they can be contacted at 6581662 and 6677370 respectively."; /*********/ length3=strlen(exit_3); bullet(exit_3,length3,xc,yc); /*******/ char exit_4[100]="thank you for using graphics editor version 1.0"; /*******/ length4=strlen(exit_4); bullet(exit_4,length4,xd,yd); /*******/ char exit_5[100]="press any key to return to the c++ compiler..."; /*******/ length5=strlen(exit_5); bullet(exit_5,length5,xe,ye); free(ptr_menu); getch(); exit(0); //quit the editor

}

oper.cpp

/* codes 0 to 14 in colours represent the 14 colours in the editor from top to bottom 0 to 8 in boxes represent the graphical object selected in the editor as given in the same order from top to bottom left mouse button:1

version 1.0

page 35 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _

*/

right mouse button:2 centre mouse button:3 no button pressed:0

/**********/ extern int left, top, colour, right, bottom, j, k, l, c, i, a, r, side; extern int button,mousex,mousey,newbutton,newmousex,newmousey; int positionx,positiony; int colour_chosen; /**********/ /* these are variables for getmouse function same as int ed_util.cpp */ int check_area(int mousex,int mousey) /* this function checks if the mouse pointer is within the work board */ { if((mousex>=150 && mousex<=605) && (mousey>=65 && mousey<=470)) return(1); /* 1 represents within the board */ else return(0); /* 0 represents outside the board */ } void click_mouse() /* to check if the mouse has been clicked or not */ { while(1) { delay(150); getmouse(&newbutton,&newmousex,&newmousey); if(newbutton==1) return; else continue; } } void operations(int item) { /*1*/ int area; /* case line */ if(item==3) { int positionx1,positiony1,positionx2,positiony2; setcolor(2); outtextxy(210,470,"press the colour of the line"); click_mouse(); colour_chosen=colour_select(newmousex,newmousey); if(colour_chosen>=0 && colour_chosen<=14) { setcolor(0); outtextxy(210,470,"press the colour of the line"); } else { unselect(); setcolor(0); outtextxy(210,470,"press the colour of the line"); return; } while(1) { setcolor(2); outtextxy(210,470,"click the two ends of the line"); delay(100); click_mouse(); area=check_area(newmousex,newmousey);

graphics editor _____________________________________________________________ ________

/* to quit lines */

}

if(newbutton==1 && area==1) { positionx1=newmousex; positiony1=newmousey; hidemouse(); circle(newmousex,newmousey,1); showmouse(); click_mouse(); area=check_area(newmousex,newmousey); if(area==1) { positionx2=newmousex; positiony2=newmousey; hidemouse(); circle(newmousex,newmousey,1); showmouse(); setcolor(0); outtextxy(210,470,"click the two ends of the line"); } else { unselect(); setcolor(0); outtextxy(210,470,"click the two ends of the line"); return; } setcolor(colour_chosen); line(positionx1,positiony1,positionx2,positiony2); continue; } if(newbutton==1 && area==0) { unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"click the two ends of the line"); return; } else continue;

}

/* case floodfill */ else if(item==0) { while(1) { getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); if(newbutton==1 && area==1) { positionx=newmousex; positiony=newmousey; setcolor(2); outtextxy(210,470,"press the colour which needs to be filled ");

version 1.0

click_mouse(); colour_chosen=colour_select(newmousex,newmousey); if(colour_chosen>=0 && colour_chosen<=14) { setfillstyle(solid_fill,colour_chosen); } else { unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"press the colour which needs to be

page 37 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ filled");

return; } setcolor(0); outtextxy(210,470,"press the colour which needs to be filled"); setcolor(2); outtextxy(210,470,"press the colour of the boundary"); click_mouse(); colour_chosen=colour_select(newmousex,newmousey); if(colour_chosen>=0 && colour_chosen<=14) { floodfill(positionx,positiony,colour_chosen); } else {

}

unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"press the colour of the boundary"); return;

setcolor(0); outtextxy(210,470,"press the colour of the boundary"); colour_unselect(); continue;

}

} else if(newbutton==1 && area==0) { unselect(); return; } else continue;

} /* case ellipse */ else if(item==1) { while(1) { getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); area=check_area(newmousex-100,newmousey-75); if(newbutton==1 && area==1) { positionx=newmousex; positiony=newmousey; setcolor(0); ellipse(positionx,positiony,0,360,100,50); continue; } else if(newbutton==1 && area==0) { unselect(); return; } else } } /* case rectangle */ if (item==2)

continue;

graphics editor _____________________________________________________________ ________ {

rectangle");

int positionx1,positiony1,positionx2,positiony2; setcolor(2); outtextxy(210,470,"click the colour of the rectangle"); click_mouse(); colour_chosen=colour_select(newmousex,newmousey); if(colour_chosen>=0 && colour_chosen<=14) { setcolor(0); outtextxy(210,470,"click the colour of the rectangle"); setcolor(2); } else { unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"click the colour of the square"); return; } while(1) { setcolor(2); outtextxy(210,470,"click the two ends of the rectangle"); delay(100); click_mouse(); area=check_area(newmousex,newmousey); if(newbutton==1 && area==1) { positionx1=newmousex; positiony1=newmousey; click_mouse(); area=check_area(newmousex,newmousey); if(area==1) { positionx2=newmousex; positiony2=newmousey; setcolor(0); outtextxy(210,470,"click the two ends of the rectangle"); } else { unselect(); setcolor(0); outtextxy(210,470,"click the two ends of the rectangle"); return; } setcolor(2); outtextxy(210,470,"click the mouse away from area of the click_mouse(); setcolor(0); outtextxy(210,470,"click the mouse away from area of the

rectangle");

setcolor(colour_chosen); rectangle(positionx1,positiony1,positionx2,positiony2); continue;

/* to quit lines */

} if(newbutton==1 && area==0) { unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"click the two ends of the rectangle"); return; } else continue;

}

version 1.0

page 39 of 41 date: 23-Oct-08

graphics editor ___________________________________________________________________________ _ } /* case pencil */ if(item==7) { setcolor(2); outtextxy(210,470,"click the colour of the pencil lead"); delay(100); click_mouse(); colour_chosen=colour_select(newmousex,newmousey); if(colour_chosen>=0 && colour_chosen<=14) { setcolor(0); outtextxy(210,470,"click the colour of the pencil lead"); } delay(100); while(1) { setcolor(colour_chosen); getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); if(newbutton==1 && area==1) { hidemouse(); circle(newmousex,newmousey,2); showmouse(); } if(newbutton==1 && area==0) { /* to quit lines */ unselect(); colour_unselect(); setcolor(0); outtextxy(210,470,"click the colour of the pencil lead"); return; } else continue; } } /* case coor */ if(item==6) { setcolor(2); outtextxy(210,470,"click the mouse within the area to get the coordinate"); while(1) { getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); if(area==1 && newbutton==1) { erase_drop(); outtextxy(37,15,"co-or near the drawing area: "); gotoxy(45,5); cout<
graphics editor _____________________________________________________________ ________ }

} return;

}

/* case circle */ /* case erase */ if(item==8) { setcolor(2); outtextxy(210,470,"sorry,this option is not in operation."); delay(1000); setcolor(black); outtextxy(210,470,"sorry,this option is not in operation."); unselect(); return; /* int x1,y1,x2,y2; while(1) { getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); if(area==1 && newbutton==1) { x1=newmousex; y1=newmousey; delay(150); while(1) { getmouse(&newbutton,&newmousex,&newmousey); area=check_area(newmousex,newmousey); if(area==1 && newbutton==1) { x2=newmousex; y2=newmousey; setcolor(2); rectangle(x1,y1,x2,y1); setfillstyle(solid_fill,black); floodfill(x1+20,y1+10,black); setfillstyle(solid_fill,white); floodfill(x1+10,y1+10,black); delay(150); break; } if(area==0 && newbutton==1) { unselect(); setcolor(0); outtextxy(210,470,"click the 2 co-ordinates"); return; } } } if(area==0 && newbutton==1) { unselect(); setcolor(0); outtextxy(210,470,"click the 2 co-ordinates"); return; } }*/ } }

/*~1*/

version 1.0

page 41 of 41 date: 23-Oct-08

Related Documents

Graphics Editor
November 2019 26
Graphics
November 2019 36
Graphics
May 2020 21
Editor
December 2019 55
Image & Graphics
June 2020 11
Information Graphics
April 2020 11