| 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
| 7 | #include <simgear/misc/strutils.hxx> |
| 8 | #include <simgear/props/propsfwd.hxx> |
| 9 | #include <simgear/structure/subsystem_mgr.hxx> |
| 10 | |
| 11 | // forward decls |
| 12 | class SGPath; |
| 13 | |
| 14 | namespace flightgear { |
| 15 | |
| 16 | class GraphicsPresets : public SGSubsystem |
| 17 | { |
| 18 | public: |
| 19 | GraphicsPresets(); |
| 20 | ~GraphicsPresets(); |
| 21 | |
| 22 | static const char* staticSubsystemClassId() { return "graphics-presets"; } |
| 23 | |
| 24 | struct GraphicsPresetInfo { |
| 25 | std::string id; |
| 26 | std::string name; // localized |
| 27 | std::string description; // localized |
| 28 | int orderNum; |
| 29 | string_list devices; |
| 30 | |
| 31 | SGPropertyNode_ptr properties; |
| 32 | }; |
| 33 | |
| 34 | using GraphicsPresetVec = std::vector<GraphicsPresetInfo>; |
| 35 | |
| 36 | // implement SGSubsystem intergace |
| 37 | void init() override; |
| 38 | void shutdown() override; |
| 39 | |
| 40 | void update(double delta_time_sec) override; |
| 41 | |
| 42 | /** |
| 43 | @brief init() is called too late (after fgOSInit), so we call this method early, |
| 44 | to load the initial preset if set, at that time. |
| 45 | */ |
| 46 | void applyInitialPreset(); |
| 47 | |
| 48 | /** |
| 49 | * @brief Apply the settings defined in the current graphics preset, |
| 50 | * to the property tree |
| 51 | * |
| 52 | */ |
| 53 | bool applyCurrentPreset(); |
| 54 | |
| 55 | bool applyCustomPreset(const SGPath& path); |
| 56 | |
| 57 | /** |
| 58 | @brief apply a preset identified by its (localized) name. This is helpful |
| 59 | for the rnedering dialog since PUI combo-boxes only record the name of |
| 60 | items and no other data. |
| 61 | */ |
| 62 | bool applyPresetByName(const std::string& name); |
| 63 | |
| 64 | /** |
| 65 | @brief retrieve all standard presets which are defined |
| 66 | */ |
| 67 | GraphicsPresetVec listPresets(); |
| 68 | |
| 69 | bool saveToXML(const SGPath& path, const std::string& name, const std::string& desc); |
| 70 | |
| 71 | private: |
| 72 | void clearPreset(); |
| 73 | |
| 74 | bool loadStandardPreset(const std::string& id, GraphicsPresetInfo& info); |
| 75 | |
| 76 | bool innerApplyPreset(const GraphicsPresetInfo& info, bool overwriteAutosaved); |
| 77 | |
| 78 | bool loadPresetXML(const SGPath& p, GraphicsPresetInfo& info); |
| 79 | |
| 80 | |
| 81 | class RequiredPropertyListener; |
| 82 | class GraphicsConfigChangeListener; |
| 83 | |
| 84 | std::unique_ptr<GraphicsConfigChangeListener> _listener; |
| 85 | std::unique_ptr<RequiredPropertyListener> _restartListener; |
| 86 | std::unique_ptr<RequiredPropertyListener> _sceneryReloadListener; |
| 87 | std::unique_ptr<RequiredPropertyListener> _compositorReloadListener; |
| 88 | |
| 89 | string_list _propertiesToSave; |
| 90 | }; |
| 91 | |
| 92 | } // namespace flightgear |