2025-05-07 19:21:51 +02:00
|
|
|
/*
|
|
|
|
|
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 as published by the Free Software Foundation; either
|
|
|
|
|
version 3.0 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-19 15:46:26 +02:00
|
|
|
module;
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <wayland-cursor.h>
|
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include <vulkan/vulkan_wayland.h>
|
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include "xdg-shell-client-protocol.h"
|
|
|
|
|
#include "wayland-xdg-decoration-unstable-v1-client-protocol.h"
|
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <print>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
#include <wayland-client-protocol.h>
|
|
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
module Crafter.Graphics;
|
|
|
|
|
import Crafter.Event;
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
|
2025-05-03 06:51:33 +02:00
|
|
|
void ScaleBitmapR8G8B8(Pixel_RU8_GU8_BU8_AU8* dst, const Pixel_RU8_GU8_BU8_AU8* src, std::uint32_t srcWidth, std::uint32_t srcHeight, std::uint32_t dstWidth, std::uint32_t dstHeight) {
|
2025-04-19 15:46:26 +02:00
|
|
|
for (std::uint32_t y = 0; y < dstHeight; y++) {
|
|
|
|
|
std::uint32_t srcY = y * srcHeight / dstHeight;
|
|
|
|
|
for (std::uint32_t x = 0; x < dstWidth; x++) {
|
|
|
|
|
std::uint32_t srcX = x * srcWidth / dstWidth;
|
2025-05-03 06:51:33 +02:00
|
|
|
const Pixel_RU8_GU8_BU8_AU8* srcPixel = src + (srcY * srcWidth + srcX);
|
|
|
|
|
Pixel_RU8_GU8_BU8_AU8* dstPixel = dst + (y * dstWidth + x);
|
2025-04-19 15:46:26 +02:00
|
|
|
dstPixel[0] = srcPixel[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WindowWaylandWayland::WindowWaylandWayland(std::string name, std::uint32_t width, std::uint32_t height) : WindowWayland(name, width, height) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WindowWaylandWayland::Start() {
|
|
|
|
|
thread = std::thread([this](){
|
|
|
|
|
while (open && wl_display_dispatch(display) != -1) {
|
|
|
|
|
wl_surface_attach(surface, buffer, 0, 0);
|
2025-05-25 23:04:56 +02:00
|
|
|
for(const UiElement& element : elements) {
|
2025-04-19 15:46:26 +02:00
|
|
|
std::int32_t realX;
|
|
|
|
|
std::int32_t realY;
|
|
|
|
|
std::int32_t elementWidth;
|
|
|
|
|
std::int32_t elementHeight;
|
2025-05-25 23:04:56 +02:00
|
|
|
if(element.ignoreScaling) {
|
|
|
|
|
if(element.useRelativeSize) {
|
|
|
|
|
elementWidth = element.relativeWidth*width;
|
|
|
|
|
elementHeight = element.relativeHeight*height;
|
2025-04-19 15:46:26 +02:00
|
|
|
} else {
|
2025-05-25 23:04:56 +02:00
|
|
|
elementWidth = element.absoluteWidth;
|
|
|
|
|
elementHeight = element.absoluteHeight;
|
2025-04-19 15:46:26 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-25 23:04:56 +02:00
|
|
|
if(element.useRelativeSize) {
|
|
|
|
|
elementWidth = element.relativeWidth*width*scale;
|
|
|
|
|
elementHeight = element.relativeHeight*height*scale;
|
2025-04-19 15:46:26 +02:00
|
|
|
} else {
|
2025-05-25 23:04:56 +02:00
|
|
|
elementWidth = element.absoluteWidth*scale;
|
|
|
|
|
elementHeight = element.absoluteHeight*scale;
|
2025-04-19 15:46:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-25 23:04:56 +02:00
|
|
|
realX = (element.anchorX*width)-(element.anchorOffsetX*elementWidth);
|
|
|
|
|
realY = (element.anchorY*height)-(element.anchorOffsetY*elementHeight);
|
2025-05-03 06:51:33 +02:00
|
|
|
std::vector<Pixel_RU8_GU8_BU8_AU8> scaled(elementWidth*elementHeight);
|
2025-05-25 23:04:56 +02:00
|
|
|
ScaleBitmapR8G8B8(scaled.data(), element.buffer.data(), element.bufferWidth, element.bufferHeight, elementWidth, elementHeight);
|
2025-04-19 15:46:26 +02:00
|
|
|
for(std::int32_t x = realX; x-realX < elementWidth; x++) {
|
|
|
|
|
for(std::int32_t y = realY; y-realY < elementHeight; y++) {
|
|
|
|
|
if(x > 0 && x < width && y > 0 && y < height) {
|
|
|
|
|
shm_data[x*width+y] = scaled[(x-realX)*elementWidth+(y-realY)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wl_surface_damage(surface, realX, realY, elementWidth, elementHeight);
|
|
|
|
|
}
|
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|