LayoutBlockBoxSpace.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCORELAYOUTBLOCKBOXSPACE_H
  28. #define ROCKETCORELAYOUTBLOCKBOXSPACE_H
  29. #include "../../Include/Rocket/Core/StyleSheetKeywords.h"
  30. namespace Rocket {
  31. namespace Core {
  32. class Element;
  33. class LayoutBlockBox;
  34. /**
  35. Each block box has a space object for managing the space occupied by its floating elements, and those of its
  36. ancestors as relevant.
  37. @author Peter Curry
  38. */
  39. class LayoutBlockBoxSpace
  40. {
  41. public:
  42. LayoutBlockBoxSpace(LayoutBlockBox* parent);
  43. ~LayoutBlockBoxSpace();
  44. /// Imports boxes from another block into this space.
  45. /// @param[in] space The space to import boxes from.
  46. void ImportSpace(const LayoutBlockBoxSpace& space);
  47. /// Generates the position for a box of a given size within our block box.
  48. /// @param[out] box_position The generated position for the box.
  49. /// @param[out] box_width The available width for the box.
  50. /// @param[in] cursor The ideal vertical position for the box.
  51. /// @param[in] dimensions The minimum available space required for the box.
  52. void PositionBox(Vector2f& box_position, float& box_width, float cursor, const Vector2f& dimensions) const;
  53. /// Generates and sets the position for a floating box of a given size within our block box. The element's box
  54. /// is then added into our list of floating boxes.
  55. /// @param[in] cursor The ideal vertical position for the box.
  56. /// @param[in] element The element to position.
  57. /// @return The offset of the bottom outer edge of the element.
  58. float PositionBox(float cursor, Element* element);
  59. /// Determines the appropriate vertical position for an object that is choosing to clear floating elements to
  60. /// the left or right (or both).
  61. /// @param[in] cursor The ideal vertical position.
  62. /// @param[in] clear_property The value of the clear property of the clearing object.
  63. /// @return The appropriate vertical position for the clearing object.
  64. float ClearBoxes(float cursor, int clear_property);
  65. /// Returns the top-left corner of the boxes within the space.
  66. /// @return The space's offset.
  67. const Vector2f& GetOffset() const;
  68. /// Returns the dimensions of the boxes within the space.
  69. /// @return The space's dimensions.
  70. Vector2f GetDimensions() const;
  71. void* operator new(size_t size);
  72. void operator delete(void* chunk);
  73. private:
  74. enum AnchorEdge
  75. {
  76. LEFT = 0,
  77. RIGHT = 1,
  78. NUM_ANCHOR_EDGES = 2
  79. };
  80. /// Generates the position for an arbitrary box within our space layout, floated against either the left or
  81. /// right edge.
  82. /// @param box_position[out] The generated position for the box.
  83. /// @param cursor[in] The ideal vertical position for the box.
  84. /// @param dimensions[in] The size of the box to place.
  85. /// @return The maximum width at the box position.
  86. float PositionBox(Vector2f& box_position, float cursor, const Vector2f& dimensions, int float_property = FLOAT_NONE) const;
  87. struct SpaceBox
  88. {
  89. SpaceBox();
  90. SpaceBox(const Vector2f& offset, const Vector2f& dimensions);
  91. Vector2f offset;
  92. Vector2f dimensions;
  93. };
  94. typedef std::vector< SpaceBox > SpaceBoxList;
  95. // Our block-box parent.
  96. LayoutBlockBox* parent;
  97. // The boxes floating in our space.
  98. SpaceBoxList boxes[NUM_ANCHOR_EDGES];
  99. // The offset and dimensions of the boxes added specifically into this space.
  100. Vector2f offset;
  101. Vector2f dimensions;
  102. };
  103. }
  104. }
  105. #endif