0% found this document useful (0 votes)
89 views

Easy Draw

This document summarizes a student project to develop a graphics editor software using C++. It includes a certificate approving the project, acknowledgements, an index of contents, and sections on the aim, abstract, introduction, design, and more. The project aims to create an interactive graphics editor for basic drawing and editing tasks. It uses object-oriented programming with classes for the toolbar, menu bar, color bar, and drawing area. The editor allows selecting tools, colors, and performing tasks like drawing lines, shapes, and more within the designated work area.

Uploaded by

techravisharma
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Easy Draw

This document summarizes a student project to develop a graphics editor software using C++. It includes a certificate approving the project, acknowledgements, an index of contents, and sections on the aim, abstract, introduction, design, and more. The project aims to create an interactive graphics editor for basic drawing and editing tasks. It uses object-oriented programming with classes for the toolbar, menu bar, color bar, and drawing area. The editor allows selecting tools, colors, and performing tasks like drawing lines, shapes, and more within the designated work area.

Uploaded by

techravisharma
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 60

-1-

EASY DRAW
A graphics editor

By:
RAVI SHARMA [ 2604241 ] CH.DEVI LAL MEMO.ENGG. COLLEGE PANNIWALA MOTA SIRSA

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-2-

KURUKSHETRA UNIVERSITYS
CH. DEVI LAL MEMORIAL ENGG. COLLEGE , PANNIWALA MOTA , SIRSA 125055

CERTIFICATE OF APPROVAL OF PROJECT WORK

This is to certify that the major project Graphics editor has been satisfactorily completed by the student

RAVI SHARMA(2604241) as prescribed by K.U computer science course in the year 2007-2008
1: 2: Signature of HOD (Mr VED PRAKASH) Name RAVI SHARMA Roll number: 2604241 DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA. Signature of Guide (Mr.SANJAY DAHIYA) Signature of Examiner

-3-

ACKNOWLEDGEMENT
No project is envisaged without the help and guidance of an experienced person respected in the field of concerned subject. Though the benefit achieved from them can never be adequately valued we would like and express hearty gratitude towards them. We have worried on our project under the rich guidance of our esteemed and beloved guide Mr.SANJAY DAHIYA his wisdom and vast experience has enabled us to conduct the project work successfully. We express our sincere thanks to the same. We also thank our H O D for his inspiration during the completion of our object we are highly grateful to our respected principal for his co-operation. We extend sincere thanks to the teaching and non-teaching staffs for their guidance and co-operation.
DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-4-

INDEX
CONTENTS
i. ii. iii. iv. v. vi. vii. viii. ix.

PAGE NO
5 6 8 10 16 18 19 55 56

AIM ABSTRACT INTRODUCTION DESIGN DETAILED DESIGN TESTING SOURCE CODE CONCLUSION BIBLIOGRAPHY

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-5-

AIM
To develop a Computer Graphics package using C/C++ to support the various features like file options, drawing, tools and other options.

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-6-

ABSTRACT
The computer graphics has grown into a very important topic in the branch of computer science. This is due to an effective and rapid communication link that provides between the man and the machine .The human eye can absorb the information content of a displayed diagram or perspective view much faster than it can scan a page of words or a table of contents. While dealing with simple matters, we need to draw simple figures to explain that matter effectively. Also for getting simple of visiting cards,greeting cards, letterheads, simple machine drawings, we need software, which allows us to edit graphics. For this purpose, if we are going to use AUTOCAD, VENTURA, etc., then it will take a lot of effort to edit the figure, and also these software cannot be used it PCs/XTs.For this purpose, we need a software to edit simple figures.This is the basic motivation of this project. The title of our project is GRAPHICS EDITOR. as the name indicates it deals with computer graphics which interacts with the user. Hence the graphics generated is interactive graphics. The features of the editor revolve around supporting the various user requirements like drawing, painting and various editing features. The editor has been implemented under the DOS environment using the TURBO C++ package using the C++ as the language tool. An Object Oriented Approach has been used here in order to utilize the various features provided by it.

The editor involves the following 4 classes : 1. TOOLBAR 2. MENUBAR. 3. COLORBAR 4. DRAWING AREA. DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-7-

The above features have been ably supported by an easy to understand mouse interface. All the tools have been organized under the toolbar. The color palette has been organized under the color bar. The file options have been organized under the menu bar. The drawing work is carried out in the rectangular work area provided in the main window. Everything here is represented in terms of objects of the various classes mentioned above. The objects call the member functions which in turn carry out the required job. The rubber band technique has also been used. The tools supported are : 1. Line. 2. Pen/pencil. 3. Rectangle/square. 4. Floodfill. 5. Rubber. 6. Circle/ellipse. 7. Paint. 8. Freedraw. The colors can be chosen from the color bar. There are 16 different colors.The drawing is done in the work area which is a rectangular drawing space.

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-8-

INTRODUCTION.
Computer Graphics is the creation and manipulation of pictures with the aid of computers. It is divided into two broad classes. (1) Non-interactive Graphics. (2) Interactive Graphics. In non-interactive graphics or passive graphics the observer has no control over the pictures produced on the screen. While in interactive graphics the pictures displayed on the screen are controlled by the user through an input device.

Interactive Computer Graphics :

This is the type of Computer Graphics in which the pictures produced can be controlled by the user. It involves two way communication between user and computer. The computer upon receiving signal from the input device can modify the displayed picture appropriately. To the user it appears that the picture is changing instantaneously in response to his commands. In this way he maintains a conversation with the computer. This requires an software that allows the user to modify drawing during its construction in order to eliminate errors or create alternative design. In other words the user may interact directly with the computer through the picture on the screen during its generation.

Graphics Adapters :
The electronic work behind the formation of images on the screen is handled by the video controller. The video controller along with the memory that holds the display data are together referred to as display adapter. There are various kinds or Display Adapters that can be used with the computers. Computers can represent data on the screen in two modes. One is the text mode in which only text or individual characters can be displayed. The other is the graphics mode, where graphics can be hown by building up a drawing made of dots.

The different types of adapters available are: DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

-9 only. Only Monochrome Display Adapter (MDA) : Used for text Black & White colors are available for text. text Hercules Display Adapter (MGA/HERC) : Used for both and graphics. When used for text the working is same as that of an MDA. When used for graphics it has a resolution of 720380 pixels. graphics. Color Graphics Adapter (CGA) : Used for both text and When used for text, it displays 2580 characters, and it can display upto 16 colors when used for text. When used for graphics, it can give different graphic modes, they are 320200 pixel graphics and 640200 pixel graphics. In 320200 pixel graphics we can use 4 colors at a time while in 640200 pixel graphics we can get only 2 colors at a time. Normally used two colors white and black. But we can use any other color also instead of white while black will be another color. Even if the signals sent are for color, the display is also depends on the types of monitor that we are using, if we use Monochrome monitor then we cannot differentiate between white and other colors, but with Color Monitors, the colors are visible. MCGA: Used for both text and graphics. It is mostly same as compared to CGA, except the fact that in graphics it will give a graphics with 640200 pixels with two colors. Enhanced Graphics Adapter (EGA): Video Graphics Adapter (VGA) : Both of these adapters in many functions. With these adapters we can extend the display memory by adding memory chips, so that they can handle the graphics with 256 colors also. But using these adapters will not allow the user to use normal Monochrome monitors, but we have to use the monitors which are designed for the particular adapter only, and the cost of the computer will then increase effectively and hence these are not commonly in use except in some particular places where the technology feels them necessary.

