2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/common_resource.h"
33 #include "../comafx/DialogName.h"
36 #include "DlgCamera.h"
39 #include "CameraTargetDlg.h"
44 static char THIS_FILE[] = __FILE__;
47 CDlgCamera g_dlgCamera;
50 void showCameraInspector() {
51 if (g_dlgCamera.GetSafeHwnd() == NULL) {
52 g_dlgCamera.Create(IDD_DLG_CAMERA);
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);
58 Sys_UpdateWindows(W_ALL);
60 g_dlgCamera.ShowWindow(SW_SHOW);
61 g_dlgCamera.setupFromCamera();
63 /////////////////////////////////////////////////////////////////////////////
67 CDlgCamera::CDlgCamera(CWnd* pParent /*=NULL*/)
68 : CDialog(CDlgCamera::IDD, pParent)
70 //{{AFX_DATA_INIT(CDlgCamera)
82 void CDlgCamera::DoDataExchange(CDataExchange* pDX)
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);
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)
110 ON_BN_CLICKED(IDC_APPLY, OnApply)
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)
123 /////////////////////////////////////////////////////////////////////////////
124 // CDlgCamera message handlers
126 void CDlgCamera::OnBtnAddevent()
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);
136 void CDlgCamera::OnBtnAddtarget()
138 CCameraTargetDlg dlg;
139 if (dlg.DoModal() == IDOK) {
140 g_splineList->addTarget(dlg.m_strName, static_cast<idCameraPosition::positionType>(dlg.m_nType));
142 m_wndSplines.SetCurSel(g_splineList->numTargets());
143 OnSelchangeComboSplines();
147 void CDlgCamera::OnBtnDelevent()
149 // TODO: Add your control notification handler code here
153 void CDlgCamera::OnBtnDeltarget()
155 // TODO: Add your control notification handler code here
159 void CDlgCamera::OnDblclkComboSplines()
161 // TODO: Add your control notification handler code here
165 void CDlgCamera::OnSelchangeComboSplines()
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();
173 g_splineList->setActiveTarget(i-1);
174 g_qeglobals.selectObject = g_splineList->getActiveTarget(i-1);
175 g_splineList->startEdit(false);
177 g_splineList->startEdit(true);
178 g_qeglobals.selectObject = g_splineList->getPositionObj();
181 // * 4.0 to set increments in quarter seconds
182 m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
184 Sys_UpdateWindows(W_ALL);
187 void CDlgCamera::OnSelchangeListEvents()
189 int sel = m_wndEvents.GetCurSel();
190 //g_splineList->setActiveSegment(sel >= 0 ? sel : 0);
193 void CDlgCamera::OnDblclkListEvents()
195 // TODO: Add your control notification handler code here
199 void CDlgCamera::setupFromCamera()
201 if (m_wndSplines.GetSafeHwnd()) {
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());
211 m_wndSplines.SetCurSel(0);
212 m_fSeconds = g_splineList->getTotalTime();
213 m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
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);
220 //m_currentSegment = g_splineList->getActiveSegment();
221 //m_numSegments = g_splineList->numSegments();
223 g_splineList->startEdit(true);
227 BOOL CDlgCamera::OnInitDialog()
229 CDialog::OnInitDialog();
231 return TRUE; // return TRUE unless you set the focus to a control
232 // EXCEPTION: OCX Property Pages should return FALSE
235 void CDlgCamera::OnOK()
237 g_dlgCamera.ShowWindow(SW_HIDE);
238 g_qeglobals.d_select_mode = sel_brush;
239 g_splineList->stopEdit();
240 Sys_UpdateWindows(W_ALL);
243 void CDlgCamera::OnDestroy()
248 SaveRegistryInfo("Radiant::CameraInspector", &rct, sizeof(rct));
250 CDialog::OnDestroy();
251 Sys_UpdateWindows(W_ALL);
255 void CDlgCamera::OnApply()
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);
264 void CDlgCamera::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
266 CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
267 int max = g_splineList->getTotalTime() * 4;
271 int n = pScrollBar->GetScrollPos();
282 n -= (float)max * 0.10;
286 n += (float)max * 0.10;
289 case SB_THUMBPOSITION : {
293 case SB_THUMBTRACK : {
299 // } else if (n >= g_splineList->numSegments()) {
300 // if (g_splineList->numSegments() == 0) {
301 // g_splineList->buildCamera();
303 // n = g_splineList->numSegments() - 1;
305 pScrollBar->SetScrollPos(n);
307 float p = (float)n / max;
308 p *= g_splineList->getTotalTime() * 1000;
309 g_splineList->startCamera(0);
310 g_splineList->buildCamera();
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;
319 Sys_UpdateWindows(W_XY | W_CAMERA);
322 void CDlgCamera::OnFileNew()
324 g_splineList->clear();
328 void CDlgCamera::OnFileOpen()
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));
337 void CDlgCamera::OnFileSave()
339 DialogName dlg("Save Camera File");
340 if (dlg.DoModal() == IDOK) {
341 g_splineList->save(va("cameras/%s.camera", dlg.m_strName));
345 void CDlgCamera::OnTestcamera()
347 // TODO: Add your control notification handler code here
351 void CDlgCamera::OnBtnDeletepoints()
353 // TODO: Add your control notification handler code here
357 void CDlgCamera::OnBtnSelectall()
359 // TODO: Add your control notification handler code here
363 void CDlgCamera::OnRadioEditpoints()
366 g_qeglobals.d_select_mode = sel_editpoint;
369 void CDlgCamera::OnRadioAddPoints()
372 g_qeglobals.d_select_mode = sel_addpoint;