2025-05-07 19:21:51 +02:00
|
|
|
/*
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-16 00:43:33 +02:00
|
|
|
module;
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
export module Crafter.Graphics:UiElement;
|
|
|
|
|
import Crafter.Event;
|
|
|
|
|
import :Types;
|
|
|
|
|
|
2025-06-14 01:45:33 +02:00
|
|
|
namespace Crafter {
|
|
|
|
|
export class UiElement {
|
2025-04-16 00:43:33 +02:00
|
|
|
public:
|
|
|
|
|
Event<MouseMoveEvent> onMouseMove;
|
|
|
|
|
Event<MouseMoveEvent> onMouseEnter;
|
|
|
|
|
Event<MouseMoveEvent> onMouseLeave;
|
|
|
|
|
Event<MousePoint> onMouseRightClick;
|
|
|
|
|
Event<MousePoint> onMouseLeftClick;
|
|
|
|
|
Event<MousePoint> onMouseRightHold;
|
|
|
|
|
Event<MousePoint> onMouseLeftHold;
|
|
|
|
|
Event<MousePoint> onMouseRightRelease;
|
|
|
|
|
Event<MousePoint> 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;
|
2025-06-13 23:59:36 +02:00
|
|
|
std::vector<Pixel_BU8_GU8_RU8_AU8> buffer;
|
2025-05-25 23:04:56 +02:00
|
|
|
std::vector<UiElement> children;
|
2025-06-14 01:45:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2025-04-16 00:43:33 +02:00
|
|
|
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);
|
2025-06-14 01:45:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2025-04-16 00:43:33 +02:00
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
}
|