-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
1216 lines (1125 loc) · 48.2 KB
/
main.cpp
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Shapes Imports
#include "Shapes/Shape.h"
#include "Drawers/Drawer.h"
#include "Shapes/Line.h"
#include "Shapes/ELLIPSE.h"
#include "Shapes/Circle.h"
#include "Shapes/Curve.h"
#include "Shapes/Rectangle.h"
#include "Shapes/Square.h"
#include "Shapes/Polygon.h"
#include "Shapes/Flood.h"
//Line Algorithms Imports
#include "Drawers/LineAlgorithms/LineDrawerDDA.h"
#include "Drawers/LineAlgorithms/LineDrawerParametric.h"
#include "Drawers/LineAlgorithms/LineDrawerMidpoint.h"
//Circle Algorithms Imports
#include "Drawers/CircleAlgorithms/CircleDrawerDirect.h"
#include "Drawers/CircleAlgorithms/CircleDrawerPolar.h"
#include "Drawers/CircleAlgorithms/CircleDrawerIterativePolar.h"
#include "Drawers/CircleAlgorithms/CircleDrawerMidpoint.h"
#include "Drawers/CircleAlgorithms/CircleDrawerModifiedMidpoint.h"
//Shapes Algorithm Import
#include "Drawers/PointAlgorithm/PointDrawer.h"
#include "Drawers/RectangleAlgorithms/RectangleDrawer.h"
//Ellipse Algorithms Imports
#include "Drawers/EllipseAlgorithms/EllipseDrawerDirect.h"
#include "Drawers/EllipseAlgorithms/EllipseDrawerPolar.h"
#include "Drawers/EllipseAlgorithms/EllipseDrawerMidpoint.h"
//Curve Algorithms Imports
#include "Drawers/CurveAlgorithms/CurveDrawerBezier.h"
#include "Drawers/CurveAlgorithms/CurveDrawerHermite.h"
//Filling Algorithms Imports
#include "Drawers/FillingAlgorithms/CircleFillers/CircleFillerWithLine.h"
#include "Drawers/FillingAlgorithms/CircleFillers/CircleFillerWithCircle.h"
#include "Drawers/FillingAlgorithms/RectangleFilling/RectangleFillerWithBezierCurve.h"
#include "Drawers/FillingAlgorithms/SquareFilling/SquareFillerWithHermiteCurve.h"
#include "Drawers/FillingAlgorithms/FloodFill/FloodFillNonRecursive.h"
#include "Drawers/FillingAlgorithms/FloodFill/FloodFillRecursive.h"
#include "Drawers/FillingAlgorithms/PolygonFillers/ConvexFiller.h"
#include "Drawers/FillingAlgorithms/PolygonFillers/NonConvexFiller.h"
//Clipping Imports
#include "Drawers/ClippingRectangleAlgorithms/ClippingRectanglePoint.h"
#include "Drawers/ClippingRectangleAlgorithms/ClippingRectangleLine.h"
#include "Drawers/ClippingCircleAlgorithms/ClippingCirclePoint.h"
#include "Drawers/ClippingCircleAlgorithms/ClippingCircleLine.h"
#include "Drawers/PolygonAlgorithms/PolygonDrawer.h"
#include "Drawers/ClippingRectangleAlgorithms/ClippingRectanglePolygon.h"
#include "Drawers/RectangleAlgorithms/SquareDrawer.h"
#include "Shapes/Container.h"
//Utility Imports
#include <stack>
#include <Windowsx.h>
#include <cmath>
//DEFINITIONS
#define CHANGE_CURSOR 10001
#define DISABLE_KEYBOARD 10002
#define SAVE_DATA 10004
#define LOAD_DATA 10005
#define DRAW_LINE_DDA 10006
#define DRAW_LINE_PARAMETRIC 10007
#define DRAW_LINE_MIDPOINT 10008
#define DRAW_CIRCLE_DIRECT 10009
#define DRAW_CIRCLE_POLAR 10010
#define DRAW_CIRCLE_ITERATIVE_POLAR 10011
#define DRAW_CIRCLE_MIDPOINT 10012
#define DRAW_CIRCLE_MODIFIED_MIDPOINT 10013
#define FILL_CIRCLE_WITH_LINE 10014
#define FILL_CIRCLE_WITH_CIRCLE 10015
#define FILL_SQUARE_WITH_HERMITE_CURVE 10016
#define FILL_RECTANGLE_WITH_BEZIER_CURVE 10017
#define CONVEX_FILLING 10018
#define NON_CONVEX_FILLING 10019
#define RECURSIVE_FLOOD_FILL 10020
#define NON_RECURSIVE_FLOOD_FILL 10021
#define CARDINAL_SPLINE_CURVE 10022
#define DRAW_ELLIPSE_DIRECT 10023
#define DRAW_ELLIPSE_POLAR 10024
#define DRAW_ELLIPSE_MIDPOINT 10025
#define CLIP_RECTANGLE_POINT 10026
#define CLIP_RECTANGLE_LINE 10027
#define CLIP_RECTANGLE_POLYGON 10028
#define CLIP_SQUARE_POINT 10029
#define CLIP_SQUARE_LINE 10030
#define CLIP_CIRCLE_POINT 10031
#define CLIP_CIRCLE_LINE 10032
#define CLEAR_WINDOW 10033
#define EXIT_WINDOW 10034
//COLORS DEFINITIONS
#define COLOR_RED 10035
#define COLOR_BLUE 10036
#define COLOR_GREEN 10037
#define COLOR_CYAN 10038
#define COLOR_MAGENTA 10039
#define COLOR_YELLOW 10040
#define COLOR_BLACK 10041
HCURSOR cursor = LoadCursorA(NULL, IDC_ARROW);
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
void AddMenu(HWND hWnd);
HMENU hMenu;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hprevInst, LPSTR args, int ncmdshow) {
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpszClassName = L"myWindowClass";
wc.lpfnWndProc = WindowProcedure;
if (!RegisterClassW(&wc))
return -1;
CreateWindowW(L"myWindowClass", L"My Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 750, 250, 800, 800, NULL, NULL,
NULL, NULL);
MSG msg = {0};
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
bool firstCreate = true;
vector<Shape *> shapes;
File file("mangaSave");
bool flag = false;
COLORREF currentColor = RGB(255, 128, 53);
void init() {
if (flag)
return;
flag = true;
/* Shapes */
Shape::addShape("point", new Point());
Shape::addShape("line", new Line());
Shape::addShape("rectangle", new RECTANGLE());
Shape::addShape("circle", new Circle());
Shape::addShape("ellipse", new ELLIPSE());
Shape::addShape("curve", new Curve());
Shape::addShape("polygon", new POLYGON());
Shape::addShape("square", new Square());
Shape::addShape("flood", new Flood());
Shape::addShape("container", new Container());
/* Line Drawer Algorithms */
Drawer::addDrawer("LineDrawerDDA", new LineDrawerDDA());
Drawer::addDrawer("LineDrawerMidpoint", new LineDrawerMidpoint());
Drawer::addDrawer("LineDrawerParametric", new LineDrawerParametric());
/* Circle Drawer Algorithms */
Drawer::addDrawer("CircleDrawerDirect", new CircleDrawerDirect());
Drawer::addDrawer("CircleDrawerIterativePolar", new CircleDrawerIterativePolar());
Drawer::addDrawer("CircleDrawerMidpoint", new CircleDrawerMidpoint());
Drawer::addDrawer("CircleDrawerModifiedMidpoint", new CircleDrawerModifiedMidpoint());
Drawer::addDrawer("CircleDrawerPolar", new CircleDrawerPolar());
/* Ellipse Drawer Algorithms */
Drawer::addDrawer("EllipseDrawerDirect", new EllipseDrawerDirect());
Drawer::addDrawer("EllipseDrawerMidpoint", new EllipseDrawerMidpoint());
Drawer::addDrawer("EllipseDrawerPolar", new EllipseDrawerPolar());
/* Curve Drawer Algorithms */
Drawer::addDrawer("CurveDrawerBezier", new CurveDrawerBezier());
Drawer::addDrawer("CurveDrawerHermite", new CurveDrawerHermite());
/* Filling Algorithms */
Drawer::addDrawer("CircleFillerWithCircle", new CircleFillerWithCircle());
Drawer::addDrawer("CircleFillerWithLine", new CircleFillerWithLine());
Drawer::addDrawer("FloodFillRecursive", new FloodFillRecursive());
Drawer::addDrawer("FloodFillNonRecursive", new FloodFillNonRecursive());
Drawer::addDrawer("ConvexFiller", new ConvexFiller());
Drawer::addDrawer("NonConvexFiller", new NonConvexFiller());
Drawer::addDrawer("SquareFillerWithHermiteCurve", new SquareFillerWithHermiteCurve());
Drawer::addDrawer("RectangleFillerWithBezierCurve", new RectangleFillerWithBezierCurve());
/* Clipping Circle Algorithms */
Drawer::addDrawer("ClippingCircleLine", new ClippingCircleLine());
Drawer::addDrawer("ClippingCirclePoint", new ClippingCirclePoint());
/* Clipping Rectangle Algorithms */
Drawer::addDrawer("ClippingRectangleLine", new ClippingRectangleLine());
Drawer::addDrawer("ClippingRectanglePoint", new ClippingRectanglePoint());
Drawer::addDrawer("ClippingRectanglePolygon", new ClippingRectanglePolygon());
/* Point Drawer */
Drawer::addDrawer("PointDrawer", new PointDrawer());
/* Polygon Algorithms */
Drawer::addDrawer("PolygonDrawer", new PolygonDrawer());
/* Rectangle Algorithms */
Drawer::addDrawer("RectangleDrawer", new RectangleDrawer());
Drawer::addDrawer("SquareDrawer", new SquareDrawer());
}
stack <int> xInputs;
stack <int> yInputs;
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
int x1, x2, x3, x4;
int y1, y2, y3, y4;
int a, b;
HDC hdc;
Shape *shape;
Drawer *dr;
init();
switch (msg) /* handle the messages */
{
case WM_COMMAND:
switch (wp)
{
case CHANGE_CURSOR:
cursor=LoadCursorA(NULL, IDC_CROSS);
SetCursor(cursor);
break;
case DISABLE_KEYBOARD:
break;
case COLOR_RED:
currentColor=RGB(255, 0, 0);
break;
case COLOR_BLUE:
currentColor=RGB(0, 0, 255);
break;
case COLOR_GREEN:
currentColor=RGB(0, 255, 0);
break;
case COLOR_CYAN:
currentColor=RGB(0, 255, 255);
break;
case COLOR_MAGENTA:
currentColor=RGB(255, 0, 255);
break;
case COLOR_YELLOW:
currentColor=RGB(255, 255, 0);
break;
case COLOR_BLACK:
currentColor=RGB(0, 0, 0);
break;
case SAVE_DATA:
file.clear();
for(int i=0; i < shapes.size(); ++i)
{
shapes[i]->save(file);
}
break;
case LOAD_DATA:
{
string s=file.get();
hdc=GetDC(hWnd);
vector<string> vec=UT::split(s, '\n');
for(int i=0; i < vec.size(); ++i)
{
vector<string> cur=UT::split(vec[i], ':');
shape=Shape::shapes[stoi(cur[0])]->copy(cur[1]);
shape->drawer=Drawer::drawers[stoi(cur[2])]->copy();
shape->draw(hdc);
shapes.push_back(shape);
}
ReleaseDC(hWnd, hdc);
}
break;
case DRAW_LINE_DDA:
if(xInputs.size() < 2)
{
std::cout << "You need at least 2 points to draw a line\n";
return 0;
}
//Extracting Line Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new LineDrawerDDA();
shape=new Line(x1, y1, x2, y2, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_LINE_PARAMETRIC:
if(xInputs.size() < 2)
{
std::cout << "You need at least 2 points to draw a line\n";
return 0;
}
//Extracting Line Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new LineDrawerParametric();
shape=new Line(x1, y1, x2, y2, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_LINE_MIDPOINT:
if(xInputs.size() < 2)
{
std::cout << "You need at least 2 points to draw a line\n";
return 0;
}
//Extracting Line Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new LineDrawerMidpoint();
shape=new Line(x1, y1, x2, y2, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_CIRCLE_DIRECT:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
dr=new CircleDrawerDirect();
shape=new Circle(x2, y2, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_CIRCLE_POLAR:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
dr=new CircleDrawerPolar();
shape=new Circle(x2, y2, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_CIRCLE_ITERATIVE_POLAR:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
dr=new CircleDrawerIterativePolar();
shape=new Circle(x2, y2, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_CIRCLE_MIDPOINT:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
//Constructing objects needed for circle
dr=new CircleDrawerMidpoint();
shape=new Circle(x2, y2, a, currentColor, dr);
//Drawing Circle
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_CIRCLE_MODIFIED_MIDPOINT:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
dr=new CircleDrawerModifiedMidpoint();
shape=new Circle(x2, y2, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case FILL_CIRCLE_WITH_LINE:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
cout << "Enter the number of quarter you would like to fill (1 to 4 inclusive)\n-> ";
cin >> x3;
cout << endl;
dr=new CircleFillerWithLine();
shape=new Circle(x2, y2, a, x3, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case FILL_CIRCLE_WITH_CIRCLE:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a circle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
cout << "Enter the number of quarter you would like to fill (1 to 4 inclusive)\n-> ";
cin >> x3;
cout << endl;
dr=new CircleFillerWithCircle();
shape=new Circle(x2, y2, a, x3, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case FILL_SQUARE_WITH_HERMITE_CURVE:
if(xInputs.size() < 2){
std::cout << "You need to register at least 2 input points in order to draw a square\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new SquareFillerWithHermiteCurve();
hdc=GetDC(hWnd);
//INPUT MUST BE TOP-LEFT TO BOTTOM-RIGHT IN ORDER
shape=new Square(x1, y1, x2, y2, currentColor, dr);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case FILL_RECTANGLE_WITH_BEZIER_CURVE:
if(xInputs.size() < 2)
{
std::cout << "You need to register at least 2 input points in order to draw a rectangle\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new RectangleFillerWithBezierCurve();
hdc=GetDC(hWnd);
shape=new RECTANGLE(x1, y1, x2, y2, currentColor, dr);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case CONVEX_FILLING:
{
//need number of points for polygon
int n;
cout << "enter number of points needed";
cin >> n;
if(xInputs.size() < n && n > 3)
{
std::cout << "You need to register at least " << n
<< " or at least 3" << " input points in order to draw a Polygon of Size " << n
<< "\n";
return 0;
}
dr=new ConvexFiller();
hdc=GetDC(hWnd);
Point *points=new Point[n];
for(int i=0; i < n; ++i)
{
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
points[i].x=x1;
points[i].y=y1;
}
shape=new POLYGON(points, n,currentColor,dr);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case NON_CONVEX_FILLING:
{
//need number of points for polygon
int n;
cout << "enter number of points needed";
cin >> n;
if(xInputs.size() < n && n > 3)
{
std::cout << "You need to register at least " << n
<< " or at least 3" << " input points in order to draw a Polygon of Size " << n
<< "\n";
return 0;
}
dr=new NonConvexFiller();
hdc=GetDC(hWnd);
Point *points=new Point[n];
for(int i=0; i < n; ++i)
{
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
points[i].x=x1;
points[i].y=y1;
}
shape=new POLYGON(points, n,currentColor,dr);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case RECURSIVE_FLOOD_FILL:
{
if(xInputs.size() < 1)
{
std::cout << "You need to register at least 1 input point in order to Fill\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
Point p(x1, y1);
dr=new FloodFillRecursive();
shape=new Flood(p, currentColor, dr);
shape->c=currentColor;
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case NON_RECURSIVE_FLOOD_FILL:
{
if(xInputs.size() < 1)
{
std::cout << "You need to register at least 1 input point in order to Fill\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
Point p(x1, y1);
dr=new FloodFillNonRecursive();
shape=new Flood(p, currentColor, dr);
shape->c=currentColor;
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case CARDINAL_SPLINE_CURVE:
if(xInputs.size() < 4)
{
std::cout << "You need to register at least 4 input points in order to draw a curve\n";
return 0;
}
//Extracting Circle Input
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
x4=xInputs.top();
y4=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new CurveDrawerBezier();
shape=new Curve(x1, y1, x2, y2, x3, y3, x4, y4, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_ELLIPSE_DIRECT:
if(xInputs.size() < 3)
{
std::cout << "You need to register at least 3 input points in order to draw an ellipse\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
b=sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
dr=new EllipseDrawerDirect();
shape=new ELLIPSE(x3, y3, b, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_ELLIPSE_POLAR:
if(xInputs.size() < 3)
{
std::cout << "You need to register at least 3 input points in order to draw an ellipse\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
b=sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
dr=new EllipseDrawerPolar();
shape=new ELLIPSE(x3, y3, b, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case DRAW_ELLIPSE_MIDPOINT:
if(xInputs.size() < 3)
{
std::cout << "You need to register at least 3 input points in order to draw an ellipse\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
a=sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
b=sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
dr=new EllipseDrawerMidpoint();
shape=new ELLIPSE(x3, y3, b, a, currentColor, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
case CLIP_RECTANGLE_POINT:
{
if(xInputs.size() < 3)
{
std::cout
<< "You need to register at least 3 input points in order to clip a point on a rectangle\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new RectangleDrawer();
Shape *rect=new RECTANGLE(x1, y1, x2, y2, currentColor, dr);
hdc=GetDC(hWnd);
rect->draw(hdc);
shapes.push_back(rect);
dr=new PointDrawer();
Shape *point=new Point(x3, y3, RGB(255, 255, 255), dr);
dr=new ClippingRectanglePoint();
shape = new Container(rect, point, dr);
hdc = GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case CLIP_RECTANGLE_LINE:
{
if(xInputs.size() < 4)
{
std::cout
<< "You need to register 4 input points in order to clip a line on a rectangle\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
x4=xInputs.top();
y4=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new RectangleDrawer();
Shape *rect=new RECTANGLE(x1, y1, x2, y2, currentColor, dr);
hdc=GetDC(hWnd);
rect->draw(hdc);
shapes.push_back(rect);
dr=new LineDrawerDDA();
Shape *line=new Line(x3, y3, x4, y4, currentColor, dr);
dr=new ClippingRectangleLine();
shape = new Container(rect, line, dr);
hdc=GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case CLIP_RECTANGLE_POLYGON:
{
int n;
cout << "enter number of points needed";
cin >> n;
if(xInputs.size() < n && n > 5)
{
std::cout << "You need to register at least " << n
<< " or at least 5" << " input points in order to draw a Polygon of Size " << n
<< "\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
hdc=GetDC(hWnd);
dr=new RectangleDrawer();
Shape *rect=new RECTANGLE(x1, y1, x2, y2, currentColor, dr);
Point *points=new Point[n];
for(int i=0; i < n; ++i)
{
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
points[i].x=x1;
points[i].y=y1;
}
rect->draw(hdc);
shapes.push_back(rect);
dr=new PolygonDrawer();
Shape *poly=new POLYGON(points, n, currentColor, dr);
dr=new ClippingRectanglePolygon();
((ClippingRectanglePolygon *) dr)->draw(rect, poly, hdc);
ReleaseDC(hWnd, hdc);
break;
}
case CLIP_SQUARE_POINT:
{
if(xInputs.size() < 2)
{
std::cout
<< "You need to register at least 4 input points in order to clip a point on a rectangle\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
dr=new RectangleDrawer();
int r=sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)));
//x1 & x2 must be top-left
Shape *sq=new RECTANGLE(x1, y1, x1+r, y1+r, currentColor, dr);
hdc=GetDC(hWnd);
sq->draw(hdc);
shapes.push_back(sq);
dr=new PointDrawer();
Shape *point=new Point(x3, y3, RGB(255, 255, 255), dr);
dr=new ClippingRectanglePoint();
((ClippingRectanglePoint *) dr)->draw(sq, point, hdc);
ReleaseDC(hWnd, hdc);
break;
}
case CLIP_SQUARE_LINE:
{
if(xInputs.size() < 3)
{
std::cout
<< "You need to register 4 input points in order to clip a line on a square\n";
return 0;
}
x1=xInputs.top();
y1=yInputs.top();
xInputs.pop();
yInputs.pop();
x2=xInputs.top();
y2=yInputs.top();
xInputs.pop();
yInputs.pop();
x3=xInputs.top();
y3=yInputs.top();
xInputs.pop();
yInputs.pop();
x4=xInputs.top();
y4=yInputs.top();
xInputs.pop();
yInputs.pop();
dr = new RectangleDrawer();
int r=sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)));
Shape *sq = new RECTANGLE(x1, y1, x1 + r, y1 + r, currentColor, dr);
sq->draw(hdc);
dr = new LineDrawerDDA();
Shape *line = new Line(x3, y3, x4, y4, currentColor, dr);
dr = new ClippingRectangleLine();
shape = new Container(sq, line, dr);
hdc = GetDC(hWnd);
shape->draw(hdc);
ReleaseDC(hWnd, hdc);
shapes.push_back(shape);
break;
}
case CLIP_CIRCLE_POINT: {
if (xInputs.size() < 3) {
std::cout
<< "You need to register at least 3 input points in order to clip a point on a Circle\n";