the great text and type rewrite
This commit is contained in:
parent
a220e40d13
commit
d0cc3ad16a
15 changed files with 628 additions and 318 deletions
|
|
@ -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