Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
image.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 WerWolv
3 Copyright 2019 p-sam
4 Copyright 2020-2021 natinusala
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17*/
18
19#pragma once
20
21#include <memory>
22#include <aurore/core/event.hpp>
23#include <aurore/core/theme.hpp>
24#include <aurore/core/view.hpp>
25
26namespace aurore
27{
28
33{
35 FIT,
37 FILL,
39 STRETCH,
41 CENTER,
42};
43
46{
47 LINEAR,
49};
50
53{
54 TOP,
55 RIGHT,
56 BOTTOM,
57 LEFT,
58 CENTER,
59};
60
66class Image : public View
67{
68 public:
72
73 void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) override;
74 void onLayout() override;
75
87
94 void setImageFromRes(const std::string& name);
95
102 void setImageFromFile(const std::string& path);
103
111 void setImageFromFileAsync(const std::string& path);
112
119 void setImageFromMem(const unsigned char* data, int size);
120
127 void setImageFromRGBA(const unsigned char* pixels, int width, int height);
128
136 void setThemeImage(const std::string& key);
138 const std::string& getThemeImage() const { return this->themeImageKey; }
139
141 virtual void innerSetImage(int texture);
142
146 void setImageAsync(std::function<void(std::function<void(const std::string&, size_t length)>)> cb);
147
149 void clear();
150
157
160
169
173 void setFreeTexture(bool value);
175
181
183 static View* create();
184
185 protected:
189
190 int texture = 0;
191
192 NVGpaint paint;
193
196 size_t checkCache(const std::string& path);
197
200
201 float imageX = 0;
202 float imageY = 0;
203 float imageHeight = 0;
204 float imageWidth = 0;
205
206 bool freeTexture = true;
207
209 unsigned asyncGeneration = 0;
210
213
214 private:
216 std::string themeImageKey;
217 std::shared_ptr<ThemeImage> themeImage;
218 std::shared_ptr<ThemeImage> themeImagePending;
219 bool settingThemeImage = false;
220 bool followingTheme = false;
223 std::shared_ptr<char> themeToken;
226 void refreshThemeImage();
227 void stopFollowingTheme();
228};
229
230} // namespace aurore
CallbacksList::iterator Subscription
Definition event.hpp:45
Definition frame_context.hpp:30
Definition image.hpp:67
const std::string & getThemeImage() const
The image slot followed (setThemeImage()), "" for none.
Definition image.hpp:138
void onLayout() override
float originalImageWidth
Definition image.hpp:198
float originalImageHeight
Definition image.hpp:199
unsigned asyncGeneration
Bumped each time the image is set: an async load set before is stale.
Definition image.hpp:209
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
float getOriginalImageHeight()
float imageX
Definition image.hpp:201
void setImageFromRGBA(const unsigned char *pixels, int width, int height)
float imageWidth
Definition image.hpp:204
bool getFreeTexture()
ImageScalingType scalingType
Definition image.hpp:186
bool freeTexture
Definition image.hpp:206
void setImageFromRes(const std::string &name)
void releaseTexture()
Deletes the texture if owned, or hands it back to TextureCache.
ImageScalingType getScalingType()
See setScalingType().
Image()
An empty image (FIT, centred, linear interpolation).
void invalidateImageBounds()
int getImageFlags()
float getOriginalImageWidth()
The size of the picture shown, in pixels.
void setInterpolation(ImageInterpolation interpolation)
ImageInterpolation interpolation
Definition image.hpp:188
float imageY
Definition image.hpp:202
NVGpaint paint
Definition image.hpp:192
size_t checkCache(const std::string &path)
virtual void innerSetImage(int texture)
Shows the nanovg image texture (what every setImage* ends with).
void clear()
Shows nothing (the texture freed when the image owns it).
void setFreeTexture(bool value)
void setImageAsync(std::function< void(std::function< void(const std::string &, size_t length)>)> cb)
void setThemeImage(const std::string &key)
void setImageFromFile(const std::string &path)
int getTexture()
The nanovg image shown, 0 for none.
float imageHeight
Definition image.hpp:203
void setImageAlign(ImageAlignment align)
int texture
Definition image.hpp:190
void setImageFromFileAsync(const std::string &path)
ImageAlignment align
Definition image.hpp:187
void setScalingType(ImageScalingType scalingType)
void setImageFromMem(const unsigned char *data, int size)
static View * create()
Makes an image for XML (<aurore:Image>).
Simple wrapper around StyleValues for the array operator.
Definition style.hpp:115
Definition view.hpp:232
Definition actions.hpp:25
ImageAlignment
Alignment of the image inside the view for FIT and CROP scaling types.
Definition image.hpp:53
ImageInterpolation
This dictates what interpolation to use when down / up scaling the image.
Definition image.hpp:46
ImageScalingType
Definition image.hpp:33
@ FIT
The image is scaled to fit the view boundaries, aspect ratio is conserved.
@ FILL
The image is scaled to fill the view boundaries, aspect ratio is conserved.
@ BOTTOM
decor.bottom: along its bottom edge
@ TOP
decor.top: a strip along the top edge of the screen