| 255 | } |
| 256 | |
| 257 | void CEditor::DoAudioPreview(CUIRect View, const void *pPlayPauseButtonId, const void *pStopButtonId, const void *pSeekBarId, int SampleId) |
| 258 | { |
| 259 | CUIRect Button, SeekBar; |
| 260 | // play/pause button |
| 261 | { |
| 262 | View.VSplitLeft(View.h, &Button, &View); |
| 263 | if(DoButton_FontIcon(pPlayPauseButtonId, Sound()->IsPlaying(SampleId) ? FontIcon::PAUSE : FontIcon::PLAY, 0, &Button, BUTTONFLAG_LEFT, "Play/pause audio preview.", IGraphics::CORNER_ALL) || |
| 264 | (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_SPACE))) |
| 265 | { |
| 266 | if(Sound()->IsPlaying(SampleId)) |
| 267 | { |
| 268 | Sound()->Pause(SampleId); |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | if(SampleId != m_ToolbarPreviewSound && m_ToolbarPreviewSound >= 0 && Sound()->IsPlaying(m_ToolbarPreviewSound)) |
| 273 | Sound()->Pause(m_ToolbarPreviewSound); |
| 274 | |
| 275 | Sound()->Play(CSounds::CHN_GUI, SampleId, ISound::FLAG_PREVIEW, 1.0f); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | // stop button |
| 280 | { |
| 281 | View.VSplitLeft(2.0f, nullptr, &View); |
| 282 | View.VSplitLeft(View.h, &Button, &View); |
| 283 | if(DoButton_FontIcon(pStopButtonId, FontIcon::STOP, 0, &Button, BUTTONFLAG_LEFT, "Stop audio preview.", IGraphics::CORNER_ALL)) |
| 284 | { |
| 285 | Sound()->Stop(SampleId); |
| 286 | } |
| 287 | } |
| 288 | // do seekbar |
| 289 | { |
| 290 | View.VSplitLeft(5.0f, nullptr, &View); |
| 291 | const float Cut = std::min(View.w, 200.0f); |
| 292 | View.VSplitLeft(Cut, &SeekBar, &View); |
| 293 | SeekBar.HMargin(2.5f, &SeekBar); |
| 294 | |
| 295 | const float Rounding = 5.0f; |
| 296 | |
| 297 | char aBuffer[64]; |
| 298 | const float CurrentTime = Sound()->GetSampleCurrentTime(SampleId); |
| 299 | const float TotalTime = Sound()->GetSampleTotalTime(SampleId); |
| 300 | |
| 301 | // draw seek bar |
| 302 | SeekBar.Draw(ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, Rounding); |
| 303 | |
| 304 | // draw filled bar |
| 305 | const float Amount = CurrentTime / TotalTime; |
| 306 | CUIRect FilledBar = SeekBar; |
| 307 | FilledBar.w = 2 * Rounding + (FilledBar.w - 2 * Rounding) * Amount; |
| 308 | FilledBar.Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, Rounding); |
| 309 | |
| 310 | // draw time |
| 311 | char aCurrentTime[32]; |
| 312 | str_time_float(CurrentTime, TIME_HOURS, aCurrentTime, sizeof(aCurrentTime)); |
| 313 | char aTotalTime[32]; |
| 314 | str_time_float(TotalTime, TIME_HOURS, aTotalTime, sizeof(aTotalTime)); |
no test coverage detected