-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.cpp
219 lines (215 loc) · 5.46 KB
/
files.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
#include"head.h"
PIMAGE Read = nullptr;
FILE* savefiles = nullptr;
TCHAR filename[MAX_PATH] = _T("newimage");
TCHAR FileName[MAX_PATH] = {};
bool FunOpen()
{
PIMAGE ImageOpen = newimage();
getimage(ImageOpen, TEXT("JPG"), MAKEINTRESOURCE(IMAGEOPEN));
putimage(0, 0, ImageOpen);
delimage(ImageOpen);
Read = newimage();
flushmouse();
for (;is_run();delay_fps(360))
{
mouse_msg m = getmouse();
if (m.is_left())
{
/*若点击退出,则直接退出*/
if (m.x > 500 && m.x < 1050 && m.y>680 && m.y < 780)
exit(1);
/*读取文件部分(暂时以PNG格式保存与读取文件)*/
else if (m.x > 500 && m.x < 1050 && m.y>280 && m.y < 380)
{
char str[2] = {};
while (1)
{
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = _T("图像文件(*.draw)\0*.draw\0\0");
ofn.lpstrInitialDir = _T(".\\Images\\");
ofn.lpstrFile = FileName;
ofn.nMaxFile = sizeof(FileName) / sizeof(*FileName);
ofn.nFilterIndex = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;
BOOL ReadOk = GetOpenFileName(&ofn);
if (ReadOk != 1)
{
return false;
}
return true;
}
}
/*不读取文件*/
else if (m.x > 500 && m.x < 1050 && m.y>480 && m.y < 580)
{
FileName[250] = 1;
return true;
}
/*进入帮助部分*/
else if (m.x > 100 && m.x < 200 && m.y>300 && m.y < 700)
{
Help();
return false;
}
}
}
return false;//未知错误时返回
}
void ReadFromFile(TCHAR* fn)
{
FILE* openfile = _wfopen(fn, _T("r"));
int ReadMode = -1;
for (;is_run();delay_fps(FPS))
{
int n=fwscanf(openfile, _T("%d "), &ReadMode);
if (n <= 0)
return;
switch (ReadMode)
{
case 2:
{
int* XY = (int*)malloc(MAX * 2 * sizeof(int));
int r = 0, g = 0, b = 0;
double wi = 0;
int N = 0;
fwscanf(openfile, _T("%d "), &N);
for (int a = 0;a < (2 * N - 2);++a)
{
fwscanf(openfile, _T("%d "), &XY[a]);
}
fwscanf(openfile, _T("%d %d %d %lf"), &r, &g, &b, &wi);
setlinewidth(wi);
setcolor(EGEACOLOR(0xFF, EGERGB(r, g, b)));
for (int a = 2;a < (2 * N - 2);a = a + 2)
{
ege_line(XY[a - 2], XY[a - 1], XY[a], XY[a + 1]);
}
free(XY);
break;
}
case 3:
{
int x1 = 0, x2 = 0, y1 = 0, y2 = 0, r = 0, g = 0, b = 0;
double wi = 0;
fwscanf(openfile, _T("%d %d %d %d %d %d %d %lf\n"), &x1, &y1, &x2, &y2, &r, &g, &b, &wi);
setlinewidth(wi);
setcolor(EGEACOLOR(0xFF, EGERGB(r, g, b)));
ege_line(x1, y1, x2, y2);
break;
}
case 4:
{
int x1 = 0, x2 = 0, y1 = 0, y2 = 0, r = 0, g = 0, b = 0;
double wi = 0;
fwscanf(openfile, _T("%d %d %d %d %d %d %d %lf\n"), &x1, &y1, &x2, &y2, &r, &g, &b, &wi);
setlinewidth(wi);
setcolor(EGEACOLOR(0xFF, EGERGB(r, g, b)));
float R = float(sqrt(pow(double(x2 - x1), 2) + pow(double(y2 - y1), 2)));
ege_ellipse(x1 - R, y1 - R, 2 * R, 2 * R);
break;
}
case 5:
{
int pt[100] = {};
int r = 0, g = 0, b = 0;
double wi = 0;
int N = 0;
fwscanf(openfile, _T("%d "), &N);
for (int n = 0;n < N;++n)
{
fwscanf(openfile, _T("%d %d "), &pt[2 * n], &pt[2 * n + 1]);
}
setlinewidth(wi);
setcolor(EGEACOLOR(0xFF, EGERGB(r, g, b)));
fillpoly(N, pt);
break;
}
}
}
}
void SaveFile()
{
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = _T("图像文件(*.draw)\0*.draw\0\0");
ofn.lpstrInitialDir = _T("./Images/");
ofn.lpstrFile = filename;
ofn.nMaxFile = sizeof(filename) / sizeof(*filename);
ofn.nFilterIndex = 0;
ofn.lpstrDefExt = _T(".draw");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_OVERWRITEPROMPT;
BOOL saveok = GetSaveFileName(&ofn);
if (saveok != 1)
return;
savefiles = _wfopen(filename,_T("w"));
for (int a = 0;a < Save;++a)
{
WriteToFile(RMake[a]);
}
fclose(savefiles);
savefiles = nullptr;
return;
}
void WriteToFile(Draw_Modes IM)
{
switch (IM.Mode)
{
case CLEAR:
{
fclose(savefiles);
savefiles = nullptr;
savefiles = _wfopen(filename, _T("w"));
break;
}
case PIXEL:
{
fwprintf(savefiles, _T("2 %04d "),IM.pixel_[0].x);
for (int n = 1;n < IM.pixel_[0].x;++n)
{
fwprintf(savefiles, _T("%04d %04d "), IM.pixel_[n].x, IM.pixel_[n].y);
}
fwprintf(savefiles, _T("%04d %04d %04d %.04lf\n"), EGEGET_R(IM.Color), EGEGET_G(IM.Color), EGEGET_B(IM.Color), IM.Width);
break;
}
case LINE:
{
fwprintf(savefiles, _T("3 %04d %04d %04d %04d %04d %04d %04d %.04lf\n"), IM.coor[1].x, IM.coor[1].y, IM.coor[2].x, IM.coor[2].y, EGEGET_R(IM.Color), EGEGET_G(IM.Color), EGEGET_B(IM.Color), IM.Width);
break;
}
case CIRCLE:
{
fwprintf(savefiles, _T("4 %04d %04d %04d %04d %04d %04d %04d %.04lf\n"), IM.coor[1].x, IM.coor[1].y, IM.coor[2].x, IM.coor[2].y, EGEGET_R(IM.Color), EGEGET_G(IM.Color), EGEGET_B(IM.Color), IM.Width);
break;
}
case Homework_Polygon:
{
fwprintf(savefiles, _T("5 %04d "), IM.coor[0].x);
for (int n = 0;n < IM.coor[0].x;++n)
{
fwprintf(savefiles, _T("%04d %04d "), IM.coor[n + 1].x, IM.coor[n + 1].y);
}
fwprintf(savefiles, _T("%04d %04d %04d %.04lf\n"), EGEGET_R(IM.Color), EGEGET_G(IM.Color), EGEGET_B(IM.Color), IM.Width);
break;
}
}
return;
}
/*调出帮助文档*/
void Help()
{
PIMAGE HelpFirst = newimage();
getimage(HelpFirst, TEXT("JPG"), MAKEINTRESOURCE(HELPFIRST));
putimage(0, 0, HelpFirst);
flushmouse();
for (;is_run();delay_fps(FPS))
{
mouse_msg m = getmouse();
if (m.x > 10 && m.x < 160 && m.y>800 && m.y < 900&&m.is_down())
{
delimage(HelpFirst);
return;
}
}
}