/* 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 version 3.0 as published by the Free Software Foundation; 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 */ module Crafter.Graphics:Window_impl; import :Window; import :Transform; import std; using namespace Crafter; Window::Window(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) { } void Window::ScaleElement(Transform& element) { element.scaled.width = MappedToPixel(element.relativeWidth, width); element.scaled.height = MappedToPixel(element.relativeHeight, height); element.scaled.x = MappedToPixel(element.anchorX, width) - MappedToPixel(element.anchorOffsetX, element.scaled.width); element.scaled.y = MappedToPixel(element.anchorY, height) - MappedToPixel(element.anchorOffsetY, element.scaled.height); } void Window::ScaleElement(Transform& element, Transform& parent) { element.scaled.width = MappedToPixel(element.relativeWidth, parent.scaled.width); element.scaled.height = MappedToPixel(element.relativeHeight, parent.scaled.height); element.scaled.x = MappedToPixel(element.anchorX, parent.scaled.width) - MappedToPixel(element.anchorOffsetX, element.scaled.width) + parent.scaled.x; element.scaled.y = MappedToPixel(element.anchorY, parent.scaled.height) - MappedToPixel(element.anchorOffsetY, element.scaled.height) + parent.scaled.y; } void Window::ScaleMouse(Transform& element, Transform& parent) { std::int_fast32_t boundlessWidth = PixelToMappedBoundless(parent.scaled.width, width); std::int_fast32_t boundlessHeight = PixelToMappedBoundless(parent.scaled.height, height); element.scaled.width = BoundToBoundless(MappedToPixel(element.relativeWidth, PixelToMapped(parent.scaled.width, width))); element.scaled.height = BoundToBoundless(MappedToPixel(element.relativeHeight, PixelToMapped(parent.scaled.height, height))); element.scaled.x = MappedToPixelBoundless(element.anchorX, boundlessWidth) - MappedToPixelBoundless(element.anchorOffsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width); element.scaled.y = MappedToPixelBoundless(element.anchorY, boundlessHeight) - MappedToPixelBoundless(element.anchorOffsetY, element.scaled.height) + PixelToMappedBoundless(parent.scaled.y, height); } void Window::ScaleMouse(Transform& element) { // std::int_fast32_t boundlessWidth = PixelToMappedBoundless(parent.scaled.width, width); // std::int_fast32_t boundlessHeight = PixelToMappedBoundless(parent.scaled.height, height); // element.scaled.width = BoundToBoundless(MappedToPixel(element.relativeWidth, width)); // element.scaled.height = BoundToBoundless(MappedToPixel(element.relativeHeight, height)); // element.scaled.x = MappedToPixelBoundless(element.anchorX, boundlessWidth) - MappedToPixelBoundless(element.anchorOffsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width); // element.scaled.y = MappedToPixelBoundless(element.anchorY, boundlessHeight) - MappedToPixelBoundless(element.anchorOffsetY, element.scaled.height) + PixelToMappedBoundless(parent.scaled.y, height); }