mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
widgets: allow background to take a color
This commit is contained in:
parent
81ca6f068b
commit
6a31b2f182
5 changed files with 25 additions and 6 deletions
|
@ -24,6 +24,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("background", "path", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("background", "color", Hyprlang::INT{0xFF111111});
|
||||
|
||||
m_config.addSpecialCategory("input-field", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("input-field", "monitor", Hyprlang::STRING{""});
|
||||
|
@ -70,6 +71,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
|
||||
{
|
||||
{"path", m_config.getSpecialConfigValue("background", "path", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("background", "color", k.c_str())},
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
|
@ -57,6 +57,10 @@ void CAsyncResourceGatherer::gather() {
|
|||
progress += 1.0 / (preloads + 1.0);
|
||||
|
||||
std::string path = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
if (path.empty())
|
||||
continue;
|
||||
|
||||
std::string id = std::string{"background:"} + path;
|
||||
|
||||
// preload bg img
|
||||
|
|
|
@ -251,9 +251,11 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
|
|||
continue;
|
||||
|
||||
// by type
|
||||
if (c.type == "background")
|
||||
widgets[surf].emplace_back(std::make_unique<CBackground>(surf->size, std::string{"background:"} + std::any_cast<Hyprlang::STRING>(c.values.at("path"))));
|
||||
else if (c.type == "input-field") {
|
||||
if (c.type == "background") {
|
||||
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
widgets[surf].emplace_back(
|
||||
std::make_unique<CBackground>(surf->size, PATH.empty() ? "" : std::string{"background:"} + PATH, std::any_cast<Hyprlang::INT>(c.values.at("color"))));
|
||||
} else if (c.type == "input-field") {
|
||||
const auto SIZE = std::any_cast<Hyprlang::VEC2>(c.values.at("size"));
|
||||
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(
|
||||
surf->size, Vector2D{SIZE.x, SIZE.y}, std::any_cast<Hyprlang::INT>(c.values.at("outer_color")), std::any_cast<Hyprlang::INT>(c.values.at("inner_color")),
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
#include "Background.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
|
||||
CBackground::CBackground(const Vector2D& viewport_, const std::string& resourceID_) : viewport(viewport_), resourceID(resourceID_) {
|
||||
CBackground::CBackground(const Vector2D& viewport_, const std::string& resourceID_, const CColor& color_) : viewport(viewport_), resourceID(resourceID_), color(color_) {
|
||||
;
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty()) {
|
||||
CBox monbox = {0, 0, viewport.x, viewport.y};
|
||||
CColor col = color;
|
||||
col.a *= data.opacity;
|
||||
g_pRenderer->renderRect(monbox, col, 0);
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
|
||||
if (!asset)
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
|
||||
|
|
|
@ -2,18 +2,20 @@
|
|||
|
||||
#include "IWidget.hpp"
|
||||
#include "../../helpers/Vector2D.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include <string>
|
||||
|
||||
struct SPreloadedAsset;
|
||||
|
||||
class CBackground : public IWidget {
|
||||
public:
|
||||
CBackground(const Vector2D& viewport, const std::string& resourceID);
|
||||
CBackground(const Vector2D& viewport, const std::string& resourceID, const CColor& color);
|
||||
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
private:
|
||||
Vector2D viewport;
|
||||
std::string resourceID;
|
||||
CColor color;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
};
|
Loading…
Reference in a new issue