]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/DlgCamera.cpp
hello world
[icculus/iodoom3.git] / neo / tools / radiant / DlgCamera.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "../../sys/win32/rc/common_resource.h"
33 #include "../comafx/DialogName.h"
34
35 #include "qe3.h"
36 #include "DlgCamera.h"
37 #include "DlgEvent.h"
38 #include "splines.h"
39 #include "CameraTargetDlg.h"
40
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #undef THIS_FILE
44 static char THIS_FILE[] = __FILE__;
45 #endif
46
47 CDlgCamera g_dlgCamera;
48
49
50 void showCameraInspector() {
51         if (g_dlgCamera.GetSafeHwnd() == NULL) {
52                 g_dlgCamera.Create(IDD_DLG_CAMERA);
53                 CRect rct;
54                 LONG lSize = sizeof(rct);
55                 if (LoadRegistryInfo("Radiant::CameraInspector", &rct, &lSize)) {
56                         g_dlgCamera.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
57                 }
58                 Sys_UpdateWindows(W_ALL);
59         } 
60         g_dlgCamera.ShowWindow(SW_SHOW);
61         g_dlgCamera.setupFromCamera();
62 }
63 /////////////////////////////////////////////////////////////////////////////
64 // CDlgCamera dialog
65
66
67 CDlgCamera::CDlgCamera(CWnd* pParent /*=NULL*/)
68         : CDialog(CDlgCamera::IDD, pParent)
69 {
70         //{{AFX_DATA_INIT(CDlgCamera)
71         m_strName = _T("");
72         m_fSeconds = 0.0f;
73         m_trackCamera = TRUE;
74         m_numSegments = 0;
75         m_currentSegment = 0;
76         m_strType = _T("");
77         m_editPoints = 0;
78         //}}AFX_DATA_INIT
79 }
80
81
82 void CDlgCamera::DoDataExchange(CDataExchange* pDX)
83 {
84         CDialog::DoDataExchange(pDX);
85         //{{AFX_DATA_MAP(CDlgCamera)
86         DDX_Control(pDX, IDC_SCROLLBAR_SEGMENT, m_wndSegments);
87         DDX_Control(pDX, IDC_LIST_EVENTS, m_wndEvents);
88         DDX_Control(pDX, IDC_COMBO_SPLINES, m_wndSplines);
89         DDX_Text(pDX, IDC_EDIT_CAM_NAME, m_strName);
90         DDX_Text(pDX, IDC_EDIT_LENGTH, m_fSeconds);
91         DDX_Check(pDX, IDC_CHECK_TRACKCAMERA, m_trackCamera);
92         DDX_Text(pDX, IDC_EDIT_TOTALSEGMENTS, m_numSegments);
93         DDX_Text(pDX, IDC_EDIT_SEGMENT, m_currentSegment);
94         DDX_Text(pDX, IDC_EDIT_TYPE, m_strType);
95         DDX_Radio(pDX, IDC_RADIO_EDITPOINTS, m_editPoints);
96         //}}AFX_DATA_MAP
97 }
98
99
100 BEGIN_MESSAGE_MAP(CDlgCamera, CDialog)
101         //{{AFX_MSG_MAP(CDlgCamera)
102         ON_BN_CLICKED(IDC_BTN_ADDEVENT, OnBtnAddevent)
103         ON_BN_CLICKED(IDC_BTN_ADDTARGET, OnBtnAddtarget)
104         ON_BN_CLICKED(IDC_BTN_DELEVENT, OnBtnDelevent)
105         ON_CBN_DBLCLK(IDC_COMBO_SPLINES, OnDblclkComboSplines)
106         ON_CBN_SELCHANGE(IDC_COMBO_SPLINES, OnSelchangeComboSplines)
107         ON_LBN_SELCHANGE(IDC_LIST_EVENTS, OnSelchangeListEvents)
108         ON_LBN_DBLCLK(IDC_LIST_EVENTS, OnDblclkListEvents)
109         ON_WM_DESTROY()
110         ON_BN_CLICKED(IDC_APPLY, OnApply)
111         ON_WM_HSCROLL()
112         ON_BN_CLICKED(ID_FILE_NEW, OnFileNew)
113         ON_BN_CLICKED(ID_FILE_OPEN, OnFileOpen)
114         ON_BN_CLICKED(ID_FILE_SAVE, OnFileSave)
115         ON_BN_CLICKED(IDC_TESTCAMERA, OnTestcamera)
116         ON_BN_CLICKED(IDC_BTN_DELETEPOINTS, OnBtnDeletepoints)
117         ON_BN_CLICKED(IDC_BTN_SELECTALL, OnBtnSelectall)
118         ON_BN_CLICKED(IDC_RADIO_EDITPOINTS, OnRadioEditpoints)
119         ON_BN_CLICKED(IDC_RADIO_EDITPOINTS2, OnRadioAddPoints)
120         //}}AFX_MSG_MAP
121 END_MESSAGE_MAP()
122
123 /////////////////////////////////////////////////////////////////////////////
124 // CDlgCamera message handlers
125
126 void CDlgCamera::OnBtnAddevent() 
127 {
128         CDlgEvent dlg;
129         if (dlg.DoModal() == IDOK) {
130                 long n = m_wndSegments.GetScrollPos() / 4 * 1000;
131                 g_splineList->addEvent(static_cast<idCameraEvent::eventType>(dlg.m_event+1), dlg.m_strParm, n);
132                 setupFromCamera();
133         }
134 }
135
136 void CDlgCamera::OnBtnAddtarget() 
137 {
138         CCameraTargetDlg dlg;
139         if (dlg.DoModal() == IDOK) {
140                 g_splineList->addTarget(dlg.m_strName, static_cast<idCameraPosition::positionType>(dlg.m_nType));
141                 setupFromCamera();
142                 m_wndSplines.SetCurSel(g_splineList->numTargets());
143                 OnSelchangeComboSplines();
144         }
145 }
146
147 void CDlgCamera::OnBtnDelevent() 
148 {
149         // TODO: Add your control notification handler code here
150         
151 }
152
153 void CDlgCamera::OnBtnDeltarget() 
154 {
155         // TODO: Add your control notification handler code here
156         
157 }
158
159 void CDlgCamera::OnDblclkComboSplines() 
160 {
161         // TODO: Add your control notification handler code here
162         
163 }
164
165 void CDlgCamera::OnSelchangeComboSplines() 
166 {
167         UpdateData(TRUE);
168         g_qeglobals.d_select_mode = (m_editPoints == 0) ? sel_editpoint : sel_addpoint;
169         g_qeglobals.d_numpoints = 0;
170         g_qeglobals.d_num_move_points = 0;
171         int i = m_wndSplines.GetCurSel();
172         if (i > 0) {
173                 g_splineList->setActiveTarget(i-1);
174                 g_qeglobals.selectObject = g_splineList->getActiveTarget(i-1);
175                 g_splineList->startEdit(false);
176         } else {
177                 g_splineList->startEdit(true);
178                 g_qeglobals.selectObject = g_splineList->getPositionObj();
179         }
180
181         // * 4.0 to set increments in quarter seconds
182         m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
183
184         Sys_UpdateWindows(W_ALL);
185 }
186
187 void CDlgCamera::OnSelchangeListEvents() 
188 {
189         int sel = m_wndEvents.GetCurSel();
190         //g_splineList->setActiveSegment(sel >= 0 ? sel : 0);
191 }
192
193 void CDlgCamera::OnDblclkListEvents() 
194 {
195         // TODO: Add your control notification handler code here
196         
197 }
198
199 void CDlgCamera::setupFromCamera()
200 {
201         if (m_wndSplines.GetSafeHwnd()) {
202                 int i;
203                 idStr str;
204                 m_strName = g_splineList->getName();
205                 m_strType = g_splineList->getPositionObj()->typeStr();
206                 m_wndSplines.ResetContent();
207                 m_wndSplines.AddString("Path");
208                 for (i = 0; i < g_splineList->numTargets(); i++) {
209                         m_wndSplines.AddString(g_splineList->getActiveTarget(i)->getName());
210                 }
211                 m_wndSplines.SetCurSel(0);
212                 m_fSeconds = g_splineList->getTotalTime();
213                 m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
214
215                 m_wndEvents.ResetContent();
216                 for (i = 0; i < g_splineList->numEvents(); i++) {
217                         str = va("%s\t%s", g_splineList->getEvent(i)->typeStr(), g_splineList->getEvent(i)->getParam());
218                         m_wndEvents.AddString(str);
219                 }
220                 //m_currentSegment = g_splineList->getActiveSegment();
221                 //m_numSegments = g_splineList->numSegments();
222         }
223         g_splineList->startEdit(true);
224         UpdateData(FALSE);
225 }
226
227 BOOL CDlgCamera::OnInitDialog() 
228 {
229         CDialog::OnInitDialog();
230         setupFromCamera();
231         return TRUE;  // return TRUE unless you set the focus to a control
232                       // EXCEPTION: OCX Property Pages should return FALSE
233 }
234
235 void CDlgCamera::OnOK() 
236 {
237         g_dlgCamera.ShowWindow(SW_HIDE);
238         g_qeglobals.d_select_mode = sel_brush;
239         g_splineList->stopEdit();
240         Sys_UpdateWindows(W_ALL);
241 }
242
243 void CDlgCamera::OnDestroy() 
244 {
245         if (GetSafeHwnd()) {
246                 CRect rct;
247                 GetWindowRect(rct);
248                 SaveRegistryInfo("Radiant::CameraInspector", &rct, sizeof(rct));
249         }
250         CDialog::OnDestroy();
251         Sys_UpdateWindows(W_ALL);
252 }
253
254
255 void CDlgCamera::OnApply() 
256 {
257         UpdateData(TRUE);
258         g_splineList->setBaseTime(m_fSeconds);
259         g_splineList->setName(m_strName);
260         g_splineList->buildCamera();
261         m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
262 }
263
264 void CDlgCamera::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
265 {
266         CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
267         int max = g_splineList->getTotalTime() * 4;
268         if (max == 0) {
269                 max = 1;
270         }
271         int n = pScrollBar->GetScrollPos();
272         switch (nSBCode) {
273                 case SB_LINEUP : {
274                         n--;
275                 }
276                 break;
277                 case SB_LINEDOWN : {
278                         n++;
279                 }
280                 break;
281                 case SB_PAGEUP : {
282                         n -= (float)max * 0.10;
283                 }
284                 break;
285                 case SB_PAGEDOWN : {
286                         n += (float)max * 0.10;
287                 }
288                 break;
289                 case SB_THUMBPOSITION : {
290                         n = nPos;
291                 }
292                 break;
293                 case SB_THUMBTRACK : {
294                         n = nPos;
295                 }
296         }
297 //      if (n < 0) {
298 //              n = 0;
299 //      } else if (n >= g_splineList->numSegments()) {
300 //              if (g_splineList->numSegments() == 0) {
301 //                      g_splineList->buildCamera();
302 //              }
303 //              n = g_splineList->numSegments() - 1;
304 //      }
305         pScrollBar->SetScrollPos(n);
306         if (m_trackCamera) {
307                 float p = (float)n / max;
308                 p *= g_splineList->getTotalTime() * 1000;
309                 g_splineList->startCamera(0);
310                 g_splineList->buildCamera();
311                 idVec3 dir;
312                 float fov;
313                 g_splineList->getCameraInfo(p, g_pParentWnd->GetCamera()->Camera().origin, dir, &fov);
314                 g_pParentWnd->GetCamera()->Camera().angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
315                 g_pParentWnd->GetCamera()->Camera().angles[0] = asin (dir[2])*180/3.14159;
316
317         }
318         UpdateData(FALSE);
319         Sys_UpdateWindows(W_XY | W_CAMERA);
320 }
321
322 void CDlgCamera::OnFileNew() 
323 {
324         g_splineList->clear();
325         setupFromCamera();
326 }
327
328 void CDlgCamera::OnFileOpen() 
329 {
330         DialogName dlg("Open Camera File");
331         if (dlg.DoModal() == IDOK) {
332                 g_splineList->clear();
333                 g_splineList->load(va("cameras/%s.camera", dlg.m_strName));
334         }
335 }
336
337 void CDlgCamera::OnFileSave() 
338 {
339         DialogName dlg("Save Camera File");
340         if (dlg.DoModal() == IDOK) {
341                 g_splineList->save(va("cameras/%s.camera", dlg.m_strName));
342         }
343 }
344
345 void CDlgCamera::OnTestcamera() 
346 {
347         // TODO: Add your control notification handler code here
348         
349 }
350
351 void CDlgCamera::OnBtnDeletepoints() 
352 {
353         // TODO: Add your control notification handler code here
354         
355 }
356
357 void CDlgCamera::OnBtnSelectall() 
358 {
359         // TODO: Add your control notification handler code here
360         
361 }
362
363 void CDlgCamera::OnRadioEditpoints() 
364 {
365         UpdateData(TRUE);
366         g_qeglobals.d_select_mode = sel_editpoint;
367 }
368
369 void CDlgCamera::OnRadioAddPoints() 
370 {
371         UpdateData(TRUE);
372         g_qeglobals.d_select_mode = sel_addpoint;
373 }