merged uielement
This commit is contained in:
parent
39f151e865
commit
02a6a64c56
12 changed files with 200 additions and 506 deletions
|
|
@ -18,10 +18,15 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
module;
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../lib/stb_image.h"
|
||||
#include "../lib/stb_truetype.h"
|
||||
module Crafter.Graphics:UiElement_impl;
|
||||
import :UiElement;
|
||||
import :Window;
|
||||
import :Types;
|
||||
import :Font;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
|
@ -30,14 +35,122 @@ Transform::Transform(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::
|
|||
|
||||
}
|
||||
|
||||
UiElement::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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
UiElement::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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), mouseTransform(FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0, false) {
|
||||
|
||||
}
|
||||
|
||||
UiElementMouse::UiElementMouse(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
UiElement::UiElement(std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), bufferWidth(bufferWidth), bufferHeight(bufferHeight), buffer(bufferWidth*bufferHeight), mouseTransform(FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0, false) {
|
||||
|
||||
}
|
||||
|
||||
UiElementBuffer::UiElementBuffer(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {
|
||||
|
||||
UiElement::UiElement(const std::string_view imagePath, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), mouseTransform(FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0, false) {
|
||||
RenderImage(imagePath);
|
||||
}
|
||||
|
||||
UiElement::UiElement(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 pixel, Font& font, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), mouseTransform(FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0, false) {
|
||||
RenderText(text, size, pixel, font);
|
||||
}
|
||||
|
||||
UiElement::UiElement(Transform transform) : transform(transform), mouseTransform(FractionalToMapped(0), FractionalToMapped(0), FractionalToMapped(1), FractionalToMapped(1), FractionalToMapped(0), FractionalToMapped(0), 0, false) {
|
||||
|
||||
}
|
||||
|
||||
void UiElement::ResizeBuffer(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
this->bufferWidth = width;
|
||||
this->bufferHeight = height;
|
||||
buffer.resize(width * height);
|
||||
}
|
||||
|
||||
void UiElement::RenderImage(const std::string_view path) {
|
||||
std::filesystem::path abs = std::filesystem::absolute(path);
|
||||
int xSize;
|
||||
int ySize;
|
||||
unsigned char* bgData = stbi_load(abs.string().c_str(), &xSize, &ySize, nullptr, 4);
|
||||
|
||||
ResizeBuffer(xSize, ySize);
|
||||
|
||||
for(std::uint_fast32_t x = 0; x < xSize; x++) {
|
||||
for(std::uint_fast32_t y = 0; y < ySize; y++) {
|
||||
std::uint_fast32_t idx = (x*ySize+y)*4;
|
||||
buffer[x*ySize+y].r = bgData[idx];
|
||||
buffer[x*ySize+y].g = bgData[idx+1];
|
||||
buffer[x*ySize+y].b = bgData[idx+2];
|
||||
buffer[x*ySize+y].a = bgData[idx+3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UiElement::RenderText(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 color, Font& font) {
|
||||
buffer.clear();
|
||||
|
||||
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
|
||||
|
||||
int baseline = (int)(font.ascent * scale);
|
||||
|
||||
std::uint_fast32_t bufferWidth = 0;
|
||||
for (const char c : text) {
|
||||
int advance, lsb;
|
||||
stbtt_GetCodepointHMetrics(&font.font, c, &advance, &lsb);
|
||||
bufferWidth += (int)(advance * scale);
|
||||
}
|
||||
|
||||
ResizeBuffer(bufferWidth, (font.ascent - font.descent) * scale);
|
||||
|
||||
int x = 0;
|
||||
for (std::uint_fast32_t i = 0; i < text.size(); i++) {
|
||||
int codepoint = text[i];
|
||||
|
||||
int ax;
|
||||
int lsb;
|
||||
stbtt_GetCodepointHMetrics(&font.font, codepoint, &ax, &lsb);
|
||||
|
||||
int c_x1, c_y1, c_x2, c_y2;
|
||||
stbtt_GetCodepointBitmapBox(&font.font, codepoint, scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);
|
||||
|
||||
int w = c_x2 - c_x1;
|
||||
int h = c_y2 - c_y1;
|
||||
|
||||
std::vector<unsigned char> bitmap(w * h);
|
||||
stbtt_MakeCodepointBitmap(&font.font, bitmap.data(), w, h, w, scale, scale, codepoint);
|
||||
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
buffer[(baseline + j + c_y1) * bufferWidth + (x + i + c_x1)] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
}
|
||||
}
|
||||
|
||||
x += (int)(ax * scale);
|
||||
|
||||
if (i + 1 < text.size()) {
|
||||
x += (int)stbtt_GetCodepointKernAdvance(&font.font, codepoint, text[i+1] * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UiElement::UpdatePosition(Window& window) {
|
||||
window.ScaleElement(transform);
|
||||
scaled.resize(transform.scaled.width * transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(), transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
}
|
||||
|
||||
void UiElement::UpdatePosition(Window& window, UiElement& parent) {
|
||||
window.ScaleElement(transform, parent.transform);
|
||||
scaled.resize(transform.scaled.width * transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(),transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
UpdatePosition(window, *child);
|
||||
}
|
||||
}
|
||||
|
||||
void UiElement::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
|
||||
for (std::uint_fast32_t y = 0; y < dstHeight; y++) {
|
||||
std::uint_fast32_t srcY = y * bufferHeight / dstHeight;
|
||||
for (std::uint_fast32_t x = 0; x < dstWidth; x++) {
|
||||
std::uint_fast32_t srcX = x * bufferWidth / dstWidth;
|
||||
dst[y * dstWidth + x] = buffer[srcY * bufferWidth + srcX];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
module Crafter.Graphics:UiElementBufferBuffer_impl;
|
||||
import :UiElement;
|
||||
import :Window;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
UiElementBufferBuffer::UiElementBufferBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElement(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
|
||||
}
|
||||
|
||||
UiElementBufferBuffer::UiElementBufferBuffer(std::uint_fast32_t width, std::uint_fast32_t height, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElement(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementBufferBufferBase(width, height){
|
||||
|
||||
}
|
||||
|
||||
void UiElementBufferBuffer::UpdatePosition(WindowFramebuffer& window) {
|
||||
window.ScaleElement(transform);
|
||||
scaled.resize(transform.scaled.width*transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(), transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
}
|
||||
|
||||
void UiElementBufferBuffer::UpdatePosition(WindowFramebuffer& window, UiElement& parent) {
|
||||
window.ScaleElement(transform, parent.transform);
|
||||
scaled.resize(transform.scaled.width*transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(),transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
UpdatePosition(window, *child);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
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 version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
module Crafter.Graphics:UiElementBufferBufferBase_impl;
|
||||
import :UiElement;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
UiElementBufferBufferBase::UiElementBufferBufferBase(std::uint_fast32_t width, std::uint_fast32_t height) : UiElementBuffer(width, height), buffer(width*height) {
|
||||
|
||||
}
|
||||
void UiElementBufferBufferBase::Create(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
buffer.resize(width * height);
|
||||
}
|
||||
void UiElementBufferBufferBase::Resize(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
buffer.resize(width*height);
|
||||
}
|
||||
void UiElementBufferBufferBase::Resize(std::uint_fast32_t width, std::uint_fast32_t height, std::uint_fast32_t offsetX, std::uint_fast32_t offsetY) {
|
||||
|
||||
}
|
||||
void UiElementBufferBufferBase::ResizeNearestNeighbour(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
|
||||
}
|
||||
void UiElementBufferBufferBase::ResizeBicubic(std::uint_fast32_t width, std::uint_fast32_t height) {
|
||||
|
||||
}
|
||||
void UiElementBufferBufferBase::Destroy() {
|
||||
buffer.clear();
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
void UiElementBufferBufferBase::Copy(Pixel_BU8_GU8_RU8_AU8* dst) const {
|
||||
std::memcpy(dst, buffer.data(), width*height*sizeof(Pixel_BU8_GU8_RU8_AU8));
|
||||
}
|
||||
|
||||
void UiElementBufferBufferBase::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
|
||||
for (std::uint_fast32_t y = 0; y < dstHeight; y++) {
|
||||
std::uint_fast32_t srcY = y * height / dstHeight;
|
||||
for (std::uint_fast32_t x = 0; x < dstWidth; x++) {
|
||||
std::uint_fast32_t srcX = x * width / dstWidth;
|
||||
dst[y * dstWidth + x] = buffer[srcY * width + srcX];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UiElementBufferBufferBase::CopyBicubic(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
|
||||
|
||||
}
|
||||
void UiElementBufferBufferBase::Write(Pixel_BU8_GU8_RU8_AU8* pixels) {
|
||||
std::memcpy(buffer.data(), pixels, width*height*sizeof(Pixel_BU8_GU8_RU8_AU8));
|
||||
}
|
||||
void UiElementBufferBufferBase::Write(std::uint_fast32_t x, std::uint_fast32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) {
|
||||
buffer[y * width + x] = pixel;
|
||||
}
|
||||
Pixel_BU8_GU8_RU8_AU8 UiElementBufferBufferBase::Read(std::uint_fast32_t x, std::uint_fast32_t y) const {
|
||||
return buffer[y * width + x];
|
||||
}
|
||||
const Pixel_BU8_GU8_RU8_AU8* UiElementBufferBufferBase::Read() const {
|
||||
return buffer.data();
|
||||
}
|
||||
Pixel_BU8_GU8_RU8_AU8* UiElementBufferBufferBase::Get() {
|
||||
return buffer.data();
|
||||
}
|
||||
void UiElementBufferBufferBase::Store() {
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
module Crafter.Graphics:UiElementBufferMouseBuffer_impl;
|
||||
import :UiElement;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
UiElementBufferMouseBuffer::UiElementBufferMouseBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
||||
UiElementBufferMouseBuffer::UiElementBufferMouseBuffer(std::uint_fast32_t width, std::uint_fast32_t height, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(width, height, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
module;
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../lib/stb_image.h"
|
||||
module Crafter.Graphics:UiElementImage_impl;
|
||||
import :UiElement;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
|
||||
UiElementImageBuffer::UiElementImageBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
|
||||
}
|
||||
|
||||
UiElementImageBuffer::UiElementImageBuffer(const std::string_view path, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
Load(path);
|
||||
}
|
||||
|
||||
void UiElementImageBuffer::Load(const std::string_view path) {
|
||||
std::filesystem::path abs = std::filesystem::absolute(path);
|
||||
int xSize;
|
||||
int ySize;
|
||||
unsigned char* bgData = stbi_load(abs.string().c_str(), &xSize, &ySize, nullptr, 4);
|
||||
|
||||
Create(xSize, ySize);
|
||||
|
||||
for(std::uint_fast32_t x = 0; x < xSize; x++) {
|
||||
for(std::uint_fast32_t y = 0; y < ySize; y++) {
|
||||
std::uint_fast32_t idx = (x*ySize+y)*4;
|
||||
buffer[x*ySize+y].r = bgData[idx];
|
||||
buffer[x*ySize+y].g = bgData[idx+1];
|
||||
buffer[x*ySize+y].b = bgData[idx+2];
|
||||
buffer[x*ySize+y].a = bgData[idx+3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UiElementImageMouseBuffer::UiElementImageMouseBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementImageBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
||||
UiElementImageMouseBuffer::UiElementImageMouseBuffer(const std::string_view path, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementImageBuffer(path, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
module;
|
||||
#include "../lib/stb_truetype.h"
|
||||
module Crafter.Graphics:UiElementTextBuffer_impl;
|
||||
import :UiElement;
|
||||
import :Font;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
|
||||
UiElementTextBuffer::UiElementTextBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
|
||||
}
|
||||
|
||||
UiElementTextBuffer::UiElementTextBuffer(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 color, Font& font, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementBufferBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
|
||||
Render(text, size, color, font);
|
||||
}
|
||||
|
||||
void UiElementTextBuffer::Render(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 color, Font& font) {
|
||||
buffer.clear();
|
||||
|
||||
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
|
||||
|
||||
int baseline = (int)(font.ascent * scale);
|
||||
|
||||
std::uint_fast32_t bufferWidth = 0;
|
||||
for (const char c : text) {
|
||||
int advance, lsb;
|
||||
stbtt_GetCodepointHMetrics(&font.font, c, &advance, &lsb);
|
||||
bufferWidth += (int)(advance * scale);
|
||||
}
|
||||
|
||||
Create(bufferWidth, (font.ascent -font.descent) * scale);
|
||||
|
||||
int x = 0;
|
||||
for (std::uint_fast32_t i = 0; i < text.size(); i++) {
|
||||
int codepoint = text[i];
|
||||
|
||||
int ax;
|
||||
int lsb;
|
||||
stbtt_GetCodepointHMetrics(&font.font, codepoint, &ax, &lsb);
|
||||
|
||||
int c_x1, c_y1, c_x2, c_y2;
|
||||
stbtt_GetCodepointBitmapBox(&font.font, codepoint, scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);
|
||||
|
||||
int w = c_x2 - c_x1;
|
||||
int h = c_y2 - c_y1;
|
||||
|
||||
std::vector<unsigned char> bitmap(w * h);
|
||||
stbtt_MakeCodepointBitmap(&font.font, bitmap.data(), w, h, w, scale, scale, codepoint);
|
||||
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
buffer[(baseline + j + c_y1) * bufferWidth + (x + i + c_x1)] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
}
|
||||
}
|
||||
|
||||
x += (int)(ax * scale);
|
||||
|
||||
if (i + 1 < text.size()) {
|
||||
x += (int)stbtt_GetCodepointKernAdvance(&font.font, codepoint, text[i+1] * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UiElementTextMouseBuffer::UiElementTextMouseBuffer(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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementTextBuffer(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
||||
UiElementTextMouseBuffer::UiElementTextMouseBuffer(const std::string_view text, float size, Pixel_BU8_GU8_RU8_AU8 color, Font& font, 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, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElementTextBuffer(text, size, color, font, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementMouse() {
|
||||
|
||||
}
|
||||
|
|
@ -20,10 +20,34 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module Crafter.Graphics:Window_impl;
|
||||
import :Window;
|
||||
import :UiElement;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
Window::Window(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Window::ScaleElement(Transform& element) {
|
||||
element.scaled.width = MappedToPixel(element.relativeWidth, width);
|
||||
element.scaled.height = MappedToPixel(element.relativeHeight, height);
|
||||
element.scaled.x = MappedToPixel(element.anchorX, width) - MappedToPixel(element.anchorOffsetX, element.scaled.width);
|
||||
element.scaled.y = MappedToPixel(element.anchorY, height) - MappedToPixel(element.anchorOffsetY, element.scaled.height);
|
||||
}
|
||||
|
||||
void Window::ScaleElement(Transform& element, Transform& parent) {
|
||||
element.scaled.width = MappedToPixel(element.relativeWidth, parent.scaled.width);
|
||||
element.scaled.height = MappedToPixel(element.relativeHeight, parent.scaled.height);
|
||||
element.scaled.x = MappedToPixel(element.anchorX, parent.scaled.width) - MappedToPixel(element.anchorOffsetX, element.scaled.width) + parent.scaled.x;
|
||||
element.scaled.y = MappedToPixel(element.anchorY, parent.scaled.height) - MappedToPixel(element.anchorOffsetY, 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.relativeWidth, PixelToMapped(parent.scaled.width, width)));
|
||||
element.scaled.height = BoundToBoundless(MappedToPixel(element.relativeHeight, PixelToMapped(parent.scaled.height, height)));
|
||||
element.scaled.x = MappedToPixelBoundless(element.anchorX, boundlessWidth) - MappedToPixelBoundless(element.anchorOffsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width);
|
||||
element.scaled.y = MappedToPixelBoundless(element.anchorY, boundlessHeight) - MappedToPixelBoundless(element.anchorOffsetY, element.scaled.height) + PixelToMappedBoundless(parent.scaled.y, height);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,30 +51,6 @@ WindowFramebuffer::WindowFramebuffer(std::uint_fast32_t width, std::uint_fast32
|
|||
|
||||
}
|
||||
|
||||
|
||||
void WindowFramebuffer::ScaleElement(Transform& element) {
|
||||
element.scaled.width = MappedToPixel(element.relativeWidth, width);
|
||||
element.scaled.height = MappedToPixel(element.relativeHeight, height);
|
||||
element.scaled.x = MappedToPixel(element.anchorX, width) - MappedToPixel(element.anchorOffsetX, element.scaled.width);
|
||||
element.scaled.y = MappedToPixel(element.anchorY, height) - MappedToPixel(element.anchorOffsetY, element.scaled.height);
|
||||
}
|
||||
|
||||
void WindowFramebuffer::ScaleElement(Transform& element, Transform& parent) {
|
||||
element.scaled.width = MappedToPixel(element.relativeWidth, parent.scaled.width);
|
||||
element.scaled.height = MappedToPixel(element.relativeHeight, parent.scaled.height);
|
||||
element.scaled.x = MappedToPixel(element.anchorX, parent.scaled.width) - MappedToPixel(element.anchorOffsetX, element.scaled.width) + parent.scaled.x;
|
||||
element.scaled.y = MappedToPixel(element.anchorY, parent.scaled.height) - MappedToPixel(element.anchorOffsetY, element.scaled.height) + parent.scaled.y;
|
||||
}
|
||||
|
||||
void WindowFramebuffer::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.relativeWidth, PixelToMapped(parent.scaled.width, width)));
|
||||
element.scaled.height = BoundToBoundless(MappedToPixel(element.relativeHeight, PixelToMapped(parent.scaled.height, height)));
|
||||
element.scaled.x = MappedToPixelBoundless(element.anchorX, boundlessWidth) - MappedToPixelBoundless(element.anchorOffsetX, element.scaled.width) + PixelToMappedBoundless(parent.scaled.x, width);
|
||||
element.scaled.y = MappedToPixelBoundless(element.anchorY, boundlessHeight) - MappedToPixelBoundless(element.anchorOffsetY, element.scaled.height) + PixelToMappedBoundless(parent.scaled.y, height);
|
||||
}
|
||||
|
||||
WindowWayland::WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height) : WindowFramebuffer(width, height) {
|
||||
display = wl_display_connect(NULL);
|
||||
if (display == NULL) {
|
||||
|
|
@ -159,7 +135,7 @@ void WindowWayland::StartSync() {
|
|||
|
||||
|
||||
|
||||
void RenderElement(UiElementBufferBuffer* element, WindowWayland* window) {
|
||||
void RenderElement(UiElement* element, WindowWayland* window) {
|
||||
for (std::int_fast32_t x = element->transform.scaled.x; x - element->transform.scaled.x < element->transform.scaled.width; x++) {
|
||||
for (std::int_fast32_t y = element->transform.scaled.y; y - element->transform.scaled.y < element->transform.scaled.height; y++) {
|
||||
if (x >= 0 && x < window->width && y >= 0 && y < window->height) {
|
||||
|
|
@ -183,20 +159,20 @@ void RenderElement(UiElementBufferBuffer* element, WindowWayland* window) {
|
|||
}
|
||||
std::sort(element->children.begin(), element->children.end(), [](UiElement* a, UiElement* b){ return a->transform.z < b->transform.z; });
|
||||
for(UiElement* child : element->children) {
|
||||
RenderElement(static_cast<UiElementBufferBuffer*>(child), window);
|
||||
RenderElement(child, window);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowWayland::Render() {
|
||||
std::sort(elements.begin(), elements.end(), [](UiElementBufferBuffer* a, UiElementBufferBuffer* b){ return a->transform.z < b->transform.z; });
|
||||
std::sort(elements.begin(), elements.end(), [](UiElement* a, UiElement* b){ return a->transform.z < b->transform.z; });
|
||||
|
||||
for (std::int_fast32_t x = 0; x < width; x++) {
|
||||
for (std::int_fast32_t y = 0; y - height; y++) {
|
||||
for (std::uint_fast32_t x = 0; x < width; x++) {
|
||||
for (std::uint_fast32_t y = 0; y - height; y++) {
|
||||
framebuffer[y * width + x] = {0,0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
for(UiElementBufferBuffer* element : elements) {
|
||||
for(UiElement* element : elements) {
|
||||
RenderElement(element, this);
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +240,7 @@ void WindowWayland::wl_surface_frame_done(void* data, struct wl_callback *cb, ui
|
|||
cb = wl_surface_frame(window->surface);
|
||||
wl_callback_add_listener(cb, &WindowWayland::wl_callback_listener, window);
|
||||
auto startUpdate = std::chrono::high_resolution_clock::now();
|
||||
window->onUpdate.Invoke({start, start-window->lastFrameEnd});
|
||||
window->onUpdate.Invoke({start, start-window->lastFrameBegin});
|
||||
auto endUpdate = std::chrono::high_resolution_clock::now();
|
||||
auto startRender = std::chrono::high_resolution_clock::now();
|
||||
window->Render();
|
||||
|
|
@ -275,7 +251,7 @@ void WindowWayland::wl_surface_frame_done(void* data, struct wl_callback *cb, ui
|
|||
|
||||
|
||||
framEnd = std::chrono::high_resolution_clock::now();
|
||||
window->lastFrameEnd = start;
|
||||
window->lastFrameBegin = start;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
@ -284,17 +260,17 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
if(state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
window->mouseLeftHeld = true;
|
||||
window->onMouseLeftClick.Invoke(window->currentMousePos);
|
||||
for(UiElementMouse* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->transform.scaled.x && window->currentMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->currentMousePos.y > element->transform.scaled.y && window->currentMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseLeftClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
for(UiElement* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->mouseTransform.scaled.x && window->currentMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->currentMousePos.y > element->mouseTransform.scaled.y && window->currentMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseLeftClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
window->mouseLeftHeld = false;
|
||||
window->onMouseLeftRelease.Invoke(window->currentMousePos);
|
||||
for(UiElementMouse* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->transform.scaled.x && window->currentMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->currentMousePos.y > element->transform.scaled.y && window->currentMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseLeftRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
for(UiElement* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->mouseTransform.scaled.x && window->currentMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->currentMousePos.y > element->mouseTransform.scaled.y && window->currentMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseLeftRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -302,17 +278,17 @@ void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::
|
|||
if(state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
window->mouseRightHeld = true;
|
||||
window->onMouseRightClick.Invoke(window->currentMousePos);
|
||||
for(UiElementMouse* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->transform.scaled.x && window->currentMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->currentMousePos.y > element->transform.scaled.y && window->currentMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseRightClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
for(UiElement* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->mouseTransform.scaled.x && window->currentMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->currentMousePos.y > element->mouseTransform.scaled.y && window->currentMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseRightClick.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
window->mouseRightHeld = true;
|
||||
window->onMouseRightRelease.Invoke(window->currentMousePos);
|
||||
for(UiElementMouse* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->transform.scaled.x && window->currentMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->currentMousePos.y > element->transform.scaled.y && window->currentMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseRightRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
for(UiElement* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->mouseTransform.scaled.x && window->currentMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->currentMousePos.y > element->mouseTransform.scaled.y && window->currentMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseRightRelease.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -326,14 +302,14 @@ void WindowWayland::PointerListenerHandleMotion(void* data, wl_pointer* wl_point
|
|||
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(UiElementMouse* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->transform.scaled.x && window->currentMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->currentMousePos.y > element->transform.scaled.y && window->currentMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseMove.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
if(!(window->lastMousePos.x >= element->transform.scaled.x && window->lastMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->lastMousePos.y > element->transform.scaled.y && window->lastMousePos.y < element->transform.scaled.y+element->transform.scaled.height)) {
|
||||
element->onMouseEnter.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
for(UiElement* element : window->mouseElements) {
|
||||
if(window->currentMousePos.x >= element->mouseTransform.scaled.x && window->currentMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->currentMousePos.y > element->mouseTransform.scaled.y && window->currentMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseMove.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
if(!(window->lastMousePos.x >= element->mouseTransform.scaled.x && window->lastMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->lastMousePos.y > element->mouseTransform.scaled.y && window->lastMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height)) {
|
||||
element->onMouseEnter.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
} else if(window->lastMousePos.x >= element->transform.scaled.x && window->lastMousePos.x <= element->transform.scaled.x+element->transform.scaled.width && window->lastMousePos.y > element->transform.scaled.y && window->lastMousePos.y < element->transform.scaled.y+element->transform.scaled.height) {
|
||||
element->onMouseLeave.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->transform.scaled.x) / element->transform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->transform.scaled.y) / element->transform.scaled.height)});
|
||||
} else if(window->lastMousePos.x >= element->mouseTransform.scaled.x && window->lastMousePos.x <= element->mouseTransform.scaled.x+element->mouseTransform.scaled.width && window->lastMousePos.y > element->mouseTransform.scaled.y && window->lastMousePos.y < element->mouseTransform.scaled.y+element->mouseTransform.scaled.height) {
|
||||
element->onMouseLeave.Invoke({FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.x - element->mouseTransform.scaled.x) / element->mouseTransform.scaled.width), FractionalToMappedBoundless(static_cast<double>(window->currentMousePos.y - element->mouseTransform.scaled.y) / element->mouseTransform.scaled.height)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue