wayland rewrite complete
This commit is contained in:
parent
5ff43e240c
commit
721ff8f42f
8 changed files with 134 additions and 87 deletions
|
|
@ -23,8 +23,8 @@ import std;
|
|||
|
||||
namespace Crafter {
|
||||
export struct MousePoint {
|
||||
std::uint_fast32_t x;
|
||||
std::uint_fast32_t y;
|
||||
std::int_fast32_t x;
|
||||
std::int_fast32_t y;
|
||||
};
|
||||
|
||||
export struct MouseMoveEvent {
|
||||
|
|
@ -101,22 +101,45 @@ namespace Crafter {
|
|||
export constexpr std::int_fast32_t SCALE = std::numeric_limits<std::int_fast32_t>::max() / BOUND;
|
||||
export constexpr double SCALEDOUBLE = static_cast<double>(std::numeric_limits<std::int_fast32_t>::max()) / BOUND;
|
||||
|
||||
export constexpr std::int_fast32_t SCALEBOUNDLESS = std::numeric_limits<std::int_fast32_t>::max();
|
||||
export constexpr double SCALEDOUBLEBOUNDLESS = static_cast<double>(std::numeric_limits<std::int_fast32_t>::max());
|
||||
|
||||
export constexpr std::int_fast32_t FractionalToMapped(double f) {
|
||||
return std::int_fast32_t(f * SCALEDOUBLE);
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t MappedToPixel(std::int_fast32_t mapped, std::int_fast32_t width) {
|
||||
return mapped / (SCALE / width);
|
||||
}
|
||||
|
||||
export constexpr double MappedToFractional(std::int_fast32_t mapped) {
|
||||
return static_cast<double>(mapped) / SCALEDOUBLE;
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t MappedToPixel(std::int_fast32_t mapped, std::int_fast32_t width) {
|
||||
return mapped / (SCALE / width);
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t PixelToMapped(std::int_fast32_t pixel, std::int_fast32_t width) {
|
||||
return pixel * (SCALE / width);
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t BoundToBoundless(std::int_fast32_t bound) {
|
||||
return bound * BOUND;
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t FractionalToMappedBoundless(double f) {
|
||||
return std::int_fast32_t(f * SCALEDOUBLEBOUNDLESS);
|
||||
}
|
||||
|
||||
export constexpr double MappedToFractionalBoundless(std::int_fast32_t mapped) {
|
||||
return static_cast<double>(mapped) / SCALEDOUBLEBOUNDLESS;
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t MappedToPixelBoundless(std::int_fast32_t mapped, std::int_fast32_t width) {
|
||||
return mapped / (SCALEBOUNDLESS / width);
|
||||
}
|
||||
|
||||
export constexpr std::int_fast32_t PixelToMappedBoundless(std::int_fast32_t pixel, std::int_fast32_t width) {
|
||||
return pixel * (SCALEBOUNDLESS / width);
|
||||
}
|
||||
|
||||
// export constexpr double bound = 10;
|
||||
|
||||
// export constexpr std::uint_fast32_t FractionalToMapped(double fractional) {
|
||||
|
|
@ -166,8 +189,4 @@ namespace Crafter {
|
|||
|
||||
// return static_cast<std::int_fast32_t>(t * static_cast<double>(size));
|
||||
// }
|
||||
|
||||
export constexpr std::uint_fast32_t PixelToMapped(double pixel, std::uint_fast32_t size) {
|
||||
return static_cast<std::uint_fast32_t>((pixel / size) * static_cast<double>((std::numeric_limits<std::uint_fast32_t>::max() / 10)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ import Crafter.Event;
|
|||
import :Types;
|
||||
|
||||
export namespace Crafter {
|
||||
class Window;
|
||||
class UiElement {
|
||||
public:
|
||||
class Transform {
|
||||
public:
|
||||
std::int_fast32_t z;
|
||||
std::int_fast32_t anchorX;
|
||||
std::int_fast32_t anchorY;
|
||||
|
|
@ -34,19 +33,26 @@ export namespace Crafter {
|
|||
std::uint_fast32_t relativeWidth;
|
||||
std::uint_fast32_t relativeHeight;
|
||||
bool ignoreScaling;
|
||||
std::vector<UiElement*> children;
|
||||
ScaleData scaled;
|
||||
Transform(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);
|
||||
};
|
||||
|
||||
class WindowFramebuffer;
|
||||
class UiElement {
|
||||
public:
|
||||
Transform transform;
|
||||
std::vector<UiElement*> children;
|
||||
|
||||
UiElement(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);
|
||||
UiElement(UiElement&) = delete;
|
||||
UiElement& operator=(UiElement&) = delete;
|
||||
// void UpdatePosition(Window& window);
|
||||
// void UpdatePosition(UiElement& parent);
|
||||
void UpdatePosition(WindowFramebuffer& window);
|
||||
void UpdatePosition(WindowFramebuffer& window, UiElement& parent);
|
||||
};
|
||||
|
||||
class UiElementMouse {
|
||||
public:
|
||||
ScaleData clickArea;
|
||||
Transform transform;
|
||||
Event<MouseMoveEvent> onMouseMove;
|
||||
Event<MouseMoveEvent> onMouseEnter;
|
||||
Event<MouseMoveEvent> onMouseLeave;
|
||||
|
|
@ -56,6 +62,7 @@ export namespace Crafter {
|
|||
Event<MousePoint> onMouseLeftHold;
|
||||
Event<MousePoint> onMouseRightRelease;
|
||||
Event<MousePoint> onMouseLeftRelease;
|
||||
UiElementMouse(std::int_fast32_t anchorX = FractionalToMapped(0), std::int_fast32_t anchorY = FractionalToMapped(0), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0), std::int_fast32_t anchorOffsetY = FractionalToMapped(0), std::int_fast32_t z = 0, bool ignoreScaling = false);
|
||||
};
|
||||
|
||||
class UiElementBuffer {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ export namespace Crafter {
|
|||
virtual void StartSync() = 0;
|
||||
virtual void StartUpdate() = 0;
|
||||
virtual void StopUpdate() = 0;
|
||||
ScaleData ScaleElement(const UiElement& element);
|
||||
};
|
||||
|
||||
class WindowKeyboard {
|
||||
|
|
@ -99,6 +98,7 @@ export namespace Crafter {
|
|||
virtual void SetTitle(const std::string_view title) = 0;
|
||||
};
|
||||
|
||||
class Transform;
|
||||
class WindowFramebuffer {
|
||||
public:
|
||||
std::uint_fast32_t width;
|
||||
|
|
@ -113,7 +113,9 @@ export namespace Crafter {
|
|||
virtual Pixel_BU8_GU8_RU8_AU8* Get() = 0;
|
||||
virtual void Store() = 0;
|
||||
virtual void Render() = 0;
|
||||
ScaleData ScaleElementAbsolute(const UiElement& element);
|
||||
void ScaleElement(Transform& element, Transform& parent);
|
||||
void ScaleElement(Transform& element);
|
||||
void ScaleMouse(Transform& element, Transform& parent);
|
||||
};
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WAYLAND
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue