actually sensible classes
This commit is contained in:
parent
9bbefbc021
commit
c3b8761102
13 changed files with 128 additions and 152 deletions
|
|
@ -25,9 +25,9 @@ import :Transform;
|
|||
|
||||
export namespace Crafter {
|
||||
class Window;
|
||||
class MouseElement {
|
||||
class WindowMouse;
|
||||
class MouseElement : public Transform {
|
||||
public:
|
||||
Transform transform;
|
||||
Event<MouseMoveEvent> onMouseMove;
|
||||
Event<MouseMoveEvent> onMouseEnter;
|
||||
Event<MouseMoveEvent> onMouseLeave;
|
||||
|
|
@ -38,11 +38,11 @@ export namespace Crafter {
|
|||
Event<MousePoint> onMouseRightRelease;
|
||||
Event<MousePoint> onMouseLeftRelease;
|
||||
|
||||
MouseElement(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
MouseElement(Transform transform);
|
||||
MouseElement(WindowMouse& window, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
MouseElement(std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
MouseElement(MouseElement&) = delete;
|
||||
MouseElement& operator=(MouseElement&) = delete;
|
||||
void UpdatePosition(Window& window);
|
||||
void UpdatePosition(Window& window, Transform& parent);
|
||||
void UpdatePosition(Window& window) override;
|
||||
void UpdatePosition(Window& window, Transform& parent) override;
|
||||
};
|
||||
}
|
||||
|
|
@ -25,20 +25,18 @@ import :Types;
|
|||
export namespace Crafter {
|
||||
class Window;
|
||||
class Font;
|
||||
class RenderingElement {
|
||||
class RenderingElement : public Transform {
|
||||
public:
|
||||
Transform transform;
|
||||
std::vector<Pixel_BU8_GU8_RU8_AU8> buffer;
|
||||
std::vector<Pixel_BU8_GU8_RU8_AU8> scaled;
|
||||
std::vector<Pixel_BU8_GU8_RU8_AU8> bufferScaled;
|
||||
std::uint_fast32_t bufferWidth;
|
||||
std::uint_fast32_t bufferHeight;
|
||||
|
||||
RenderingElement(Transform transform);
|
||||
RenderingElement(Transform transform, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight);
|
||||
RenderingElement(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(const std::string_view imagePath, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement();
|
||||
RenderingElement(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling);
|
||||
RenderingElement(std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(const std::string_view imagePath, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingElement(RenderingElement&) = delete;
|
||||
RenderingElement& operator=(RenderingElement&) = delete;
|
||||
|
||||
|
|
@ -46,7 +44,7 @@ export namespace Crafter {
|
|||
void CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const;
|
||||
void RenderText(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font);
|
||||
void RenderImage(const std::string_view path);
|
||||
void UpdatePosition(Window& window);
|
||||
void UpdatePosition(Window& window, Transform& parent);
|
||||
void UpdatePosition(Window& window) override;
|
||||
void UpdatePosition(Window& window, Transform& parent) override;
|
||||
};
|
||||
}
|
||||
|
|
@ -22,9 +22,9 @@ import std;
|
|||
import :Types;
|
||||
|
||||
export namespace Crafter {
|
||||
class Window;
|
||||
class Transform {
|
||||
public:
|
||||
void* element;
|
||||
std::int_fast32_t z;
|
||||
std::int_fast32_t anchorX;
|
||||
std::int_fast32_t anchorY;
|
||||
|
|
@ -35,6 +35,11 @@ export namespace Crafter {
|
|||
bool ignoreScaling;
|
||||
ScaleData scaled;
|
||||
std::vector<Transform*> children;
|
||||
Transform(void* element, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
Transform(std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
Transform(Transform&) = delete;
|
||||
Transform& operator=(Transform&) = delete;
|
||||
virtual ~Transform() = default;
|
||||
virtual void UpdatePosition(Window& window);
|
||||
virtual void UpdatePosition(Window& window, Transform& parent);
|
||||
};
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
export module Crafter.Graphics:UiElement;
|
||||
import std;
|
||||
import Crafter.Event;
|
||||
import :Types;
|
||||
import :Transform;
|
||||
import :RenderingElement;
|
||||
import :MouseElement;
|
||||
|
||||
export namespace Crafter {
|
||||
// Combined UI element that can have both rendering and interaction
|
||||
class RenderingMouseElement {
|
||||
public:
|
||||
RenderingElement rendering;
|
||||
MouseElement mouse;
|
||||
RenderingMouseElement(const std::string_view imagePath, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingMouseElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingMouseElement(std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingMouseElement(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
RenderingMouseElement(Transform transform, Transform mouseTransform);
|
||||
RenderingMouseElement(RenderingMouseElement&) = delete;
|
||||
RenderingMouseElement& operator=(RenderingMouseElement&) = delete;
|
||||
void UpdatePosition(Window& window);
|
||||
void UpdatePosition(Window& window, Transform& parent);
|
||||
};
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ export namespace Crafter {
|
|||
std::uint_fast32_t width;
|
||||
std::uint_fast32_t height;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastFrameBegin;
|
||||
std::vector<Transform*> elements;
|
||||
Event<void> onClose;
|
||||
Event<FrameTime> onUpdate;
|
||||
bool open = true;
|
||||
|
|
@ -126,7 +127,6 @@ export namespace Crafter {
|
|||
class WindowWayland final : public WindowKeyboard, public WindowMouse, public WindowFramebuffer, public WindowTitle {
|
||||
public:
|
||||
Pixel_BU8_GU8_RU8_AU8* framebuffer = nullptr;
|
||||
std::vector<RenderingElement*> elements;
|
||||
WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height);
|
||||
WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height, const std::string_view title);
|
||||
~WindowWayland();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ export import :Window;
|
|||
export import :Transform;
|
||||
export import :RenderingElement;
|
||||
export import :MouseElement;
|
||||
export import :UiElement;
|
||||
export import :Types;
|
||||
export import :Font;
|
||||
export import :Shm;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue