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