102 lines
No EOL
3.2 KiB
C++
102 lines
No EOL
3.2 KiB
C++
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 "cat.h"
|
|
#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;
|
|
|
|
|
|
void ScaleBitmapR8G8B8(Pixel* dst, const Pixel* src, std::uint32_t srcWidth, std::uint32_t srcHeight, std::uint32_t dstWidth, std::uint32_t dstHeight) {
|
|
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;
|
|
const Pixel* srcPixel = src + (srcY * srcWidth + srcX);
|
|
Pixel* dstPixel = dst + (y * dstWidth + x);
|
|
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);
|
|
for(UiElement* element : elements.components) {
|
|
std::int32_t realX;
|
|
std::int32_t realY;
|
|
std::int32_t elementWidth;
|
|
std::int32_t elementHeight;
|
|
if(element->ignoreScaling) {
|
|
if(element->useRelativeSize) {
|
|
elementWidth = element->relativeWidth*width;
|
|
elementHeight = element->relativeHeight*height;
|
|
} else {
|
|
elementWidth = element->absoluteWidth;
|
|
elementHeight = element->absoluteHeight;
|
|
}
|
|
} else {
|
|
if(element->useRelativeSize) {
|
|
elementWidth = element->relativeWidth*width*scale;
|
|
elementHeight = element->relativeHeight*height*scale;
|
|
} else {
|
|
elementWidth = element->absoluteWidth*scale;
|
|
elementHeight = element->absoluteHeight*scale;
|
|
}
|
|
}
|
|
realX = (element->anchorX*width)-(element->anchorOffsetX*elementWidth);
|
|
realY = (element->anchorY*height)-(element->anchorOffsetY*elementHeight);
|
|
std::vector<Pixel> scaled(elementWidth*elementHeight);
|
|
ScaleBitmapR8G8B8(scaled.data(), element->buffer.data(), element->bufferWidth, element->bufferHeight, elementWidth, elementHeight);
|
|
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);
|
|
}
|
|
});
|
|
} |