ElementDecoration.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICOREELEMENTDECORATION_H
  29. #define RMLUICOREELEMENTDECORATION_H
  30. #include "../../Include/RmlUi/Core/Types.h"
  31. namespace Rml {
  32. namespace Core {
  33. class Decorator;
  34. class Element;
  35. /**
  36. Manages an elements decorator state
  37. @author Lloyd Weehuizen
  38. */
  39. class ElementDecoration
  40. {
  41. public:
  42. /// Constructor
  43. /// @param element The element this decorator with acting on
  44. ElementDecoration(Element* element);
  45. ~ElementDecoration();
  46. // Releases existing decorators and loads all decorators required by the element's definition.
  47. bool ReloadDecorators();
  48. /// Renders all appropriate decorators.
  49. void RenderDecorators();
  50. /// Mark decorators as dirty and force them to reset themselves
  51. void DirtyDecorators();
  52. /// Iterates over all active decorators attached to the decoration's element.
  53. /// @param[inout] index Index to fetch. This is incremented after the fetch.
  54. /// @param[out] pseudo_classes The pseudo-classes the decorator required to be active before it renders.
  55. /// @param[out] name The name of the decorator at the specified index.
  56. /// @param[out] decorator The decorator at the specified index.
  57. /// @param[out] decorator_data This element's handle to any data is has stored against the decorator.
  58. /// @return True if a decorator was successfully fetched, false if not.
  59. bool IterateDecorators(int& index, PseudoClassList& pseudo_classes, String& name, Decorator*& decorator, DecoratorDataHandle& decorator_data) const;
  60. private:
  61. // Loads a single decorator and adds it to the list of loaded decorators for this element.
  62. int LoadDecorator(Decorator* decorator);
  63. // Releases all existing decorators and frees their data.
  64. void ReleaseDecorators();
  65. // Updates the list of active decorators (if necessary)
  66. void UpdateActiveDecorators();
  67. struct DecoratorHandle
  68. {
  69. Decorator* decorator;
  70. DecoratorDataHandle decorator_data;
  71. };
  72. typedef std::vector< DecoratorHandle > DecoratorList;
  73. typedef std::pair< PseudoClassList, int > PseudoClassDecoratorIndex;
  74. typedef std::vector< PseudoClassDecoratorIndex > PseudoClassDecoratorIndexList;
  75. typedef std::map< String, PseudoClassDecoratorIndexList > DecoratorIndex;
  76. // The element this decorator belongs to
  77. Element* element;
  78. // The list of every decorator used by this element in every class.
  79. DecoratorList decorators;
  80. // The list of currently active decorators.
  81. std::vector< int > active_decorators;
  82. bool active_decorators_dirty;
  83. // For each unique decorator name, this stores (in order of specificity) the name of the pseudo-class that has
  84. // a definition for it, and the index into the list of decorators.
  85. DecoratorIndex decorator_index;
  86. };
  87. }
  88. }
  89. #endif