Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / animation_dlg.cpp
blob30b8012565cddd6d1bff895ef93e40cd477f6c8b
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std_afx.h"
18 #include "object_viewer.h"
19 #include "animation_dlg.h"
20 #include <math.h>
21 #include <nel/misc/time_nl.h>
23 using namespace NLMISC;
24 using namespace NL3D;
26 #define SPEED_FOREWARD 3
28 /////////////////////////////////////////////////////////////////////////////
29 // CAnimationDlg dialog
32 CAnimationDlg::CAnimationDlg(class CObjectViewer* main, CWnd* pParent /*=NULL*/)
33 : CDialog(CAnimationDlg::IDD, pParent)
35 //{{AFX_DATA_INIT(CAnimationDlg)
36 End = 0.0f;
37 Speed = 30.0f;
38 Start = 0.0f;
39 Loop = TRUE;
40 UICurrentFrame = 0;
41 CurrentFrame = 0.0f;
42 Inplace = FALSE;
43 IncPos = TRUE;
44 //}}AFX_DATA_INIT
45 LastFrame = 0;
46 Playing=false;
47 Main=main;
50 void CAnimationDlg::DoDataExchange(CDataExchange* pDX)
52 CDialog::DoDataExchange(pDX);
53 //{{AFX_DATA_MAP(CAnimationDlg)
54 DDX_Control(pDX, IDC_FRW, FRWCtrl);
55 DDX_Control(pDX, IDC_FFW, FFWCtrl);
56 DDX_Control(pDX, IDC_TIME_LINE, TimeLineCtrl);
57 DDX_Control(pDX, IDC_PLAY, PlayCtrl);
58 DDX_Control(pDX, IDC_STOP, StopCtrl);
59 DDX_Text(pDX, IDC_END_EDIT, End);
60 DDX_Text(pDX, IDC_SPEED, Speed);
61 DDX_Text(pDX, IDC_START_EDIT, Start);
62 DDX_Check(pDX, IDC_LOOP, Loop);
63 DDX_Text(pDX, IDC_CURRENT_FRAME, UICurrentFrame);
64 DDX_Check(pDX, IDC_INPLACE, Inplace);
65 DDX_Check(pDX, IDC_INC_POS, IncPos);
66 //}}AFX_DATA_MAP
70 BEGIN_MESSAGE_MAP(CAnimationDlg, CDialog)
71 //{{AFX_MSG_MAP(CAnimationDlg)
72 ON_BN_CLICKED(IDC_END, OnEnd)
73 ON_BN_CLICKED(IDC_PLAY, OnPlay)
74 ON_BN_CLICKED(IDC_STOP, OnStop)
75 ON_EN_CHANGE(IDC_CURRENT_FRAME, OnChangeCurrentFrame)
76 ON_EN_CHANGE(IDC_END_EDIT, OnChangeEndEdit)
77 ON_EN_CHANGE(IDC_SPEED, OnChangeSpeed)
78 ON_BN_CLICKED(IDC_START, OnStart)
79 ON_EN_CHANGE(IDC_START_EDIT, OnChangeStartEdit)
80 ON_WM_HSCROLL()
81 ON_WM_DESTROY()
82 //}}AFX_MSG_MAP
83 END_MESSAGE_MAP()
85 /////////////////////////////////////////////////////////////////////////////
86 // CAnimationDlg message handlers
88 void CAnimationDlg::OnEnd()
90 UpdateData ();
91 CurrentFrame=End;
92 LastFrame=End;
93 UICurrentFrame=(int)CurrentFrame;
94 UpdateData (FALSE);
95 updateBar ();
98 void CAnimationDlg::OnPlay()
100 // play
101 UpdateData ();
102 StopCtrl.SetCheck (0);
103 PlayCtrl.SetCheck (1);
104 PlayCtrl.EnableWindow (FALSE);
105 StopCtrl.EnableWindow (TRUE);
107 if (!Playing)
109 Playing=true;
111 Main->enableFXs(true);
114 void CAnimationDlg::OnStop()
116 // Is checked ?
117 UpdateData ();
118 Playing=false;
119 StopCtrl.SetCheck (1);
120 PlayCtrl.SetCheck (0);
121 PlayCtrl.EnableWindow (TRUE);
122 StopCtrl.EnableWindow (FALSE);
123 UpdateData (FALSE);
124 Main->enableFXs(false);
127 void CAnimationDlg::OnChangeCurrentFrame()
129 // TODO: If this is a RICHEDIT control, the control will not
130 // send this notification unless you override the CDialog::OnInitDialog()
131 // function and call CRichEditCtrl().SetEventMask()
132 // with the ENM_CHANGE flag ORed into the mask.
134 // Update values
135 UpdateData ();
137 // Clamp current frame
138 clamp (UICurrentFrame, (int)Start, (int)End);
139 CurrentFrame=(float)UICurrentFrame;
140 LastFrame=CurrentFrame;
142 // Update
143 updateBar ();
144 UpdateData (FALSE);
147 void CAnimationDlg::OnChangeEndEdit()
149 // TODO: If this is a RICHEDIT control, the control will not
150 // send this notification unless you override the CDialog::OnInitDialog()
151 // function and call CRichEditCtrl().SetEventMask()
152 // with the ENM_CHANGE flag ORed into the mask.
154 // TODO: Add your control notification handler code here
156 // Update values
157 UpdateData ();
159 // Clamp current frame
160 if (End<Start)
161 Start=End;
162 if (End<CurrentFrame)
164 CurrentFrame=End;
165 LastFrame=End;
167 UICurrentFrame=(int)CurrentFrame;
169 // Update
170 UpdateData (FALSE);
171 Main->setAnimTime (Start, End);
174 void CAnimationDlg::OnChangeSpeed()
176 // TODO: If this is a RICHEDIT control, the control will not
177 // send this notification unless you override the CDialog::OnInitDialog()
178 // function and call CRichEditCtrl().SetEventMask()
179 // with the ENM_CHANGE flag ORed into the mask.
181 UpdateData();
182 if (Speed<=0.001f)
183 Speed=0.001f;
184 Start=Speed*Start;
185 End=Speed*End;
186 UpdateData(FALSE);
187 Main->setAnimTime (Start, End);
190 void CAnimationDlg::OnStart()
192 UpdateData ();
193 CurrentFrame=Start;
194 LastFrame=Start;
195 UICurrentFrame=(int)CurrentFrame;
196 UpdateData (FALSE);
197 updateBar ();
200 void CAnimationDlg::OnChangeStartEdit()
202 // TODO: If this is a RICHEDIT control, the control will not
203 // send this notification unless you override the CDialog::OnInitDialog()
204 // function and call CRichEditCtrl().SetEventMask()
205 // with the ENM_CHANGE flag ORed into the mask.
207 // Update values
208 UpdateData ();
210 // Clamp current frame
211 if (End<Start)
212 End=Start;
213 if (CurrentFrame<Start)
215 CurrentFrame=Start;
216 LastFrame=Start;
218 UICurrentFrame=(int)CurrentFrame;
220 // Update
221 UpdateData (FALSE);
222 Main->setAnimTime (Start, End);
225 void CAnimationDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
227 // TODO: Add your message handler code here and/or call default
229 // Drag the time line ?
230 if (pScrollBar==GetDlgItem (IDC_TIME_LINE))
232 // Update values
233 UpdateData ();
235 // Setup current pos
236 CurrentFrame=(float)TimeLineCtrl.GetPos()*(End-Start)/65535.f+Start;
237 CurrentFrame=(float)floor(CurrentFrame+0.5f);
238 LastFrame=CurrentFrame;
239 UICurrentFrame=(int)CurrentFrame;
241 // Update values
242 UpdateData (FALSE);
245 CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
248 void CAnimationDlg::handle ()
250 // New time
251 uint64 newTime=NLMISC::CTime::getLocalTime ();
253 // Forward or rewind ?
254 bool forward=(((CButton*)GetDlgItem (IDC_FFW))->GetState()&BST_PUSHED)!=0;
255 bool rewind=(((CButton*)GetDlgItem (IDC_FRW))->GetState()&BST_PUSHED)!=0;
257 // If play, back last frame
258 if (Playing)
259 LastFrame=CurrentFrame;
261 if (forward||rewind||Playing)
263 UpdateData ();
265 // Delta time
266 uint deltaTime=(uint)(newTime-LastTime);
268 if (forward)
270 // Fast forward
271 CurrentFrame+=(float)((float)deltaTime*SPEED_FOREWARD*Speed/1000.0);
273 else if (rewind)
275 // Fast rewind
276 CurrentFrame-=(float)((float)deltaTime*SPEED_FOREWARD*Speed/1000.0);
278 else
280 // Compute new time
281 if (Playing)
283 CurrentFrame+=(float)((float)deltaTime*Speed/1000.0);
287 // Loop
288 if (Loop&&(!forward)&&(!rewind)&&Playing)
290 float backup = CurrentFrame;
291 CurrentFrame=(float)fmod ((CurrentFrame-Start), End-Start)+Start;
292 if (backup!=CurrentFrame)
294 LastFrame = CurrentFrame;
295 Main->enableFXs(false);
296 Main->enableFXs(true);
300 // Clamp time
301 if (CurrentFrame>End)
303 CurrentFrame=End;
304 LastFrame=CurrentFrame;
305 UpdateData (FALSE);
307 // Stop animation
308 OnStop ();
311 if (CurrentFrame<Start)
313 CurrentFrame=Start;
314 LastFrame=CurrentFrame;
315 UpdateData (FALSE);
317 // Stop animation
318 OnStop ();
321 UICurrentFrame=(int)CurrentFrame;
322 UpdateData (FALSE);
323 updateBar ();
326 // If not play, copy current frame
327 if (!Playing)
328 LastFrame=CurrentFrame;
330 // Setup new time
331 LastTime=newTime;
334 BOOL CAnimationDlg::OnInitDialog()
336 CDialog::OnInitDialog();
338 // Stop
339 LastTime=NLMISC::CTime::getLocalTime ();
340 StopCtrl.SetCheck (1);
342 // Set time line range
343 TimeLineCtrl.SetRangeMin (0);
344 TimeLineCtrl.SetRangeMax (65535);
346 // Update the time line
347 updateBar ();
349 return TRUE; // return TRUE unless you set the focus to a control
350 // EXCEPTION: OCX Property Pages should return FALSE
353 void CAnimationDlg::setAnimTime (float animStart, float animEnd)
355 UpdateData();
356 Start=animStart;
357 End=animEnd;
358 UpdateData(FALSE);
359 updateBar ();
362 void CAnimationDlg::updateBar ()
364 // Update value
365 UpdateData();
367 // Set cursor position
368 int position;
369 if (fabs (End-Start)<0.00001f)
370 position=0;
371 else
372 position=(int)((CurrentFrame-Start)*65535.f/(End-Start));
373 clamp (position, 0, 65535);
374 TimeLineCtrl.SetPos(position);
376 // Update value
377 UpdateData (FALSE);
380 NL3D::TAnimationTime CAnimationDlg::getTime ()
382 // Return current time in second
383 return CurrentFrame/Speed;
386 NL3D::TAnimationTime CAnimationDlg::getLastTime ()
388 // Return current time in second
389 return LastFrame/Speed;
392 void CAnimationDlg::OnDestroy()
394 setRegisterWindowState (this, REGKEY_OBJ_VIEW_ANIMATION_DLG);
396 CDialog::OnDestroy();
399 void CAnimationDlg::setCurrentFrame (float currentFrame)
401 // Update values
402 UpdateData ();
404 // Setup current pos
405 CurrentFrame=currentFrame;
406 LastFrame=CurrentFrame;
407 UICurrentFrame=(int)CurrentFrame;
409 // Update values
410 UpdateData (FALSE);
411 updateBar ();
414 BOOL CAnimationDlg::EnableWindow(BOOL enable /*=TRUE*/)
416 PlayCtrl.EnableWindow(Playing && enable);
417 StopCtrl.EnableWindow(FALSE);
418 FRWCtrl.EnableWindow(enable);
419 FFWCtrl.EnableWindow(enable);
420 TimeLineCtrl.EnableWindow(enable);
421 PlayCtrl.EnableWindow(enable);
422 StopCtrl.EnableWindow(enable);
423 GetDlgItem(IDC_END)->EnableWindow(enable);
424 GetDlgItem(IDC_START)->EnableWindow(enable);
425 GetDlgItem(IDC_LOOP)->EnableWindow(enable);
426 GetDlgItem(IDC_START_EDIT)->EnableWindow(enable);
427 GetDlgItem(IDC_CURRENT_FRAME)->EnableWindow(enable);
428 GetDlgItem(IDC_SPEED)->EnableWindow(enable);
429 GetDlgItem(IDC_END_EDIT)->EnableWindow(enable);
430 return TRUE;