2025-07-06 20:43:53 +03:00
|
|
|
#include "SVGIcon.hpp"
|
|
|
|
|
#include "Helpers/ConvertVec.hpp"
|
|
|
|
|
#include <include/core/SkColorFilter.h>
|
|
|
|
|
#include <include/core/SkColorSpace.h>
|
|
|
|
|
#include <iostream>
|
2026-03-27 09:51:53 +03:00
|
|
|
#include "../GUIManager.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
SVGIcon::SVGIcon(GUIManager& gui):
|
|
|
|
|
Element(gui) {}
|
|
|
|
|
|
|
|
|
|
void SVGIcon::layout(const std::string& newSvgPath, bool newIsHighlighted) {
|
|
|
|
|
auto& io = *gui.io;
|
2025-07-06 20:43:53 +03:00
|
|
|
auto findSVGData = io.svgData.find(newSvgPath);
|
2025-11-21 10:36:46 +03:00
|
|
|
if(findSVGData == io.svgData.end())
|
|
|
|
|
throw std::runtime_error("[SVGIcon::update] Could not load icon " + newSvgPath);
|
2025-07-06 20:43:53 +03:00
|
|
|
else
|
|
|
|
|
svgDom = findSVGData->second;
|
|
|
|
|
|
|
|
|
|
highlighted = newIsHighlighted;
|
|
|
|
|
|
2025-12-02 16:09:30 +03:00
|
|
|
CLAY_AUTO_ID({
|
2025-07-06 20:43:53 +03:00
|
|
|
.layout = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }
|
|
|
|
|
},
|
|
|
|
|
.custom = { .customData = this }
|
2026-03-27 09:51:53 +03:00
|
|
|
}) {}
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-20 20:53:59 +03:00
|
|
|
void SVGIcon::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
2025-07-06 20:43:53 +03:00
|
|
|
if(!svgDom)
|
|
|
|
|
return;
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
auto& bb = boundingBox.value();
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
canvas->translate(bb.min.x(), bb.min.y());
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(0.0f, 0.0f, bb.width(), bb.height());
|
|
|
|
|
canvas->clipRect(r);
|
|
|
|
|
SkPaint blendingPaint;
|
|
|
|
|
blendingPaint.setColorFilter(SkColorFilters::Blend(highlighted ? io.theme->frontColor1 : io.theme->frontColor2, SkColorSpace::MakeSRGB(), SkBlendMode::kSrcIn));
|
|
|
|
|
canvas->saveLayer(r, &blendingPaint);
|
|
|
|
|
canvas->scale(bb.width() / svgDom->containerSize().width(), bb.height() / svgDom->containerSize().height());
|
|
|
|
|
svgDom->render(canvas);
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|