guiTheoraCtrl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. String 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. /// Which transcoder to use on the Theora decoder. This is mostly
  50. /// meant as a development aid.
  51. OggTheoraDecoder::ETranscoder mTranscoder;
  52. /// If true, stop video playback when the control goes to sleep. Otherwise,
  53. /// the video will be paused.
  54. ///
  55. /// @note We do not currently support to keep video running in the background
  56. /// as the Theora decoder does not yet support skipping through bulks of
  57. /// outdated data. This means that when the Theora texture gets its next
  58. /// refresh, the decoder will frantically try to wade through a huge amount
  59. /// of outdated ogg_packets which even though the actual decoding does not
  60. /// take place takes a lot of time.
  61. bool mStopOnSleep;
  62. /// Are we done with playback?
  63. bool mDone;
  64. /// If true, renders some text information into the frame.
  65. bool mRenderDebugInfo;
  66. /// Our background color.
  67. ColorI mBackgroundColor;
  68. public:
  69. GuiTheoraCtrl();
  70. /// Load the given Theora video file. Does not start playback.
  71. void setFile( const String& filename );
  72. /// Start video playback.
  73. void play();
  74. /// Pause video playback.
  75. void pause();
  76. /// Stop video playback.
  77. void stop();
  78. /// Return true if the video has finished playing.
  79. bool isPlaybackDone() const { return mDone; }
  80. /// Return the current playback position.
  81. F32 getCurrentTime()
  82. {
  83. return F32( mTheoraTexture.getPosition() ) / 1000.f;
  84. }
  85. // GuiControl.
  86. virtual bool onWake();
  87. virtual void onSleep();
  88. virtual void onRender( Point2I offset, const RectI &updateRect );
  89. virtual void inspectPostApply();
  90. static void initPersistFields();
  91. DECLARE_CONOBJECT( GuiTheoraCtrl );
  92. DECLARE_CATEGORY( "Gui Images" );
  93. DECLARE_DESCRIPTION( "A control for playing Theora videos." );
  94. };
  95. typedef OggTheoraDecoder::ETranscoder GuiTheoraTranscoder;
  96. DefineEnumType( GuiTheoraTranscoder );
  97. #endif // TORQUE_OGGTHEORA
  98. #endif // !_GUITHEORACTRL_H_