1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
18 #include "object_viewer.h"
19 #include "animation_dlg.h"
21 #include <nel/misc/time_nl.h>
23 using namespace NLMISC
;
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)
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
);
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
)
85 /////////////////////////////////////////////////////////////////////////////
86 // CAnimationDlg message handlers
88 void CAnimationDlg::OnEnd()
93 UICurrentFrame
=(int)CurrentFrame
;
98 void CAnimationDlg::OnPlay()
102 StopCtrl
.SetCheck (0);
103 PlayCtrl
.SetCheck (1);
104 PlayCtrl
.EnableWindow (FALSE
);
105 StopCtrl
.EnableWindow (TRUE
);
111 Main
->enableFXs(true);
114 void CAnimationDlg::OnStop()
119 StopCtrl
.SetCheck (1);
120 PlayCtrl
.SetCheck (0);
121 PlayCtrl
.EnableWindow (TRUE
);
122 StopCtrl
.EnableWindow (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.
137 // Clamp current frame
138 clamp (UICurrentFrame
, (int)Start
, (int)End
);
139 CurrentFrame
=(float)UICurrentFrame
;
140 LastFrame
=CurrentFrame
;
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
159 // Clamp current frame
162 if (End
<CurrentFrame
)
167 UICurrentFrame
=(int)CurrentFrame
;
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.
187 Main
->setAnimTime (Start
, End
);
190 void CAnimationDlg::OnStart()
195 UICurrentFrame
=(int)CurrentFrame
;
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.
210 // Clamp current frame
213 if (CurrentFrame
<Start
)
218 UICurrentFrame
=(int)CurrentFrame
;
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
))
236 CurrentFrame
=(float)TimeLineCtrl
.GetPos()*(End
-Start
)/65535.f
+Start
;
237 CurrentFrame
=(float)floor(CurrentFrame
+0.5f
);
238 LastFrame
=CurrentFrame
;
239 UICurrentFrame
=(int)CurrentFrame
;
245 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
248 void CAnimationDlg::handle ()
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
259 LastFrame
=CurrentFrame
;
261 if (forward
||rewind
||Playing
)
266 uint deltaTime
=(uint
)(newTime
-LastTime
);
271 CurrentFrame
+=(float)((float)deltaTime
*SPEED_FOREWARD
*Speed
/1000.0);
276 CurrentFrame
-=(float)((float)deltaTime
*SPEED_FOREWARD
*Speed
/1000.0);
283 CurrentFrame
+=(float)((float)deltaTime
*Speed
/1000.0);
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);
301 if (CurrentFrame
>End
)
304 LastFrame
=CurrentFrame
;
311 if (CurrentFrame
<Start
)
314 LastFrame
=CurrentFrame
;
321 UICurrentFrame
=(int)CurrentFrame
;
326 // If not play, copy current frame
328 LastFrame
=CurrentFrame
;
334 BOOL
CAnimationDlg::OnInitDialog()
336 CDialog::OnInitDialog();
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
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
)
362 void CAnimationDlg::updateBar ()
367 // Set cursor position
369 if (fabs (End
-Start
)<0.00001f
)
372 position
=(int)((CurrentFrame
-Start
)*65535.f
/(End
-Start
));
373 clamp (position
, 0, 65535);
374 TimeLineCtrl
.SetPos(position
);
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
)
405 CurrentFrame
=currentFrame
;
406 LastFrame
=CurrentFrame
;
407 UICurrentFrame
=(int)CurrentFrame
;
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
);