CPrologEpilogVideo.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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), exitCb(callback)
  20. {
  21. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  22. addUsedEvents(LCLICK);
  23. pos = center(Rect(0, 0, 800, 600));
  24. updateShadow();
  25. CCS->videoh->open(spe.prologVideo);
  26. CCS->musich->playMusic(spe.prologMusic, true, true);
  27. voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
  28. auto onVoiceStop = [this]()
  29. {
  30. voiceStopped = true;
  31. };
  32. CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
  33. text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText);
  34. text->scrollTextTo(-100);
  35. }
  36. void CPrologEpilogVideo::show(Canvas & to)
  37. {
  38. to.drawColor(pos, Colors::BLACK);
  39. //BUG: some videos are 800x600 in size while some are 800x400
  40. //VCMI should center them in the middle of the screen. Possible but needs modification
  41. //of video player API which I'd like to avoid until we'll get rid of Windows-specific player
  42. CCS->videoh->update(pos.x, pos.y, 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. exitCb();
  57. }