| 1 | // viewmgr.hxx -- class for managing all the views in the flightgear world. |
| 2 | // |
| 3 | // Written by Curtis Olson, started October 2000. |
| 4 | // |
| 5 | // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License as |
| 9 | // published by the Free Software Foundation; either version 2 of the |
| 10 | // License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but |
| 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | // General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | // $Id$ |
| 22 | |
| 23 | |
| 24 | #ifndef _VIEWMGR_HXX |
| 25 | #define _VIEWMGR_HXX |
| 26 | |
| 27 | #include <vector> |
| 28 | |
| 29 | #include <simgear/compiler.h> |
| 30 | #include <simgear/structure/subsystem_mgr.hxx> |
| 31 | #include <simgear/props/props.hxx> |
| 32 | #include <simgear/props/tiedpropertylist.hxx> |
| 33 | #include <simgear/math/SGMath.hxx> |
| 34 | #include <simgear/screen/video-encoder.hxx> |
| 35 | |
| 36 | |
| 37 | // forward decls |
| 38 | namespace flightgear |
| 39 | { |
| 40 | class View; |
| 41 | typedef SGSharedPtr<flightgear::View> ViewPtr; |
| 42 | } |
| 43 | |
| 44 | // Define a structure containing view information |
| 45 | class FGViewMgr : public SGSubsystem |
| 46 | { |
| 47 | public: |
| 48 | // Constructor |
| 49 | FGViewMgr( void ); |
| 50 | |
| 51 | // Destructor |
| 52 | ~FGViewMgr( void ); |
| 53 | |
| 54 | // Subsystem API. |
| 55 | void bind() override; |
| 56 | void init() override; |
| 57 | void postinit() override; |
| 58 | void reinit() override; |
| 59 | void shutdown() override; |
| 60 | void unbind() override; |
| 61 | void update(double dt) override; |
| 62 | |
| 63 | // Subsystem identification. |
| 64 | static const char* staticSubsystemClassId() { return "view-manager"; } |
| 65 | |
| 66 | // getters |
| 67 | inline int size() const { return views.size(); } |
| 68 | |
| 69 | int getCurrentViewIndex() const; |
| 70 | |
| 71 | flightgear::View* get_current_view(); |
| 72 | const flightgear::View* get_current_view() const; |
| 73 | |
| 74 | flightgear::View* get_view( int i ); |
| 75 | const flightgear::View* get_view( int i ) const; |
| 76 | |
| 77 | flightgear::View* next_view(); |
| 78 | flightgear::View* prev_view(); |
| 79 | |
| 80 | // Support for extra view windows. This only works if --compositer-viewer=1 was specified. |
| 81 | // |
| 82 | |
| 83 | // Calls SviewPush(). |
| 84 | void view_push(); |
| 85 | |
| 86 | // These all end up calling SviewCreate(). |
| 87 | void clone_current_view(const SGPropertyNode* config); |
| 88 | void clone_last_pair(const SGPropertyNode* config); |
| 89 | void clone_last_pair_double(const SGPropertyNode* config); |
| 90 | void view_new(const SGPropertyNode* config); |
| 91 | |
| 92 | // setters |
| 93 | void clear(); |
| 94 | |
| 95 | void add_view( flightgear::View * v ); |
| 96 | |
| 97 | // Start video encoding of main window. |
| 98 | // |
| 99 | // name |
| 100 | // If "", we generate a name containing aircraft name, date and |
| 101 | // time and with suffix /sim/video/container, and we also create a |
| 102 | // softlink with the same name excluding date and time. Both names are |
| 103 | // converted into paths by prepending with /sim/video/directory. |
| 104 | // |
| 105 | // Otherwise we prepend with /sim/video/directory, and do not create |
| 106 | // a softlink. In this case, <name> should end with a name that is a |
| 107 | // recognised video container, such as '.mp4'. |
| 108 | // |
| 109 | // List of supported containers can be found with 'ffmpeg -formats'. |
| 110 | // codec_name |
| 111 | // Name of codec or "" to use /sim/video/codec. Passed to |
| 112 | // avcodec_find_encoder_by_name(). List of supported codecs can be |
| 113 | // found with 'ffmpeg -codecs'. |
| 114 | // quality |
| 115 | // Encoding quality in range 0..1 or -1 to use /sim/video/quality. |
| 116 | // speed: |
| 117 | // Encoding speed in range 0..1 or -1 to use /sim/video/speed. |
| 118 | // bitrate |
| 119 | // Target bitratae in bits/sec or -1 to use /sim/video/bitrate. |
| 120 | // |
| 121 | // We show popup warning if values are out of range - quality and speed |
| 122 | // must be -1 or 0-1, bitrate must be >= 0. |
| 123 | // |
| 124 | // Returns false if we fail to start video encoding. |
| 125 | // |
| 126 | bool video_start( |
| 127 | const std::string& name="", |
| 128 | const std::string& codec="", |
| 129 | double quality=-1, |
| 130 | double speed=-1, |
| 131 | int bitrate=0 |
| 132 | ); |
| 133 | |
| 134 | // Stop video encoding of main window. |
| 135 | // |
| 136 | void video_stop(); |
| 137 | |
| 138 | private: |
| 139 | simgear::TiedPropertyList _tiedProperties; |
| 140 | |
| 141 | void setCurrentViewIndex(int newview); |
| 142 | |
| 143 | bool _inited = false; |
| 144 | std::vector<SGPropertyNode_ptr> config_list; |
| 145 | SGPropertyNode_ptr _viewNumberProp; |
| 146 | typedef std::vector<flightgear::ViewPtr> viewer_list; |
| 147 | viewer_list views; |
| 148 | |
| 149 | int _current = 0; |
| 150 | |
| 151 | std::unique_ptr<simgear::VideoEncoder> _video_encoder; |
| 152 | }; |
| 153 | |
| 154 | #endif // _VIEWMGR_HXX |