infinipaint/src/GUIStuff/Elements/Element.cpp

69 lines
2.3 KiB
C++
Raw Normal View History

2025-07-06 20:43:53 +03:00
#include "Element.hpp"
#include "Helpers/MathExtras.hpp"
#include <chrono>
2025-07-06 20:43:53 +03:00
namespace GUIStuff {
SkFont get_setup_skfont() {
SkFont font;
font.setLinearMetrics(true);
font.setHinting(SkFontHinting::kNormal);
//font.setForceAutoHinting(true);
font.setSubpixel(true);
font.setBaselineSnap(true);
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
//paint.setAntiAlias(true);
return font;
}
SkFont UpdateInputData::get_font(float fSize) const {
SkFont f = get_setup_skfont();
f.setTypeface(textTypeface);
f.setSize(fSize);
return f;
}
std::shared_ptr<Theme> get_default_dark_mode() {
std::shared_ptr<Theme> theme(std::make_shared<Theme>());
theme->fillColor1 = {0.65f, 0.64f, 1.0f, 1.0f};
2025-11-01 20:47:34 +03:00
theme->fillColor2 = {0.6f, 0.6f, 0.785f, 1.0f};
theme->backColor1 = {0.156f, 0.156f, 0.18f, 1.0f};
theme->backColor2 = {0.24f, 0.24f, 0.29f, 1.0f};
2025-11-01 18:07:39 +03:00
theme->frontColor1 = {0.87f, 0.87f, 0.87f, 1.0f};
theme->frontColor2 = {0.64f, 0.64f, 0.64f, 1.0f};
2025-07-06 20:43:53 +03:00
return theme;
}
SCollision::AABB<float> Element::get_bb(Clay_RenderCommand* command) {
return {{command->boundingBox.x, command->boundingBox.y}, {command->boundingBox.x + command->boundingBox.width, command->boundingBox.y + command->boundingBox.height}};
}
void SelectionHelper::update(bool isHovering, bool isLeftClick, bool isLeftHeld, const Vector2f& cursorPos) {
2025-07-06 20:43:53 +03:00
hovered = isHovering;
clicked = false;
tapped = false;
2025-07-06 20:43:53 +03:00
justUnselected = false;
bool oldSelected = selected;
if(isLeftClick) {
if(hovered) {
held = true;
clicked = true;
selected = true;
timeClicked = std::chrono::steady_clock::now();
clickPos = cursorPos;
2025-07-06 20:43:53 +03:00
}
else
selected = false;
}
else if(!isLeftHeld) {
if(held && hovered && (std::chrono::steady_clock::now() - timeClicked) < std::chrono::milliseconds(250) && vec_distance_sqrd(clickPos, cursorPos) < (25 * 25))
tapped = true;
2025-07-06 20:43:53 +03:00
held = false;
}
2025-07-06 20:43:53 +03:00
if(!selected && oldSelected)
justUnselected = true;
}
}