1#include "FontSelectorComponent.h"
5#include "EntityStore.h"
7#include "Components/Core/TextComponent.h"
9#include "Resources/FontManager.h"
11#include "Scene/SceneTraversal.h"
15void Cogs::Core::FontSelectorComponent::registerType()
18 {
"ApplyToChildren", FontSelectorFlags::ApplyToChildren },
19 {
"SelfOnly", FontSelectorFlags::SelfOnly },
22 TypeDatabase::createType<FontSelectorFlags>().setEnumerators(enums);
31 Method(
Name(
"initialize"), &FontSelectorComponent::initialize),
32 Method(
Name(
"update"), &FontSelectorComponent::update),
35 DynamicComponent::registerDerivedType<FontSelectorComponent>().setFields(fields).setMethods(methods);
38void Cogs::Core::FontSelectorComponent::initialize(Context * context)
40 this->context = context;
43void Cogs::Core::FontSelectorComponent::update()
45 if (!hasChanged())
return;
48 fontHandle = context->fontManager->loadFont(fontName, fontSize, NoResourceId);
51 case Cogs::Core::FontSelectorFlags::ApplyToChildren:
53 recurseFontSelection(
this, getContainer());
55 const FontSelectorComponent* fontSelectorComponent = entity->getComponent<FontSelectorComponent>();
56 return fontSelectorComponent ==
nullptr || fontSelectorComponent->
flags == FontSelectorFlags::ApplyToChildren;
61 case Cogs::Core::FontSelectorFlags::SelfOnly:
63 auto textComponent = getComponent<TextComponent>();
66 textComponent->fontHandle = fontHandle;
67 textComponent->setChanged();
75void Cogs::Core::FontSelectorComponent::recurseFontSelection(
const FontSelectorComponent* source,
const Entity* parent)
77 const SceneComponent* sceneComponent = parent->getComponent<SceneComponent>();
79 for (
auto& child : sceneComponent->children) {
80 FontSelectorComponent* fontSelectorComponent = child->getComponent<FontSelectorComponent>();
81 if (fontSelectorComponent) {
82 if (fontSelectorComponent->fontName != source->fontName) {
83 fontSelectorComponent->fontName = source->fontName;
84 fontSelectorComponent->setChanged();
86 if (fontSelectorComponent->fontSize != source->fontSize) {
87 fontSelectorComponent->fontSize = source->fontSize;
88 fontSelectorComponent->setChanged();
91 if (fontSelectorComponent->flags == FontSelectorFlags::ApplyToChildren) {
92 recurseFontSelection(source, child.get());
std::string fontName
Name of Font.
float fontSize
Size of font.
FontHandle fontHandle
Handle to the font resource to use when rendering text.
Field definition describing a single data member of a data structure.
Simple method definition.
void applyRecursiveFieldChange(ComponentModel::Entity *entity, MemberType ComponentType::*member, MemberType value, Recurse recurse)
Contains reflection support.
Atomic< uint32_t > flags
Resource flags.
Represents an unique name.