FontEffectShadow.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "FontEffectShadow.h"
  2. #include "../../Include/RmlUi/Core/PropertyDefinition.h"
  3. namespace Rml {
  4. FontEffectShadow::FontEffectShadow() : offset(0, 0)
  5. {
  6. SetLayer(Layer::Back);
  7. }
  8. FontEffectShadow::~FontEffectShadow() {}
  9. bool FontEffectShadow::Initialise(const Vector2i _offset)
  10. {
  11. offset = _offset;
  12. return true;
  13. }
  14. bool FontEffectShadow::HasUniqueTexture() const
  15. {
  16. return false;
  17. }
  18. bool FontEffectShadow::GetGlyphMetrics(Vector2i& origin, Vector2i& /*dimensions*/, const FontGlyph& glyph) const
  19. {
  20. if (glyph.color_format == ColorFormat::RGBA8)
  21. return false;
  22. origin += offset;
  23. return true;
  24. }
  25. FontEffectShadowInstancer::FontEffectShadowInstancer() :
  26. id_offset_x(PropertyId::Invalid), id_offset_y(PropertyId::Invalid), id_color(PropertyId::Invalid)
  27. {
  28. id_offset_x = RegisterProperty("offset-x", "0px", true).AddParser("length").GetId();
  29. id_offset_y = RegisterProperty("offset-y", "0px", true).AddParser("length").GetId();
  30. id_color = RegisterProperty("color", "white", false).AddParser("color").GetId();
  31. RegisterShorthand("offset", "offset-x, offset-y", ShorthandType::FallThrough);
  32. RegisterShorthand("font-effect", "offset-x, offset-y, color", ShorthandType::FallThrough);
  33. }
  34. FontEffectShadowInstancer::~FontEffectShadowInstancer() {}
  35. SharedPtr<FontEffect> FontEffectShadowInstancer::InstanceFontEffect(const String& /*name*/, const PropertyDictionary& properties)
  36. {
  37. Vector2i offset;
  38. offset.x = properties.GetProperty(id_offset_x)->Get<int>();
  39. offset.y = properties.GetProperty(id_offset_y)->Get<int>();
  40. Colourb color = properties.GetProperty(id_color)->Get<Colourb>();
  41. auto font_effect = MakeShared<FontEffectShadow>();
  42. if (font_effect->Initialise(offset))
  43. {
  44. font_effect->SetColour(color);
  45. return font_effect;
  46. }
  47. return nullptr;
  48. }
  49. } // namespace Rml