You are on page 1of 7

//All the required Standard Header Files

#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <math.h>
#include <dos.h>
//Other header files required to run CANVAS 1.0
#include texttool.h
#include schema.h
#define TRUE 1
#define FALSE 0
union REGS in,out;
int x,y, cl;
void menu();
class tools{
public:
int choice;
//variable to determine tool is active
tools(){choice = 0;}
void tool_selection(char *,int,int,int,int,int); //this function determines whic
h tool user has selected
};
void tools::tool_selection(char * tname,int toolnum,int x1,int x2,int y1=(getmax
y()-40), int y2 = getmaxy()){
if (x>x1 && y > y1 && x < x2 && y < y2){
settextstyle(3,0,2);
setcolor(10);
outtextxy(510,16,tname);
delay(100);
setcolor(0);
outtextxy(510,16,tname);
if (cl == 1){
choice = toolnum;
}
}
}
class mouse {
public:
int mousehide(){
in.x.ax = 2;
int86(51,&in, &out);
return 1;
}
int callmouse(){ //function that shows/displays the mouse [when ax=1]
in.x.ax = 1;
int86 (51, &in, &out);
return 1;
}
void mouseposition(int &xpos, int &ypos, int &click){ //function to know the
in.x.ax = 3;
//state of the mouse
int86(51, &in, &out);
//it s position and

click
= out.x.bx;
xpos = out.x.cx;
ypos = out.x.dx;
}

//which button is clicked

void setposi(int &xpos,int &ypos){ //function to set the position of mouse


in.x.ax=4;
//mouse pointer initially
in.x.cx=xpos;
in.x.dx=ypos;
int86(51,&in,&out);
}
};
class colors{
public:
int choice;
colors(){choice=6;}
void color_selection();
};
void colors::color_selection(){
for (int count=0; count <= 240; count+=30){
if (x > 0 && y > getmaxy()/2 + count && x < 40 && y < getmaxy()/2 + count + 30){
if (cl==1)
choice = count/30;
}
else if (x > 40 && y > getmaxy()/2 + count && x < 80 && y < getmaxy()/2 + count
+ 30){
if (cl==1)
choice = count/30+8;
}
}
}
int drawn=0;
int i = 1;
int clk=0;
char far *img;
unsigned numbytes;
void main(){
//creating objects for the classes mouse, tools, colors.
mouse M;
tools T;
colors C;
cl = 0;
int gd=DETECT,gm;
int x1 , y1, x2, y2 ;
initgraph(&gd,&gm, C:/Turbo/TC/BGI ); //initializing graphics
//check for graphics error
cleardevice();
numbytes = (unsigned int)imagesize(0,0,354,354);
M.setposi(getmaxx()/2,getmaxy()/2);
M.callmouse();
schema();

int
int
int
int

vertex1;
vertex2 = 0;
vertex = 0;
radius = 0;

while (1) {
setviewport(0,0,getmaxx(),getmaxy(),0);
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection
T.tool_selection

(
(
(
(
(
(
(
(
(
(

PENCIL ,1,80,140);
BRUSH ,2,140,200);
LINE ,3,200,260);
RECTANGLE ,4,260,320);
CIRCLE ,5,320,380);
POLYGON ,6,380,440) ;
TEXT ,7,440,500);
ERASER ,8,500,560);
FILL ,9,0,80,140,190);
EXIT ,0,getmaxx()-27,getmaxx(),1,20);

if (C.choice<15){
setcolor(WHITE);
rectangle(0,190,80,getmaxy()/2);
setfillstyle (1, C.choice);
floodfill (39,210,WHITE);
}
else if (C.choice=15){
setfillstyle (1, WHITE);
setcolor(BROWN);
rectangle(0,190,80,getmaxy()/2);
floodfill (39,210,BROWN);
}
settextstyle(2,0,5);
if ( x >= 81 && y >= 41 && x <= getmaxx()
char xx[10];
sprintf (xx, %d,%d , x
81, y
41);
setcolor(WHITE);
outtextxy (572,451, xx);
delay(10);
setcolor(BLACK);
outtextxy (572,451, xx);
}

1 && y <= getmaxy()

menu();
//defining the workspace
setviewport (81,41,getmaxx()

1 ,getmaxy()

41, 1);

//the new button clears the workspace


if (x>0 && y>20 && x<80 && y<40 && cl==1){
clearviewport();
}
if (x>160 && y>20 && x<240 && y<40 && cl==1){
if ((img=(char far *)malloc(numbytes)) == (char far *)NULL){
setcolor (YELLOW);
outtextxy (1,1, NOT ENOUGH MEMORY !!! );
}
getimage(81,41,getmaxx() 41,getmaxy()
1,img);

41){

clearviewport();
outtextxy(1,1, Image saved !!! );
delay(1000);
setcolor (0);
outtextxy(1,1, Image saved !!! );
clearviewport();
}
if (x>100 && y>20 && x<160 && y<40 && cl==1){
putimage (81,41,img,OR_PUT);
}
C.color_selection();
setcolor(C.choice);
M.mouseposition(x,y,cl);
if (T.choice==0){
if (x>(getmaxx()
exit(1);
}

27) && y > 1 && x < getmaxx() && y < 20 && cl==1)

if (T.choice==1 && x > 81 && y > 41 && x < getmaxx()


if (cl==1){
M.mousehide();
line(x1-81,y1-41,x-81,y-41);
x1 = x;
y1 = y;
M.callmouse();
}
else{
x1=x;y1=y;
}
}

1 && y <getmaxy()

41){

if (T.choice==2){
if (cl==1){
M.mousehide();
circle (x-81,y-41,1);
circle (x-81,y-41,2);
circle (x-81,y-41,3);
circle (x-81,y-41,4);
M.callmouse();
}
}
if (T.choice==3){
if (cl == 1 && x > 81 && y > 41 && x < getmaxx() 1 && y <getmaxy()
41){
x2=x;
y2=y;
vertex1=1;
}
else if (cl == 2 && x > 81 && y > 41 && x < getmaxx()
1 && y <getmaxy()
41){
x1 = x;
y1 = y;
if (vertex1 == 1){
M.mousehide();
line (x1-81,y1-41,x2-81,y2-41);
M.callmouse();
vertex1=0;
}

}
else if (x1 == x2 && y1 == y2){
vertex1 = 1;
}
}
if (T.choice==4){
cl=0;
M.mouseposition(x,y,cl);
if (cl == 1 && x > 81 && y > 41 && x < getmaxx() 1 && y <getmaxy()
41){
x1=x;
y1=y;
vertex1=1;
}
else if (cl == 2 && x > 81 && y > 41 && x < getmaxx()
1 && y <getmaxy()
41){
x2 = x;
y2 = y;
vertex2 = 1;
}
if (vertex1 == 1 && vertex2==1) {
if(cl==0){
M.mousehide();
rectangle (x1-81,y1-41,x2-81,y2-41);
M.callmouse();
vertex1=0;
vertex2=0;
drawn = 1;
}
}
}
if(T.choice==5){
if (cl == 1){
x1 = x;
y1 = y;
vertex = 1;
}
if (cl == 2){
x2 = x;
y2 = y;
if (vertex==1){
radius = sqrt ( pow ( (x2 81)
M.mousehide();
circle (x2-81,y2-41,radius);
M.callmouse();
vertex = 0;
}
}
}

(x1

81),2) + pow ( (y2

if(T.choice==6){
if (cl == 1 && x > 81 && y > 41 && x < getmaxx()
x2=x;
y2=y;
if (vertex1 == 0){
M.mousehide();
line (x1-81,y1-41,x2-81,y2-41);
M.callmouse();
}
vertex1=1;

41)

(y1

1 && y <getmaxy()

41),2) );

41){

}
else if (cl == 2 && x > 81 && y > 41 && x < getmaxx()
x1 = x;
y1 = y;
if (vertex1 == 1){
M.mousehide();
line (x1-81,y1-41,x2-81,y2-41);
M.callmouse();
vertex1=0;
}
}

1 && y <getmaxy()

41){

}
if (T.choice==7){
setcolor(C.choice);
settextstyle(1,0,2);
if (cl==1 && x > 81 && y > 41 && x < (getmaxx()
1) && y < (getmaxy()
M.mousehide();
textbox(x-81,y-41,getmaxx()-81,C.choice,getpixel(x-81,y-41));
M.callmouse();
}
}
if(T.choice==8){
setcolor(0);
if (cl==1 && x > 81 && y > 41 && x < (getmaxy()-1) && y < (getmaxy()
M.mousehide();
for (int count = 1; count<=10; count++){
circle(x-81,y-41,count);
}
M.callmouse();
}
}
if (T.choice==9){
if(x > 81 && y > 41 && x < (getmaxy()-1) && y < (getmaxy()
if (cl==1){
setfillstyle (1,C.choice);
M.mousehide();
floodfill (x-81, y 41,C.choice);
M.callmouse();
}
}
}

41)){

41)){

41)){

}
}
void menu(){
char menuitems[7][6] = { NEW , OPEN , SAVE , PRINT ,
int locations[6] = {22,96,176,257,340,410};
int xloc;
for (xloc=0; xloc<=480; xloc=xloc+80){
if (x>xloc && y>20 && x<xloc+80 && y<40){
settextstyle(3,0,2);
setcolor(10);
outtextxy(locations[xloc/80],16,menuitems[xloc/80]);
}
else {

HELP ,

ABOUT };

settextstyle(3,0,2);
setcolor(14);
outtextxy(locations[xloc/80],16,menuitems[xloc/80]);
}
}
}

You might also like