guiTheoraCtrl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUITHEORACTRL_H_
  23. #define _GUITHEORACTRL_H_
  24. #ifdef TORQUE_OGGTHEORA
  25. #ifndef _THEORATEXTURE_H_
  26. #include "gfx/video/theoraTexture.h"
  27. #endif
  28. #ifndef _OGGTHEORADECODER_H_
  29. #include "core/ogg/oggTheoraDecoder.h"
  30. #endif
  31. #ifndef _DYNAMIC_CONSOLETYPES_H_
  32. #include "console/dynamicTypes.h"
  33. #endif
  34. /// Control to play back a Theora video file.
  35. class GuiTheoraCtrl : public GuiControl
  36. {
  37. public:
  38. typedef GuiControl Parent;
  39. protected:
  40. /// The Theora file we should play.
  41. StringTableEntry mFilename;
  42. /// Theora video player backend.
  43. TheoraTexture mTheoraTexture;
  44. /// If true, the control's extents will be matched to the video size.
  45. bool mMatchVideoSize;
  46. /// If true, playback will start automatically when the control receives its
  47. /// onWake().
  48. bool mPlayOnWake;
  49. bool mLoop;
  50. /// Which transcoder to use on the Theora decoder. This is mostly
  51. /// meant as a development aid.
  52. OggTheoraDecoder::ETranscoder mTranscoder;
  53. /// If true, stop video playback when the control goes to sleep. Otherwise,
  54. /// the video will be paused.
  55. ///
  56. /// @note We do not currently support to keep video running in the background
  57. /// as the Theora decoder does not yet support skipping through bulks of
  58. /// outdated data. This means that when the Theora texture gets its next
  59. /// refresh, the decoder will frantically try to wade through a huge amount
  60. /// of outdated ogg_packets which even though the actual decoding does not
  61. /// take place takes a lot of time.
  62. bool mStopOnSleep;
  63. /// Are we done with playback?
  64. bool mDone;
  65. /// If true, renders some text information into the frame.
  66. bool mRenderDebugInfo;
  67. /// Our background color.
  68. ColorI mBackgroundColor;
  69. public:
  70. GuiTheoraCtrl();
  71. /// Load the given Theora video file. Does not start playback.
  72. void setFile( const String& filename );
  73. /// Start video playback.
  74. void play();
  75. /// Pause video playback.
  76. void pause();
  77. /// Stop video playback.
  78. void stop();
  79. /// Return true if the video has finished playing.
  80. bool isPlaybackDone() const { return mDone; }
  81. /// Return the current playback position.
  82. F32 getCurrentTime()
  83. {
  84. return F32( mTheoraTexture.getPosition() ) / 1000.f;
  85. }
  86. // GuiControl.
  87. virtual bool onWake();
  88. virtual void onSleep();
  89. virtual void onRender( Point2I offset, const RectI &updateRect );
  90. virtual void inspectPostApply();
  91. static void initPersistFields();
  92. DECLARE_CONOBJECT( GuiTheoraCtrl );
  93. DECLARE_CATEGORY( "Gui Images" );
  94. DECLARE_DESCRIPTION( "A control for playing Theora videos." );
  95. };
  96. typedef OggTheoraDecoder::ETranscoder GuiTheoraTranscoder;
  97. DefineEnumType( GuiTheoraTranscoder );
  98. #endif // TORQUE_OGGTHEORA
  99. #endif // !_GUITHEORACTRL_H_