mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-02-01 09:52:25 -05:00
53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
|
|
|
|
#pragma once
|
|
|
|
#include "Axes.hpp"
|
|
#include "gui/Common.hpp"
|
|
#include <cstdint>
|
|
#include <limits>
|
|
#include <string>
|
|
|
|
namespace gui
|
|
{
|
|
/// defines both: size & position
|
|
/// size is always in: { zero_size < max_size }
|
|
/// position is always in: { min_position < zero_position < max_position }
|
|
class BoundingBox
|
|
{
|
|
public:
|
|
static constexpr Length zero_size = 0;
|
|
static constexpr Length max_size = std::numeric_limits<Length>::max();
|
|
static constexpr Length min_size = std::numeric_limits<Length>::min();
|
|
|
|
static constexpr Position zero_position = 0;
|
|
static constexpr Position max_position = std::numeric_limits<Position>::max();
|
|
static constexpr Position min_position = std::numeric_limits<Position>::min();
|
|
|
|
struct
|
|
{
|
|
Position x = zero_position, y = zero_position;
|
|
Length w = zero_size, h = zero_size;
|
|
};
|
|
|
|
BoundingBox() = default;
|
|
BoundingBox(Position x, Position y, Length w, Length h);
|
|
|
|
static bool intersect(const BoundingBox &box1, const BoundingBox &box2, BoundingBox &result);
|
|
|
|
/// set x,y,w,h to zero
|
|
void clear();
|
|
/// get size in axis - in x get width in y get height
|
|
[[nodiscard]] Length size(gui::Axis axis) const;
|
|
/// get position in axis - in x get x, in y get y
|
|
[[nodiscard]] Position pos(gui::Axis axis) const;
|
|
[[nodiscard]] std::string str() const;
|
|
/// assign width and/or height of bigger bounding box
|
|
void expandSize(const BoundingBox &box);
|
|
|
|
bool operator==(const BoundingBox &box) const;
|
|
bool operator!=(const BoundingBox &box) const;
|
|
};
|
|
} /* namespace gui */
|