Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canvas-drawing-app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jalay
canvas-drawing-app
Commits
9eccebec
Commit
9eccebec
authored
Aug 21, 2021
by
Jalay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload new file
parent
8bdbce9b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
389 additions
and
0 deletions
+389
-0
EDITOR.C
EDITOR.C
+389
-0
No files found.
EDITOR.C
0 → 100644
View file @
9eccebec
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include "edfile.c"
//#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
union
REGS
i
,
o
;
int
leftcolor
[
15
];
double
bez
(
double
t
,
int
p
[],
int
a
,
int
b
)
{
if
(
a
==
b
)
return
p
[
a
];
else
return
(
1
-
t
)
*
bez
(
t
,
p
,
a
,
b
-
1
)
+
t
*
bez
(
t
,
p
,
a
+
1
,
b
);
}
int
get_key
()
{
union
REGS
i
,
o
;
i
.
h
.
ah
=
0
;
int86
(
22
,
&
i
,
&
o
);
return
(
o
.
h
.
ah
);
}
void
draw_color_panel
()
{
int
left
,
top
,
c
,
color
;
left
=
5
;
top
=
215
;
color
=
getcolor
();
setcolor
(
BLACK
);
outtextxy
(
left
,
top
,
"color"
);
outtextxy
(
left
,
top
+
15
,
"palette"
);
top
+=
30
;
for
(
c
=
1
;
c
<=
16
;
c
+=
2
)
{
setfillstyle
(
SOLID_FILL
,
c
);
bar
(
left
,
top
,
left
+
20
,
top
+
20
);
rectangle
(
left
,
top
,
left
+
20
,
top
+
20
);
setfillstyle
(
SOLID_FILL
,
c
+
1
);
bar
(
left
+
30
,
top
,
left
+
50
,
top
+
20
);
rectangle
(
left
+
30
,
top
,
left
+
50
,
top
+
20
);
leftcolor
[
c
-
1
]
=
left
;
top
+=
30
;
}
setcolor
(
color
);
}
void
draw_shape_panel
()
{
int
left
,
top
,
c
,
color
,
points
[]
=
{
15
,
157
,
7
,
173
,
15
,
165
,
23
,
173
,
15
,
157
};
left
=
5
;
top
=
5
;
color
=
getcolor
();
setfillstyle
(
SOLID_FILL
,
LIGHTGRAY
);
bar
(
1
,
1
,
60
,
480
);
// bar(100,100,200,200);
setcolor
(
BLACK
);
outtextxy
(
left
,
top
,
"Tools"
);
top
+=
30
;
for
(
c
=
1
;
c
<=
11
;
c
+=
2
)
{
rectangle
(
left
,
top
,
left
+
20
,
top
+
20
);
rectangle
(
left
+
30
,
top
,
left
+
50
,
top
+
20
);
top
+=
30
;
}
setfillstyle
(
SOLID_FILL
,
BLACK
);
bar
(
7
,
40
,
23
,
50
);
rectangle
(
37
,
40
,
53
,
50
);
line
(
7
,
83
,
22
,
68
);
line
(
37
,
83
,
43
,
73
);
line
(
43
,
73
,
45
,
73
);
line
(
45
,
73
,
47
,
76
);
line
(
47
,
76
,
49
,
76
);
line
(
49
,
76
,
53
,
68
);
fillellipse
(
15
,
105
,
8
,
6
);
ellipse
(
45
,
105
,
0
,
360
,
8
,
6
);
fillellipse
(
15
,
135
,
7
,
7
);
ellipse
(
45
,
135
,
0
,
360
,
7
,
7
);
fillpoly
(
5
,
points
);
for
(
c
=
0
;
c
<=
8
;
c
+=
2
)
{
points
[
c
]
+=
30
;
}
drawpoly
(
5
,
points
);
//5 185
line
(
7
,
203
,
12
,
187
);
line
(
12
,
187
,
18
,
187
);
line
(
18
,
187
,
23
,
203
);
setfillstyle
(
SOLID_FILL
,
WHITE
);
bar
(
38
,
189
,
52
,
200
);
// erase();
setcolor
(
color
);
}
void
change_color
(
int
x
,
int
y
)
{
int
c
,
left
=
5
,
top
=
245
;
// printf("H");
// line(left,top,left+50,top);
for
(
c
=
1
;
c
<=
16
;
c
+=
2
)
{
if
(
x
>
left
&&
x
<
left
+
20
&&
y
>
top
&&
y
<
top
+
20
)
{
setcolor
(
c
);
break
;
}
if
(
x
>
left
+
30
&&
x
<
left
+
50
&&
y
>
top
&&
y
<
top
+
20
)
{
setcolor
(
c
+
1
);
break
;
}
top
+=
30
;
}
}
char
change_shape
(
int
x
,
int
y
)
{
int
c
,
left
,
top
;
char
flag
=
'a'
;
left
=
5
;
top
=
35
;
for
(
c
=
1
;
c
<=
11
;
c
+=
2
,
flag
+=
2
)
{
if
(
x
>
left
&&
y
>
top
&&
x
<
left
+
20
&&
y
<
top
+
20
)
return
flag
;
if
(
x
>
left
+
30
&&
y
>
top
&&
x
<
left
+
50
&&
y
<
top
+
20
)
return
flag
+
1
;
top
+=
30
;
}
return
flag
;
}
void
showmouseptr
()
{
i
.
x
.
ax
=
1
;
int86
(
0x33
,
&
i
,
&
o
);
}
void
hidemouseptr
()
{
i
.
x
.
ax
=
2
;
int86
(
0x33
,
&
i
,
&
o
);
}
void
restrictmouseptr
(
int
x1
,
int
y1
,
int
x2
,
int
y2
)
{
i
.
x
.
ax
=
7
;
i
.
x
.
cx
=
x1
;
i
.
x
.
dx
=
x2
;
int86
(
0x33
,
&
i
,
&
o
);
i
.
x
.
ax
=
8
;
i
.
x
.
cx
=
y1
;
i
.
x
.
dx
=
y2
;
int86
(
0x33
,
&
i
,
&
o
);
}
void
getmousepos
(
int
*
button
,
int
*
x
,
int
*
y
)
{
i
.
x
.
ax
=
3
;
int86
(
0x33
,
&
i
,
&
o
);
*
button
=
o
.
x
.
bx
;
*
x
=
o
.
x
.
cx
;
*
y
=
o
.
x
.
dx
;
}
main
()
{
int
gd
=
DETECT
,
gm
;
dp
*
temp
;
int
maxx
,
maxy
,
x
,
y
,
button
,
prevx
,
prevy
,
temp1
,
temp2
,
key
,
color
,
points
[
50
];
int
step
,
j
,
l
,
k
,
arrx
[
30
],
arry
[
30
];
char
ch
=
'a'
;
int
i
,
signdx
,
signdy
;
float
len
,
abx
,
aby
,
dx
,
dy
,
xx
,
yy
;
double
size
,
t
,
xi
,
yi
;
initgraph
(
&
gd
,
&
gm
,
"..//BGI"
);
maxx
=
getmaxx
();
maxy
=
getmaxy
();
setcolor
(
WHITE
);
rectangle
(
0
,
0
,
maxx
,
maxy
);
setcolor
(
YELLOW
);
/* settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
outtextxy(maxx/2-120,maxy-23,"*** DRAWING WINDOW ***");
*/
draw_shape_panel
();
draw_color_panel
();
setviewport
(
1
,
1
,
maxx
-
1
,
maxy
-
1
,
1
);
restrictmouseptr
(
1
,
1
,
maxx
-
1
,
maxy
-
1
);
showmouseptr
();
setcolor
(
BLUE
);
setfillstyle
(
SOLID_FILL
,
15
);
bar
(
60
,
1
,
640
,
480
);
setviewport
(
60
,
2
,
639
,
479
,
1
);
temp
=
openeditor
();
while
(
1
)
{
// printf("d");
if
(
kbhit
())
{
key
=
get_key
();
if
(
1
)
{
closegraph
();
closeeditor
();
exit
(
0
);
}
}
getmousepos
(
&
button
,
&
x
,
&
y
);
if
(
button
==
1
)
{
if
(
x
>
1
&&
x
<
60
&&
y
>
1
&&
y
<
245
)
ch
=
change_shape
(
x
,
y
);
else
if
(
x
>
1
&&
x
<
60
&&
y
>
245
&&
y
<
480
)
change_color
(
x
,
y
);
temp1
=
x
;
temp2
=
y
;
// printf("%c",ch);
if
(
ch
==
'd'
)
{
// printf("j");
hidemouseptr
();
moveto
(
x
-
60
,
y
);
temp
=
saveeditor
(
temp
,
0
,
getcolor
(),
x
-
60
,
y
);
while
(
button
==
1
)
{
line
(
temp1
-
60
,
temp2
,
x
-
60
,
y
);
temp
=
saveeditor
(
temp
,
4
,
getcolor
(),
x
-
60
,
y
);
temp1
=
x
;
temp2
=
y
;
getmousepos
(
&
button
,
&
x
,
&
y
);
}
showmouseptr
();
}
while
(
button
==
1
)
{
//printf("k");
getmousepos
(
&
button
,
&
x
,
&
y
);
}
/* to avoid interference of mouse while drawing */
hidemouseptr
();
if
(
ch
==
'a'
)
{
// printf("D");
setfillstyle
(
SOLID_FILL
,
getcolor
());
bar
(
temp1
-
60
,
temp2
,
x
-
60
,
y
);
}
else
if
(
ch
==
'c'
)
{
line
(
temp1
-
60
,
temp2
,
x
-
60
,
y
);
}
else
if
(
ch
==
'f'
)
ellipse
(
temp1
-
60
,
temp2
,
0
,
360
,
abs
(
x
-
temp1
),
abs
(
y
-
temp2
));
else
if
(
ch
==
'e'
)
{
setfillstyle
(
SOLID_FILL
,
getcolor
());
fillellipse
(
temp1
-
60
,
temp2
,
abs
(
x
-
temp1
),
abs
(
y
-
temp2
));
}
else
if
(
ch
==
'g'
)
{
setfillstyle
(
SOLID_FILL
,
getcolor
());
fillellipse
(
temp1
-
60
,
temp2
,
abs
(
x
-
temp1
),
abs
(
x
-
temp1
));
}
else
if
(
ch
==
'h'
)
ellipse
(
temp1
-
60
,
temp2
,
0
,
360
,
abs
(
x
-
temp1
),
abs
(
x
-
temp1
));
else
if
(
ch
==
'b'
)
rectangle
(
temp1
-
60
,
temp2
,
x
-
60
,
y
);
else
if
(
ch
==
'l'
)
{
ch
=
'a'
;
// setting to freehand drawing
clearviewport
();
color
=
getcolor
();
setcolor
(
WHITE
);
setfillstyle
(
SOLID_FILL
,
15
);
bar
(
0
,
0
,
640
,
480
);
setcolor
(
color
);
removeall
();
}
else
if
(
ch
==
'j'
||
ch
==
'i'
||
ch
==
'k'
)
{
i
=
0
;
//xx=-1; delay(10);
while
(
1
)
{
// restrictmouseptr(60,2,639,479);
if
(
kbhit
())
{
key
=
get_key
();
if
(
key
==
1
)
{
closegraph
();
exit
(
0
);
}
}
showmouseptr
();
getmousepos
(
&
button
,
&
x
,
&
y
);
if
(
button
==
1
)
{
// printf("G");
// printf("%d%d",xx,i);
while
(
button
==
1
)
getmousepos
(
&
button
,
&
x
,
&
y
);
// if(xx==i)continue;
// printf("g"); hidemouseptr;
if
(
i
!=
0
)
{
if
(
abs
(
x
-
60
-
points
[
0
])
<
4
&&
abs
(
y
-
points
[
1
])
<
4
)
{
// printf("h");
points
[
i
]
=
points
[
0
];
points
[
i
+
1
]
=
points
[
1
];
// printf("%d%d",points[i],points[i+1]);
i
+=
2
;
hidemouseptr
();
// printf("i/2=%d",i/2);
if
(
ch
==
'j'
)
drawpoly
(
i
/
2
,
points
);
else
if
(
ch
==
'i'
)
{
setfillstyle
(
SOLID_FILL
,
getcolor
());
fillpoly
(
i
/
2
,
points
);
}
else
{
// setfillstyle(SOLID_FILL,WHITE);
// fillpoly(i/2,points);
step
=
500
;
size
=
1
.
0
/
(
double
)
step
;
l
=
0
;
k
=
getcolor
();
setcolor
(
WHITE
);
for
(
j
=
0
;
j
<
i
;
j
+=
2
)
{
line
(
points
[
j
],
points
[
j
+
1
],
points
[
j
+
2
],
points
[
j
+
3
]);
}
setcolor
(
k
);
for
(
k
=
0
;
k
<=
i
;
k
+=
2
)
{
arrx
[
l
]
=
points
[
k
];
arry
[
l
]
=
points
[
k
+
1
];
l
++
;
}
moveto
(
arrx
[
0
],
arry
[
0
]);
temp
=
saveeditor
(
temp
,
0
,
getcolor
(),
arrx
[
0
],
arry
[
0
]);
//printf("%d %d",arrx[0],arry[0]);
for
(
j
=
1
;
j
<
step
;
j
++
)
{
t
=
size
*
(
double
)
j
;
//printf("%df",t);
xi
=
bez
(
t
,
arrx
,
0
,
i
/
2
-
2
);
yi
=
bez
(
t
,
arry
,
0
,
i
/
2
-
2
);
//if(j<10)
//printf("%f%f ",xi,yi);
lineto
(
xi
,
yi
);
temp
=
saveeditor
(
temp
,
1
,
getcolor
(),
xi
,
yi
);
}
}
break
;
}
else
{
points
[
i
]
=
x
-
60
;
points
[
i
+
1
]
=
y
;
// if(ch!='k')
line
(
points
[
i
],
points
[
i
+
1
],
points
[
i
-
2
],
points
[
i
-
1
]);
i
+=
2
;
}
}
else
{
points
[
i
]
=
x
-
60
;
points
[
i
+
1
]
=
y
;
i
+=
2
;
}
}
// xx=i;
}
i
=
0
;
}
showmouseptr
();
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment