/* Crafter®.Graphics Copyright (C) 2025 Catcrafts® Catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ export module Crafter.Graphics:UiElement; import std; import Crafter.Event; import :Types; namespace Crafter { /** * @brief General use UiElement for handeling input events. * Add to a window's elements member to start recieving events. */ export class UiElement { public: Event onMouseMove; Event onMouseEnter; Event onMouseLeave; Event onMouseRightClick; Event onMouseLeftClick; Event onMouseRightHold; Event onMouseLeftHold; Event onMouseRightRelease; Event onMouseLeftRelease; float z; float anchorX; float anchorY; bool useRelativeSize; bool ignoreScaling; std::uint32_t bufferWidth; std::uint32_t bufferHeight; std::uint32_t absoluteWidth; std::uint32_t absoluteHeight; float relativeWidth; float relativeHeight; float anchorOffsetX; float anchorOffsetY; std::vector buffer; std::vector children; /** * @brief Constructs a UiElement with absolute dimensions * @param anchorX Relative position where this elements x anchor (top-left) is placed to its parent x anchor * @param anchorY Relative position where this elements y anchor (top-left) is placed to its parent y anchor * @param bufferWidth The width of this elements pixel buffer * @param bufferHeight The height of this elements pixel buffer * @param absoluteWidth The absolute x size in pixels this element should be scaled to * @param absoluteHeight The absolute y size in pixels this element should be scaled to * @param anchorOffsetX The amount this element's anchor should be offset from the top left corner (0.5 to in the middle) * @param anchorOffsetY The amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle) * @param z This elements Z position * @param ignoreScaling Wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale */ UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, std::uint32_t absoluteWidth, std::uint32_t absoluteHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); /** * @brief Constructs a UiElement with relative dimensions * @param anchorX Relative position where this elements x anchor (top-left) is placed to its parent x anchor * @param anchorY Relative position where this elements y anchor (top-left) is placed to its parent y anchor * @param bufferWidth The width of this elements pixel buffer * @param bufferHeight The height of this elements pixel buffer * @param relativeWidth The relative x size this element should be scaled to compared to its parent * @param relativeHeight The relative y size this element should be scaled to compared to its parent * @param anchorOffsetX The amount this element's anchor should be offset from the top left corner (0.5 to in the middle) * @param anchorOffsetY The amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle) * @param z This elements Z position * @param ignoreScaling Wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale */ UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); }; }