Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5430: Add EClassColourManager interface and implementing module whic…
…h will deal with the colour overrides for certain entity classes.
- Loading branch information
1 parent
67c635f
commit 2227fd5
Showing
7 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "imodule.h" | ||
#include "ieclass.h" | ||
#include "math/Vector3.h" | ||
|
||
namespace eclass | ||
{ | ||
|
||
/** | ||
* Manages the entity class colour overrides that are applied | ||
* to certain eclasses as defined in the currently active | ||
* colour scheme. | ||
*/ | ||
class IColourManager : | ||
public RegisterableModule | ||
{ | ||
public: | ||
virtual ~IColourManager() {} | ||
|
||
// Register an override for the given entity class, such that the wire/fill shader | ||
// colours of the named entity class are using the given colour instead of the one | ||
// defined in the entityDef block. | ||
// Adding an override for an entity class will replace any existing overrides. | ||
// The colour is given in RGB values with each component in the interval [0..1]. | ||
virtual void addOverrideColour(const std::string& eclass, const Vector3& colour) = 0; | ||
|
||
// Applies a possible colour override to the given entity class | ||
virtual void applyColours(const IEntityClassPtr& eclass) = 0; | ||
|
||
// Removes the override colour for the given entity class | ||
virtual void removeOverrideColour(const std::string& eclass) = 0; | ||
}; | ||
|
||
} | ||
|
||
const char* const MODULE_ECLASS_COLOUR_MANAGER("EclassColourManager"); | ||
|
||
/** | ||
* Return the global IEClassColourManager to the application. | ||
* \ingroup eclass | ||
*/ | ||
inline eclass::IColourManager& GlobalEclassColourManager() | ||
{ | ||
static module::InstanceReference<eclass::IColourManager> _reference(MODULE_ECLASS_COLOUR_MANAGER); | ||
return _reference; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "EClassColourManager.h" | ||
|
||
#include "module/StaticModule.h" | ||
|
||
namespace eclass | ||
{ | ||
|
||
void EClassColourManager::addOverrideColour(const std::string& eclass, const Vector3& colour) | ||
{ | ||
_overrides[eclass] = colour; | ||
} | ||
|
||
void EClassColourManager::applyColours(const IEntityClassPtr& eclass) | ||
{ | ||
auto foundOverride = _overrides.find(eclass->getName()); | ||
|
||
if (foundOverride != _overrides.end()) | ||
{ | ||
eclass->setColour(foundOverride->second); | ||
} | ||
} | ||
|
||
void EClassColourManager::removeOverrideColour(const std::string& eclass) | ||
{ | ||
_overrides.erase(eclass); | ||
} | ||
|
||
const std::string& EClassColourManager::getName() const | ||
{ | ||
static std::string _name(MODULE_ECLASS_COLOUR_MANAGER); | ||
return _name; | ||
} | ||
|
||
const StringSet& EClassColourManager::getDependencies() const | ||
{ | ||
static StringSet _dependencies; | ||
return _dependencies; | ||
} | ||
|
||
void EClassColourManager::initialiseModule(const IApplicationContext& ctx) | ||
{ | ||
rMessage() << getName() << "::initialiseModule called." << std::endl; | ||
} | ||
|
||
module::StaticModule<EClassColourManager> eclassColourManagerModule; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include "ieclasscolours.h" | ||
|
||
namespace eclass | ||
{ | ||
|
||
class EClassColourManager : | ||
public IColourManager | ||
{ | ||
private: | ||
std::map<std::string, Vector3> _overrides; | ||
|
||
public: | ||
// IColourManager implementation | ||
|
||
void addOverrideColour(const std::string& eclass, const Vector3& colour) override; | ||
void applyColours(const IEntityClassPtr& eclass) override; | ||
void removeOverrideColour(const std::string& eclass) override; | ||
|
||
// RegisterableModule implementation | ||
|
||
const std::string& getName() const override; | ||
const StringSet& getDependencies() const override; | ||
void initialiseModule(const IApplicationContext& ctx) override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters