Start work on touchscreen support

This commit is contained in:
Yousef Khadadeh 2026-02-27 16:16:51 +03:00
parent 815737ce3e
commit ae88521b32
14 changed files with 171 additions and 76 deletions

View file

@ -102,6 +102,8 @@ struct UpdateInputData {
std::string textInput;
bool hoverObstructed = false;
std::vector<SCollision::AABB<float>> hoverObstructingAABBs;
std::vector<SCollision::Circle<float>> hoverObstructingCircles;
bool acceptingTextInput = false;
float deltaTime = 0.0f;

View file

@ -78,7 +78,8 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
clickedOut = false;
}
if(dropdownOpen) {
CLAY_AUTO_ID({
Clay_ElementId localID = CLAY_ID_LOCAL("Font picker floating element");
CLAY(localID, {
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)},
.layoutDirection = CLAY_TOP_TO_BOTTOM
@ -100,7 +101,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
.width = CLAY_BORDER_OUTSIDE(1)
}
}) {
gui->obstructing_window();
gui->obstructing_window(localID);
if(Clay_Hovered())
clickedOut = false;
gui->scroll_bar_many_entries_area("Font Selector", ENTRY_HEIGHT, sortedFontList.size(), true, [fontName, gui, &fontChangedFromSelection, &sortedFontList = sortedFontList, val, &io = io](size_t i, bool listHovered) {

View file

@ -1,6 +1,7 @@
#include "PaintCircleMenu.hpp"
#include "Helpers/ConvertVec.hpp"
#include <include/core/SkPathBuilder.h>
#include "../GUIManager.hpp"
namespace GUIStuff {
@ -10,7 +11,8 @@ constexpr float CIRCLE_END = 150.0f;
constexpr double ROTATE_BAR_SNAP_DISTANCE = 0.2;
constexpr double ROTATE_BAR_SNAP_DISTRIBUTION = std::numbers::pi * 0.25;
void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::function<void()>& elemUpdate) {
void PaintCircleMenu::update(GUIManager& gui, const Data& data, const std::function<void()>& elemUpdate) {
auto& io = *gui.io;
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}
},
@ -19,7 +21,6 @@ void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::f
bool isHoveredNoObstruction = Clay_Hovered() && !io.hoverObstructed;
Vector2f vecFromCenter = (io.mouse.pos - bb.center()).normalized();
float distFromCenter = vec_distance(io.mouse.pos, bb.center());
bool rotateHovered = false;
if(data.newRotationAngle) {
rotateBarSelect.update(isHoveredNoObstruction && distFromCenter > ROTATE_START && distFromCenter < CIRCLE_END, io.mouse.leftClick, io.mouse.leftHeld);
if(rotateBarSelect.held) {
@ -38,9 +39,7 @@ void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::f
}
else
*data.newRotationAngle = data.currentRotationAngle;
rotateHovered = rotateBarSelect.hovered;
}
bool colorHovered = false;
if(!data.palette.empty() && data.selectedColor) {
colorBarSelect.update(isHoveredNoObstruction && distFromCenter > PALETTE_START && distFromCenter < ROTATE_START, io.mouse.leftClick, io.mouse.leftHeld);
if(colorBarSelect.hovered) {
@ -54,9 +53,9 @@ void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::f
selectedColor.z() = data.palette[colorSelectionIndex].z();
}
}
colorHovered = colorBarSelect.hovered;
}
if(rotateHovered || colorHovered)
io.hoverObstructingCircles.emplace_back(bb.center() + gui.windowPos, CIRCLE_END);
if(SCollision::collide(io.hoverObstructingCircles.back(), io.mouse.pos))
io.hoverObstructed = true;
if(elemUpdate)
elemUpdate();
@ -72,6 +71,9 @@ void PaintCircleMenu::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_Rend
draw_rotate_bar(canvas, io);
draw_palette_bar(canvas, io);
SkPaint p;
p.setColor4f(color_mul_alpha(io.theme->backColor1, 0.5f));
canvas->drawCircle(0.0f, 0.0f, PALETTE_START, p);
canvas->restore();
}

View file

@ -3,6 +3,8 @@
namespace GUIStuff {
class GUIManager;
class PaintCircleMenu : public Element {
public:
struct Data {
@ -11,7 +13,7 @@ class PaintCircleMenu : public Element {
Vector4f* selectedColor = nullptr;
std::vector<Vector3f> palette;
};
void update(UpdateInputData& io, const Data& data, const std::function<void()>& elemUpdate);
void update(GUIManager& gui, const Data& data, const std::function<void()>& elemUpdate);
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) override;
private:
void draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io);