are same

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 10 All of these adapters will contain a display memory, which we can address in the usual way. We can display text or graphics by placing appropriate data in this area of memory. For displaying text, the ASCII value of the character which has to be displayed is stored in one byte, followed by one attribute byte which contains information about the color of display and the intensity.

DESIGN
Software requirement specification :
During the time of requirement analysis the following requirements were noted : A good and easy to understand user interface to support proper handling of the CG Editor. For this the mouse interface was also required and it was decided to implement the project taking the mouse interface into consideration. Ability to open, edit and save files. Another user requirement is the tools that he requires in order to carry out the required operations. This user requirement gave rise to the toolbar which consists of the various tools that the user can select from. The other requirement is the color with which the user would like to work with. This user requirement gave rise to the colorbar or the color pallette from which the user can select the color to work with. The color bar consists of 16 different colors to choose from. The user is provided with the rectangular area called the drawing_Area to work with. The user can select the required tool and also the required color when drawing with a tool. The user can invoke the appropriate options in the drawing_Area. Suppose the user when drawing goes out of range of the drawing or the work area, proper care has been taken to see that nothing is written outside the drawing area. This is yet another user requirement which has been taken care of. DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 11 The various mouse positions of the user are also depicted on the tatus bar at the bottom of the window in order to enable him to know his current position. The user has been provided with a number of tools that work with the rubber band technique in order to allow him to dynamically change the position of the endpoints of the objects that he wants to draw. This gives him the option to shrink or enlarge a particular object on the spot.

A number of functions are there which provide the user with the various requirements discussed above. Some of the functions are menu Bar->handle() -> this handles the various menu options like new, save, open and exit. Exit button has also been provided. color_Bar->handle () -> this handles the various color options that the user requires while drawing on the drawing area. tool_Bar->handle () -> this handles the various tools that are required by the user in order to carry out his task. The various other functions that were required to satisfy the user needs are : line () -> to draw a line. pencil () -> to provide the pen/pencil options. circle () / ellipse() -> to draw the circle or ellipse. rectangle () -> to draw rectangle or square. rubber () -> to erase the contents on the screen. paint () -> to provide the spray paint option to the user. floodfill () -> to fill the work area with the desired color. new () -> to create a new file. save () / saveas () -> to save a file. DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 12 open () -> to open a file from the existing directory.

ToolBox

FillStylesBox

ColorBox

Menubar

Canvas

Graphics Editor

The main routine of the graphics editor has been written keeping modular and functional needs in mind. This makes the source code of the editor easier to understand and debug. The main algorithm of EASYDRAW is as shown below EASYDRAW_init WHILE NOT quit BEGIN Mouse.read IF mouse.lbutton THEN BEGIN Mouse.get_postion DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 13 IF inCanvas THEN CallTool ELSE IF inColorbox THEN SetColor ELSE IF fillstylesBox THEN SetFillstyle ELSE IF menubar THEN CallMenu END END EASYDRAW_shutdown In the design of the graphics editor the following main components have been used

Menubar
The menubar holds the buttons to open and save pictures. It also holds the exit button. The bar shows information like the editor name and the filename.

Toolbox
The toolbox holds the various tools available to the user to apply on the canvas. Some of the important tools are line, box and ellipse. The toolbox has been implemented as a class that holds buttons, where each button represents a tool.

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 14 -

Toolbox

The class structure of the toolbox is given below, class Toolbox { private: Button button[16]; int width; int height; int count; public: Toolbox(); void draw(); int check(int x, int y); };

Fillstyles Box
The fillstyles box holds the various fill styles that can be applied to fill objects.

Fillstyles box

EASYDRAW supports the following fill styles Empty fill DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 15 Solid fill Line fill Ltslash fill Slash fill Bkslash fill Ltbkslash fill Hatch fill Xhatch fill Interleave fill Wide dot fill Close dot fill

The data structure of the fillstyles box is given below class FillstylesBox { private: Button button[12]; int width; int height; int gap; int count; public: FillstylesBox(); void draw(); int check(int x, int y); };

Colorbox
The colorbox holds the colors that can be used to draw and fill the objects on the canvas. EASYDRAW supports 16 colors.

Colorbox

The datastructure of the colorbox is shown below, DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 16 class Colorbox { private: Button button[16]; int width; int height; int gap; int count; public: Colorbox(); void draw(); int check_fg(int x, int y); };

Canvas
The canvas is the screen space over which all the objects are drawn. It is bounded on four sides with a border. When a drawing operation is being performed on the canvas, the mouse movement is limited to the canvas size.

DETAILED DESIGN
EASYDRAW has various sub routines and functions to perform its operation. Some of the important ones are void easydraw_init(); This function performs the initialization needed to start the editor. void freehand(); This routines is used to provide freehand drawing to the user. void drawline(); DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 17 The drawline routine enables the user to draw lines. void drawrect(); Using the drawrect function the user is able to draw boxes and rectangles. void fillrect(); The fillrect routines is used to draw filled rectangles and boxes. void drawellipse(); The drawellipse function enables the user to draw circles and ellipses. void fillellipse(); This function is used to draw filled circles and ellipses. void drawpolygon(); The drawpolygon function is used to draw polygons consisting of any number of sides. void fillpolygon(); The fillpolygon function is used to draw filled polygons. void drawspiral(); The drawspiral routine can be used to draw spirals.

void clip(); This routines clips the selected area. void scale(); Scales the selected area. void rotate(); Rotates the selected area. void loadfile(); Loads a picture file onto the canvas. DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 18 void savefile(); Saves the canvas onto a file. void easydraw_shutdown(); Performs the shutdown of the editor.

TESTING
The testing comprises of one of the most important parts of our project. As and when a particular module was developed it was tested immediately to see whether it catered to the requirements of the user specifications and requirements. The project was subjected to the following kinds of testing :Unit testing. Module testing. Sub-system testing System testing. Acceptance testing. DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 19 The testing was a very tough process as it had to be verified that the user requirements were being met or not. The testing started off with fundamental components and works upwards thus following the path of Bottom-up testing. The graphics editor has been tested under DOS and Windows and has been found to provide ease of use and manipulation to the user. However, we found many limitations in our editor like Features like Undo and Redo could not be provided Only selected area based transformations are provided Just a Single Document Interface (SDI) to the editor Limited to 16 colors

SOURCE CODE
********************************************************************************

EASYDRAW.H
********************************************************************************
----------------------------------------------------------------------C o n s t a n t s ----------------------------------------------------------------------const int COLOR = LIGHTGRAY; // default color const int MAXCOLOR = 15; // maximum available colors const int MAXX = 639; const int MAXY = 479; // maximum X coordinate // maximum Y coordinate

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 20 // Canvas const int const int const int const int bounds LEFT TOP RIGHT BOTTOM = = = = 78; 34; MAXX - 10; 422;

// Mouse buttons const int L_BUTTON = 0x0001; const int R_BUTTON = 0x0002; const int TOOLCOUNT = 16; // Tool identifiers const int FREEHAND = 0; const int LINE = 1; const int RECT = 2; const int FILLEDRECT = 3; const int ELLIPSE = 4; const int FILLEDELLIPSE = 5; const int POLYGON = 6; //const int FILLPOLYGON = 7; const int SPIRAL = 7; const int MARK = 8; const int TRANSLATE = 9; const int SCALE = 10; const int ROTATE = 11; const int CLIP = 12; const int CLEAR = 13; const int LOAD = 14; const int SAVE = 15; const int DELAY = 15; // delay during XOR // number of tools available + 1

----------------------------------------------------------------------U s e r - D e f i n e d D a t a T y p e s ----------------------------------------------------------------------enum {false = 0, true = 1}; // used for stdC++ true/false emulation */

/* Block holds the `marked' canvas info class Block { private: int left; int top; int right; int bottom; int use; public: Block();

int contains(int x, int y); void set(int l, int t, int r, int b); void clip(); void clipIn();

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 21 void translate(int tx, int ty); void rotate(); void scale(); }; /* Mouse class is used for all operations on the mouse */

class Mouse { private: union REGS in, out; struct SREGS seg; public: int x, y; int lbutton; int rbutton; // present (x, y) position of mouse // left button status // right button status

void init(); int reset(); void show(); void hide(); void read(); void read_status(int *button, int *x, int *y); void read_motion(int *x, int *y); void set_position(int x, int y); void set_bound(int x1, int y1, int x2, int y2); void set_hbound(int x1, int x2); void set_vbound(int y1, int y2); }; /* */ class Button { public: int left, top; int right, bottom; int down; int color; A generic class used to generate `button' type objects that can be clicked upon to set options

// button status

public: Button(); Button(int left, int top, int right, int bottom); Button(int left, int top, int right, int bottom, int color); void draw(); void draw(int color); int inBound(int x, int y); // check if point is within button }; /* Used to display text buttons */

class TextButton : public Button

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 22 { public: char *info; public: void draw(); }; /* Used for setting, displaying and manipulation of tools */ // text displayed on button

class Toolbox { private: Button button[TOOLCOUNT]; int width; int height; public: Toolbox(); void draw(); int check(int x, int y); void drawFreehandPic(); void drawLinePic(); void drawRectPic(); void drawFilledRectPic(); void drawEllipsePic(); void drawFilledEllipsePic(); void drawPolygonPic(); void drawSpiralPic(); void drawMarkPic(); void drawTranslatePic(); void drawRotatePic(); void drawScalePic(); void drawClipPic(); void drawClearPic(); void drawLoadPic(); void drawSavePic(); }; /* Used to display color buttons and set colors class Colorbox { private: Button button[16]; int width; int height; int gap; // gap between buttons int count; // no of colorbox buttons public: Colorbox(); void draw(); int check(int x, int y); }; /* Shows the current color and fill style status */ // check and set fg color */

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 23 class Statusbox { private: Button statusButton; int width; int height; public: Statusbox(); void draw(); void setColor(int color); // set color void setFillStyle(int fillStyle); }; /* Used to display fillstyle buttons and to set fill style */

class FillStylebox { private: Button button[12]; int width; int height; int gap; public: FillStylebox(); void draw(); int check(int x, int y); }; /* Holds the buttons on the menubar */

class Menubar { private: TextButton exitButton; int width; int height; public: Menubar(); void draw(); void check(int x, int y); }; /* Used to display messages and take keyboard inputs from the user */

class MessageBox { private: int left; int top; int right; int bottom; public:

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 24 MessageBox(); void draw(); void clear(); void put(const char *msg, int wait); int putGetInt(const char *msg); void putGetString(const char *msg, char *get); void readString(char *get, int nleft); }; /* Used for manipulations on the canvas */

class Canvas { public: void clear(); int in(int x, int y); void save(); void load(); void putpoint(const int x, const int y, const int ccolor); }; /*----------------------------------- End ------------------------------ */

// Function prototypes void void void void void Easydraw_init(); EasydrawDrawSkin(); Easydraw_shutdown(); Easydraw_exit(); put_error( const char * errmsg );

void drawBlock(int left, int top, int right, int bottom, int down, int color); void drawBlock(int left, int top, int right, int bottom, int down); void callTool(); void void void void void void void freehand(); drawLine(); drawRect(int fill); drawEllipse(int fill); drawPolygon(); drawSpiral(); drawMark();

void plotEllipse(int xcen, int ycen, float radx, float rady); void plotEllipsePoints(int xcen, int ycen, int x, int y); void plotSpiral(int x, int y, int rad);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 25 ********************************************************************************

EASYDRAW.C
********************************************************************************
// Standard includes #include <alloc.h> #include <conio.h> #include <dos.h> #include <graphics.h> #include <iostream.h> #include <math.h> #include <process.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include " Easydraw.h" /*----------------------------------------------------------------------- *\ G l o b a l V a r i a b l e s \*----------------------------------------------------------------------- */ int Easydraw_quit = false; int curColor = BLACK; int curFillStyle = SOLID_FILL; int tool = 0; int prevtool = 0; char filename[13] = "save"; Mouse mouse; Toolbox toolbox; Colorbox colorbox; FillStylebox fillstylebox; Statusbox statusbox; Menubar menubar; Block block; MessageBox msgbox; Canvas canvas; /* ------------------------------------ End ---------------------------- */

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 26 -

/* ---------------------------------------------------------------------- *\ > M a i n < F u n c t i o n \* ---------------------------------------------------------------------- */ int main() { int x, y; int button; Easydraw_init(); while (!Easydraw_quit) { mouse.read(); // if left button was pressed if (mouse.lbutton) { x = mouse.x; y = mouse.y; // check if press was within canvas if (canvas.in(x, y)) // then call the current tool callTool(); else if (colorbox.check(x, y)) {} else if (fillstylebox.check(x, y)) {} else if (toolbox.check(x, y)) {} else menubar.check(x, y); } }

Easydraw_shutdown(); return 0; } /* ------------------------------------- End ---------------------------- */

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 27 -

/* ---------------------------------------------------------------------- *\ G e n e r a l R o u t i n e s \* ---------------------------------------------------------------------- */ void Easydraw_init() { int gd, gm; int errorcode; // Initial info display cout << " Easydraw 2D" << endl; cout << "RAKSHITH <[email protected]" << endl; cout << "PRASAD <[email protected]>" << endl; // Graphics Initialization printf("Detecting graphics driver and mode...\n"); detectgraph(&gd, &gm); printf("Initializing the graphics system...\n"); initgraph(&gd, &gm, ""); // If any errors occured during graphics init errorcode = graphresult(); if (errorcode != grOk) {

put_error(grapherrormsg(errorcode)); printf("Press any key to halt"); getch(); exit(1); } // fill the canvas setfillstyle(SOLID_FILL, WHITE); floodfill(200, 200, LIGHTGRAY); EasydrawDrawSkin(); // Wake up the mouse mouse.init(); } void EasydrawDrawSkin() { mouse.hide(); // Draw the three bars setfillstyle(SOLID_FILL, LIGHTGRAY); bar(0, 0, MAXX - 1, TOP - 1); // top bar bar(0, TOP, LEFT - 1, BOTTOM); // middle bar bar(0, BOTTOM + 1, MAXX, MAXY); // bottom bar bar(RIGHT + 1, TOP, MAXX, BOTTOM);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 28 /* Display logo and credits */

drawBlock(7, 5, 310, 28, false); setcolor(RED); rectangle(12, 8, 70, 25); rectangle(18, 11, 64, 22); rectangle(24, 14, 58, 19); settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); setcolor(RED); char name[5]; name[0] = 'E'; name[1] = 133; name[2] = 'S'; name[3] = Y; name[4] = ; name[5] = D; name[6] = R; name[7] = 133; name[8] = w; name[9] = ; name[10] = '\0'; outtextxy(82, 12, name); setcolor(WHITE); settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); outtextxy(160, 14, "the artist in you"); drawBlock(320, 5, 480, 28, false); setcolor(RED); settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); outtextxy(328, 10, "By"); settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); outtextxy(375, 8, "RAKSHITH"); outtextxy(375, 18, "PRASAD N PRABHU"); settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); // draw the menu bar settextjustify(CENTER_TEXT, CENTER_TEXT); menubar.draw();

settextjustify(LEFT_TEXT, TOP_TEXT); // draw the various boxes toolbox.draw(); // draw the toolbar colorbox.draw(); // draw the colorbox fillstylebox.draw(); // draw the fillstylebox statusbox.draw(); // draw the colorstatus box msgbox.draw(); // draw the message box // draw the Easydraw border setcolor(WHITE); line(0, 0, MAXX, 0);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 29 line(0, 0, 0, MAXY); line(1, 1, MAXX, 1); line(1, 1, 1, MAXY); setcolor(BLACK); line(MAXX, MAXY, 0, MAXY); line(MAXX, MAXY, MAXX, 0); line(MAXX - 1, MAXY - 1, 1, MAXY - 1); line(MAXX - 1, MAXY - 1, MAXX - 1, 1); // draw the canvas border setcolor(BLACK); line(LEFT - 1, BOTTOM + 1, LEFT - 1, TOP - 1); line(LEFT - 1, TOP - 1, RIGHT - 1, TOP - 1); setcolor(WHITE); line(LEFT - 1, BOTTOM + 1, RIGHT + 1, BOTTOM + 1); line(RIGHT + 1, BOTTOM + 1, RIGHT + 1, TOP - 1); setcolor(curColor); setfillstyle(SOLID_FILL, curColor); mouse.show(); } void Easydraw_shutdown() { mouse.hide(); closegraph(); } void kala_exit() { Easydraw_shutdown(); exit(1); } void put_error(const char *errmsg) { fprintf(stderr, "Error : %s\n", errmsg); } /* ---------------------- General Routines End -------------------------*/ /* Calls the current tool for drawing */

void callTool() { mouse.set_bound(LEFT, TOP, RIGHT, BOTTOM); setcolor(curColor); setfillstyle(curFillStyle, curColor); switch (tool) { case FREEHAND case LINE case RECT

: freehand(); break; : drawLine(); break; : drawRect(false); break;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 30 case FILLEDRECT case case case case case case : drawRect(true); break; ELLIPSE : drawEllipse(false); break; FILLEDELLIPSE : drawEllipse(true); break; POLYGON : drawPolygon(); break; SPIRAL : drawSpiral(); break; MARK : drawMark(); break; TRANSLATE : block.translate(mouse.x, mouse.y); break;

default : cerr << "Unknown tool" << endl; break; } mouse.set_bound(0, 0, MAXX, MAXY); }

/*

Draw freehand

*/

void freehand() { int x1, y1, x2, y2; int button; x1 = mouse.x; y1 = mouse.y; while (mouse.lbutton) { mouse.read(); x2 = mouse.x; y2 = mouse.y; if (x1 != x2 || y1 != y2) { mouse.hide(); line(x1, y1, x2, y2); mouse.show(); x1 = x2; y1 = y2; } } } /* Draws a line */

void drawLine() { int x, y; int x1, y1; x = mouse.x;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 31 y = mouse.y; x1 = x; y1 = x; setcolor(MAXCOLOR - curColor); setwritemode(XOR_PUT); mouse.hide(); while (mouse.lbutton) { mouse.read(); x1 = mouse.x; y1 = mouse.y; line(x, y, x1, y1); delay(DELAY); line(x, y, x1, y1); }; setcolor(curColor); setwritemode(COPY_PUT); line(x, y, x1, y1); mouse.show(); }

/*

Draw a rectangle (filled / unfilled)

*/

void drawRect(int fill) { int x = mouse.x; int y = mouse.y; int x1 = x; int y1 = y; setcolor(MAXCOLOR - curColor); setwritemode(XOR_PUT); mouse.hide(); do { mouse.read(); x1 = mouse.x; y1 = mouse.y; rectangle(x, y, x1, y1); delay(DELAY); rectangle(x, y, x1, y1); } while (mouse.lbutton); setwritemode(COPY_PUT);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 32 if (fill) { setfillstyle(curFillStyle, curColor); bar(x, y, x1, y1); } else { setcolor(curColor); rectangle(x, y, x1, y1); } mouse.show(); } /* Draw a ellipse (filled / unfilled) */

void drawEllipse(int fill) { int x1, y1; int x2, y2; int color; int xmid, ymid; float radx, rady; mouse.read(); x1 = mouse.x; y1 = mouse.y; setcolor(MAXCOLOR - curColor); setwritemode(XOR_PUT); mouse.hide(); while (mouse.lbutton) { mouse.read(); x2 = mouse.x; y2 = mouse.y; xmid ymid radx rady = = = = (x1 + x2)/2; (y1 + y2)/2; abs((x2 - x1) / 2); abs((y2 - y1) / 2);

if (radx < 1) radx = 1; if (rady < 1) rady = 1; plotEllipse(xmid, ymid, radx, rady); delay(DELAY); plotEllipse(xmid, ymid, radx, rady); } setcolor(curColor); setwritemode(COPY_PUT); if (fill) { setfillstyle(curFillStyle, curColor); fillellipse(xmid, ymid, radx, rady);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 33 } else ellipse(xmid, ymid, 0, 360, radx, rady); mouse.show(); } /* Draw a polygon */

void drawPolygon() { int x, y; int x1, y1; int x2, y2; x = mouse.x; y = mouse.y; x1 = x; x2 = x; y1 = y; y2 = y; while (!mouse.rbutton) { if (mouse.lbutton) { x2 = mouse.x; y2 = mouse.y; mouse.hide(); line(x1, y1, x2, y2); mouse.show(); x1 = x2; y1 = y2; } mouse.read(); } mouse.hide(); line(x, y, x2, y2); mouse.show(); }

/*

Draw a spiral

*/

void drawSpiral() { int x, y; int x1; x = mouse.x; y = mouse.y; mouse.hide(); while (mouse.lbutton) { mouse.read();

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 34 x1 = mouse.x; plotSpiral(x, y, abs(x - x1)); } mouse.show(); }

/*

Draw the Mark rectangle

*/

void drawMark() { int x = mouse.x; int y = mouse.y; int x1, y1; setcolor(WHITE); setwritemode(XOR_PUT); setlinestyle(DASHED_LINE, 1, NORM_WIDTH); mouse.hide(); do { mouse.read(); x1 = mouse.x; y1 = mouse.y; rectangle(x, y, x1, y1); delay(DELAY); rectangle(x, y, x1, y1); } while (mouse.lbutton); mouse.show(); setlinestyle(SOLID_LINE, 1, NORM_WIDTH); setwritemode(COPY_PUT); setcolor(curColor); block.set(x, y, x1, y1); }

/*

Draw a block in the given color

*/

void drawBlock(int left, int top, int right, int bottom, int down, int color) { setfillstyle(SOLID_FILL, color); bar(left, top, right, bottom); if (down) { setcolor(BLACK); line(left, top, right, top); line(left, top, left, bottom); setcolor(WHITE);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 35 line(right, bottom, right, top); line(right, bottom, left, bottom); } else { setcolor(WHITE); line(left, top, right, top); line(left, top, left, bottom); setcolor(BLACK); line(right, bottom, right, top); line(right, bottom, left, bottom); } } /* Draw a block in the default color */

void drawBlock(int left, int top, int right, int bottom, int down) { drawBlock(left, top, right, bottom, down, COLOR); } /* Ellipse drawing algorithm */

void plotEllipse(int xcen, int ycen, float radx, float rady) { float p; float px, py; float x, y; float rx, ry; float tworx, twory; ry = rady * rady; rx = radx * radx; twory = 2 * ry; tworx = 2 * rx; x = 0; y = rady; plotEllipsePoints(xcen, ycen, x, y); p = (ry - rx * rady + (0.25 * rx)); px = 0; py = tworx * y; while (px < py) { x++; px = px + twory; if (p >= 0) { y--; py = py - tworx; } if (p < 0) p = p + ry + px; else p = p + ry + px - py; plotEllipsePoints(xcen,ycen,x,y); }

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 36 p = (ry * (x + 0.5) * (x + 0.5) + rx * (y - 1) * (y - 1) - rx * ry); while (y > 0) { y--; py = py - tworx; if (p <= 0) { x++; px = px + twory; } if (p > 0) p = p + rx - py; else p = p + rx - py + px; plotEllipsePoints(xcen, ycen, x, y); } } /* Plot the points generated by the ellipse algorithm */

void plotEllipsePoints(int xcen, int ycen, int x, int y) { if (xcen + x >= LEFT && xcen + x <= RIGHT && ycen + y y <= BOTTOM) line(xcen + x, ycen + y , xcen + x, ycen + y); if (xcen - x >= LEFT && xcen - x <= RIGHT && ycen + y y <= BOTTOM) line(xcen - x, ycen + y, xcen - x, ycen + y); if (xcen + x >= LEFT && xcen + x <= RIGHT && ycen - y y <= BOTTOM) line(xcen + x, ycen - y, xcen + x, ycen - y); if (xcen - x >= LEFT && xcen - x <= RIGHT && ycen - y y <= BOTTOM) line(xcen - x, ycen - y, xcen - x, ycen - y); } /* Spiral drawing algorithm */

>= TOP && ycen + >= TOP && ycen + >= TOP && ycen >= TOP && ycen -

void plotSpiral(int x, int y, int rad) { int r = 5; int tr = r; const int INC = 5; int ty = y; do { ellipse(x, ty, 270, 90, tr += INC; ty -= INC; ellipse(x, ty, 90, 270, tr += INC; ty += INC; } while(tr < rad && x + tr + r && y + tr < BOTTOM && y } tr, tr); tr, tr); < RIGHT && x - tr > LEFT - tr - 2*r > TOP);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 37 /* --------------------------------------------------------------------- *\ B l o c k C l a s s F u n c t i o n s \* ---------------------------------------------------------------------- */ Block::Block() { left = 0; top = 0; right = 0; bottom = 0; use = false; } int Block::contains(int x, int y) { if (x >= left && x <= right && y >= top && y <= bottom) return(true); return(false); }

void Block::set(int l, int t, int r, int b) { FILE *temp; int i, j; left = l; top = t; right = r; bottom = b; temp = fopen("temp", "w"); if (temp == NULL) { msgbox.put("File open error", false); return; } for (i = top; i <= bottom; ++i) for (j = left; j <= right; ++j) fputc(getpixel(j, i), temp); fclose(temp); use = true; } void Block::translate(int tx, int ty) { int i, j; int lenX, lenY; int ccolor; FILE *temp;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 38 if (use == false) { msgbox.put("Please mark the area first", false); return; } temp = fopen("temp", "r"); mouse.hide(); setwritemode(COPY_PUT); lenX = right - left + 1; lenY = bottom - top; for (i = 0; i < lenY; ++i) { for (j = 0; j < lenX; ++j) { ccolor = fgetc(temp); canvas.putpoint(tx + j, ty + i, ccolor); } } mouse.show(); fclose(temp); use = false; }

/*

Rotate the marked area

*/

void Block::rotate() { FILE *temp; int i, j; int tx1, ty1; int tx2, ty2; int ccolor; // if area is not marked if (use == false) { msgbox.put("Please mark the area first", false); return; } int angle = msgbox.putGetInt("Input angle : "); double theta = angle * M_PI / 180.0; clipIn(); temp = fopen("temp", "r"); mouse.hide(); setwritemode(COPY_PUT); for (i = top; i < bottom; ++i) {

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 39 for (j = left; j <= right; ++j) { ccolor = fgetc(temp); tx1 = j - left; ty1 = i - top; tx2 = tx1 * cos(theta) - ty1 * sin(theta); ty2 = tx1 * sin(theta) + ty1 * cos(theta); tx2 += left; ty2 += top; canvas.putpoint(tx2, ty2, ccolor); } } mouse.show(); fclose(temp); use = false; } /* Scale a marked area on the canvas */

void Block::scale() { FILE *temp; int i, j, m, n; int ccolor; if (use == false) { msgbox.put("Please mark the area first", false); return; }

int scaleX = msgbox.putGetInt("Scale X : "); int scaleY = msgbox.putGetInt("Scale Y : "); temp = fopen("temp", "r"); int x = left; int oldx = left; int y = top; mouse.hide(); for (i = top; i < bottom; ++i) { for (j = left; j <= right; ++j) { ccolor = fgetc(temp); for (m = 0; m < scaleY; ++m) for (n = 0; n < scaleX; ++n) canvas.putpoint(x + n, y + m, ccolor); x += scaleX; } x = oldx; y += scaleY;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 40 } mouse.show(); fclose(temp); use = false; } /* Clip the block against the canvas */

void Block::clip() { if (use == false) { msgbox.put("Please mark an area to clip", false); return; } int i, j; for (i = LEFT; i <= RIGHT; ++i) for (j = TOP; j <= BOTTOM; ++j) if (contains(i, j) == false) putpixel(i, j, WHITE); use = false; } /* Clear out the block */

void Block::clipIn() { if (!use) return; mouse.hide(); for (int i = LEFT; i < RIGHT; ++i) for (int j = TOP; j < BOTTOM; ++j) if (contains(i, j)) putpixel(i, j, WHITE); mouse.show(); use = false; }

/* ---------------------------------------------------------------------- *\ M o u s e C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ void Mouse::init() { if(!reset()) { Easydraw_shutdown(); put_error("Mouse driver not found/loaded\n"); exit(1); } set_position(0, 0); set_bound(0, 0, MAXX, MAXY);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 41 show(); } int Mouse::reset() { in.x.ax = 0x0000; int86(0x33, &in, &out); return(out.x.ax); }

void Mouse::show() { in.x.ax = 0x0001; int86(0x33, &in, &out); } void Mouse::hide() { in.x.ax = 0x0002; int86(0x33, &in, &out); } void Mouse::read() { int button; read_status(&button, &x, &y); if (button == L_BUTTON) lbutton = true; else if (button == R_BUTTON) rbutton = true; else { lbutton = false; rbutton = false; } } void Mouse::read_status(int *button, int *x, int *y) { in.x.ax = 0x0003; int86(0x33, &in, &out); *button = out.x.bx; *x = out.x.cx; *y = out.x.dx; } void Mouse::read_motion(int *x, int *y) { in.x.ax = 0x000B; int86(0x33, &in, &out); *x = out.x.cx; *y = out.x.dx; } void Mouse::set_position(int x, int y)

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 42 { in.x.ax = 0x0004; in.x.cx = x; in.x.dx = y; int86(0x33, &in, &out); } void Mouse::set_bound(int x1, int y1, int x2, int y2) { set_hbound(x1, x2); set_vbound(y1, y2); } void Mouse::set_hbound( int x1, int x2 ) { in.x.ax = 0x0007; in.x.cx = x1; in.x.dx = x2; int86( 0x33, &in, &out ); } void Mouse::set_vbound( int y1, int y2 ) { in.x.ax = 0x0008; in.x.cx = y1; in.x.dx = y2; int86( 0x33, &in, &out ); } /* ------------------------------------ End -------------------------- */ /* ---------------------------------------------------------------------- *\ T o o l b o x C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ Toolbox::Toolbox() { width = 30; height = 30; int n = 0; for (int i = 0; i < TOOLCOUNT / 2; ++i) for (int j = 0; j < 2; ++j) { if (n == tool) button[n].down = true; else button[n].down = false; button[n].left = 7 + (j * (width + 5)); button[n].top = 40 + (i * (height + 5)); button[n].right = button[n].left + width; button[n].bottom = button[n].top + height; ++n; } } void Toolbox::draw() { // draw the buttons in default color

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 43 for (int i = 0; i < TOOLCOUNT; ++i) button[i].draw(); /* * draw the icons on them */ drawFreehandPic(); drawLinePic(); drawRectPic(); drawFilledRectPic(); drawEllipsePic(); drawFilledEllipsePic(); drawPolygonPic(); drawSpiralPic(); drawMarkPic(); drawTranslatePic(); drawRotatePic(); drawScalePic(); drawClipPic(); drawClearPic(); drawLoadPic(); drawSavePic(); } int Toolbox::check(int x, int y) { for (int i = 0; i < TOOLCOUNT; ++i) if (button[i].inBound(x, y)) { if (i != MARK) prevtool = tool; tool = i; for (int j = 0; j < TOOLCOUNT; ++j) button[j].down = false; button[i].down = true; mouse.hide(); draw(); mouse.show(); switch (i) { case ROTATE :

block.rotate(); tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break; case SCALE : block.scale(); tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break; case CLIP : mouse.hide(); block.clip(); mouse.show(); tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break; case CLEAR : canvas.clear();

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 44 tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break; canvas.load(); tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break; canvas.save(); tool = prevtool; check(button[prevtool].left + 2, button[prevtool].top + 2); break;

case LOAD :

case SAVE :

} return(true); } return(false); }

void Toolbox::drawFreehandPic() { int x = button[FREEHAND].left + 2; int y = button[FREEHAND].top + 2; setcolor(BLACK); setlinestyle(0, 1, 3); line(19 + x, 21 + y, 10 + x, 9 + y); setlinestyle(0, 1, 1); line(11 + x, 9 + y, 11 + x, 6 + y); line(11 + x, 6 + y, 6 + x, 4 + y); line(6 + x, 4 + y, 7 + x, 9 + y); line(7 + x, 9 + y, 11 + x, 9 + y); } void Toolbox::drawLinePic() { int x = button[LINE].left; int y = button[LINE].top; setcolor(BLACK); line(x + 5, y + 5, x + width - 5, y + height - 5); } void Toolbox::drawRectPic() { int x = button[RECT].left; int y = button[RECT].top; rectangle(x + 5, y + 5, x + width - 5, y + height - 5); } void Toolbox::drawFilledRectPic() { int x = button[FILLEDRECT].left; int y = button[FILLEDRECT].top;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 45 setfillstyle(SOLID_FILL, BLACK); bar(x + 5, y + 5, x + width - 5, y + height - 5); } void Toolbox::drawEllipsePic() { int x = button[ELLIPSE].left; int y = button[ELLIPSE].top; setcolor(BLACK); ellipse(x + width / 2, y + height / 2, 0, 360, 11, 7); } void Toolbox::drawFilledEllipsePic() { int x = button[FILLEDELLIPSE].left; int y = button[FILLEDELLIPSE].top; setfillstyle(SOLID_FILL, BLACK); fillellipse(x + width / 2, y + height / 2, 11, 7); }

void Toolbox::drawPolygonPic() { int x = button[POLYGON].left; int y = button[POLYGON].top; setcolor(BLACK); line(x + 10, y + 5, x + 25, y + 25); line(x + 25, y + 25, x + 5, y + 25); line(x + 5, y + 25, x + 15, y + 20); line(x + 15, y + 20, x + 10, y + 5); } void Toolbox::drawSpiralPic() { int midx = button[SPIRAL].left + (button[SPIRAL].right button[SPIRAL].left) / 2; int midy = button[SPIRAL].top + (button[SPIRAL].bottom button[SPIRAL].top) / 2; midy += 2; int r = 2; setcolor(BLACK); for (int i = 0; i < 3; ++i) { ellipse(midx, midy, 270, 90, r, r); r += 2; midy -= 2; ellipse(midx, midy, 90, 270, r, r); r += 2; midy += 2; } } void Toolbox::drawMarkPic()

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 46 { int x = button[MARK].left; int y = button[MARK].top; setcolor(BLACK); setlinestyle(DASHED_LINE, 1, NORM_WIDTH); rectangle(5 + x, 6 + y, 25 + x, 25 + y); setlinestyle(SOLID_LINE, 1, NORM_WIDTH); } void Toolbox::drawTranslatePic() { int x = button[TRANSLATE].left + 1; int y = button[TRANSLATE].top + 2; setcolor(BLACK); setfillstyle(SOLID_FILL, LIGHTGREEN); bar(x + 5, y + 4, x + 17, y + 16); rectangle(x + 5, y + 4, x + 17, y + 16); bar(x + 12, y + 9, x + 24, y + 21); rectangle(x + 12, y + 9, x + 24, y + 21); } void Toolbox::drawScalePic() { int x = button[SCALE].left - 1; int y = button[SCALE].top; setcolor(BLACK); setfillstyle(SOLID_FILL, LIGHTGREEN); bar(x + 5, y + 4, x + 18, y + 16); rectangle(x + 5, y + 4, x + 18, y + 16); bar(x + 12, y + 9, x + 28, y + 24); rectangle(x + 12, y + 9, x + 28, y + 24); } void Toolbox::drawRotatePic() { int x = button[ROTATE].left + 1; int y = button[ROTATE].top + 2; setcolor(BLACK); line(6 + x, 5 + y, 20 + x, 5 + y); line(20 + x, 5 + y, 20 + x, 8 + y); line(6 + x, 5 + y, 6 + x, 18 + y); line(6 + x, 18 + y, 12 + x, 18 + y); line(15 + x, 7 + y, 26 + x, 11 + y); line(26 + x, 11 + y, 21 + x, 20 + y); line(21 + x, 20 + y, 11 + x, 16 + y); line(11 + x, 16 + y, 15 + x, 7 + y); setfillstyle(1, LIGHTGREEN); floodfill(8 + x, 7 + y, BLACK); floodfill(20 + x, 18 + y, BLACK); }

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 47 void Toolbox::drawClipPic() { int x = button[CLIP].left; int y = button[CLIP].top + 2; setcolor(BLACK); rectangle(5 + x, 5 + y, 25 + x, 19 + y); setfillstyle(SOLID_FILL, WHITE); floodfill(15 + x, 12 + y, BLACK); setfillstyle(SOLID_FILL, BLACK); bar(12 + x, 10 + y, 23 + x, 17 + y); } void Toolbox::drawClearPic() { int x = button[CLEAR].left; int y = button[CLEAR].top + 2; setlinestyle(0, 1, 1); setcolor(BLACK); line(9+x, 4+y, 9+x, 20+y); line(9+x, 20+y, 21+x, 20+y); line(21+x, 20+y, 21+x, 8+y); line(9+x, 4+y, 17+x, 4+y); line(17+x, 4+y, 17+x, 8+y); line(17+x, 8+y, 21+x, 8+y); line(21+x, 8+y, 17+x, 4+y); setfillstyle(1, WHITE); floodfill(10+x, 9+y, BLACK); } void Toolbox::drawLoadPic() { int x = button[LOAD].left; int y = button[LOAD].top + 1; setlinestyle(0, 1, 1); setcolor(BLACK); line(5 + x, 20+y, 17+x, 20+y); line(17+x, 20+y, 24+x, 15+y); line(24+x, 15+y, 12+x, 15+y); line(12+x, 15+y, 5+x, 20+y); setfillstyle(1, DARKGRAY); floodfill(10+x, 18+y, BLACK); line(5+x, 20+y, 5+x, 10+y); line(5+x, 10+y, 6+x, 8+y); line(6+x, 8+y, 8+x, 8+y); line(8+x, 8+y, 9+x, 10+y); line(9+x, 10+y, 17+x, 10+y); line(17+x, 10+y, 17+x, 15+y); setfillstyle(1, YELLOW); floodfill(6+x, 12+y, BLACK); line(15+x, 7+y, 17+x, 5+y); line(17+x, 5+y, 22+x, 7+y); line(22+x, 7+y, 24+x, 12+y); line(24+x, 12+y, 20+x, 10+y); line(24+x, 12+y, 26+x, 9+y); }

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 48 void Toolbox::drawSavePic() { int x = button[SAVE].left; int y = button[SAVE].top + 3; setlinestyle(0, 1, 1); setcolor(BLACK); line(6+x, 4+y, 24+x, 4+y); line(24+x, 4+y, 24+x, 20+y); line(24+x, 20+y, 8+x, 20+y); line(8+x, 20+y, 6+x, 18+y); line(6+x, 18+y, 6+x, 4+y); line(9+x, 4+y, 9+x, 12+y); line(9+x, 12+y, 21+x, 12+y); line(21+x, 12+y, 21+x, 4+y); line(10 + x, 20 + y, 10 + x, 15 + y); line(10 + x, 15 + y, 20 + x, 15 + y); line(20 + x, 15 + y, 20 + x, 20 + y); line(17 + x, 15 + y, 17 + x, 20 + y); line(21 + x, 7 + y, 24 + x, 7 + y); setfillstyle(1, WHITE); floodfill(10 + x, 5 + y, BLACK); setfillstyle(1, LIGHTBLUE); floodfill(7 + x, 5 + y, BLACK); setfillstyle(1, DARKGRAY); floodfill(11 + x, 19 + y, BLACK); } /* ------------------------------------- End ---------------------------- */

/* ---------------------------------------------------------------------- *\ B u t t o n C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ Button::Button() {} Button::Button(int left, int top, int right, int bottom) { Button(left, top, right, bottom, COLOR); } Button::Button(int left, int top, int right, int bottom, int color) { Button::left = left;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 49 Button::top = top; Button::right = right; Button::bottom = bottom; Button::color = color; }

void Button::draw() { draw(COLOR); }

void Button::draw(int color) { mouse.hide(); // draw the button using generic drawBlock function drawBlock(left, top, right, bottom, down, color); mouse.show(); } int Button::inBound(int x, int y) { if (x > left && x < right) if (y > top && y < bottom) return(true); return(false); }

/* --------------------------------------- End ------------------------ */

/* ---------------------------------------------------------------------- *\ C o l o r b o x C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ Colorbox::Colorbox() { width = 16; height = 16; count = 16; gap = 4;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 50 int k = 0; for (int i = 0; i < 2; ++i) for (int j = 0; j < 8; ++j) { button[k].left = 80 + (j*(width + gap)); button[k].top = 433 + (i*(height + gap)); button[k].right = button[k].left + width; button[k].bottom = button[k].top + height; button[k].down = true; button[k].color = k; ++k; } } void Colorbox::draw() { // draw the colorbox holder drawBlock(75, 428, 242, 474, false); // draw the color buttons for (int i = 0; i < 16; ++i) button[i].draw(i); } int Colorbox::check(int x, int y) { for (int i = 0; i < count; ++i) if (button[i].inBound(x, y)) { statusbox.setColor(i); return(true); } return(false); } /* --------------------------------- End -------------------------------- */ /* ---------------------------------------------------------------------- *\ F i l l S t y l e B o x C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ FillStylebox::FillStylebox() { width = 16; height = 16; gap = 4;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 51 int k = 0; for (int i = 0; i < 2; ++i) for (int j = 0; j < 6; ++j) { button[k].left = 277 + (j * (width button[k].top = 433 + (i * (height button[k].right = button[k].left + button[k].bottom = button[k].top + button[k].down = true; button[k].color = BLACK; ++k; } } void FillStylebox::draw() { drawBlock(270, 428, 400, 474, false); setcolor(BLACK); for (int i = 0; i < 12; ++i) { setfillstyle(i, WHITE); bar(button[i].left, button[i].top, button[i].right, button[i].bottom); rectangle(button[i].left, button[i].top, button[i].right, button[i].bottom); } } int FillStylebox::check(int x, int y) { for (int i = 0; i < 12; ++i) if (button[i].inBound(x, y)) { statusbox.setFillStyle(i); return(true); } return(false); } /* ---------------------------------- End ------------------------------ */ + gap)); + gap)); width; height;

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 52 /* ---------------------------------------------------------------------- *\ S t a t u s C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ Statusbox::Statusbox() { width = 42; height = 38; statusButton.left = 15; statusButton.top = 430; statusButton.right = statusButton.left + width; statusButton.bottom = statusButton.top + height; } void Statusbox::draw() { setfillstyle(curFillStyle, curColor); bar(statusButton.left, statusButton.top, statusButton.right, statusButton.bottom); } void Statusbox::setColor(int color) { curColor = color; draw(); } void Statusbox::setFillStyle(int fillStyle) { curFillStyle = fillStyle; draw(); }

/* ------------------------------------ End ----------------------------- */

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 53 -

/* ---------------------------------------------------------------------- *\ M e n u b a r C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ Menubar::Menubar() { int width = 60; int height = 20; exitButton.info = "Exit"; exitButton.left = 570; exitButton.top = 8; exitButton.right = exitButton.left + width; exitButton.bottom = exitButton.top + height; exitButton.down = false; } void Menubar::draw() { exitButton.draw(); } void Menubar::check(int x, int y) { if (exitButton.inBound(x, y)) Easydraw_quit = true; }

/* ------------------------------------- End --------------------------- */

/* ---------------------------------------------------------------------- *\ T e x t b u t t o n C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ void TextButton::draw() { int x, y; Button::draw();

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 54 x = left + (right - left) / 2; y = top + (bottom - top) / 2; outtextxy(x, y, info); } /* ----------------------------------- End ------------------------------ */

/* ---------------------------------------------------------------------- *\ M e s s a g e B o x C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ MessageBox::MessageBox() { left = 410; top = 440; right = 630; bottom = 460; } /* * */

Draw the message box

void MessageBox::draw() { drawBlock(left, top, right, bottom, true); } /* * */ Clears the message box

void MessageBox::clear() { draw(); } /* * */ Put a message on the message box [generic]

void MessageBox::put(const char *msg, int wait) { clear(); mouse.hide(); outtextxy(left + 2, top + 5, msg); mouse.show(); if (wait == true) { while (!kbhit()); clear(); } }

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 55 /* * */ Put a message and get a response int

int MessageBox::putGetInt(const char *msg) { int i; char get[10]; put(msg, false); readString(get, left + textwidth(msg)); i = atoi(get); clear(); return(i); } /* * */

Put a message and get a response string

void MessageBox::putGetString(const char *msg, char *get) { put(msg, false); readString(get, left + textwidth(msg)); clear(); } /* * */

Read a user typed string

void MessageBox::readString(char *get, int nleft) { char c; int length; length = 0; setcolor(BLACK); c = getch(); while( (c != 27) && (c != 13)) { switch (c) { case '\b' : get[length - 1] = '\0'; setcolor(BLACK); outtextxy(nleft, top + 4, get); break; default : get[length] = c; get[length + 1] = '\0';

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 56 length++; outtextxy(nleft, top + 4, get); break; } c = getch(); } } /* ------------------------------------ End ----------------------------- */

/* ---------------------------------------------------------------------- *\ C a n v a s C l a s s R o u t i n e s \* ---------------------------------------------------------------------- */ /* * */ Put a pixel on the canvas

void Canvas::putpoint(const int x, const int y, const int ccolor) { if (x > LEFT && x < RIGHT && y > TOP && y < BOTTOM) { // mouse.hide(); putpixel(x, y, ccolor); // mouse.show(); } } int Canvas::in(int x, int y) { if (x > LEFT && x < RIGHT) if (y > TOP && y < BOTTOM) return(true); return(false); } /* *

Clears the canvas

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 57 */ void Canvas::clear() { mouse.hide(); setfillstyle(SOLID_FILL, WHITE); bar(LEFT, TOP, RIGHT, BOTTOM); mouse.show(); } /* * */ Save the canvas in a file

void Canvas::save() { FILE *outfile; int ccolor; char get[30]; msgbox.putGetString("Save as : ", get); // open the file outfile = fopen(get, "w"); if (outfile == NULL) { msgbox.put("File open error", false); return; } mouse.hide(); int i, j; for(i = TOP + 1; i <= BOTTOM - 1; ++i) { for(j = LEFT + 1; j <= RIGHT - 1; ++j) { ccolor = getpixel(j, i); fputc(ccolor, outfile); } } mouse.show(); fclose(outfile); } /* * */

Loads the canvas from file

void Canvas::load() { FILE *infile; int ccolor; char get[30]; msgbox.putGetString("Load : ", get); strcpy(filename, get);

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 58 infile = fopen(get, "r"); if(infile == NULL) { msgbox.put("File load error", false); return; } clear(); mouse.hide(); for(int i = TOP + 1; i <= BOTTOM - 1; ++i) { int j; for(j = LEFT + 1; j <= RIGHT - 1; ++j) { ccolor = getc(infile); putpixel(j, i, ccolor); } } mouse.show(); fclose(infile); } /* -------------------------------------- End --------------------------- */ // clear the canvas

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 59 -

CONCLUSION
The graphics editor created for the DOS operating system can be used to draw lines, boxes, circles, ellipses, spirals and polygons. It can be used to select an area and perform clipping inside, clipping outside, rotation and scaling on it. It can be used to save the canvas to file and load it from file. It has a very simple and aesthetic user interface. We found designing and developing this graphics editor - Easydraw as a very interesting and learning experience. It helped us to learn about computer graphics, design of Graphical User Interfaces, interface to the user, user interaction handling and screen management. The graphics editor provides all and more than the features that have been detailed in the university syllabi. We thank our friends and seniors who gave us valuable suggestions and guidance to carry out this project. They have been a helping hand in keeping us in good spirits throughout the project. The teachers have been a great source of technical support and inspiration without which this project would have not seen the end. We would also like to thank all of them who have been directly or indirectly responsible for helping us in completing the project successfully.

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

- 60 -

BIBLIOGRAPHY
The books that helped us in designing this graphics editor. Computer Graphics Principles And Practice (Foley, vanDam, Feiner and Hughes) This bible of Computer Graphics helped us to understand graphics generation algorithms, user interface and dialog design C++ Primer (Lippman and Lajoie) The primer provided practical knowledge on the design of C++ classes. Graphics in C (Kanetkar) The Intel Microprocessors (Brey) Referred to for mouse interrupts to provide mouse interaction.

DEPTT.OF COMPUTER SCIENCE ENGG. CDLMEC, PANNIWALA MOTA , SIRSA.

You might also like