Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
theme_image.hpp
Go to the documentation of this file.
1/*
2 Copyright 2026 JigSawFr
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <nanovg.h>
20
21#include <functional>
22#include <memory>
23#include <string>
24#include <aurore/core/event.hpp>
25#include <aurore/core/theme.hpp>
26
27namespace aurore
28{
29
34{
35 int flags = 0; // NVG_IMAGE_* (NVG_IMAGE_REPEATX...)
36 int maxSide = 0; // made smaller to fit in maxSide x maxSide; 0: MAX_WIDTH x MAX_HEIGHT
37 // A mask: white, its alpha the picture's, to be tinted when drawn (a
38 // picture with no transparent pixel: its dark parts, by luminance)
39 bool mask = false;
40};
41
49{
50 enum class State
51 {
52 LOADING,
53 READY,
54 FAILED, // cannot be read or decoded: draws nothing
55 };
56
57 std::string path; // as Theme::resolveAsset() made it
58 int flags = 0; // NVG_IMAGE_* it was made with
59 int maxSide = 0; // its ThemeImageOptions
60 bool mask = false;
62 int texture = 0; // 0 until READY
63 int width = 0, height = 0; // the texture's, after downscaling
64 NVGcolor mean {}; // its average colour, opaque, once READY
65
66 bool ready() const { return this->state == State::READY; }
67
76 bool draw(NVGcontext* vg, float x, float y, float width, float height, BackgroundFit fit,
77 const NVGcolor* tint = nullptr, float alpha = 1.0f, float corner = 0.0f) const;
78
79 ThemeImage() = default;
80 ThemeImage(const ThemeImage&) = delete;
81 ThemeImage& operator=(const ThemeImage&) = delete;
82 // Deletes the texture: the last owner lets it go on the UI thread
84};
85
102{
103 public:
104 static constexpr int MAX_WIDTH = 1920;
105 static constexpr int MAX_HEIGHT = 1080;
106 // The largest side of a theme's logo, of its icons and of its preview
107 // (ThemeImageOptions::maxSide): what the screens draw them at, with room
108 // for a 1080p screen
109 static constexpr int LOGO_SIZE = 256;
110 static constexpr int ICON_SIZE = 128;
111 static constexpr int PREVIEW_SIZE = 128;
112
117 static std::shared_ptr<ThemeImage> load(const std::string& path, int flags = 0);
118
123 static std::shared_ptr<ThemeImage> load(const std::string& path, const ThemeImageOptions& options);
124
130
137 static bool meanColor(const std::string& path, NVGcolor* color);
138
142 static bool knownMeanColor(const std::string& path, NVGcolor* color);
143
148 static bool exists(const std::string& path);
149
155 static int decoding();
156
161 static void releaseAll();
162};
163
164} // namespace aurore
Definition event.hpp:41
Definition theme_image.hpp:102
static std::shared_ptr< ThemeImage > load(const std::string &path, const ThemeImageOptions &options)
static bool meanColor(const std::string &path, NVGcolor *color)
static void releaseAll()
static int decoding()
static constexpr int MAX_HEIGHT
Definition theme_image.hpp:105
static std::shared_ptr< ThemeImage > load(const std::string &path, int flags=0)
static constexpr int ICON_SIZE
Definition theme_image.hpp:110
static bool knownMeanColor(const std::string &path, NVGcolor *color)
static constexpr int LOGO_SIZE
Definition theme_image.hpp:109
static bool exists(const std::string &path)
static Event< const ThemeImage * > * getLoadedEvent()
static constexpr int PREVIEW_SIZE
Definition theme_image.hpp:111
static constexpr int MAX_WIDTH
Definition theme_image.hpp:104
Definition actions.hpp:25
BackgroundFit
How a theme's background_image fills the window (background_fit)
Definition theme.hpp:72
Definition theme_image.hpp:34
bool mask
Definition theme_image.hpp:39
int flags
Definition theme_image.hpp:35
int maxSide
Definition theme_image.hpp:36
Definition theme_image.hpp:49
int maxSide
Definition theme_image.hpp:59
bool mask
Definition theme_image.hpp:60
bool draw(NVGcontext *vg, float x, float y, float width, float height, BackgroundFit fit, const NVGcolor *tint=nullptr, float alpha=1.0f, float corner=0.0f) const
bool ready() const
Definition theme_image.hpp:66
ThemeImage & operator=(const ThemeImage &)=delete
State
Definition theme_image.hpp:51
int width
Definition theme_image.hpp:63
int texture
Definition theme_image.hpp:62
ThemeImage()=default
State state
Definition theme_image.hpp:61
NVGcolor mean
Definition theme_image.hpp:64
int height
Definition theme_image.hpp:63
std::string path
Definition theme_image.hpp:57
int flags
Definition theme_image.hpp:58
ThemeImage(const ThemeImage &)=delete