| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
#include <functional> |
| 5 |
#include "math/Vector3.h" |
| 6 |
|
| 7 |
namespace colours |
| 8 |
{ |
| 9 |
|
| 10 |
/** |
| 11 |
* Registry key set when light volumes should be rendered in a single colour |
| 12 |
* set by the colourscheme, rather than the colour contained in their _color |
| 13 |
* key. |
| 14 |
*/ |
| 15 |
constexpr const char* RKEY_OVERRIDE_LIGHTCOL = "user/ui/colour/overrideLightColour"; |
| 16 |
|
| 17 |
class IColourItem |
| 18 |
{ |
| 19 |
public: |
| 20 |
virtual ~IColourItem() {} |
| 21 |
|
| 22 |
// Const and non-const colour accessors |
| 23 |
virtual const Vector3& getColour() const = 0; |
| 24 |
virtual Vector3& getColour() = 0; |
| 25 |
}; |
| 26 |
|
| 27 |
/// Interface for a single colour scheme |
| 28 |
class IColourScheme |
| 29 |
{ |
| 30 |
public: |
| 31 |
virtual ~IColourScheme() {} |
| 32 |
|
| 33 |
// Iterate over all colours in this scheme |
| 34 |
virtual void foreachColour(const std::function<void(const std::string& name, IColourItem& colour)>& functor) = 0; |
| 35 |
virtual void foreachColour(const std::function<void(const std::string& name, const IColourItem& colour)>& functor) const = 0; |
| 36 |
|
| 37 |
// Returns the requested colour object |
| 38 |
virtual IColourItem& getColour(const std::string& colourName) = 0; |
| 39 |
|
| 40 |
// returns the name of this colour scheme |
| 41 |
virtual const std::string& getName() const = 0; |
| 42 |
|
| 43 |
// returns true if the scheme is read-only |
| 44 |
virtual bool isReadOnly() const = 0; |
| 45 |
}; |
| 46 |
|
| 47 |
/// Module providing access to current and available colour schemes |
| 48 |
class IColourSchemeManager : |
| 49 |
public RegisterableModule |
| 50 |
{ |
| 51 |
public: |
| 52 |
virtual ~IColourSchemeManager() {} |
| 53 |
|
| 54 |
// Visit each known colour scheme with the given functor |
| 55 |
virtual void foreachScheme(const std::function<void(const std::string&, IColourScheme&)>& functor) = 0; |
| 56 |
|
| 57 |
// Get the named scheme |
| 58 |
virtual IColourScheme& getColourScheme(const std::string& schemeName) = 0; |
| 59 |
|
| 60 |
// Checks if the specified scheme already exists |
| 61 |
virtual bool schemeExists(const std::string& name) = 0; |
| 62 |
|
| 63 |
virtual void setActive(const std::string& name) = 0; |
| 64 |
|
| 65 |
/// Get a reference to the currently active colour scheme |
| 66 |
virtual IColourScheme& getActiveScheme() = 0; |
| 67 |
|
| 68 |
// greebo: Returns the named colour, returns <0,0,0> if not found |
| 69 |
virtual Vector3 getColour(const std::string& colourName) = 0; |
| 70 |
|
| 71 |
virtual void deleteScheme(const std::string& name) = 0; |
| 72 |
virtual void copyScheme(const std::string& fromName, const std::string& toName) = 0; |
| 73 |
|
| 74 |
// Loads/Saves all the schemes from/to the registry |
| 75 |
virtual void loadColourSchemes() = 0; |
| 76 |
virtual void saveColourSchemes() = 0; |
| 77 |
|
| 78 |
// Reverts all changes to the current objects and re-load them from the registry |
| 79 |
virtual void restoreColourSchemes() = 0; |
| 80 |
|
| 81 |
// Explicitly store the entity class overrides in the EclassColourManager |
| 82 |
// This is done by restore/saveColourSchemes automatically and doesn't need to be |
| 83 |
// called by client code. This is used to let the colour scheme editor force an |
| 84 |
// update of the eclasses in the current scene to allow for a better preview |
| 85 |
virtual void emitEclassOverrides() = 0; |
| 86 |
}; |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
const char* const MODULE_COLOURSCHEME_MANAGER("ColourSchemeManager"); |
| 91 |
|
| 92 |
inline colours::IColourSchemeManager& GlobalColourSchemeManager() |
| 93 |
{ |
| 94 |
static module::InstanceReference<colours::IColourSchemeManager> _reference(MODULE_COLOURSCHEME_MANAGER); |
| 95 |
return _reference; |
| 96 |
} |