2024-02-19 00:08:03 +01:00
|
|
|
#include "PasswordInputField.hpp"
|
|
|
|
#include "../Renderer.hpp"
|
|
|
|
#include "../../core/hyprlock.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
|
2024-03-05 21:24:11 +01:00
|
|
|
CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props) : shadow(this, props, viewport_) {
|
2024-03-09 17:44:58 +01:00
|
|
|
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
|
|
|
|
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
|
|
|
|
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
|
|
|
|
outThick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
|
|
|
dots.size = std::any_cast<Hyprlang::FLOAT>(props.at("dots_size"));
|
|
|
|
dots.spacing = std::any_cast<Hyprlang::FLOAT>(props.at("dots_spacing"));
|
|
|
|
dots.center = std::any_cast<Hyprlang::INT>(props.at("dots_center"));
|
|
|
|
dots.rounding = std::any_cast<Hyprlang::INT>(props.at("dots_rounding"));
|
|
|
|
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
|
|
|
fadeTimeoutMs = std::any_cast<Hyprlang::INT>(props.at("fade_timeout"));
|
|
|
|
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
|
|
|
|
hiddenInputState.enabled = std::any_cast<Hyprlang::INT>(props.at("hide_input"));
|
|
|
|
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
|
|
|
placeholder.failColor = std::any_cast<Hyprlang::INT>(props.at("fail_color"));
|
|
|
|
placeholder.failTransitionMs = std::any_cast<Hyprlang::INT>(props.at("fail_transition"));
|
|
|
|
configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text"));
|
|
|
|
viewport = viewport_;
|
|
|
|
|
|
|
|
auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
|
|
|
|
pos = {POS__.x, POS__.y};
|
|
|
|
configPos = pos;
|
|
|
|
|
|
|
|
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
|
|
|
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
|
|
|
|
|
|
|
pos = posFromHVAlign(viewport, size, pos, halign, valign);
|
|
|
|
dots.size = std::clamp(dots.size, 0.2f, 0.8f);
|
|
|
|
dots.spacing = std::clamp(dots.spacing, 0.f, 1.f);
|
|
|
|
placeholder.failTransitionMs = std::clamp(placeholder.failTransitionMs, 1, 5000);
|
2024-02-19 23:58:59 +01:00
|
|
|
|
|
|
|
std::string placeholderText = std::any_cast<Hyprlang::STRING>(props.at("placeholder_text"));
|
|
|
|
if (!placeholderText.empty()) {
|
|
|
|
placeholder.resourceID = "placeholder:" + std::to_string((uintptr_t)this);
|
|
|
|
CAsyncResourceGatherer::SPreloadRequest request;
|
|
|
|
request.id = placeholder.resourceID;
|
|
|
|
request.asset = placeholderText;
|
|
|
|
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
|
|
|
request.props["font_family"] = std::string{"Sans"};
|
|
|
|
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5};
|
2024-02-20 01:53:49 +01:00
|
|
|
request.props["font_size"] = (int)size.y / 4;
|
2024-02-19 23:58:59 +01:00
|
|
|
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
|
|
|
}
|
2024-02-19 02:22:22 +01:00
|
|
|
}
|
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
static void replaceAllFail(std::string& str, const std::string& from, const std::string& to) {
|
|
|
|
if (from.empty())
|
|
|
|
return;
|
|
|
|
size_t pos = 0;
|
|
|
|
while ((pos = str.find(from, pos)) != std::string::npos) {
|
|
|
|
str.replace(pos, from.length(), to);
|
|
|
|
pos += to.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 22:12:49 +01:00
|
|
|
static void fadeOutCallback(std::shared_ptr<CTimer> self, void* data) {
|
|
|
|
CPasswordInputField* p = (CPasswordInputField*)data;
|
|
|
|
|
|
|
|
p->onFadeOutTimer();
|
|
|
|
|
|
|
|
for (auto& o : g_pHyprlock->m_vOutputs) {
|
|
|
|
o->sessionLockSurface->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPasswordInputField::onFadeOutTimer() {
|
|
|
|
fade.allowFadeOut = true;
|
|
|
|
fade.fadeOutTimer.reset();
|
|
|
|
}
|
|
|
|
|
2024-02-19 02:22:22 +01:00
|
|
|
void CPasswordInputField::updateFade() {
|
|
|
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
|
|
|
|
|
|
|
if (!fadeOnEmpty) {
|
|
|
|
fade.a = 1.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-06 22:12:49 +01:00
|
|
|
if (PASSLEN > 0 && fade.allowFadeOut)
|
|
|
|
fade.allowFadeOut = false;
|
|
|
|
|
|
|
|
if (PASSLEN > 0 && fade.fadeOutTimer.get()) {
|
|
|
|
fade.fadeOutTimer->cancel();
|
|
|
|
fade.fadeOutTimer.reset();
|
|
|
|
}
|
|
|
|
|
2024-02-19 02:22:22 +01:00
|
|
|
if (PASSLEN == 0 && fade.a != 0.0 && (!fade.animated || fade.appearing)) {
|
2024-03-06 22:12:49 +01:00
|
|
|
if (fade.allowFadeOut || fadeTimeoutMs == 0) {
|
|
|
|
fade.a = 1.0;
|
|
|
|
fade.animated = true;
|
|
|
|
fade.appearing = false;
|
|
|
|
fade.start = std::chrono::system_clock::now();
|
|
|
|
fade.allowFadeOut = false;
|
|
|
|
} else if (!fade.fadeOutTimer.get())
|
|
|
|
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), fadeOutCallback, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PASSLEN > 0 && fade.a != 1.0 && (!fade.animated || !fade.appearing)) {
|
2024-02-19 02:22:22 +01:00
|
|
|
fade.a = 0.0;
|
|
|
|
fade.animated = true;
|
|
|
|
fade.appearing = true;
|
|
|
|
fade.start = std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fade.animated) {
|
|
|
|
if (fade.appearing)
|
|
|
|
fade.a = std::clamp(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0);
|
|
|
|
else
|
|
|
|
fade.a = std::clamp(1.0 - std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0);
|
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
if ((fade.appearing && fade.a == 1.0) || (!fade.appearing && fade.a == 0.0)) {
|
2024-02-19 02:22:22 +01:00
|
|
|
fade.animated = false;
|
2024-03-09 17:44:58 +01:00
|
|
|
redrawShadow = true;
|
|
|
|
}
|
2024-02-19 02:22:22 +01:00
|
|
|
}
|
2024-02-19 00:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPasswordInputField::updateDots() {
|
|
|
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
|
|
|
|
2024-02-19 22:09:00 +01:00
|
|
|
if (PASSLEN == dots.currentAmount)
|
|
|
|
return;
|
|
|
|
|
2024-02-20 03:47:03 +01:00
|
|
|
if (std::abs(PASSLEN - dots.currentAmount) > 1) {
|
|
|
|
dots.currentAmount = std::clamp(dots.currentAmount, PASSLEN - 1.f, PASSLEN + 1.f);
|
|
|
|
dots.lastFrame = std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dots.lastFrame).count(), 0, 20000);
|
2024-02-19 22:09:00 +01:00
|
|
|
|
2024-02-20 03:47:03 +01:00
|
|
|
const float TOADD = DELTA / 1000000.0 * dots.speedPerSecond;
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-02-19 22:09:00 +01:00
|
|
|
if (PASSLEN > dots.currentAmount) {
|
|
|
|
dots.currentAmount += TOADD;
|
|
|
|
if (dots.currentAmount > PASSLEN)
|
|
|
|
dots.currentAmount = PASSLEN;
|
|
|
|
} else if (PASSLEN < dots.currentAmount) {
|
|
|
|
dots.currentAmount -= TOADD;
|
|
|
|
if (dots.currentAmount < PASSLEN)
|
|
|
|
dots.currentAmount = PASSLEN;
|
2024-02-19 00:08:03 +01:00
|
|
|
}
|
|
|
|
|
2024-02-19 22:09:00 +01:00
|
|
|
dots.lastFrame = std::chrono::system_clock::now();
|
2024-02-19 00:08:03 +01:00
|
|
|
}
|
|
|
|
|
2024-02-19 17:26:08 +01:00
|
|
|
bool CPasswordInputField::draw(const SRenderData& data) {
|
2024-02-19 00:08:03 +01:00
|
|
|
CBox inputFieldBox = {pos, size};
|
2024-03-04 18:59:36 +01:00
|
|
|
CBox outerBox = {pos - Vector2D{outThick, outThick}, size + Vector2D{outThick * 2, outThick * 2}};
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
if (firstRender || redrawShadow) {
|
|
|
|
firstRender = false;
|
|
|
|
redrawShadow = false;
|
2024-03-05 21:24:11 +01:00
|
|
|
shadow.markShadowDirty();
|
|
|
|
}
|
|
|
|
|
2024-02-20 01:53:49 +01:00
|
|
|
bool forceReload = false;
|
|
|
|
|
2024-02-19 02:22:22 +01:00
|
|
|
updateFade();
|
2024-02-19 00:08:03 +01:00
|
|
|
updateDots();
|
2024-02-20 01:53:49 +01:00
|
|
|
updateFailTex();
|
2024-03-09 17:44:58 +01:00
|
|
|
updateOuter();
|
2024-02-20 15:42:04 +01:00
|
|
|
updateHiddenInputState();
|
2024-02-20 01:53:49 +01:00
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
static auto ORIGSIZEX = size.x;
|
|
|
|
static auto ORIGPOS = pos;
|
|
|
|
|
|
|
|
if (placeholder.failAsset && placeholder.failAsset->texture.m_vSize.x > ORIGSIZEX) {
|
|
|
|
if (placeholder.failAsset->texture.m_vSize.x > size.x)
|
|
|
|
redrawShadow = true;
|
|
|
|
|
|
|
|
size.x = placeholder.failAsset->texture.m_vSize.x + inputFieldBox.h;
|
|
|
|
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
|
|
|
|
} else {
|
|
|
|
size.x = ORIGSIZEX;
|
|
|
|
pos = ORIGPOS;
|
|
|
|
}
|
|
|
|
|
2024-03-05 21:24:11 +01:00
|
|
|
SRenderData shadowData = data;
|
|
|
|
shadowData.opacity *= fade.a;
|
|
|
|
shadow.draw(shadowData);
|
|
|
|
|
2024-02-20 01:53:49 +01:00
|
|
|
float passAlpha = g_pHyprlock->passwordCheckWaiting() ? 0.5 : 1.0;
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-02-19 02:22:22 +01:00
|
|
|
CColor outerCol = outer;
|
2024-02-20 17:34:59 +01:00
|
|
|
outerCol.a *= fade.a * data.opacity;
|
2024-02-19 02:22:22 +01:00
|
|
|
CColor innerCol = inner;
|
2024-02-20 17:29:23 +01:00
|
|
|
innerCol.a *= fade.a * data.opacity;
|
|
|
|
CColor fontCol = font;
|
2024-02-20 01:53:49 +01:00
|
|
|
fontCol.a *= fade.a * data.opacity * passAlpha;
|
2024-02-19 02:22:22 +01:00
|
|
|
|
2024-03-04 02:54:27 +01:00
|
|
|
g_pRenderer->renderRect(outerBox, outerCol, rounding == -1 ? outerBox.h / 2.0 : rounding);
|
2024-02-20 15:42:04 +01:00
|
|
|
|
|
|
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
|
|
|
|
|
|
|
if (PASSLEN != 0 && hiddenInputState.enabled) {
|
|
|
|
CBox outerBoxScaled = outerBox;
|
|
|
|
Vector2D p = outerBox.pos();
|
|
|
|
outerBoxScaled.translate(-p).scale(0.5).translate(p);
|
|
|
|
if (hiddenInputState.lastQuadrant > 1)
|
|
|
|
outerBoxScaled.y += outerBoxScaled.h;
|
|
|
|
if (hiddenInputState.lastQuadrant % 2 == 1)
|
|
|
|
outerBoxScaled.x += outerBoxScaled.w;
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(outerBoxScaled.x, outerBoxScaled.y, outerBoxScaled.w, outerBoxScaled.h);
|
2024-03-04 02:54:27 +01:00
|
|
|
g_pRenderer->renderRect(outerBox, hiddenInputState.lastColor, rounding == -1 ? outerBox.h / 2.0 : rounding);
|
2024-02-20 15:42:04 +01:00
|
|
|
glScissor(0, 0, viewport.x, viewport.y);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2024-03-04 18:59:36 +01:00
|
|
|
g_pRenderer->renderRect(inputFieldBox, innerCol, rounding == -1 ? inputFieldBox.h / 2.0 : rounding - outThick);
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-03-04 18:59:36 +01:00
|
|
|
const int PASS_SIZE = std::nearbyint(inputFieldBox.h * dots.size * 0.5f) * 2.f;
|
|
|
|
const int PASS_SPACING = std::floor(PASS_SIZE * dots.spacing);
|
2024-02-26 01:33:19 +01:00
|
|
|
const int DOT_PAD = (inputFieldBox.h - PASS_SIZE) / 2;
|
|
|
|
const int DOT_AREA_WIDTH = inputFieldBox.w - DOT_PAD * 2; // avail width for dots
|
|
|
|
const int MAX_DOTS = std::round(DOT_AREA_WIDTH * 1.0 / (PASS_SIZE + PASS_SPACING)); // max amount of dots that can fit in the area
|
|
|
|
const int DOT_FLOORED = std::floor(dots.currentAmount);
|
|
|
|
const float DOT_ALPHA = fontCol.a;
|
2024-02-24 15:14:10 +01:00
|
|
|
// Calculate the total width required for all dots including spaces between them
|
|
|
|
const int TOTAL_DOTS_WIDTH = (PASS_SIZE + PASS_SPACING) * dots.currentAmount - PASS_SPACING;
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-02-20 15:42:04 +01:00
|
|
|
if (!hiddenInputState.enabled) {
|
2024-02-24 15:14:10 +01:00
|
|
|
// Calculate starting x-position to ensure dots stay centered within the input field
|
2024-02-26 01:33:19 +01:00
|
|
|
int xstart = dots.center ? (DOT_AREA_WIDTH - TOTAL_DOTS_WIDTH) / 2 + DOT_PAD : DOT_PAD;
|
2024-02-21 12:42:18 +01:00
|
|
|
|
2024-02-26 01:33:19 +01:00
|
|
|
if (dots.currentAmount > MAX_DOTS)
|
|
|
|
xstart = (inputFieldBox.w + MAX_DOTS * (PASS_SIZE + PASS_SPACING) - PASS_SPACING - 2 * TOTAL_DOTS_WIDTH) / 2;
|
|
|
|
|
2024-03-04 18:59:36 +01:00
|
|
|
if (dots.rounding == -1)
|
|
|
|
dots.rounding = PASS_SIZE / 2.0;
|
|
|
|
else if (dots.rounding == -2)
|
|
|
|
dots.rounding = rounding == -1 ? PASS_SIZE / 2.0 : rounding * dots.size;
|
|
|
|
|
2024-02-26 01:33:19 +01:00
|
|
|
for (int i = 0; i < dots.currentAmount; ++i) {
|
|
|
|
if (i < DOT_FLOORED - MAX_DOTS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dots.currentAmount != DOT_FLOORED) {
|
|
|
|
if (i == DOT_FLOORED)
|
|
|
|
fontCol.a *= (dots.currentAmount - DOT_FLOORED) * data.opacity;
|
|
|
|
else if (i == DOT_FLOORED - MAX_DOTS)
|
|
|
|
fontCol.a *= (1 - dots.currentAmount + DOT_FLOORED) * data.opacity;
|
|
|
|
}
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-03-04 18:59:36 +01:00
|
|
|
Vector2D dotPosition =
|
|
|
|
inputFieldBox.pos() + Vector2D{xstart + (int)inputFieldBox.w % 2 / 2.f + i * (PASS_SIZE + PASS_SPACING), inputFieldBox.h / 2.f - PASS_SIZE / 2.f};
|
|
|
|
CBox box{dotPosition, Vector2D{PASS_SIZE, PASS_SIZE}};
|
|
|
|
g_pRenderer->renderRect(box, fontCol, dots.rounding);
|
2024-02-26 01:33:19 +01:00
|
|
|
fontCol.a = DOT_ALPHA;
|
2024-02-20 15:42:04 +01:00
|
|
|
}
|
2024-02-19 22:09:00 +01:00
|
|
|
}
|
|
|
|
|
2024-02-19 23:58:59 +01:00
|
|
|
if (PASSLEN == 0 && !placeholder.resourceID.empty()) {
|
2024-02-20 01:53:49 +01:00
|
|
|
SPreloadedAsset* currAsset = nullptr;
|
|
|
|
|
|
|
|
if (!placeholder.failID.empty()) {
|
|
|
|
if (!placeholder.failAsset)
|
|
|
|
placeholder.failAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(placeholder.failID);
|
|
|
|
|
|
|
|
currAsset = placeholder.failAsset;
|
|
|
|
} else {
|
|
|
|
if (!placeholder.asset)
|
|
|
|
placeholder.asset = g_pRenderer->asyncResourceGatherer->getAssetByID(placeholder.resourceID);
|
2024-02-19 23:58:59 +01:00
|
|
|
|
2024-02-20 01:53:49 +01:00
|
|
|
currAsset = placeholder.asset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currAsset) {
|
2024-02-19 23:58:59 +01:00
|
|
|
Vector2D pos = outerBox.pos() + outerBox.size() / 2.f;
|
2024-02-20 01:53:49 +01:00
|
|
|
pos = pos - currAsset->texture.m_vSize / 2.f;
|
|
|
|
CBox textbox{pos, currAsset->texture.m_vSize};
|
|
|
|
g_pRenderer->renderTexture(textbox, currAsset->texture, data.opacity * fade.a, 0);
|
|
|
|
} else
|
|
|
|
forceReload = true;
|
|
|
|
}
|
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
return dots.currentAmount != PASSLEN || fade.animated || outerAnimated || redrawShadow || data.opacity < 1.0 || forceReload;
|
2024-02-20 01:53:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPasswordInputField::updateFailTex() {
|
|
|
|
const auto FAIL = g_pHyprlock->passwordLastFailReason();
|
|
|
|
|
|
|
|
if (g_pHyprlock->passwordCheckWaiting())
|
|
|
|
placeholder.canGetNewFail = true;
|
|
|
|
|
|
|
|
if (g_pHyprlock->getPasswordBufferLen() != 0) {
|
|
|
|
if (placeholder.failAsset) {
|
|
|
|
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.failAsset);
|
|
|
|
placeholder.failAsset = nullptr;
|
|
|
|
placeholder.failID = "";
|
2024-03-09 17:44:58 +01:00
|
|
|
redrawShadow = true;
|
2024-02-19 23:58:59 +01:00
|
|
|
}
|
2024-02-20 01:53:49 +01:00
|
|
|
return;
|
2024-02-19 23:58:59 +01:00
|
|
|
}
|
|
|
|
|
2024-02-20 01:53:49 +01:00
|
|
|
if (!FAIL.has_value() || !placeholder.canGetNewFail)
|
|
|
|
return;
|
|
|
|
|
2024-03-09 17:44:58 +01:00
|
|
|
placeholder.failText = configFailText;
|
|
|
|
replaceAllFail(placeholder.failText, "$FAIL", FAIL.value());
|
|
|
|
replaceAllFail(placeholder.failText, "$ATTEMPTS", std::to_string(g_pHyprlock->getPasswordFailedAttempts()));
|
|
|
|
|
2024-02-20 01:53:49 +01:00
|
|
|
// query
|
|
|
|
CAsyncResourceGatherer::SPreloadRequest request;
|
|
|
|
request.id = "input-error:" + std::to_string((uintptr_t)this) + ",time:" + std::to_string(time(nullptr));
|
|
|
|
placeholder.failID = request.id;
|
2024-03-09 17:44:58 +01:00
|
|
|
request.asset = placeholder.failText;
|
2024-02-20 01:53:49 +01:00
|
|
|
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
|
|
|
request.props["font_family"] = std::string{"Sans"};
|
2024-03-09 17:44:58 +01:00
|
|
|
request.props["color"] = placeholder.failColor;
|
2024-02-20 01:53:49 +01:00
|
|
|
request.props["font_size"] = (int)size.y / 4;
|
|
|
|
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
|
|
|
|
|
|
|
placeholder.canGetNewFail = false;
|
|
|
|
}
|
2024-02-20 15:42:04 +01:00
|
|
|
|
|
|
|
void CPasswordInputField::updateHiddenInputState() {
|
|
|
|
if (!hiddenInputState.enabled || (size_t)hiddenInputState.lastPasswordLength == g_pHyprlock->getPasswordBufferLen())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// randomize new thang
|
|
|
|
hiddenInputState.lastPasswordLength = g_pHyprlock->getPasswordBufferLen();
|
|
|
|
|
2024-03-03 23:55:27 +01:00
|
|
|
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
2024-02-20 15:42:04 +01:00
|
|
|
float r1 = (rand() % 100) / 255.0;
|
|
|
|
float r2 = (rand() % 100) / 255.0;
|
|
|
|
int r3 = rand() % 3;
|
|
|
|
int r4 = rand() % 2;
|
|
|
|
int r5 = rand() % 2;
|
|
|
|
|
|
|
|
((float*)&hiddenInputState.lastColor.r)[r3] = r1 + 155 / 255.0;
|
|
|
|
((float*)&hiddenInputState.lastColor.r)[(r3 + r4) % 3] = r2 + 155 / 255.0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
if (i != r3 && i != ((r3 + r4) % 3)) {
|
|
|
|
((float*)&hiddenInputState.lastColor.r)[i] = 1.0 - ((float*)&hiddenInputState.lastColor.r)[r5 ? r3 : ((r3 + r4) % 3)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hiddenInputState.lastColor.a = 1.0;
|
|
|
|
hiddenInputState.lastQuadrant = (hiddenInputState.lastQuadrant + rand() % 3 + 1) % 4;
|
|
|
|
}
|
2024-03-09 17:44:58 +01:00
|
|
|
|
|
|
|
void CPasswordInputField::updateOuter() {
|
|
|
|
if (outThick == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static auto OUTERCOL = outer;
|
|
|
|
static auto TIMER = std::chrono::system_clock::now();
|
|
|
|
bool changeToOuter = placeholder.failID.empty();
|
|
|
|
|
|
|
|
outerAnimated = false;
|
|
|
|
|
|
|
|
if (changeToOuter) {
|
|
|
|
if (outer == OUTERCOL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (outer == placeholder.failColor)
|
|
|
|
TIMER = std::chrono::system_clock::now();
|
|
|
|
} else if (!changeToOuter) {
|
|
|
|
if (fade.animated || fade.a < 1.0)
|
|
|
|
changeToOuter = true;
|
|
|
|
|
|
|
|
if (outer == OUTERCOL)
|
|
|
|
TIMER = std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto MULTI = std::clamp(
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - TIMER).count() / (double)placeholder.failTransitionMs, 0.001, 0.5);
|
|
|
|
const auto DELTA = changeToOuter ? OUTERCOL - placeholder.failColor : placeholder.failColor - OUTERCOL;
|
|
|
|
const auto TARGET = changeToOuter ? OUTERCOL : placeholder.failColor;
|
|
|
|
const auto SOURCE = changeToOuter ? placeholder.failColor : OUTERCOL;
|
|
|
|
|
|
|
|
if (outer.r != TARGET.r) {
|
|
|
|
outer.r += DELTA.r * MULTI;
|
|
|
|
outerAnimated = true;
|
|
|
|
|
|
|
|
if ((SOURCE.r < TARGET.r && outer.r > TARGET.r) || (SOURCE.r > TARGET.r && outer.r < TARGET.r))
|
|
|
|
outer.r = TARGET.r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outer.g != TARGET.g) {
|
|
|
|
outer.g += DELTA.g * MULTI;
|
|
|
|
outerAnimated = true;
|
|
|
|
|
|
|
|
if ((SOURCE.g < TARGET.g && outer.g > TARGET.g) || (SOURCE.g > TARGET.g && outer.g < TARGET.g))
|
|
|
|
outer.g = TARGET.g;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outer.b != TARGET.b) {
|
|
|
|
outer.b += DELTA.b * MULTI;
|
|
|
|
outerAnimated = true;
|
|
|
|
|
|
|
|
if ((SOURCE.b < TARGET.b && outer.b > TARGET.b) || (SOURCE.b > TARGET.b && outer.b < TARGET.b))
|
|
|
|
outer.b = TARGET.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outer.a != TARGET.a) {
|
|
|
|
outer.a += DELTA.a * MULTI;
|
|
|
|
outerAnimated = true;
|
|
|
|
|
|
|
|
if ((SOURCE.a < TARGET.a && outer.a > TARGET.a) || (SOURCE.a > TARGET.a && outer.a < TARGET.a))
|
|
|
|
outer.a = TARGET.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIMER = std::chrono::system_clock::now();
|
|
|
|
}
|