-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectGraphicsFinal.cpp
More file actions
453 lines (403 loc) · 17.8 KB
/
ProjectGraphicsFinal.cpp
File metadata and controls
453 lines (403 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#include<graphics.h>
#include<windows.h>
#include<direct.h>
#include<conio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
DWORD screenWidth=GetSystemMetrics(SM_CXSCREEN);
DWORD screenHeight =GetSystemMetrics(SM_CYSCREEN);
int radii,colr,shape;
class Paint{
public:
void scribble_screen(){
loading();
cleardevice();
toolbar();
setcolor(7);
rectangle(0,20,screenWidth,21);
displaybar();
setcolor(7);
rectangle(0,58,screenWidth,59);
canvas();
}
void loading(){//loading the bar
readimagefile("Logowt.jpg",385,250,585,450);//to display image
setcolor(BLUE);
outtextxy(screenWidth/2-40,screenHeight/2,(char*)"Developed by Gazal And Harsha");
setcolor(BLUE);
rectangle(screenWidth/2-150,screenHeight/2,screenWidth/2+260,screenHeight/2);
for(int i=0;i<260;i++)//loading bar at begining
{
setcolor(13);
rectangle(screenWidth/2-150,screenHeight/2,screenWidth/2+i,screenHeight/2);
delay(0);
}
}
void toolbar(){
setcolor(WHITE);
rectangle(0,0,screenWidth,20%screenHeight);
setcolor(BLACK);
// outtextxy(10,2,"File");
// button=CreateWindow("Button","File",WS_VISIBLE|WS_CHILD|WS_BORDER,20,50,200,20,hwnd,NULL,NULL,NULL);
// outtextxy(50,2,"Home");
outtextxy(100,2,"Save");
// outtextxy(150,2,"Undo");
// outtextxy(200,2,"Redo");
// Save
// UNDO
// REDO
}
void displaybar(){
setcolor(WHITE);
rectangle(0,20,screenWidth,50);
//font declaration for displaybar
// eraser creation
for(int i=15;i<=35;i++){
for(int j=25;j<=40;j++){
putpixel(i,j,13);
}
}
setcolor(BLACK);
outtextxy(0,40,"Eraser");
//eraser-brushes partition
setcolor(7);
for(int i=48;i<=50;i++)
rectangle(48,22,i,58);
//brushes circle
setcolor(BLACK);
for(int i=0;i<=3;i++)
circle(78,33,3+i);
outtextxy(53,40,"Brushes");
brushes();
//brushes-color partition
setcolor(7);
for(int i=110;i<=112;i++)
rectangle(110,22,i,58);
//creating a button;
//creating a dropdown menu-bar for brushes containing its pixel sizes
//color pallete
rectangle(120,25,440,37.5);
setcolor(BLACK);
outtextxy(245,40,"Color Pallete");
for(int i=0;i<15;i++)
colorpallete(i);
//color pallete and shapes boundary
setcolor(7);
for(int i=447;i<=450;i++)
rectangle(447,22,i,58);
//Generating Shapes
setcolor(BLACK);
shapes();
outtextxy(460,40,"Shapes");
//border between shapes and text
setcolor(7);
for(int i=520;i<=523;i++)
rectangle(520,22,i,58);
//text style
setcolor(0);
settextstyle(1,0,4);
outtextxy(522,25,"T");
}
void brushes(){//after the size column
outtextxy(685,37.5,"<-size");
setfillstyle(HATCH_FILL,BLUE);
circle(569,31,2);
outtextxy(559,40,"2px");
circle(593,31,3);
outtextxy(587,40,"4px");
circle(622,31,4);
outtextxy(615,40,"8px");
circle(658,31,8);
outtextxy(645,40,"16px");
}
void colorpallete(int k){
for(int i=120+20*k;i<=140+20*k;i++){
for(int j=25;j<=37.5;j++){
putpixel(i,j,k);
}
}
}
void shapes(){
rectangle(453,25,461,37.5);
line(463,25,470,37.5);
circle(480,31,8);
arc(495,45,10,90,18);
}
void canvas(){
POINT cursorposition;
setcolor(BLACK);
settextstyle(1,0,1);
outtextxy(0,70,"canvas");
shape=1;
while(1){
setcolor(0);
GetCursorPos(&cursorposition);
ScreenToClient(GetForegroundWindow(), &cursorposition);//convert screen to window coordinate
//using canva
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) &&shape==1&& cursorposition.x > 50 && cursorposition.x <screenHeight && cursorposition.y > 0 && cursorposition.y < screenWidth) // getkeystate detects the mouse left button press
{
setcolor(colr);
setfillstyle(SOLID_FILL,colr);
circle(cursorposition.x,cursorposition.y,radii);
}
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) &&shape==2&& cursorposition.x > 50 && cursorposition.x <screenHeight && cursorposition.y > 0 && cursorposition.y < screenWidth) // getkeystate detects the mouse left button press
{
setcolor(colr);
setfillstyle(SOLID_FILL,colr);
rectangle(cursorposition.x,cursorposition.y,cursorposition.x+10,cursorposition.y+15);
}
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) &&shape==3&& cursorposition.x > 50 && cursorposition.x <screenHeight && cursorposition.y > 0 && cursorposition.y < screenWidth) // getkeystate detects the mouse left button press
{
setcolor(colr);
setfillstyle(SOLID_FILL,colr);
line(cursorposition.x,cursorposition.y,cursorposition.x+10,cursorposition.y+15);
}
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) &&shape==4&& cursorposition.x > 50 && cursorposition.x <screenHeight && cursorposition.y > 0 && cursorposition.y < screenWidth) // getkeystate detects the mouse left button press
{
setcolor(colr);
setfillstyle(SOLID_FILL,colr);
arc(cursorposition.x,cursorposition.y,10,90,18);
}
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) &&shape==5&& cursorposition.x > 50 && cursorposition.x <screenHeight && cursorposition.y > 0 && cursorposition.y < screenWidth) // getkeystate detects the mouse left button press
{
setcolor(colr);
setfillstyle(SOLID_FILL,colr);
getch();
}
//save
if (((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 100 && cursorposition.x < 140 && cursorposition.y > 2 && cursorposition.y < 20) // getkeystate detects the mouse left button press
{
writeimagefile("Screenshot.jpg",0,60,screenWidth,0,screenHeight);
outtextxy(screenHeight,0,"Screenshot taken ");
}
//eraser
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 10 && cursorposition.x < 35 && cursorposition.y > 20 && cursorposition.y < 40) // getkeystate detects the mouse left button press
{
setcolor(BLACK);
colr=15;
radii=3;
shape=1;
outtextxy(screenHeight, 0, (char *)"Eraser In use ");
}
//brushes
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 53 && cursorposition.x < 89 && cursorposition.y > 20 && cursorposition.y < 40) // getkeystate detects the mouse left button press
{
setcolor(BLACK);
colr=0;
radii=3;
shape=1;
outtextxy(screenHeight, 0, (char *)"Brushes in Use ");
}
//colorpallete/*------------------------------------*/
//Color0
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 120 && cursorposition.x < 140 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(BLACK);
colr=15;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Black ");
}
//color1
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 140 && cursorposition.x < 160 && cursorposition.y > 25&& cursorposition.y <37.5) // getkeystate detects the mouse left button press
{
setcolor(1);
colr=1;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Blue ");
}
//Color2
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 160 && cursorposition.x < 180 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(2);
colr=2;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Green ");
}
//Color3
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 180 && cursorposition.x < 200 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(3);
colr=3;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Cyan ");
}
//Color4
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 200 && cursorposition.x < 220 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(4);
colr=4;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Red ");
}
//Color5
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 220 && cursorposition.x < 240 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(5);
colr=5;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Magenta ");
}
//Color6
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 240 && cursorposition.x <260 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(6);
colr=6;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Brown ");
}
//color7
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 260 && cursorposition.x < 280 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(7);
colr=7;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Gray ");
}
//color8
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 280 && cursorposition.x < 300 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(8);
colr=8;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Dark Gray ");
}
//Color9
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 300 && cursorposition.x < 320 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(9);
colr=9;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Blue ");
}
//color10
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 320 && cursorposition.x < 340 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(10);
colr=10;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Green ");
}
//color11
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 340 && cursorposition.x < 360 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(11);
colr=11;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Cyan ");
}
//color12
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 360 && cursorposition.x < 380 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(12);
colr=12;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Red ");
}
//color13
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 380 && cursorposition.x < 400 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(13);
colr=13;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Light Magenta ");
}
//color14
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 400 && cursorposition.x < 420 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(14);
colr=14;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color Yellow ");
}
//color15
else if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 420 && cursorposition.x < 440 && cursorposition.y > 25 && cursorposition.y < 37.5) // getkeystate detects the mouse left button press
{
setcolor(15);
colr=15;
radii=3;
outtextxy(screenHeight, 0, (char *)"Color White ");
}
/**-----------------------------------*/
//Shapes
//rectangle
if (((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 453 && cursorposition.x < 461 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr = 0;
shape=2;
outtextxy(screenHeight, 0, (char *)"Rectangle ");
}
//line
if (((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 463 && cursorposition.x < 470 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr = 0;
shape=3;
outtextxy(screenHeight, 0, (char *)"Line ");
}
//circle
if (((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 472 && cursorposition.x < 488 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr = 0;
shape=1;
outtextxy(screenHeight, 0, (char *)"Circle ");
}
// arc
if (((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 495 && cursorposition.x < 520 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr = 0;
shape=4;
outtextxy(screenHeight, 0, (char *)"Arc ");
}
/**--------------------------*/
//text
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 522 && cursorposition.x <550 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr=0;
shape=5;
outtextxy(screenHeight, 0, (char *)"Text ");
}
//Brush size/**-------------------------------------------*/
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 559 && cursorposition.x < 571 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr=0;
radii=2;
outtextxy(screenHeight, 0, (char *)" 2px ");
}
if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 575 && cursorposition.x < 596 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr=0;
radii=4;
outtextxy(screenHeight, 0, (char *)"4px ");
} if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 600 && cursorposition.x < 630 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr=0;
radii=8;
outtextxy(screenHeight, 0, (char *)"8px ");
} if(((GetKeyState(VK_LBUTTON) & 0x8000) != 0) && cursorposition.x > 635 && cursorposition.x < 666 && cursorposition.y > 25 && cursorposition.y < 37.5)
{
colr=0;
radii=16;
outtextxy(screenHeight, 0, (char *)"16px ");
}
}
} };
// };
int main(){
//creating the workspace
int gd=DETECT,gm;
initgraph(&gd, &gm, (char*)"C:\\MinGW\\lib\\libbgi.a");
//DWORD is a type of 32 bit unsigned integer using this because format windows depends on this
// DWORD screenWidth =GetSystemMetrics(SM_CXSCREEN);//get screen width that is the x coordinates
// DWORD screenHeight =GetSystemMetrics(SM_CYSCREEN);//get screen height that is the y coordinates
// https://www.youtube.com/watch?v=SLudnS7nzaI&list=PL5UFsTza4wWSNhe0xuO6ELw7ORU-UHNDO&index=36
initwindow(screenWidth,screenHeight,(char*)"Paint Application",-2,0,false,true);//https://www.youtube.com/watch?v=puX16SFgS9I
/**width,height,title->is important otherwise can't access the main functions like minimize ,maximie and close buttons,
* space from left most corner, righmost corner, double buffering-> used ot show no flicker or any other artifacts, use of close button-> true to use it */
setbkcolor(WHITE);
cleardevice();
Paint p;
p.scribble_screen();
getch();
closegraph();
return 0;
}