-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnowModelDlgs.cpp
273 lines (254 loc) · 8.21 KB
/
SnowModelDlgs.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
#include "stdafx.h"
//#include <wchar.h>
#include <CommCtrl.h>
#include "SnowModel.h"
#include "CSnow.h"
extern HINSTANCE hInst;
extern HWND hTemperatureDlg;
extern HWND hEditLayerDlg;
extern BOOL bEditLayer;
int currentT = -1;
BOOL bEdit = FALSE;
HWND hEditDlg;
INT_PTR CALLBACK EditDlgProc(HWND, UINT, WPARAM, LPARAM);
//BOOL TEMPDLG_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
void TEMPDLG_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
void TEMPDLG_OnNotify(HWND hWnd, int id, LPNMHDR lpnmhdr);
void TEMPDLG_OnDestroy(HWND hWnd);
void EDITLAYERDLG_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
INT_PTR CALLBACK TempDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
HWND hChild;
RECT rect;
LV_COLUMN lvc;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
hTemperatureDlg = hDlg;
hEditDlg = NULL;
hMenu = GetMenu(GetParent(hDlg));
CheckMenuItem(hMenu, IDM_TEMPERATURE_DLG, MF_CHECKED);
GetClientRect(hDlg, &rect);
hChild = CreateWindow(WC_LISTVIEW, _T(""), WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL, 0, 0, rect.right, rect.bottom - 74, hDlg, (HMENU)IDC_TEMPERATURE_LIST, hInst, NULL);
ListView_SetExtendedListViewStyle(hChild, LVS_EX_AUTOSIZECOLUMNS | LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
ZeroMemory(&lvc,sizeof(lvc));
lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;//Ìàñêà
lvc.fmt=LVCFMT_LEFT;//Âûðàâíèâàíèå âëåâî
lvc.cx=rect.right/2;//Ðàçìåð ïåðâîãî ïîëÿ çàãîëîâêà
lvc.pszText=_T("time");//Ñòðîêà ñ òåêñòîì ïåðâîãî ïîëÿ çàãîëîâêà
ListView_InsertColumn(hChild,0,&lvc);//Âêëþ÷àåì ïîëå â çàãîëîâîê
lvc.pszText=_T("T");//Ñòðîêà ñ òåêñòîì ïåðâîãî ïîëÿ çàãîëîâêà
ListView_InsertColumn(hChild,1,&lvc);//Âêëþ÷àåì ïîëå â çàãîëîâîê
UpdateTemperatureLog();
break;
//case WM_INITDIALOG: HANDLE_WM_INITDIALOG(hDlg, wParam, lParam, NULL);//TEMPDLG_OnInitDialog); break;
HANDLE_MSG(hDlg, WM_COMMAND, TEMPDLG_OnCommand);
HANDLE_MSG(hDlg, WM_DESTROY, TEMPDLG_OnDestroy);
case WM_NOTIFY: HANDLE_WM_NOTIFY(hDlg, wParam, lParam, TEMPDLG_OnNotify); break;
default:
return (INT_PTR)FALSE;
}
return (INT_PTR)TRUE;
}
void TEMPDLG_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDOK:
case IDCANCEL:
DestroyWindow(hWnd);
break;
case IDC_EDIT_BTN:
bEdit = TRUE;
if (!hEditDlg)
hEditDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_EDIT_TEMPERATURE), hWnd, EditDlgProc);
SetDlgItemText(hEditDlg, IDOK, _T("Edit"));
if (currentT >= 0 && currentT < CSnow::current()->getTLogSize()) {
SetDlgItemText(hEditDlg, IDC_EDIT1, ToString(CSnow::current()->getTLog(currentT).first).c_str());
SetDlgItemText(hEditDlg, IDC_EDIT2, ToString(CSnow::current()->getTLog(currentT).second).c_str());
EnableWindow(GetDlgItem(hEditDlg, IDOK), TRUE);
} else {
EnableWindow(GetDlgItem(hEditDlg, IDOK), FALSE);
}
break;
case IDC_ADD_BTN:
bEdit = FALSE;
if (!hEditDlg)
hEditDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_EDIT_TEMPERATURE), hWnd, EditDlgProc);
SetDlgItemText(hEditDlg, IDOK, _T("Add"));
SetDlgItemText(hEditDlg, IDC_EDIT1, _T(""));
SetDlgItemText(hEditDlg, IDC_EDIT2, _T(""));
EnableWindow(GetDlgItem(hEditDlg, IDOK), TRUE);
break;
case IDC_DELETE_BTN:
CSnow::current()->removeTLog(currentT);
//currentT--;
UpdateAll();
//if (currentT >= 0)
// ListView_SetItemState(GetDlgItem(hWnd, IDC_LAYERS_LIST), currentT, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
break;
}
}
void TEMPDLG_OnDestroy(HWND hWnd)
{
HMENU hMenu;
hMenu = GetMenu(GetParent(hWnd));
CheckMenuItem(hMenu, IDM_TEMPERATURE_DLG, 0);
hTemperatureDlg = NULL;
}
void TEMPDLG_OnNotify(HWND hWnd, int id, LPNMHDR lpnmhdr)
{
if(lpnmhdr->idFrom == IDC_TEMPERATURE_LIST) {
if(lpnmhdr->code == LVN_ITEMCHANGED) {
if(((NM_LISTVIEW *)lpnmhdr)->uNewState & LVIS_FOCUSED) {
currentT = ((NM_LISTVIEW *)lpnmhdr)->iItem;
if (hEditDlg && bEdit && (currentT >= 0 && currentT < CSnow::current()->getTLogSize()))
{
SetDlgItemText(hEditDlg, IDC_EDIT1, ToString(CSnow::current()->getTLog(currentT).first).c_str());
SetDlgItemText(hEditDlg, IDC_EDIT2, ToString(CSnow::current()->getTLog(currentT).second).c_str());
EnableWindow(GetDlgItem(hEditDlg, IDOK), TRUE);
}
}
}
}
}
INT_PTR CALLBACK EditDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rect;
RECT listRect;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
GetWindowRect(hDlg, &rect);
GetWindowRect(GetDlgItem(GetParent(hDlg), IDC_TEMPERATURE_LIST), &listRect);
MoveWindow(GetDlgItem(GetParent(hDlg), IDC_TEMPERATURE_LIST), 0, rect.bottom - rect.top, rect.right - rect.left, listRect.bottom - listRect.top - rect.bottom + rect.top, TRUE);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
TCHAR str[80];
GetDlgItemText(hDlg, IDC_EDIT1, str, sizeof(str));
double time = _wtof(str);
GetDlgItemText(hDlg, IDC_EDIT2, str, sizeof(str));
double T = _wtof(str);
if (bEdit) {
CSnow::current()->editTLog(currentT, time, T);
} else {
CSnow::current()->addTLog(time, T);
}
UpdateAll();
} else if (LOWORD(wParam) == IDCANCEL)
{
DestroyWindow(hDlg);
}
break;
case WM_DESTROY:
GetClientRect(GetParent(hDlg), &rect);
MoveWindow(GetDlgItem(GetParent(hDlg), IDC_TEMPERATURE_LIST), 0, 0, rect.right, rect.bottom - 74, TRUE);
hEditDlg = NULL;
break;
default:
return (INT_PTR)FALSE;
}
return (INT_PTR)TRUE;
}
INT_PTR CALLBACK EditLayerDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
//RECT rect;
//RECT listRect;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)_T("Ñâåæèé ñíåã"));
SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)_T("Ìåòåëåâûé ñíåã"));
SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)_T("Ñíåæíàÿ êðóïà"));
SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)_T("Ëåäÿíîé äîæäü"));
SendDlgItemMessage(hDlg, IDC_COMBO1, CB_SETCURSEL, 0, 0);
SetDlgItemText(hDlg, IDC_EDIT1, _T("0"));
SetDlgItemText(hDlg, IDC_EDIT2, _T("0"));
SetDlgItemText(hDlg, IDC_EDIT4, _T("0.1"));
SetDlgItemText(hDlg, IDC_EDIT5, _T("0.1"));
break;
HANDLE_MSG(hDlg, WM_COMMAND, EDITLAYERDLG_OnCommand);
case WM_DESTROY:
hEditLayerDlg = NULL;
break;
default:
return (INT_PTR)FALSE;
}
return (INT_PTR)TRUE;
}
void EDITLAYERDLG_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDOK:
{
TCHAR str[80];
GetDlgItemText(hWnd, IDC_EDIT1, str, sizeof(str));
double time = _wtof(str);
GetDlgItemText(hWnd, IDC_EDIT2, str, sizeof(str));
double duration = _wtof(str);
GetDlgItemText(hWnd, IDC_EDIT3, str, sizeof(str));
double life_time = _wtof(str);
GetDlgItemText(hWnd, IDC_EDIT4, str, sizeof(str));
double density = _wtof(str);
GetDlgItemText(hWnd, IDC_EDIT5, str, sizeof(str));
double size = _wtof(str);
GetDlgItemText(hWnd, IDC_EDIT6, str, sizeof(str));
double height = _wtof(str);
if (bEditLayer) {
CLayer* layer = CSnow::current()->getLayer();
if (layer)
{
layer->SetTime0(time);
layer->SetDuration(duration);
layer->SetLifetime(life_time);
layer->SetDensity0(density);
layer->SetParticleSize0(size);
layer->SetHeight0(height);
layer->Reset();
}
UpdateAll();
//CSnow::current()->editTLog(currentT, time, T);
} else {
CSnow::current()->add(density, height, time, size, life_time, duration);
UpdateAll();
}
break;
}
case IDCANCEL:
DestroyWindow(hWnd);
break;
case IDC_COMBO1:
if (codeNotify == CBN_SELCHANGE)
{
switch (SendMessage(hwndCtl, CB_GETCURSEL, 0, 0))
{
case 0:
SetDlgItemText(hWnd, IDC_EDIT4, _T("0.1"));
SetDlgItemText(hWnd, IDC_EDIT5, _T("0.1"));
break;
case 1:
SetDlgItemText(hWnd, IDC_EDIT4, _T("0.3"));
SetDlgItemText(hWnd, IDC_EDIT5, _T("0.05"));
break;
case 2:
SetDlgItemText(hWnd, IDC_EDIT4, _T("0.2"));
SetDlgItemText(hWnd, IDC_EDIT5, _T("1.0"));
break;
case 3:
SetDlgItemText(hWnd, IDC_EDIT4, _T("0.8"));
SetDlgItemText(hWnd, IDC_EDIT5, _T("0.5"));
break;
}
}
break;
default:
FORWARD_WM_COMMAND(hWnd, id, hwndCtl, codeNotify, DefWindowProc);
}
}