1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "object_viewer.h"
22 #include "sound_anim_dlg.h"
23 #include "pick_sound.h"
24 #include "sound_system.h"
26 #include "nel/sound/u_audio_mixer.h"
27 #include "nel/sound/sound_anim_marker.h"
30 using namespace NLMISC
;
31 using namespace NLSOUND
;
35 // ********************************************************
37 CSoundAnimDlg::CSoundAnimDlg(CObjectViewer
* objView
, CAnimationDlg
* animDlg
, CWnd
* pParent
/*=NULL*/)
38 : CDialog(CSoundAnimDlg::IDD
, pParent
)
40 //{{AFX_DATA_INIT(CSoundAnimDlg)
41 // NOTE: the ClassWizard will add member initialization here
45 _AnimationDlg
= animDlg
;
49 // ********************************************************
51 int CSoundAnimDlg::OnCreate(LPCREATESTRUCT lpCreateStruct
)
53 if (CDialog::OnCreate(lpCreateStruct
) == -1)
64 _AnimView
.Create(_ObjView
, _AnimationDlg
, this, r
);
69 // ********************************************************
71 BOOL
CSoundAnimDlg::OnInitDialog()
73 CDialog::OnInitDialog();
78 // ********************************************************
80 void CSoundAnimDlg::handle()
82 float sec
= _AnimationDlg
->getTime();
83 std::string text
= toString("time: %.3f", sec
);
84 GetDlgItem(IDC_SOUNDANIMINFO
)->SetWindowText(nlUtf8ToTStr(text
));
86 _AnimView
.updateCursor();
89 // ********************************************************
91 void CSoundAnimDlg::setAnimTime(float animStart
, float animEnd
)
93 nlwarning("START=%.3f - END=%.3f", animStart
, animEnd
);
94 _AnimView
.setAnimTime(animStart
, animEnd
);
97 // ********************************************************
99 void CSoundAnimDlg::updateScroll(uint pos
, uint min
, uint max
)
101 CScrollBar
* scroll
= (CScrollBar
*) GetDlgItem(IDC_SOUND_ANIM_SCROLLBAR
);
103 scroll
->SetScrollRange(min
, max
, FALSE
);
104 scroll
->SetScrollPos(pos
, TRUE
);
107 // ********************************************************
109 void CSoundAnimDlg::DoDataExchange(CDataExchange
* pDX
)
111 CDialog::DoDataExchange(pDX
);
112 //{{AFX_DATA_MAP(CSoundAnimDlg)
113 // NOTE: the ClassWizard will add DDX and DDV calls here
117 // ********************************************************
119 void CSoundAnimDlg::selectMarker(CSoundAnimMarker
* marker
)
121 _SelectedMarker
= marker
;
125 // ********************************************************
127 void CSoundAnimDlg::updateSounds()
129 if (_SelectedMarker
!= 0)
131 vector
<NLMISC::TStringId
> sounds
;
133 _SelectedMarker
->getSounds(sounds
);
135 CListBox
* list
= (CListBox
*) GetDlgItem(IDC_SOUND_ANIM_LIST
);
136 list
->ResetContent();
138 vector
<NLMISC::TStringId
>::iterator iter
;
140 for (iter
= sounds
.begin(); iter
!= sounds
.end(); iter
++)
142 list
->AddString(nlUtf8ToTStr(CStringMapper::unmap(*iter
).c_str()));
149 // ********************************************************
151 void CSoundAnimDlg::OnAddSound()
153 if (_SelectedMarker
!= 0)
155 // CPickSound::TNameVect names;
156 vector
<NLMISC::TStringId
> names
;
159 NLSOUND::UAudioMixer
*audioMixer
= CSoundSystem::getAudioMixer();
162 audioMixer
->getSoundNames(names
);
165 CPickSound
ps(names
, this);
167 if (ps
.DoModal() == IDOK
)
169 // string name = ps.getName();
170 _SelectedMarker
->addSound(ps
.getName());
176 // ********************************************************
178 void CSoundAnimDlg::OnRemoveSound()
180 if (_SelectedMarker
!= 0)
183 CListBox
* list
= (CListBox
*) GetDlgItem(IDC_SOUND_ANIM_LIST
);
185 if (list
->GetText(list
->GetCurSel(), s
) != LB_ERR
)
187 _SelectedMarker
->removeSound(CStringMapper::map(tStrToUtf8(s
)));
193 // ********************************************************
195 void CSoundAnimDlg::OnSave()
200 // ********************************************************
202 void CSoundAnimDlg::OnZoomOut()
207 // ********************************************************
209 void CSoundAnimDlg::OnZoomIn()
214 // ********************************************************
216 void CSoundAnimDlg::OnMark()
221 // ********************************************************
223 void CSoundAnimDlg::OnDelete()
225 _AnimView
.deleteMarker();
228 // ********************************************************
230 void CSoundAnimDlg::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
232 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
234 nlwarning("CSoundAnimDlg::OnHScroll");
236 // Get the minimum and maximum scroll-bar positions.
239 pScrollBar
->GetScrollRange(&minpos
, &maxpos
);
240 maxpos
= pScrollBar
->GetScrollLimit();
242 // Get the current position of scroll box.
243 int curpos
= pScrollBar
->GetScrollPos();
245 // Determine the new position of scroll box.
248 case SB_LEFT
: // Scroll to far left.
252 case SB_RIGHT
: // Scroll to far right.
256 case SB_ENDSCROLL
: // End scroll.
259 case SB_LINELEFT
: // Scroll left.
267 case SB_LINERIGHT
: // Scroll right.
275 case SB_PAGELEFT
: // Scroll one page left.
277 // Get the page size.
279 pScrollBar
->GetScrollInfo(&info
, SIF_ALL
);
283 curpos
= std::max(minpos
, curpos
- (int) info
.nPage
);
288 case SB_PAGERIGHT
: // Scroll one page right.
290 // Get the page size.
292 pScrollBar
->GetScrollInfo(&info
, SIF_ALL
);
296 curpos
= std::min(maxpos
, curpos
+ (int) info
.nPage
);
301 case SB_THUMBPOSITION
: // Scroll to absolute position. nPos is the position
302 curpos
= nPos
; // of the scroll box at the end of the drag operation.
305 case SB_THUMBTRACK
: // Drag scroll box to specified position. nPos is the
306 curpos
= nPos
; // position that the scroll box has been dragged to.
310 // Set the new position of the thumb (scroll box).
311 pScrollBar
->SetScrollPos(curpos
);
313 _AnimView
.changeScroll(curpos
);
315 CWnd::OnHScroll(nSBCode
, nPos
, pScrollBar
);
318 // ********************************************************
320 BEGIN_MESSAGE_MAP(CSoundAnimDlg
, CDialog
)
321 //{{AFX_MSG_MAP(CSoundAnimDlg)
322 ON_BN_CLICKED(IDC_ANIM_SOUND_ADD
, OnAddSound
)
323 ON_BN_CLICKED(IDC_ANIM_SOUND_REMOVE
, OnRemoveSound
)
324 ON_BN_CLICKED(IDC_ANIM_SOUND_SAVE
, OnSave
)
325 ON_BN_CLICKED(IDC_ANIM_SOUND_ZOOMIN
, OnZoomIn
)
326 ON_BN_CLICKED(IDC_ANIM_SOUND_ZOOMOUT
, OnZoomOut
)
327 ON_BN_CLICKED(IDC_ANIM_SOUND_MARK
, OnMark
)
328 ON_BN_CLICKED(IDC_ANIM_SOUND_DELETE
, OnDelete
)