CPrologEpilogVideo.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //BUG: some videos are 800x600 in size while some are 800x400
  42. //VCMI should center them in the middle of the screen. Possible but needs modification
  43. //of video player API which I'd like to avoid until we'll get rid of Windows-specific player
  44. CCS->videoh->update(pos.x, pos.y, to.getInternalSurface(), true, false);
  45. //move text every 5 calls/frames; seems to be good enough
  46. ++positionCounter;
  47. if(positionCounter % 5 == 0)
  48. text->scrollTextBy(1);
  49. else
  50. text->showAll(to); // blit text over video, if needed
  51. if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
  52. clickPressed(GH.getCursorPosition());
  53. }
  54. void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
  55. {
  56. close();
  57. CCS->soundh->stopSound(voiceSoundHandle);
  58. CCS->soundh->stopSound(videoSoundHandle);
  59. exitCb();
  60. }