/* 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:Window; import std; import Crafter.Event; import :UiElement; import :Types; export namespace Crafter { struct ScaleData { std::int32_t x; std::int32_t y; std::int32_t width; std::int32_t height; }; /** * @brief Represents a GUI window handling input events, mouse states, keyboard states, and UI elements. * * The Window class encapsulates event handling for mouse and keyboard interactions, * manages the state of the mouse and keyboard, and stores UI elements contained within the window. * It also holds window-specific properties such as name, dimensions, and scaling factor. */ class Window { public: Event onMouseRightClick; Event onMouseLeftClick; Event onMouseRightHold; Event onMouseLeftHold; Event onMouseRightRelease; Event onMouseLeftRelease; Event onMouseMove; Event onMouseEnter; Event onMouseLeave; Event onMouseScroll; Event onClose; MousePoint currentMousePos; MousePoint lastMousePos; MousePoint mouseDelta; bool mouseLeftHeld = false; bool mouseRightHeld = false; bool heldkeys[255] = {}; Event onKeyDown[255]; Event onKeyHold[255]; Event onKeyUp[255]; Event onAnyKeyDown; Event onAnyKeyHold; Event onAnyKeyUp; std::vector elements; std::string name; std::uint32_t width; std::uint32_t height; float scale = 1; bool open = true; /** * @brief Constructs a Window with a given name and dimensions. * @param name The title of the window. * @param width The width of the window in pixels. * @param height The height of the window in pixels. */ Window(std::string name, std::uint32_t width, std::uint32_t height); /** * @brief Calculates the real position and size of an UiElement * * @param element The UI element to get the position from. * @return The actual position and size of the element after scaling. */ ScaleData ScaleElement(const UiElement& element); }; }