Debian Codegraph @

editor/ObjectPropertiesDialog.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // ObjectPropertiesDialog.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "PropertyAIDlg.h"
25 #include "PropertyPhysicsDlg.h"
26 #include "ObjectPropertiesDialog.h"
27 #include "pserror.h"
28 #include "ddio.h"
29
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #undef THIS_FILE
33 static char THIS_FILE[] = __FILE__;
34 #endif
35
36 /////////////////////////////////////////////////////////////////////////////
37 // CObjectPropertiesDialog dialog
38
39 CObjectPropertiesDialog::CObjectPropertiesDialog(CWnd *pParent /*=NULL*/)
40 : CDialog(CObjectPropertiesDialog::IDD, pParent) {
41 //{{AFX_DATA_INIT(CObjectPropertiesDialog)
42 // NOTE: the ClassWizard will add member initialization here
43 //}}AFX_DATA_INIT
44 m_Parent = pParent;
45 m_Initializing = FALSE;
46 m_KeypadTabDialog = NULL;
47 m_PropPhysicsDlg = NULL;
48 m_current_tab = 0;
49 }
50
51 void CObjectPropertiesDialog::DoDataExchange(CDataExchange *pDX) {
52 CDialog::DoDataExchange(pDX);
53 //{{AFX_DATA_MAP(CObjectPropertiesDialog)
54 // NOTE: the ClassWizard will add DDX and DDV calls here
55 //}}AFX_DATA_MAP
56 }
57
58 BEGIN_MESSAGE_MAP(CObjectPropertiesDialog, CDialog)
59 //{{AFX_MSG_MAP(CObjectPropertiesDialog)
60 ON_WM_SHOWWINDOW()
61 ON_WM_SIZE()
62 ON_WM_MOVE()
63 ON_WM_CREATE()
64 //}}AFX_MSG_MAP
65 END_MESSAGE_MAP()
66
67 /////////////////////////////////////////////////////////////////////////////
68 // CObjectPropertiesDialog message handlers
69
70 BOOL CObjectPropertiesDialog::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT &rect,
71 CWnd *pParentWnd, UINT nID, CCreateContext *pContext) {
72 // TODO: Add your specialized code here and/or call the base class
73
74 return CDialog::Create(IDD, pParentWnd);
75 }
76
77 BOOL CObjectPropertiesDialog::OnInitDialog() {
78 CDialog::OnInitDialog();
79
80 CTabCtrl *tab_ctrl;
81 TC_ITEM tc_item;
82
83 m_current_tab = 0;
84
85 tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);
86
87 // Add tabs to tabcontrol in the keypad dialog bar.
88 tc_item.mask = TCIF_TEXT;
89 tc_item.pszText = "Physics";
90 tc_item.cchTextMax = lstrlen(tc_item.pszText) + 1;
91 tab_ctrl->InsertItem(TAB_PHYSICS, &tc_item);
92
93 tc_item.mask = TCIF_TEXT;
94 tc_item.pszText = "AI";
95 tc_item.cchTextMax = lstrlen(tc_item.pszText) + 1;
96 tab_ctrl->InsertItem(TAB_AI, &tc_item);
97
98 // fit keypad dialogs in tab control
99 RECT tab_rect, tab_winrect;
100 int tx, ty, tw, th;
101
102 tab_ctrl->GetWindowRect(&tab_winrect);
103 ::CopyRect(&tab_rect, &tab_winrect);
104 tab_ctrl->AdjustRect(FALSE, &tab_rect);
105 tx = tab_rect.left - tab_winrect.left;
106 ty = tab_rect.top - tab_winrect.top;
107 tw = tab_rect.right - tab_rect.left;
108 th = tab_rect.bottom - tab_rect.top;
109
110 // Create tab dialogs
111 // resize them to fit the tab control
112 // set scroll bars accordingly
113 m_PropAIDlg = new CPropertyAIDlg(tab_ctrl);
114 m_PropAIDlg->Create();
115 m_PropAIDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
116
117 m_PropPhysicsDlg = new CPropertyPhysicsDlg(tab_ctrl);
118 m_PropPhysicsDlg->Create();
119 m_PropPhysicsDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
120
121 // Display current tab dialog
122 switch (m_current_tab) {
123 case TAB_PHYSICS:
124 m_KeypadTabDialog = m_PropPhysicsDlg;
125 break;
126 case TAB_AI:
127 m_KeypadTabDialog = m_PropAIDlg;
128 break;
129 default:
130 Int3();
131 }
132
133 tab_ctrl->SetCurSel(m_current_tab);
134
135 return TRUE; // return TRUE unless you set the focus to a control
136 // EXCEPTION: OCX Property Pages should return FALSE
137 }
138
139 void CObjectPropertiesDialog::RunKeypadFunction(int code) {
140 if (m_KeypadTabDialog)
141 m_KeypadTabDialog->RunKeypadFunction(code);
142 }
143
144 void CObjectPropertiesDialog::Activate() {
145 if (m_KeypadTabDialog)
146 m_KeypadTabDialog->Activate();
147 }
148
149 void CObjectPropertiesDialog::Deactivate() {
150 if (m_KeypadTabDialog)
151 m_KeypadTabDialog->Deactivate();
152 }
153
154 void CObjectPropertiesDialog::OnShowWindow(BOOL bShow, UINT nStatus) {
155 CDialog::OnShowWindow(bShow, nStatus);
156
157 m_Initializing = FALSE;
158
159 if (bShow)
160 m_KeypadTabDialog->ShowWindow(SW_SHOW);
161 }
162
163 BOOL CObjectPropertiesDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *pResult) {
164 // TODO: Add your specialized code here and/or call the base class
165 // Perform notification requests on the keypad tab dialog bar and other
166 // custom control bars.
167 NMHDR *nmhdr;
168
169 assert(lParam != 0);
170
171 nmhdr = (NMHDR *)lParam;
172
173 switch (wParam) {
174 case IDC_PROPERTYTAB:
175 DoKeypadTabNotify(nmhdr);
176 break;
177 }
178
179 return CDialog::OnNotify(wParam, lParam, pResult);
180 }
181
182 void CObjectPropertiesDialog::OnSize(UINT nType, int cx, int cy) {
183 RECT rect;
184 CTabCtrl *tab_ctrl;
185
186 CDialog::OnSize(nType, cx, cy);
187
188 if (m_Initializing)
189 return;
190
191 SetRect(&rect, 0, 0, cx, cy);
192 ::AdjustWindowRect(&rect, GetStyle(), FALSE);
193
194 m_keypad_w = rect.right - rect.left;
195 m_keypad_h = rect.bottom - rect.top;
196
197 SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
198
199 // Resize tab to fit current modeless dialog size
200 RECT tab_rect, tab_winrect;
201 int tx, ty, tw, th;
202
203 tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);
204
205 GetClientRect(&tab_rect);
206 tab_ctrl->MoveWindow(&tab_rect);
207
208 tab_ctrl->GetWindowRect(&tab_winrect);
209 ::CopyRect(&tab_rect, &tab_winrect);
210 tab_ctrl->AdjustRect(FALSE, &tab_rect);
211 tx = tab_rect.left - tab_winrect.left;
212 ty = tab_rect.top - tab_winrect.top;
213 tw = tab_rect.right - tab_rect.left;
214 th = tab_rect.bottom - tab_rect.top;
215
216 m_PropAIDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
217 m_PropPhysicsDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
218 }
219
220 void CObjectPropertiesDialog::OnMove(int x, int y) {
221 CDialog::OnMove(x, y);
222
223 // TODO: Add your message handler code here
224 // if we haven't placed this dialog anywhere, wait till parent does it for us.
225 if (m_Initializing)
226 return;
227
228 RECT rect;
229 GetWindowRect(&rect);
230 GetParent()->ScreenToClient(&rect);
231 m_keypad_x = rect.left;
232 m_keypad_y = rect.top;
233
234 SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
235 }
236
237 int CObjectPropertiesDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) {
238 if (CDialog::OnCreate(lpCreateStruct) == -1)
239 return -1;
240
241 // TODO: Add your specialized creation code here
242 m_Initializing = TRUE;
243
244 return 0;
245 }
246
247 void CObjectPropertiesDialog::DoKeypadTabNotify(NMHDR *nmhdr) // take care of tab control notifications
248 {
249 CTabCtrl *tab_ctrl;
250
251 tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);
252
253 switch (nmhdr->code) {
254 case TCN_SELCHANGE:
255 // Tab control changed. So update the controls currently displayed.
256 m_current_tab = (int)tab_ctrl->GetCurSel();
257 assert(m_current_tab > -1);
258
259 switch (m_current_tab) {
260 case TAB_AI:
261 if (m_KeypadTabDialog)
262 m_KeypadTabDialog->ShowWindow(SW_HIDE);
263 m_KeypadTabDialog = m_PropAIDlg;
264 m_KeypadTabDialog->ShowWindow(SW_SHOW);
265 break;
266
267 case TAB_PHYSICS:
268 if (m_KeypadTabDialog)
269 m_KeypadTabDialog->ShowWindow(SW_HIDE);
270 m_KeypadTabDialog = m_PropPhysicsDlg;
271 m_KeypadTabDialog->ShowWindow(SW_SHOW);
272 break;
273 }
274 break;
275 }
276 }
277
278 void CObjectPropertiesDialog::OnOK() {
279 // TODO: Add extra validation here
280 ddio_KeyFlush();
281 m_PropPhysicsDlg->UpdateData(true);
282 CDialog::OnOK();
283 m_bBounce = m_PropPhysicsDlg->m_bBounce;
284 m_fDrag = m_PropPhysicsDlg->m_fDrag;
285 m_fFullRotThrust = m_PropPhysicsDlg->m_fFullRotThrust;
286 m_fFullThrust = m_PropPhysicsDlg->m_fFullThrust;
287 m_bGravity = m_PropPhysicsDlg->m_bGravity;
288 m_bLevelling = m_PropPhysicsDlg->m_bLevelling;
289 m_bMagnetism = m_PropPhysicsDlg->m_bMagnetism;
290 m_fMass = m_PropPhysicsDlg->m_fMass;
291 m_fMaxTurnrollrate = m_PropPhysicsDlg->m_fMaxTurnrollrate;
292 m_iNumBounces = m_PropPhysicsDlg->m_iNumBounces;
293 m_bPersistent = m_PropPhysicsDlg->m_bPersistent;
294 m_fRotDrag = m_PropPhysicsDlg->m_fRotDrag;
295 m_fRotThrustX = m_PropPhysicsDlg->m_fRotThrustX;
296 m_fRotThrustY = m_PropPhysicsDlg->m_fRotThrustY;
297 m_fRotThrustZ = m_PropPhysicsDlg->m_fRotThrustZ;
298 m_fRotVelX = m_PropPhysicsDlg->m_fRotVelX;
299 m_fRotVelY = m_PropPhysicsDlg->m_fRotVelY;
300 m_fRotVelZ = m_PropPhysicsDlg->m_fRotVelZ;
301 m_bSticks = m_PropPhysicsDlg->m_bSticks;
302 m_fThrustX = m_PropPhysicsDlg->m_fThrustX;
303 m_fThrustY = m_PropPhysicsDlg->m_fThrustY;
304 m_fThrustZ = m_PropPhysicsDlg->m_fThrustZ;
305 m_bTurnroll = m_PropPhysicsDlg->m_bTurnroll;
306 m_fTurnrollRatio = m_PropPhysicsDlg->m_fTurnrollRatio;
307 m_sTurnrollAngle = m_PropPhysicsDlg->m_sTurnrollAngle;
308 m_bUsesThrust = m_PropPhysicsDlg->m_bUsesThrust;
309 m_fVelocityX = m_PropPhysicsDlg->m_fVelocityX;
310 m_fVelocityY = m_PropPhysicsDlg->m_fVelocityY;
311 m_fVelocityZ = m_PropPhysicsDlg->m_fVelocityZ;
312 m_bWiggle = m_PropPhysicsDlg->m_bWiggle;
313 m_fWiggleAmplitude = m_PropPhysicsDlg->m_fWiggleAmplitude;
314 m_fWigglesPerSecond = m_PropPhysicsDlg->m_fWigglesPerSecond;
315 m_bWind = m_PropPhysicsDlg->m_bWind;
316 m_bUnlimitedBounce = m_PropPhysicsDlg->m_bUnlimitedBounce;
317 }
318
319 void CObjectPropertiesDialog::OnCancel() {
320 // TODO: Add extra cleanup here
321 ddio_KeyFlush();
322 CDialog::OnCancel();
323 }