Decorator.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../../Include/RmlUi/Core/Decorator.h"
  2. #include "../../Include/RmlUi/Core/PropertyDefinition.h"
  3. #include "../../Include/RmlUi/Core/RenderManager.h"
  4. #include "../../Include/RmlUi/Core/StyleSheet.h"
  5. #include "../../Include/RmlUi/Core/Texture.h"
  6. #include <algorithm>
  7. namespace Rml {
  8. Decorator::Decorator() {}
  9. Decorator::~Decorator() {}
  10. int Decorator::AddTexture(Texture texture)
  11. {
  12. if (!texture)
  13. return -1;
  14. if (!first_texture)
  15. first_texture = texture;
  16. if (first_texture == texture)
  17. return 0;
  18. auto it = std::find(additional_textures.begin(), additional_textures.end(), texture);
  19. if (it != additional_textures.end())
  20. return (int)(it - additional_textures.begin()) + 1;
  21. additional_textures.push_back(texture);
  22. return (int)additional_textures.size();
  23. }
  24. int Decorator::GetNumTextures() const
  25. {
  26. int result = (first_texture ? 1 : 0);
  27. result += (int)additional_textures.size();
  28. return result;
  29. }
  30. Texture Decorator::GetTexture(int index) const
  31. {
  32. if (index == 0)
  33. return first_texture;
  34. index -= 1;
  35. if (index < 0 || index >= (int)additional_textures.size())
  36. return {};
  37. return additional_textures[index];
  38. }
  39. DecoratorInstancer::DecoratorInstancer() {}
  40. DecoratorInstancer::~DecoratorInstancer() {}
  41. const Sprite* DecoratorInstancerInterface::GetSprite(const String& name) const
  42. {
  43. return style_sheet.GetSprite(name);
  44. }
  45. Texture DecoratorInstancerInterface::GetTexture(const String& filename) const
  46. {
  47. if (!property_source)
  48. {
  49. Log::Message(Log::LT_WARNING, "Texture name '%s' in decorator could not be loaded, no property source available.", filename.c_str());
  50. return {};
  51. }
  52. return render_manager.LoadTexture(filename, property_source->path);
  53. }
  54. RenderManager& DecoratorInstancerInterface::GetRenderManager() const
  55. {
  56. return render_manager;
  57. }
  58. } // namespace Rml