the great text and type rewrite
This commit is contained in:
parent
a220e40d13
commit
d0cc3ad16a
15 changed files with 628 additions and 318 deletions
|
|
@ -26,23 +26,23 @@ import std;
|
|||
|
||||
using namespace Crafter;
|
||||
|
||||
GridElement::GridElement(std::uint_fast32_t columns, std::uint_fast32_t rows, std::int_fast32_t spacingX, std::int_fast32_t spacingY, std::int_fast32_t paddingX, std::int_fast32_t paddingY, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY), paddingX(paddingX), paddingY(paddingY) {
|
||||
GridElement::GridElement(std::uint32_t columns, std::uint32_t rows, std::int32_t spacingX, std::int32_t spacingY, std::int32_t paddingX, std::int32_t paddingY, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY), paddingX(paddingX), paddingY(paddingY) {
|
||||
|
||||
}
|
||||
|
||||
void GridElement::UpdatePositionScaled(Window& window) {
|
||||
std::int_fast32_t cellWidth = (SCALE - (paddingX * 2) - (spacingX * (columns - 1))) / columns;
|
||||
std::int_fast32_t cellHeight = (SCALE - (paddingY * 2) - (spacingY * (rows - 1))) / rows;
|
||||
std::int32_t cellWidth = (SCALE32 - (paddingX * 2) - (spacingX * (columns - 1))) / columns;
|
||||
std::int32_t cellHeight = (SCALE32 - (paddingY * 2) - (spacingY * (rows - 1))) / rows;
|
||||
|
||||
std::size_t childIndex = 0;
|
||||
for (std::uint_fast32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint_fast32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
for (std::uint32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
Transform* child = children[childIndex];
|
||||
|
||||
// Calculate position for this child
|
||||
std::int_fast32_t childX = (cellWidth * col) + (spacingX * col) + paddingX;
|
||||
std::int32_t childX = (cellWidth * col) + (spacingX * col) + paddingX;
|
||||
|
||||
std::int_fast32_t childY = (cellHeight * row) + (spacingY * row) + paddingY;
|
||||
std::int32_t childY = (cellHeight * row) + (spacingY * row) + paddingY;
|
||||
|
||||
// Apply relative positioning
|
||||
child->anchor.x = childX;
|
||||
|
|
|
|||
|
|
@ -35,17 +35,18 @@ MouseElement::MouseElement(Anchor anchor) : Transform(anchor) {
|
|||
|
||||
}
|
||||
|
||||
MouseElement::MouseElement(WindowMouse& window) : Transform({FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0}) {
|
||||
MouseElement::MouseElement(WindowMouse& window) : Transform({FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(1), FractionalToMapped<std::uint32_t>(1), FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(0), 0}) {
|
||||
window.mouseElements.push_back(this);
|
||||
}
|
||||
|
||||
MouseElement::MouseElement() : Transform({FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0}) {
|
||||
MouseElement::MouseElement() : Transform({FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(1), FractionalToMapped<std::uint32_t>(1), FractionalToMapped<std::uint32_t>(0), FractionalToMapped<std::uint32_t>(0), 0}) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MouseElement::UpdatePosition(Window& window) {
|
||||
window.ScaleMouse(*this);
|
||||
window.ScaleElement(*this);
|
||||
for(Transform* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
|
|
@ -53,6 +54,7 @@ void MouseElement::UpdatePosition(Window& window) {
|
|||
|
||||
void MouseElement::UpdatePosition(Window& window, Transform& parent) {
|
||||
window.ScaleMouse(*this, parent);
|
||||
window.ScaleElement(*this, parent);
|
||||
for(Transform* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
|
||||
Anchor::Anchor(std::int_fast32_t x, std::int_fast32_t y, std::uint_fast32_t width, std::uint_fast32_t height, std::int_fast32_t offsetX, std::int_fast32_t offsetY, std::int_fast32_t z, bool maintainAspectRatio): x(x), y(y), width(width), height(height), offsetX(offsetX), offsetY(offsetY), z(z), maintainAspectRatio(maintainAspectRatio) {
|
||||
Anchor::Anchor(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height, std::int32_t offsetX, std::int32_t offsetY, std::int32_t z, bool maintainAspectRatio): x(x), y(y), width(width), height(height), offsetX(offsetX), offsetY(offsetY), z(z), maintainAspectRatio(maintainAspectRatio) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,51 +20,59 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
module Crafter.Graphics:Window_impl;
|
||||
import :Window;
|
||||
import :Transform;
|
||||
import :MouseElement;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
Window::Window(std::int_fast32_t width, std::int_fast32_t height) : width(width), height(height) {
|
||||
Window::Window(std::int32_t width, std::int32_t height) : width(width), height(height) {
|
||||
|
||||
}
|
||||
|
||||
void Window::ScaleElement(Transform& element) {
|
||||
if(element.anchor.maintainAspectRatio) {
|
||||
if(width > height) {
|
||||
element.scaled.width = MappedToPixel(element.anchor.width, height);
|
||||
element.scaled.height = MappedToPixel(element.anchor.height, height);
|
||||
element.scaled.width = MappedToAbsolute(element.anchor.width, height);
|
||||
element.scaled.height = MappedToAbsolute(element.anchor.height, height);
|
||||
} else {
|
||||
element.scaled.width = MappedToPixel(element.anchor.width, width);
|
||||
element.scaled.height = MappedToPixel(element.anchor.height, width);
|
||||
element.scaled.width = MappedToAbsolute(element.anchor.width, width);
|
||||
element.scaled.height = MappedToAbsolute(element.anchor.height, width);
|
||||
}
|
||||
} else {
|
||||
element.scaled.width = MappedToPixel(element.anchor.width, width);
|
||||
element.scaled.height = MappedToPixel(element.anchor.height, height);
|
||||
element.scaled.width = MappedToAbsolute(element.anchor.width, width);
|
||||
element.scaled.height = MappedToAbsolute(element.anchor.height, height);
|
||||
}
|
||||
|
||||
element.scaled.x = MappedToPixel(element.anchor.x, width) - MappedToPixel(element.anchor.offsetX, element.scaled.width);
|
||||
element.scaled.y = MappedToPixel(element.anchor.y, height) - MappedToPixel(element.anchor.offsetY, element.scaled.height);
|
||||
element.scaled.x = MappedToAbsolute(element.anchor.x, width) - MappedToAbsolute(element.anchor.offsetX, element.scaled.width);
|
||||
element.scaled.y = MappedToAbsolute(element.anchor.y, height) - MappedToAbsolute(element.anchor.offsetY, element.scaled.height);
|
||||
}
|
||||
|
||||
void Window::ScaleElement(Transform& element, Transform& parent) {
|
||||
element.scaled.width = MappedToPixel(element.anchor.width, parent.scaled.width);
|
||||
element.scaled.height = MappedToPixel(element.anchor.height, parent.scaled.height);
|
||||
element.scaled.x = MappedToPixel(element.anchor.x, parent.scaled.width) - MappedToPixel(element.anchor.offsetX, element.scaled.width) + parent.scaled.x;
|
||||
element.scaled.y = MappedToPixel(element.anchor.y, parent.scaled.height) - MappedToPixel(element.anchor.offsetY, element.scaled.height) + parent.scaled.y;
|
||||
element.scaled.width = MappedToAbsolute(element.anchor.width, parent.scaled.width);
|
||||
element.scaled.height = MappedToAbsolute(element.anchor.height, parent.scaled.height);
|
||||
element.scaled.x = MappedToAbsolute(element.anchor.x, parent.scaled.width) - MappedToAbsolute(element.anchor.offsetX, element.scaled.width) + parent.scaled.x;
|
||||
element.scaled.y = MappedToAbsolute(element.anchor.y, parent.scaled.height) - MappedToAbsolute(element.anchor.offsetY, 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.anchor.width, PixelToMapped(parent.scaled.width, width)));
|
||||
element.scaled.height = BoundToBoundless(MappedToPixel(element.anchor.height, PixelToMapped(parent.scaled.height, height)));
|
||||
element.scaled.x = MappedToPixelBoundless(element.anchor.x, boundlessWidth) - MappedToPixelBoundless(element.anchor.offsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width);
|
||||
element.scaled.y = MappedToPixelBoundless(element.anchor.y, boundlessHeight) - MappedToPixelBoundless(element.anchor.offsetY, element.scaled.height) + PixelToMappedBoundless(parent.scaled.y, height);
|
||||
void Window::ScaleMouse(MouseElement& element, Transform& parent) {
|
||||
// element.scaled.width = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.width), parent.scaled.width);
|
||||
// element.scaled.height = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.height), parent.scaled.height);
|
||||
// element.scaled.x = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.x), parent.scaled.width) - MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.offsetX), element.scaled.width) + BoundToBoundless(parent.scaled.x);
|
||||
// element.scaled.y = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.y), parent.scaled.height) - MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.offsetY), element.scaled.height) + BoundToBoundless(parent.scaled.y);
|
||||
|
||||
std::uint32_t mappedParentWidth = AbsoluteToMappedBoundless(parent.scaled.width, width);
|
||||
std::uint32_t mappedParentHeight = AbsoluteToMappedBoundless(parent.scaled.height, height);
|
||||
std::uint32_t mappedParentX = AbsoluteToMappedBoundless(parent.scaled.x, width);
|
||||
std::uint32_t mappedParentY = AbsoluteToMappedBoundless(parent.scaled.y, height);
|
||||
element.mouseScaled.width = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.width), mappedParentWidth);
|
||||
element.mouseScaled.height = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.height), mappedParentHeight);
|
||||
element.mouseScaled.x = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.x), mappedParentWidth) - MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.offsetX), element.mouseScaled.width) + mappedParentX;
|
||||
element.mouseScaled.y = MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.y), mappedParentHeight) - MappedToAbsoluteBoundless(BoundToBoundless(element.anchor.offsetY), element.mouseScaled.height) + mappedParentY;
|
||||
}
|
||||
|
||||
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);
|
||||
void Window::ScaleMouse(MouseElement& element) {
|
||||
// std::int32_t boundlessWidth = PixelToMappedBoundless(parent.scaled.width, width);
|
||||
// std::int32_t boundlessHeight = PixelToMappedBoundless(parent.scaled.height, height);
|
||||
// element.scaled.width = BoundToBoundless(MappedToPixel(element.anchor.width, width));
|
||||
// element.scaled.height = BoundToBoundless(MappedToPixel(element.anchor.height, height));
|
||||
// element.scaled.x = MappedToPixelBoundless(element.anchor.x, boundlessWidth) - MappedToPixelBoundless(element.anchor.offsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width);
|
||||
|
|
@ -78,7 +86,7 @@ void Window::LogTiming() {
|
|||
std::cout << std::format("\t{} {}", reinterpret_cast<const void*>(entry.first), duration_cast<std::chrono::microseconds>(entry.second)) << std::endl;
|
||||
}
|
||||
std::cout << std::format("Render: {}", duration_cast<std::chrono::milliseconds>(totalRender)) << std::endl;
|
||||
for (const std::tuple<const RenderingElement*, std::uint_fast32_t, std::uint_fast32_t, std::chrono::nanoseconds>& entry : renderTimings) {
|
||||
for (const std::tuple<const RenderingElement*, std::uint32_t, std::uint32_t, std::chrono::nanoseconds>& entry : renderTimings) {
|
||||
std::cout << std::format("\t{} {}x{} {}", reinterpret_cast<const void*>(std::get<0>(entry)), std::get<1>(entry), std::get<2>(entry), duration_cast<std::chrono::microseconds>(std::get<3>(entry))) << std::endl;
|
||||
}
|
||||
std::cout << std::format("Total: {}", duration_cast<std::chrono::milliseconds>(totalUpdate+totalRender)) << std::endl;
|
||||
|
|
@ -112,9 +120,9 @@ void Window::LogTiming() {
|
|||
|
||||
void Window::AddDirtyRect(ScaleData scale) {
|
||||
ClipRect rect {
|
||||
.left = std::max(scale.x, std::int_fast32_t(0)),
|
||||
.left = std::max(scale.x, std::int32_t(0)),
|
||||
.right = std::min(scale.x + scale.width, width),
|
||||
.top = std::max(scale.y, std::int_fast32_t(0)),
|
||||
.top = std::max(scale.y, std::int32_t(0)),
|
||||
.bottom = std::min(scale.y + scale.height, height),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ import Crafter.Event;
|
|||
|
||||
using namespace Crafter;
|
||||
|
||||
WindowFramebuffer::WindowFramebuffer(std::uint_fast32_t width, std::uint_fast32_t height) : Window(width, height) {
|
||||
WindowFramebuffer::WindowFramebuffer(std::uint32_t width, std::uint32_t height) : Window(width, height) {
|
||||
|
||||
}
|
||||
|
||||
WindowWayland::WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height) : WindowFramebuffer(width, height) {
|
||||
WindowWayland::WindowWayland(std::uint32_t width, std::uint32_t height) : WindowFramebuffer(width, height) {
|
||||
display = wl_display_connect(NULL);
|
||||
if (display == NULL) {
|
||||
std::cerr << "failed to create display" << std::endl;
|
||||
|
|
@ -127,7 +127,7 @@ WindowWayland::WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height
|
|||
wl_surface_commit(surface);
|
||||
}
|
||||
|
||||
WindowWayland::WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height, const std::string_view title) : WindowWayland(width, height) {
|
||||
WindowWayland::WindowWayland(std::uint32_t width, std::uint32_t height, const std::string_view title) : WindowWayland(width, height) {
|
||||
xdg_toplevel_set_title(xdgToplevel, title.data());
|
||||
}
|
||||
|
||||
|
|
@ -182,17 +182,17 @@ void WindowWayland::RenderElement(Transform* transform) {
|
|||
dirty.bottom = std::min(element->scaled.y+element->scaled.height, dirty.bottom);
|
||||
|
||||
const Pixel_BU8_GU8_RU8_AU8* src_buffer = element->buffer.data();
|
||||
std::int_fast32_t src_width = element->scaled.width;
|
||||
std::int_fast32_t src_height = element->scaled.height;
|
||||
std::int32_t src_width = element->scaled.width;
|
||||
std::int32_t src_height = element->scaled.height;
|
||||
|
||||
switch (element->opaque) {
|
||||
case OpaqueType::FullyOpaque:
|
||||
// For fully opaque, just copy pixels directly
|
||||
for (std::int_fast32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int_fast32_t src_y = y - element->scaled.y;
|
||||
for (std::int32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int32_t src_y = y - element->scaled.y;
|
||||
|
||||
for (std::int_fast32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int_fast32_t src_x = x - element->scaled.x;
|
||||
for (std::int32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int32_t src_x = x - element->scaled.x;
|
||||
|
||||
framebuffer[y * width + x] = src_buffer[src_y * src_width + src_x];
|
||||
}
|
||||
|
|
@ -201,11 +201,11 @@ void WindowWayland::RenderElement(Transform* transform) {
|
|||
|
||||
case OpaqueType::SemiOpaque:
|
||||
// For semi-opaque, we can avoid blending when alpha is 0 or 255
|
||||
for (std::int_fast32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int_fast32_t src_y = y - element->scaled.y;
|
||||
for (std::int32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int32_t src_y = y - element->scaled.y;
|
||||
|
||||
for (std::int_fast32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int_fast32_t src_x = x - element->scaled.x;
|
||||
for (std::int32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int32_t src_x = x - element->scaled.x;
|
||||
Pixel_BU8_GU8_RU8_AU8 src_pixel = src_buffer[src_y * src_width + src_x];
|
||||
|
||||
if (src_pixel.a == 0) {
|
||||
|
|
@ -218,11 +218,11 @@ void WindowWayland::RenderElement(Transform* transform) {
|
|||
|
||||
case OpaqueType::Transparent:
|
||||
// For transparent, always perform blending
|
||||
for (std::int_fast32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int_fast32_t src_y = y - element->scaled.y;
|
||||
for (std::int32_t y = dirty.top; y < dirty.bottom; y++) {
|
||||
std::int32_t src_y = y - element->scaled.y;
|
||||
|
||||
for (std::int_fast32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int_fast32_t src_x = x - element->scaled.x;
|
||||
for (std::int32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int32_t src_x = x - element->scaled.x;
|
||||
blend_pixel_optimized(framebuffer[y * width + x], src_buffer[src_y * src_width + src_x]);
|
||||
}
|
||||
}
|
||||
|
|
@ -248,9 +248,9 @@ void WindowWayland::Render() {
|
|||
|
||||
//std::vector<ClipRect> newClip;
|
||||
|
||||
// for (std::uint_fast32_t i = 0; i < dirtyRects.size(); i++) {
|
||||
// for (std::uint32_t i = 0; i < dirtyRects.size(); i++) {
|
||||
// ClipRect rect = dirtyRects[i];
|
||||
// for (std::uint_fast32_t i2 = i + 1; i2 < dirtyRects.size(); i2++) {
|
||||
// for (std::uint32_t i2 = i + 1; i2 < dirtyRects.size(); i2++) {
|
||||
// ClipRect existing = dirtyRects[i2];
|
||||
// if(rect.bottom >= existing.top && rect.top <= existing.top) {
|
||||
// newClip.push_back({
|
||||
|
|
@ -337,8 +337,8 @@ void WindowWayland::Render() {
|
|||
// color.r, color.g, color.b, color.a
|
||||
// ) << std::endl;
|
||||
|
||||
// for (std::int_fast32_t y = rect.top; y < rect.bottom; ++y) {
|
||||
// for (std::int_fast32_t x = rect.left; x < rect.right; ++x) {
|
||||
// for (std::int32_t y = rect.top; y < rect.bottom; ++y) {
|
||||
// for (std::int32_t x = rect.left; x < rect.right; ++x) {
|
||||
// framebuffer[y * width + x] = color;
|
||||
// }
|
||||
// }
|
||||
|
|
@ -348,8 +348,8 @@ void WindowWayland::Render() {
|
|||
|
||||
if (!dirtyRects.empty()) {
|
||||
for (ClipRect rect : dirtyRects) {
|
||||
for (std::int_fast32_t y = rect.top; y < rect.bottom; y++) {
|
||||
for (std::int_fast32_t x = rect.left; x < rect.right; x++) {
|
||||
for (std::int32_t y = rect.top; y < rect.bottom; y++) {
|
||||
for (std::int32_t x = rect.left; x < rect.right; x++) {
|
||||
framebuffer[y * width + x] = {0, 0, 0, 0};
|
||||
}
|
||||
}
|
||||
|
|
@ -392,7 +392,7 @@ void WindowWayland::SetTitle(const std::string_view title) {
|
|||
xdg_toplevel_set_title(xdgToplevel, title.data());
|
||||
}
|
||||
|
||||
void WindowWayland::Resize(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
void WindowWayland::Resize(std::uint32_t width, std::uint32_t height) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -400,11 +400,11 @@ void WindowWayland::Write(Pixel_BU8_GU8_RU8_AU8* pixels) {
|
|||
std::memcpy(framebuffer, pixels, width*height*sizeof(Pixel_BU8_GU8_RU8_AU8));
|
||||
}
|
||||
|
||||
void WindowWayland::Write(std::uint_fast32_t x, std::uint_fast32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) {
|
||||
void WindowWayland::Write(std::uint32_t x, std::uint32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) {
|
||||
framebuffer[y * width + x] = pixel;
|
||||
}
|
||||
|
||||
Pixel_BU8_GU8_RU8_AU8 WindowWayland::Read(std::uint_fast32_t x, std::uint_fast32_t y) const{
|
||||
Pixel_BU8_GU8_RU8_AU8 WindowWayland::Read(std::uint32_t x, std::uint32_t y) const{
|
||||
return framebuffer[y * width + x];
|
||||
}
|
||||
|
||||
|
|
@ -477,14 +477,15 @@ void WindowWayland::wl_surface_frame_done(void* data, struct wl_callback *cb, ui
|
|||
|
||||
void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state) {
|
||||
WindowWayland* window = reinterpret_cast<WindowWayland*>(data);
|
||||
|
||||
if (button == BTN_LEFT) {
|
||||
if(state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
window->mouseLeftHeld = true;
|
||||
window->onMouseLeftClick.Invoke(window->currentMousePos);
|
||||
for(MouseElement* element : window->mouseElements) {
|
||||
if(element) {
|
||||
if(window->currentMousePos.x >= element->scaled.x && window->currentMousePos.x <= element->scaled.x+element->scaled.width && window->currentMousePos.y > element->scaled.y && window->currentMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseLeftClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(window->currentMousePos.x >= element->mouseScaled.x && window->currentMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->currentMousePos.y > element->mouseScaled.y && window->currentMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseLeftClick.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -493,8 +494,8 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
window->onMouseLeftRelease.Invoke(window->currentMousePos);
|
||||
for(MouseElement* element : window->mouseElements) {
|
||||
if(element) {
|
||||
if(window->currentMousePos.x >= element->scaled.x && window->currentMousePos.x <= element->scaled.x+element->scaled.width && window->currentMousePos.y > element->scaled.y && window->currentMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseLeftRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(window->currentMousePos.x >= element->mouseScaled.x && window->currentMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->currentMousePos.y > element->mouseScaled.y && window->currentMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseLeftRelease.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -505,8 +506,8 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
window->onMouseRightClick.Invoke(window->currentMousePos);
|
||||
for(MouseElement* element : window->mouseElements) {
|
||||
if(element) {
|
||||
if(window->currentMousePos.x >= element->scaled.x && window->currentMousePos.x <= element->scaled.x+element->scaled.width && window->currentMousePos.y > element->scaled.y && window->currentMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseRightClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(window->currentMousePos.x >= element->mouseScaled.x && window->currentMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->currentMousePos.y > element->mouseScaled.y && window->currentMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseRightClick.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -515,8 +516,8 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
window->onMouseRightRelease.Invoke(window->currentMousePos);
|
||||
for(MouseElement* element : window->mouseElements) {
|
||||
if(element) {
|
||||
if(window->currentMousePos.x >= element->scaled.x && window->currentMousePos.x <= element->scaled.x+element->scaled.width && window->currentMousePos.y > element->scaled.y && window->currentMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseRightRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(window->currentMousePos.x >= element->mouseScaled.x && window->currentMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->currentMousePos.y > element->mouseScaled.y && window->currentMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseRightRelease.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -529,20 +530,20 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
|
||||
void WindowWayland::PointerListenerHandleMotion(void* data, wl_pointer* wl_pointer, uint time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||
WindowWayland* window = reinterpret_cast<WindowWayland*>(data);
|
||||
MousePoint pos = {FractionalToMappedBoundless((wl_fixed_to_double(surface_x) * window->scale) / window->width), FractionalToMappedBoundless((wl_fixed_to_double(surface_y) * window->scale) / window->height)};
|
||||
MousePoint pos = {FractionalToMappedBoundless<std::uint32_t>((wl_fixed_to_double(surface_x) * window->scale) / window->width), FractionalToMappedBoundless<std::uint32_t>((wl_fixed_to_double(surface_y) * window->scale) / window->height)};
|
||||
window->lastMousePos = window->currentMousePos;
|
||||
window->currentMousePos = pos;
|
||||
window->mouseDelta = {window->currentMousePos.x-window->lastMousePos.x, window->currentMousePos.y-window->lastMousePos.y};
|
||||
window->onMouseMove.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
|
||||
for(MouseElement* element : window->mouseElements) {
|
||||
if(element) {
|
||||
if(window->currentMousePos.x >= element->scaled.x && window->currentMousePos.x <= element->scaled.x+element->scaled.width && window->currentMousePos.y > element->scaled.y && window->currentMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseMove.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(!(window->lastMousePos.x >= element->scaled.x && window->lastMousePos.x <= element->scaled.x+element->scaled.width && window->lastMousePos.y > element->scaled.y && window->lastMousePos.y < element->scaled.y+element->scaled.height)) {
|
||||
element->onMouseEnter.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
if(window->currentMousePos.x >= element->mouseScaled.x && window->currentMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->currentMousePos.y > element->mouseScaled.y && window->currentMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseMove.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
if(!(window->lastMousePos.x >= element->mouseScaled.x && window->lastMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->lastMousePos.y > element->mouseScaled.y && window->lastMousePos.y < element->mouseScaled.y+element->mouseScaled.height)) {
|
||||
element->onMouseEnter.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
} else if(window->lastMousePos.x >= element->scaled.x && window->lastMousePos.x <= element->scaled.x+element->scaled.width && window->lastMousePos.y > element->scaled.y && window->lastMousePos.y < element->scaled.y+element->scaled.height) {
|
||||
element->onMouseLeave.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->scaled.x) / element->scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->scaled.y) / element->scaled.height)});
|
||||
} else if(window->lastMousePos.x >= element->mouseScaled.x && window->lastMousePos.x <= element->mouseScaled.x+element->mouseScaled.width && window->lastMousePos.y > element->mouseScaled.y && window->lastMousePos.y < element->mouseScaled.y+element->mouseScaled.height) {
|
||||
element->onMouseLeave.Invoke({AbsoluteToMappedBoundless(window->currentMousePos.x - element->mouseScaled.x, element->mouseScaled.width), AbsoluteToMappedBoundless(window->currentMousePos.y - element->mouseScaled.y, element->mouseScaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -556,7 +557,7 @@ void WindowWayland::PointerListenerHandleEnter(void* data, wl_pointer* wl_pointe
|
|||
|
||||
void WindowWayland::PointerListenerHandleLeave(void* data, wl_pointer*, std::uint32_t, wl_surface*) {
|
||||
WindowWayland* window = reinterpret_cast<WindowWayland*>(data);
|
||||
window->onMouseEnter.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
|
||||
window->onMouseLeave.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
|
||||
}
|
||||
|
||||
void WindowWayland::PointerListenerHandleAxis(void*, wl_pointer*, std::uint32_t, std::uint32_t, wl_fixed_t value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue