CPrologEpilogVideo.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * CPrologEpilogVideo.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CPrologEpilogVideo.h"
  12. #include "../CGameInfo.h"
  13. #include "../CMusicHandler.h"
  14. #include "../CVideoHandler.h"
  15. #include "../gui/CGuiHandler.h"
  16. #include "../widgets/TextControls.h"
  17. #include "../render/Canvas.h"
  18. CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback)
  19. : CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback)
  20. {
  21. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  22. addUsedEvents(LCLICK);
  23. pos = center(Rect(0, 0, 800, 600));
  24. updateShadow();
  25. auto audioData = CCS->videoh->getAudio(spe.prologVideo);
  26. videoSoundHandle = CCS->soundh->playSound(audioData);
  27. CCS->videoh->open(spe.prologVideo);
  28. CCS->musich->playMusic(spe.prologMusic, true, true);
  29. voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
  30. auto onVoiceStop = [this]()
  31. {
  32. voiceStopped = true;
  33. };
  34. CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
  35. text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
  36. text->scrollTextTo(-100);
  37. }
  38. void CPrologEpilogVideo::show(Canvas & to)
  39. {
  40. to.drawColor(pos, Colors::BLACK);
  41. //some videos are 800x600 in size while some are 800x400
  42. CCS->videoh->update(pos.x, pos.y + (CCS->videoh->size().y == 400 ? 100 : 0), to.getInternalSurface(), true, false);
  43. //move text every 5 calls/frames; seems to be good enough
  44. ++positionCounter;
  45. if(positionCounter % 5 == 0)
  46. text->scrollTextBy(1);
  47. else
  48. text->showAll(to); // blit text over video, if needed
  49. if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
  50. clickPressed(GH.getCursorPosition());
  51. }
  52. void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
  53. {
  54. close();
  55. CCS->soundh->stopSound(voiceSoundHandle);
  56. CCS->soundh->stopSound(videoSoundHandle);
  57. exitCb();
  58. }