CPrologEpilogVideo.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText);
  29. text->scrollTextTo(-100);
  30. }
  31. void CPrologEpilogVideo::show(Canvas & to)
  32. {
  33. to.drawColor(pos, Colors::BLACK);
  34. //BUG: some videos are 800x600 in size while some are 800x400
  35. //VCMI should center them in the middle of the screen. Possible but needs modification
  36. //of video player API which I'd like to avoid until we'll get rid of Windows-specific player
  37. CCS->videoh->update(pos.x, pos.y, to.getInternalSurface(), true, false);
  38. //move text every 5 calls/frames; seems to be good enough
  39. ++positionCounter;
  40. if(positionCounter % 5 == 0)
  41. text->scrollTextBy(1);
  42. else
  43. text->showAll(to); // blit text over video, if needed
  44. if(text->textSize.y + 100 < positionCounter / 5)
  45. clickPressed(GH.getCursorPosition());
  46. }
  47. void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
  48. {
  49. close();
  50. CCS->soundh->stopSound(voiceSoundHandle);
  51. exitCb();
  52. }