-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawing2DProgram.cpp
More file actions
171 lines (136 loc) · 4.38 KB
/
Drawing2DProgram.cpp
File metadata and controls
171 lines (136 loc) · 4.38 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
#include <Windows.h>
#include <bits/stdc++.h>
#include "include/ProgramState.h"
#include "include/Constants.h"
#include "include/MainMenu.h"
#include "include/HandleCommand.h"
#include "include/HandleLBUP.h"
#include "include/HandleLBDown.h"
#include "include/HandleRBDown.h"
using namespace std;
using namespace Constants;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
HDC hdc = nullptr;
HMENU mainMenu;
static ProgramState state;
static HBRUSH &BGBrush = state.BGBrush;
static int &x1 = state.x1 , &y1 = state.y1, &x2 = state.x2, &y2 = state.y2 , &x = state.x, &y = state.y;
static int &xc = state.xc, &yc = state.yc, &r = state.r, &a = state.a, &b = state.b;
static vector<POINT>& convexPoints = state.convexPoints , & nonConvexPoints = state.nonConvexPoints;
static vector<Vector2>& splinePoints = state.splinePoints;
static vector<Point>& clipPoints = state.clipPoints;
static int& currentTool = state.currentTool;
static COLORREF &c = state.c;
static bool & rectClipActive = state.rectClipActive
, & squareClipActive = state.sqrClipActive, & circleClipActive = state.circleClipActive;
if(currentTool != FILL_CONVEX){
convexPoints.clear();
}
if(currentTool != FILL_NON_CONVEX){
nonConvexPoints.clear();
}
if(currentTool != CARDINAL_SPLINE){
splinePoints.clear();
}
if(currentTool != CLIP_RECT_POLYGON){
clipPoints.clear();
}
if(rectClipActive && (currentTool < 611 || currentTool > 614)){
rectClipActive = false;
}
if(squareClipActive && (currentTool < 621 || currentTool > 623)){
squareClipActive = false;
}
if(circleClipActive && (currentTool < 631 || currentTool > 633)){
circleClipActive = false;
}
switch (msg) {
case WM_CREATE: {
mainMenu = CreateMainMenu();
SetMenu(hwnd, mainMenu);
break;
}
case WM_COMMAND: {
HandleCommand(hwnd, wp, state);
break;
}
case WM_LBUTTONDOWN: {
HandleLBDown(hwnd, wp, lp, hdc, state);
break;
}
case WM_LBUTTONUP: {
HandleLBUP(hwnd, wp, lp, hdc , state);
break;
}
case WM_RBUTTONDOWN: {
HandleRBDown(hwnd , wp , lp , hdc , state);
break;
}
case WM_ERASEBKGND: {
hdc = (HDC)wp;
RECT rc;
GetClientRect(hwnd, &rc);
FillRect(hdc, &rc, BGBrush);
return 1;
}
case WM_PAINT: {
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
for (const auto& pt : convexPoints) {
Ellipse(hdc, pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2);
}
for (const auto& pt : nonConvexPoints) {
Ellipse(hdc, pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2);
}
for (const auto& pt : splinePoints) {
Ellipse(hdc, int(pt.x) - 2, int(pt.y) - 2, int(pt.x) + 2, int(pt.y) + 2);
}
for (const auto& pt : clipPoints) {
Ellipse(hdc, int(pt.x) - 2, int(pt.y) - 2, int(pt.x) + 2, int(pt.y) + 2);
}
EndPaint(hwnd, &ps);
break;
}
case WM_CLOSE: {
DestroyWindow(hwnd);
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default: {
return DefWindowProc(hwnd, msg, wp, lp);
}
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hi, HINSTANCE pi, LPSTR cmd, int nsh) {
const char* CLASS_NAME = "2D drawing program";
WNDCLASS wc = {};
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
wc.lpszClassName = CLASS_NAME;
wc.lpfnWndProc = WndProc;
wc.hInstance = hi;
if (!RegisterClass(&wc)) {
return -1;
}
HWND hwnd = CreateWindow(
CLASS_NAME, CLASS_NAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
nullptr, nullptr, hi, nullptr);
if (!hwnd) {
return -1;
}
ShowWindow(hwnd, nsh);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}