mirror of
https://github.com/hyprwm/hyprgraphics.git
synced 2025-12-20 20:20:23 +01:00
move buffer to StaticImageResource
This commit is contained in:
parent
ee86d75cd7
commit
d41c77ea2e
4 changed files with 53 additions and 11 deletions
|
|
@ -18,7 +18,6 @@ namespace Hyprgraphics {
|
||||||
};
|
};
|
||||||
|
|
||||||
CImageResource(const std::string& path);
|
CImageResource(const std::string& path);
|
||||||
CImageResource(const std::span<const uint8_t> data, eImageFormat format);
|
|
||||||
CImageResource(const std::string& svg, const Hyprutils::Math::Vector2D& size);
|
CImageResource(const std::string& svg, const Hyprutils::Math::Vector2D& size);
|
||||||
virtual ~CImageResource() = default;
|
virtual ~CImageResource() = default;
|
||||||
|
|
||||||
|
|
@ -27,8 +26,5 @@ namespace Hyprgraphics {
|
||||||
private:
|
private:
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
Hyprutils::Math::Vector2D m_svgSize;
|
Hyprutils::Math::Vector2D m_svgSize;
|
||||||
|
|
||||||
const std::span<const uint8_t> m_data;
|
|
||||||
const eImageFormat m_format = eImageFormat::IMAGE_FORMAT_PNG;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AsyncResource.hpp"
|
||||||
|
#include "../../color/Color.hpp"
|
||||||
|
#include "hyprgraphics/image/Image.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include <hyprutils/math/Vector2D.hpp>
|
||||||
|
|
||||||
|
namespace Hyprgraphics {
|
||||||
|
class CStaticImageResource : public IAsyncResource {
|
||||||
|
public:
|
||||||
|
enum eTextAlignmentMode : uint8_t {
|
||||||
|
TEXT_ALIGN_LEFT = 0,
|
||||||
|
TEXT_ALIGN_CENTER,
|
||||||
|
TEXT_ALIGN_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
CStaticImageResource(const std::span<const uint8_t> data, eImageFormat format);
|
||||||
|
virtual ~CStaticImageResource() = default;
|
||||||
|
|
||||||
|
virtual void render();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::span<const uint8_t> m_data;
|
||||||
|
const eImageFormat m_format = eImageFormat::IMAGE_FORMAT_PNG;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -13,16 +13,12 @@ CImageResource::CImageResource(const std::string& path) : m_path(path) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
CImageResource::CImageResource(const std::span<const uint8_t> data, eImageFormat format) : m_data(data), m_format(format) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
CImageResource::CImageResource(const std::string& svg, const Hyprutils::Math::Vector2D& size) : m_path(svg), m_svgSize(size) {
|
CImageResource::CImageResource(const std::string& svg, const Hyprutils::Math::Vector2D& size) : m_path(svg), m_svgSize(size) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CImageResource::render() {
|
void CImageResource::render() {
|
||||||
auto image = m_data.size() > 0 ? CImage(m_data, m_format) : CImage(m_path, m_svgSize);
|
auto image = CImage(m_path, m_svgSize);
|
||||||
|
|
||||||
m_asset.cairoSurface = image.cairoSurface();
|
m_asset.cairoSurface = image.cairoSurface();
|
||||||
m_asset.pixelSize = m_asset.cairoSurface && m_asset.cairoSurface->cairo() ? m_asset.cairoSurface->size() : Hyprutils::Math::Vector2D{};
|
m_asset.pixelSize = m_asset.cairoSurface && m_asset.cairoSurface->cairo() ? m_asset.cairoSurface->size() : Hyprutils::Math::Vector2D{};
|
||||||
|
|
|
||||||
21
src/resource/resources/StaticImageResource.cpp
Normal file
21
src/resource/resources/StaticImageResource.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include <hyprgraphics/resource/resources/StaticImageResource.hpp>
|
||||||
|
#include <hyprgraphics/image/Image.hpp>
|
||||||
|
#include <hyprutils/memory/Atomic.hpp>
|
||||||
|
#include <hyprutils/memory/Casts.hpp>
|
||||||
|
|
||||||
|
#include <cairo/cairo.h>
|
||||||
|
#include <pango/pangocairo.h>
|
||||||
|
|
||||||
|
using namespace Hyprgraphics;
|
||||||
|
using namespace Hyprutils::Memory;
|
||||||
|
|
||||||
|
CStaticImageResource::CStaticImageResource(const std::span<const uint8_t> data, eImageFormat format) : m_data(data), m_format(format) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CStaticImageResource::render() {
|
||||||
|
auto image = CImage(m_data, m_format);
|
||||||
|
|
||||||
|
m_asset.cairoSurface = image.cairoSurface();
|
||||||
|
m_asset.pixelSize = m_asset.cairoSurface && m_asset.cairoSurface->cairo() ? m_asset.cairoSurface->size() : Hyprutils::Math::Vector2D{};
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue