File: LayoutBlockBoxSpace.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (128 lines) | stat: -rw-r--r-- 4,566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * This source file is part of libRocket, the HTML/CSS Interface Middleware
 *
 * For the latest information, see http://www.librocket.com
 *
 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#ifndef ROCKETCORELAYOUTBLOCKBOXSPACE_H
#define ROCKETCORELAYOUTBLOCKBOXSPACE_H

#include "../../Include/Rocket/Core/StyleSheetKeywords.h"

namespace Rocket {
namespace Core {

class Element;
class LayoutBlockBox;

/**
	Each block box has a space object for managing the space occupied by its floating elements, and those of its
	ancestors as relevant.

	@author Peter Curry
 */

class LayoutBlockBoxSpace
{
public:
	LayoutBlockBoxSpace(LayoutBlockBox* parent);
	~LayoutBlockBoxSpace();

	/// Imports boxes from another block into this space.
	/// @param[in] space The space to import boxes from.
	void ImportSpace(const LayoutBlockBoxSpace& space);

	/// Generates the position for a box of a given size within our block box.
	/// @param[out] box_position The generated position for the box.
	/// @param[out] box_width The available width for the box.
	/// @param[in] cursor The ideal vertical position for the box.
	/// @param[in] dimensions The minimum available space required for the box.
	void PositionBox(Vector2f& box_position, float& box_width, float cursor, const Vector2f& dimensions) const;

	/// Generates and sets the position for a floating box of a given size within our block box. The element's box
	/// is then added into our list of floating boxes.
	/// @param[in] cursor The ideal vertical position for the box.
	/// @param[in] element The element to position.
	/// @return The offset of the bottom outer edge of the element.
	float PositionBox(float cursor, Element* element);

	/// Determines the appropriate vertical position for an object that is choosing to clear floating elements to
	/// the left or right (or both).
	/// @param[in] cursor The ideal vertical position.
	/// @param[in] clear_property The value of the clear property of the clearing object.
	/// @return The appropriate vertical position for the clearing object.
	float ClearBoxes(float cursor, int clear_property);

	/// Returns the top-left corner of the boxes within the space.
	/// @return The space's offset.
	const Vector2f& GetOffset() const;
	/// Returns the dimensions of the boxes within the space.
	/// @return The space's dimensions.
	Vector2f GetDimensions() const;

	void* operator new(size_t size);
	void operator delete(void* chunk);

private:
	enum AnchorEdge
	{
		LEFT = 0,
		RIGHT = 1,
		NUM_ANCHOR_EDGES = 2
	};

	/// Generates the position for an arbitrary box within our space layout, floated against either the left or
	/// right edge.
	/// @param box_position[out] The generated position for the box.
	/// @param cursor[in] The ideal vertical position for the box.
	/// @param dimensions[in] The size of the box to place.
	/// @return The maximum width at the box position.
	float PositionBox(Vector2f& box_position, float cursor, const Vector2f& dimensions, int float_property = FLOAT_NONE) const;

	struct SpaceBox
	{
		SpaceBox();
		SpaceBox(const Vector2f& offset, const Vector2f& dimensions);

		Vector2f offset;
		Vector2f dimensions;
	};

	typedef std::vector< SpaceBox > SpaceBoxList;

	// Our block-box parent.
	LayoutBlockBox* parent;

	// The boxes floating in our space.
	SpaceBoxList boxes[NUM_ANCHOR_EDGES];

	// The offset and dimensions of the boxes added specifically into this space.
	Vector2f offset;
	Vector2f dimensions;
};

}
}

#endif