Start work on touchscreen support
This commit is contained in:
parent
815737ce3e
commit
ae88521b32
14 changed files with 171 additions and 76 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -246,8 +246,8 @@ void GUIManager::draw(SkCanvas* canvas) {
|
|||
canvas->restore();
|
||||
}
|
||||
|
||||
void GUIManager::top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate) {
|
||||
CLAY_AUTO_ID({.layout = {
|
||||
void GUIManager::top_to_bottom_window_popup_layout(const Clay_ElementId& windowLocalID, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate) {
|
||||
CLAY(windowLocalID, {.layout = {
|
||||
.sizing = {.width = x, .height = y },
|
||||
.padding = CLAY_PADDING_ALL(io->theme->padding1),
|
||||
.childGap = io->theme->childGap1,
|
||||
|
|
@ -258,8 +258,7 @@ void GUIManager::top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_Sizin
|
|||
.floating = { .attachTo = CLAY_ATTACH_TO_PARENT },
|
||||
.border = {.color = convert_vec4<Clay_Color>(io->theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)}
|
||||
}) {
|
||||
if(Clay_Hovered())
|
||||
io->hoverObstructed = true;
|
||||
obstructing_window(windowLocalID);
|
||||
elemUpdate();
|
||||
}
|
||||
}
|
||||
|
|
@ -623,7 +622,7 @@ void GUIManager::dropdown_select(const char* id, size_t* val, const std::vector<
|
|||
.width = CLAY_BORDER_OUTSIDE(1)
|
||||
}
|
||||
}) {
|
||||
obstructing_window();
|
||||
obstructing_window(localID);
|
||||
scroll_bar_many_entries_area("dropdown scroll area", 18.0f, selections.size(), true, [&](size_t i, bool) {
|
||||
bool selectedEntry = *val == i;
|
||||
|
||||
|
|
@ -851,7 +850,7 @@ void GUIManager::paint_circle_popup_menu(const char* id, const Vector2f& centerP
|
|||
}
|
||||
}) {
|
||||
PaintCircleMenu* e = insert_element<PaintCircleMenu>();
|
||||
e->update(*io, val, elemUpdate);
|
||||
e->update(*this, val, elemUpdate);
|
||||
}
|
||||
pop_id();
|
||||
}
|
||||
|
|
@ -890,7 +889,7 @@ void GUIManager::list_popup_menu(const char* id, Vector2f popupPos, const std::f
|
|||
.attachTo = CLAY_ATTACH_TO_ROOT
|
||||
}
|
||||
}) {
|
||||
obstructing_window();
|
||||
obstructing_window(localID);
|
||||
push_id(1);
|
||||
elemUpdate();
|
||||
pop_id();
|
||||
|
|
@ -905,9 +904,11 @@ void GUIManager::tree_listing(const char* id, NetworkingObjects::NetObjID rootOb
|
|||
pop_id();
|
||||
}
|
||||
|
||||
void GUIManager::obstructing_window() {
|
||||
void GUIManager::obstructing_window(const Clay_ElementId& elementID) {
|
||||
if(Clay_Hovered())
|
||||
io->hoverObstructed = true;
|
||||
const Clay_ElementData& elemData = Clay_GetElementData(elementID);
|
||||
io->hoverObstructingAABBs.emplace_back(SCollision::AABB<float>{Vector2f{elemData.boundingBox.x, elemData.boundingBox.y} + windowPos, Vector2f{elemData.boundingBox.x + elemData.boundingBox.width, elemData.boundingBox.y + elemData.boundingBox.height} + windowPos});
|
||||
}
|
||||
|
||||
void GUIManager::clay_error_handler(Clay_ErrorData errorData) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class GUIManager {
|
|||
|
||||
bool rotate_wheel(const char* id, double* angle, float size = BIG_BUTTON_SIZE, const std::function<void()>& elemUpdate = nullptr);
|
||||
|
||||
void top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void top_to_bottom_window_popup_layout(const Clay_ElementId& localID, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_layout(const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_centered_layout(const std::function<void()>& elemUpdate);
|
||||
|
|
@ -104,7 +104,7 @@ class GUIManager {
|
|||
|
||||
void tree_listing(const char* id, NetworkingObjects::NetObjID rootObjID, const TreeListing::DisplayData& displayData, TreeListing::SelectionData& selectionData);
|
||||
|
||||
void obstructing_window();
|
||||
void obstructing_window(const Clay_ElementId& elementID);
|
||||
|
||||
template <typename NewElement> NewElement* insert_element() {
|
||||
auto [it, inserted] = elements.emplace(idStack, ElementContainer());
|
||||
|
|
@ -317,7 +317,7 @@ class GUIManager {
|
|||
if(clicked)
|
||||
isOpen = true;
|
||||
if(isOpen) {
|
||||
top_to_bottom_window_popup_layout(CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&]() {
|
||||
top_to_bottom_window_popup_layout(CLAY_ID_LOCAL("COLOR PICKER"), CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&]() {
|
||||
isUpdating = color_picker_items("c", val, selectAlpha);
|
||||
if(io->mouse.leftClick && !Clay_Hovered() && !clicked)
|
||||
isOpen = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue