AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
IDrawable.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include <glm/glm.hpp>
   15#include <AUI/Util/Cache.h>
   16#include <AUI/Url/AUrl.h>
   17#include <AUI/Enum/Repeat.h>
   18#include <AUI/Enum/ImageRendering.h>
   19#include <AUI/Image/AImage.h>
   20
   21class IRenderer;
   22
   29    friend class AImageLoaderRegistry;
   30
   31    class Cache;
   32    friend class ::Cache<IDrawable, Cache, AUrl>;
   33    friend class AImageLoaderRegistry;
   34    class Cache : public ::Cache<IDrawable, Cache, AUrl> {
   35    public:
   36        static Cache& inst();
   37
   38    protected:
   39        _<IDrawable> load(const AUrl& key) override;
   40    };
   41
   42public:
   43    struct Params {
   44        glm::vec2 offset = { 0.f, 0.f };
   45        glm::vec2 size;
   46        AOptional<glm::vec2> cropUvTopLeft;
   47        AOptional<glm::vec2> cropUvBottomRight;
   48
   49        Repeat repeat = Repeat::NONE;
   50        ImageRendering imageRendering;
   51        AOptional<glm::vec2> renderingSize;
   52    };
   53
   61    virtual AImage rasterize(glm::ivec2 imageSize);
   62
   67    virtual void draw(IRenderer& render, const IDrawable::Params& params) = 0;
   68
   72    virtual glm::ivec2 getSizeHint() = 0;
   73
   77    virtual bool isDpiDependent() const { return false; }
   78
   88    API_AUI_VIEWS static _<IDrawable> fromUrl(const AUrl& url) noexcept;
   89};
Owning image representation.
Definition AImage.h:25
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
Uniform Resource Locator implementation.
Definition AUrl.h:31
An abstract image that determines itself how it is displayed. Essentially an abstraction from vector ...
Definition IDrawable.h:28
virtual void draw(IRenderer &render, const IDrawable::Params &params)=0
Called when the image needs to be displayed. It is assumed that the renderer is already set to the de...
static API_AUI_VIEWS _< IDrawable > fromUrl(const AUrl &url) noexcept
Creates a drawable from an url.
virtual bool isDpiDependent() const
Definition IDrawable.h:77
virtual AImage rasterize(glm::ivec2 imageSize)
Converts possibly vector drawable to a raster image.
virtual glm::ivec2 getSizeHint()=0
Base class for rendering.
Definition IRenderer.h:149
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
ImageRendering
Controls the image rendering type.
Definition ImageRendering.h:25
Definition IDrawable.h:43