18 std::shared_ptr<spdlog::logger> logger)
28 logger(
std::move(logger)),
29 newBlockChoiceDelegate(newBlockChoiceDelegate),
30 blockLifecycleManagerDelegate(blockLifecycleManagerDelegate),
31 windowDelegate(windowDelegate) {
68 if (
rightX > windowSize.width) {
73 if (
bottomY > windowSize.height) {
82 [[maybe_unused]]
bool isHovered) {
86 if (outputPorts.size() != 1) {
92 std::ostringstream oss;
93 oss << std::scientific
123 return std::make_optional(port);
129 std::optional<const business_logic::elements::structures::Port*>
133 if (
auto maybePort =
checkPort(&port, point)) {
140 if (
auto maybePort =
checkPort(&port, point)) {
154 return maybeValueIt->second;
Delegate that manages the lifecycles of blocks.
virtual void onBlockDeleted(const business_logic::elements::blocks::BaseBlock *block)=0
Called when a block is deleted.
Delegate that is notified when a new block is chosen to be added to the canvas.
The delegate for the window.
virtual geometry::Size2D getWindowSize()=0
Get the window size.
business_logic::delegate::IBlockLifecycleManagerDelegate * blockLifecycleManagerDelegate
std::optional< const structures::Port * > checkPort(const structures::Port *port, const geometry::Point2D &point) const
Checks if a point is inside the hitbox of a port.
std::shared_ptr< spdlog::logger > logger
std::unordered_map< const structures::Port *, geometry::Point2D > portCoordinates
Caches the (center) coordinates of the ports of the block; must be updated after rendering.
void onDragStart() override
Called when dragging starts.
void cacheCornerCoordinates()
Caches the bottom right corner of the block, so that it is not recalculated every time isHovered() is...
business_logic::delegate::IWindowDelegate * windowDelegate
BaseBlock(int cx, int cy, int blockWidth, int blockHeight, business_logic::delegate::INewBlockChoiceDelegate *newBlockChoiceDelegate, business_logic::delegate::IBlockLifecycleManagerDelegate *blockLifecycleManagerDelegate, business_logic::delegate::IWindowDelegate *windowDelegate, std::shared_ptr< spdlog::logger > logger)
Constructor.
const FloatingPoint & getPortValue(const structures::Port *port) const
Gets the value of the port.
std::unordered_map< const structures::Port *, geometry::Point2D > & getPortCoordinates()
Gets the cache of (center) coordinates of the ports of the block; updated after rendering.
virtual const std::vector< structures::Port > & getOutputPorts() const =0
Gets the output ports of the block.
void onDragEnd() override
Called when dragging ends.
~BaseBlock() noexcept override
static const FloatingPoint NaN
std::optional< const structures::Port * > getPortAtCoordinates(const geometry::Point2D &point) const
Gets the port at given coordinates.
virtual const std::vector< structures::Port > & getInputPorts() const =0
Gets the input ports of the block.
std::unordered_map< const structures::Port *, FloatingPoint > portValues
The registry of port values.
void updateWidthHeight(int newWidth, int newHeight)
Updates the width and height of the block.
void onDragProgress(int x, int y) override
Called during dragging.
virtual std::string getSelfId() const =0
virtual std::optional< std::string > getValueToRenderAboveBlock(bool isHovered)
Wrapper that gets the value of the output port above the block; if more or less than 1 output port is...
void setPortValue(const business_logic::elements::structures::Port *port, const FloatingPoint &value)
Sets the value of the port.
constexpr int TOTAL_PORT_HITBOX_RADIUS
constexpr int DEFAULT_VALUE_DISPLAY_PRECISION
The base classes and structs for elements.
bool isCircleHovered(int mouseX, int mouseY, int cX, int cY, int radius)
Check if a point is within a circle.
Represents a port on a block.
A basic struct representing a 2D point.
boost::multiprecision::cpp_dec_float_50 FloatingPoint