AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
IDrawable.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 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
28{
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 protected:
38 _<IDrawable> load(const AUrl& key) override;
39 };
40
41public:
42
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
69
73 virtual glm::ivec2 getSizeHint() = 0;
74
75
79 virtual bool isDpiDependent() const
80 {
81 return false;
82 }
83
84
94 API_AUI_VIEWS static _<IDrawable> fromUrl(const AUrl& url) noexcept;
95};
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
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...
virtual AImage rasterize(glm::ivec2 imageSize)
Converts possibly vector drawable to a raster image.
Definition: IDrawable.cpp:52
virtual bool isDpiDependent() const
Definition: IDrawable.h:79
virtual glm::ivec2 getSizeHint()=0
static API_AUI_VIEWS _< IDrawable > fromUrl(const AUrl &url) noexcept
Creates a drawable from an url.
Definition: IDrawable.cpp:19
Base class for rendering.
Definition: IRenderer.h:149
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
ImageRendering
Controls the image rendering type.
Definition: ImageRendering.h:26
Definition: IDrawable.h:43