// Generates the border geometry for a single box. void ElementBorder::GenerateBorder(Vertex*& vertices, Index*& indices, Index& index_offset, const Box& box, const Colourb* colours) { // The axis of extrusion for each of the edges. Vector2f box_extrusions[4] = { Vector2f(0, -1 * box.GetEdge(Box::BORDER, Box::TOP)), Vector2f(box.GetEdge(Box::BORDER, Box::RIGHT), 0), Vector2f(0, box.GetEdge(Box::BORDER, Box::BOTTOM)), Vector2f(-1 * box.GetEdge(Box::BORDER, Box::LEFT), 0) }; // The position of each of the corners of the inner border. Vector2f box_corners[4]; box_corners[0] = box.GetPosition(Box::PADDING); box_corners[2] = box_corners[0] + box.GetSize(Box::PADDING); box_corners[1] = Vector2f(box_corners[2].x, box_corners[0].y); box_corners[3] = Vector2f(box_corners[0].x, box_corners[2].y); for (int i = 0; i < 4; i++) { float border_width = box.GetEdge(Box::BORDER, (Box::Edge) i); if (border_width <= 0) continue; vertices[0].position = box_corners[i]; vertices[1].position = box_corners[i] + box_extrusions[i] + box_extrusions[i == 0 ? 3 : i - 1]; vertices[2].position = box_corners[i == 3 ? 0 : i + 1]; vertices[3].position = vertices[2].position + box_extrusions[i] + box_extrusions[i == 3 ? 0 : i + 1]; vertices[0].colour = colours[i]; vertices[1].colour = colours[i]; vertices[2].colour = colours[i]; vertices[3].colour = colours[i]; indices[0] = index_offset; indices[1] = index_offset + 3; indices[2] = index_offset + 1; indices[3] = index_offset; indices[4] = index_offset + 2; indices[5] = index_offset + 3; vertices += 4; indices += 6; index_offset += 4; } }
static float GetSpacing(const Box& box, Box::Edge edge) { return box.GetEdge(Box::PADDING, edge) + box.GetEdge(Box::BORDER, edge) + box.GetEdge(Box::MARGIN, edge); }
// Returns the offset from the top-left corner of this box's offset element the next child block box, of the given // dimensions, will be positioned at. This will include the margins on the new block box. void LayoutBlockBox::PositionBlockBox(Vector2f& box_position, const Box& box, int clear_property) const { PositionBox(box_position, box.GetEdge(Box::MARGIN, Box::TOP), clear_property); box_position.x += box.GetEdge(Box::MARGIN, Box::LEFT); box_position.y += box.GetEdge(Box::MARGIN, Box::TOP); }