Class · aurore

aurore::Image

On this page
aurore/views/image.hpp
#include <aurore/views/image.hpp>

class aurore::Image : public aurore::View

Description

An image. The view will try to grow as much as possible to fit the image. The scaling type dictates what to do with the image if there is not enough or too much space for the view compared to the image inside. Supported formats are: JPG, PNG, TGA, BMP and GIF (not animated).

Constructors 2

Image()

An empty image (FIT, centred, linear interpolation).

image.hpp:70
~Image()

Functions 21

virtual void draw(NVGcontext *vg,float x,float y,float width,float height,Style style,FrameContext *ctx) override

Called by frame() to draw the view onscreen. Views should not draw outside of their bounds (they may be clipped if they do so).

Overrides aurore::View::draw

image.hpp:73
virtual void onLayout() override

Called when a layout pass ends on that view.

Overrides aurore::View::onLayout

image.hpp:74
void setInterpolation(ImageInterpolation interpolation)

Sets the interpolation method for the image. Default is LINEAR.

As the interpolation is set when the texture is created, and since we don't want to always store the image buffer in the view, this only takes effect after (re) loading the image using the setImage* methods.

If you are using the interpolation XML attribute, you have to set it before the actual image attribute.

image.hpp:86
void setImageFromRes(const std::string &name)

Sets the image from the given resource name.

See Image class documentation for the list of supported image formats.

image.hpp:94
void setImageFromFile(const std::string &path)

Sets the image from the given file path.

See Image class documentation for the list of supported image formats.

image.hpp:102
void setImageFromFileAsync(const std::string &path)

Sets the image from the given file path, decoded on the decode thread (Threading::asyncDecode): the UI thread only uploads the pixels, so a grid of covers does not stall while they load. The image stays as it was until then (a cached texture is shown at once). An image set again meanwhile, or deleted, drops the result.

image.hpp:111
void setImageFromMem(const unsigned char *data, int size)

Sets the image from memory.

See Image class documentation for the list of supported image formats.

image.hpp:119
void setImageFromRGBA(const unsigned char *pixels,int width,int height)

Sets the image from raw RGBA pixels (width × height × 4 bytes), for an image made by the app (a QR code, a video frame, a thumbnail it decoded). Pixels of the same size as the image shown replace its own texture's in place, without making a new one.

image.hpp:127
void setThemeImage(const std::string &key)

Shows the picture of the image slot key (Theme::addImageSlot): the theme's, else the app's fallback, and follows the theme as it changes (the new picture shown once loaded; none: the image is cleared). XML: themeImage="playguard/loading/art". Another setImage* call, or "", stops following it.

image.hpp:136
const std::string & getThemeImage() const

The image slot followed (setThemeImage()), "" for none.

image.hpp:138
virtual void innerSetImage(int texture)

Shows the nanovg image texture (what every setImage* ends with).

image.hpp:141
void setImageAsync(std::function< void(std::function< void(const std::string &, size_t length)>)> cb)

cb gets a function to call, from any thread, with the encoded image's bytes: the image is set from them on the main thread (nothing if the view is gone or length is 0).

image.hpp:146
void clear()

Shows nothing (the texture freed when the image owns it).

image.hpp:149
void setScalingType(ImageScalingType scalingType)

Sets the scaling type for this image.

Default is FIT.

image.hpp:156
ImageScalingType getScalingType()
void setImageAlign(ImageAlignment align)

Sets the alignment of the image inside the view. Only used if scaling it set to FIT when the aspect ratio is different or CROP, to change the region of the image to draw.

Default is CENTER.

image.hpp:168
void setFreeTexture(bool value)

Whether to destroy the current texture before updating the image texture

image.hpp:173
bool getFreeTexture()
int getTexture()

The nanovg image shown, 0 for none.

image.hpp:177
float getOriginalImageWidth()

The size of the picture shown, in pixels.

image.hpp:179
float getOriginalImageHeight()

Also the functions of aurore::View (221).

Static functions 1

static View * create()

Makes an image for XML (<aurore:Image>).

image.hpp:183

Protected functions 4

void invalidateImageBounds()
int getImageFlags()
size_t checkCache(const std::string &path)
void releaseTexture()

Deletes the texture if owned, or hands it back to TextureCache.

image.hpp:212

Protected attributes 13

int texture = 0
NVGpaint paint
float originalImageWidth = 0
float originalImageHeight = 0
float imageX = 0
float imageY = 0
float imageHeight = 0
float imageWidth = 0
bool freeTexture = true
unsigned asyncGeneration = 0

Bumped each time the image is set: an async load set before is stale.

image.hpp:209

Read from Aurore's headers by Doxygen at each build · library/include