Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
aurore::Image Class Reference

#include <aurore/views/image.hpp>

Inheritance diagram for aurore::Image:
aurore::View

Public Member Functions

 Image ()
 An empty image (FIT, centred, linear interpolation).
 
 ~Image ()
 
void draw (NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
 
void onLayout () override
 
void setInterpolation (ImageInterpolation interpolation)
 
void setImageFromRes (const std::string &name)
 
void setImageFromFile (const std::string &path)
 
void setImageFromFileAsync (const std::string &path)
 
void setImageFromMem (const unsigned char *data, int size)
 
void setImageFromRGBA (const unsigned char *pixels, int width, int height)
 
void setThemeImage (const std::string &key)
 
const std::string & getThemeImage () const
 The image slot followed (setThemeImage()), "" for none.
 
virtual void innerSetImage (int texture)
 Shows the nanovg image texture (what every setImage* ends with).
 
void setImageAsync (std::function< void(std::function< void(const std::string &, size_t length)>)> cb)
 
void clear ()
 Shows nothing (the texture freed when the image owns it).
 
void setScalingType (ImageScalingType scalingType)
 
ImageScalingType getScalingType ()
 See setScalingType().
 
void setImageAlign (ImageAlignment align)
 
void setFreeTexture (bool value)
 
bool getFreeTexture ()
 
int getTexture ()
 The nanovg image shown, 0 for none.
 
float getOriginalImageWidth ()
 The size of the picture shown, in pixels.
 
float getOriginalImageHeight ()
 
- Public Member Functions inherited from aurore::View
void setScale (float scale)
 
void setScaleX (float scale)
 
void setScaleY (float scale)
 
float getScaleX () const
 
float getScaleY () const
 
 View ()
 
virtual ~View ()
 
void setBackground (ViewBackground background)
 How the view's background is drawn: none, the sidebar's, the backdrop, a plain colour or a gradient.
 
void setBackgroundLinearGradient (NVGcolor start, NVGcolor end, ViewBackground direction=ViewBackground::VERTICAL_LINEAR)
 
void shakeHighlight (FocusDirection direction)
 Shakes the focus highlight towards direction: there is nothing to go to there.
 
Rect getFrame ()
 The view's position and size on the screen, after layout (getX(), getY(), getWidth(), getHeight()).
 
float getX ()
 The position on the screen, in layout units: the parents' positions and translations added.
 
float getY ()
 
Rect getLocalFrame ()
 The position and size in the parent, as laid out by Yoga.
 
float getLocalX ()
 
float getLocalY ()
 
float getWidth ()
 The size as laid out by Yoga; the height without the collapse when includeCollapse is false.
 
float getHeight (bool includeCollapse=true)
 
virtual void invalidate ()
 
virtual View * getView (std::string id)
 
void setWidth (float width)
 
void setHeight (float height)
 
void setSize (Size size)
 
void setDimensions (float width, float height)
 
void setWidthPercentage (float percentage)
 
void setHeightPercentage (float percentage)
 
void setMinWidth (float minWidth)
 
void setMinHeight (float minHeight)
 
void setMinWidthPercentage (float percentage)
 
void setMinHeightPercentage (float percentage)
 
void setMaxWidth (float maxWidth)
 
void setMaxHeight (float maxHeight)
 
void setMaxWidthPercentage (float percentage)
 
void setMaxHeightPercentage (float percentage)
 
void setGrow (float grow)
 
void setShrink (float shrink)
 
void setMargins (float top, float right, float bottom, float left)
 
void setMarginTop (float top)
 
void setMarginRight (float right)
 
float getMarginRight ()
 
float getMarginLeft ()
 
void setMarginBottom (float right)
 
void setMarginLeft (float left)
 
void setVisibility (Visibility visibility)
 
Visibility getVisibility ()
 
void setPositionTop (float pos)
 
void setPositionRight (float pos)
 
void setPositionBottom (float pos)
 
void setPositionLeft (float pos)
 
void setPositionTopPercentage (float percentage)
 
void setPositionRightPercentage (float percentage)
 
void setPositionBottomPercentage (float percentage)
 
void setPositionLeftPercentage (float percentage)
 
void setPositionType (PositionType type)
 
void setId (std::string id)
 
const std::string & getId () const
 
void setAlignSelf (AlignSelf align)
 
void setBoxSizing (BoxSizing sizing)
 
void setLineColor (NVGcolor color)
 
void setLineTop (float thickness)
 
void setLineRight (float thickness)
 
void setLineBottom (float thickness)
 
void setLineLeft (float thickness)
 
void setBackgroundColor (NVGcolor color)
 
void setBorderColor (NVGcolor color)
 
ViewBackground getBackground () const
 
NVGcolor getBackgroundColor () const
 
NVGcolor getBorderColor () const
 
void setBorderThickness (float thickness)
 
float getBorderThickness ()
 
void setCornerRadius (float radius)
 
void setCornerRadius (float topLeft, float topRight, float bottomRight, float bottomLeft)
 
float getCornerRadius ()
 
void setThemeArea (ThemeArea area)
 
ThemeArea getThemeArea () const
 
void setShadowType (ShadowType type)
 
void setShadowVisibility (bool visible)
 
void setHideHighlightBackground (bool hide)
 
void setHideHighlightBorder (bool hide)
 
void setHideHighlight (bool hide)
 
void setHideClickAnimation (bool hide)
 No click animation when the view is clicked.
 
void setHighlightPadding (float padding)
 
void setHighlightCornerRadius (float radius)
 
virtual View * getNearestView (std::string id)
 
virtual void handleXMLElement (tinyxml2::XMLElement *element)
 
virtual void applyXMLAttributes (tinyxml2::XMLElement *element)
 
virtual bool applyXMLAttribute (std::string name, std::string value)
 
void registerAutoXMLAttribute (std::string name, AutoAttributeHandler handler)
 
void registerPercentageXMLAttribute (std::string name, FloatAttributeHandler handler)
 
void registerFloatXMLAttribute (std::string name, FloatAttributeHandler handler)
 
void registerStringXMLAttribute (std::string name, StringAttributeHandler handler)
 
void registerColorXMLAttribute (std::string name, ColorAttributeHandler handler)
 
void registerBoolXMLAttribute (std::string name, BoolAttributeHandler handler)
 
void registerFilePathXMLAttribute (std::string name, FilePathAttributeHandler handler)
 
bool isXMLAttributeValid (std::string attributeName)
 
void setMaximumAllowedXMLElements (unsigned max)
 
unsigned getMaximumAllowedXMLElements ()
 
void setInFadeAnimation (bool translucent)
 
void setFocusable (bool focusable)
 
bool isFocusable ()
 Whether the view takes the focus: focusable, and visible.
 
void removeFromSuperView (bool free=true)
 
void setFocusSound (enum Sound sound)
 
virtual enum Sound getFocusSound ()
 
void detach ()
 
bool isDetached ()
 See detach().
 
void setDetachedPosition (float x, float y)
 
void setDetachedPositionX (float x)
 
void setDetachedPositionY (float y)
 
Point getDetachedPosition () const
 
void setParent (Box *parent, void *parentUserdata=nullptr)
 The box this view is in (Box::addView sets it; parentUserdata is the box's own).
 
Box * getParent ()
 
bool hasParent ()
 
void * getParentUserData ()
 
template<class ButtonType >
ActionIterator getAction (ButtonType button)
 
ActionIterator getAction (ActionIdentifier identifier)
 The action registered under identifier, or getActions().end().
 
template<class ButtonType , class ActionType >
ActionIdentifier registerAction (const std::string &hintText, ButtonType button, const ActionListener &actionListener, bool hidden=false, bool allowRepeating=false, enum Sound sound=SOUND_NONE)
 
ActionIdentifier registerAction (const std::string &hintText, ControllerButton button, const ActionListener &actionListener, bool hidden=false, bool allowRepeating=false, enum Sound sound=SOUND_NONE)
 The same, on a controller button.
 
ActionIdentifier registerAction (AuroreKeyCombination key, const ActionListener &actionListener, bool allowRepeating=false)
 An action on a keyboard key (a combination with modifiers): no hint, no sound.
 
void func (AuroreKeyCombination key)
 
void unregisterAction (ActionIdentifier identifier)
 
void registerClickAction (const ActionListener &actionListener)
 
void updateActionHint (enum ControllerButton button, const std::string &hintText)
 Changes the hint of the action on button.
 
void setActionAvailable (enum ControllerButton button, bool available)
 Turns the action on button on or off (an action off runs nothing and shows no hint).
 
void setActionsAvailable (bool available) const
 The same for every action of the view.
 
void setActionHidden (enum ControllerButton button, bool hidden)
 
void resetClickAnimation ()
 
void playClickAnimation (bool reverse=false, bool animateBack=true, bool force=false)
 Plays the click animation (the flash over the view).
 
std::string getClassString () const
 The view's class name ("Label", "Box"…).
 
std::string describe () const
 The class name and the id, for logs: Label (id="title").
 
YGNode * getYGNode ()
 The view's Yoga node.
 
const std::vector< std::shared_ptr< Action > > & getActions ()
 The actions registered on the view.
 
const std::vector< GestureRecognizer * > & getGestureRecognizers ()
 
void interruptGestures (bool onlyIfUnsureState)
 
void addGestureRecognizer (GestureRecognizer *recognizer)
 
bool removeGestureRecognizer (GestureRecognizer *recognizer)
 
Sound gestureRecognizerRequest (TouchState touch, MouseState mouse, View *firstResponder)
 
virtual void frame (FrameContext *ctx)
 
void frameHighlight (FrameContext *ctx)
 
virtual void willAppear (bool resetState=false)
 
virtual void willDisappear (bool resetState=false)
 
virtual void onShowAnimationEnd ()
 
virtual void show (std::function< void(void)> cb)
 
virtual void show (std::function< void(void)> cb, bool animate, float animationDuration)
 
virtual float getShowAnimationDuration (TransitionAnimation animation)
 
void collapse (bool animated=true)
 
bool isCollapsed ()
 Whether collapse() hid the view.
 
void setAlpha (float alpha)
 The view's opacity, 0 to 1 (a transition when its style has one).
 
void expand (bool animated=true)
 
virtual void hide (std::function< void(void)> cb)
 
virtual void hide (std::function< void(void)> cb, bool animate, float animationDuration)
 
bool isHidden ()
 Whether hide() hid the view.
 
virtual bool isTranslucent ()
 
bool isFocused ()
 Whether the view has the focus.
 
virtual View * getDefaultFocus ()
 
virtual View * hitTest (Point point)
 
virtual View * getNextFocus (FocusDirection direction, View *currentView)
 
void setCustomNavigationRoute (FocusDirection direction, View *target)
 
void setCustomNavigationRoute (FocusDirection direction, std::string targetId)
 
bool hasCustomNavigationRouteByPtr (FocusDirection direction)
 
bool hasCustomNavigationRouteById (FocusDirection direction)
 
View * getCustomNavigationRoutePtr (FocusDirection direction)
 
std::string getCustomNavigationRouteId (FocusDirection direction)
 
virtual void onFocusGained ()
 
virtual void onFocusLost ()
 
virtual void onParentFocusGained (View *focusedView)
 
virtual void onParentFocusLost (View *focusedView)
 
virtual void onWindowSizeChanged ()
 
GenericEvent * getFocusEvent ()
 Fired with the view when it gains the focus.
 
GenericEvent * getFocusLostEvent ()
 Fired with the view when it loses the focus.
 
virtual float getAlpha (bool child=false)
 The opacity drawn: the view's alpha times its parents'.
 
float getClickAlpha ()
 
void overrideTheme (Theme *newTheme)
 
void setCulled (bool culled)
 
bool isCulled ()
 
void setAspectRatio (float value)
 The width over the height, kept by the layout (values <= 0 are ignored).
 
float getAspectRatio ()
 
void setBackgroundCornerRadii (float topLeft, float topRight, float bottomRight, float bottomLeft)
 
void setTranslationY (float translateY)
 
void setTranslationX (float translateX)
 
void setWireframeEnabled (bool wireframe)
 
bool isWireframeEnabled ()
 
AppletFrameItem * getAppletFrameItem ()
 
void updateAppletFrameItem ()
 
bool getClipsToBounds () const
 Whether the children are clipped to the view's frame when drawn.
 
void setClipsToBounds (bool value)
 
virtual AppletFrame * getAppletFrame ()
 The AppletFrame the view is in, or nullptr.
 
void present (View *view)
 Pushes view as the content of the view's AppletFrame (a page inside the frame).
 
virtual void dismiss (std::function< void(void)> cb=[] {})
 Pops the AppletFrame's content back to the one before, then runs cb.
 
std::weak_ptr< void > aliveToken ()
 
void ptrLock ()
 
void ptrUnlock ()
 
bool isPtrLocked ()
 Whether a ptrLock() holds the view.
 
void freeView ()
 Deletes the view at the end of the frame (Application::addToFreeQueue).
 
Activity * getParentActivity ()
 The activity the view is in, through its parents; nullptr when none.
 
void setParentActivity (Activity *activity)
 
bool setStateStyle (StyleState state, const std::string &property, const std::string &value)
 
void setStyleState (StyleState state, bool on)
 
bool hasStyleState (StyleState state)
 
bool setTransition (const std::string &spec)
 
virtual bool getStyleProperty (const std::string &name, StyleValue *value)
 
virtual bool setStyleProperty (const std::string &name, const StyleValue &value)
 
void keepSubscription (Subscription &&subscription)
 
bool bind (const std::string &spec)
 
virtual bool setBoundText (const std::string &text)
 
void setAccessibilityRole (AccessibilityRole role)
 
AccessibilityRole getAccessibilityRole ()
 See setAccessibilityRole().
 
void setAccessibilityLabel (const std::string &label)
 
std::string getAccessibilityLabel ()
 
void setAccessibilityValue (const std::string &value)
 
std::string getAccessibilityValue ()
 
void setAccessibilitySelected (bool selected)
 
bool isAccessibilitySelected ()
 
virtual bool getAccessibilityPosition (int *index, int *count)
 
virtual std::string getAccessibilityDescription ()
 
std::string getAccessibilityText ()
 
void announceAccessibilityValue ()
 
void resolveBindings (Activity *activity=nullptr)
 
virtual void onTextScaleChanged ()
 
bool setThemeColor (const std::string &property, const std::string &key)
 
std::string getThemeColor (const std::string &property)
 
virtual void onThemeChanged ()
 

Static Public Member Functions

static View * create ()
 Makes an image for XML (<aurore:Image>).
 
- Static Public Member Functions inherited from aurore::View
static void setHighlightGlide (bool glide)
 
static View * createFromXMLString (std::string_view xml)
 
static View * createFromXMLElement (tinyxml2::XMLElement *element)
 
static View * createFromXMLFile (std::string path)
 
static View * createFromXMLResource (std::string name)
 
static std::shared_ptr< tinyxml2::XMLDocument > getXMLCache (std::string_view path)
 
static void forgetXMLCache (const std::string &path)
 
static std::string describeXMLError (tinyxml2::XMLDocument *document, const std::string &source="")
 
static std::string describeXMLLocation (const tinyxml2::XMLElement *element)
 
static void fatalXML (const std::string &message)
 
static std::string closestXMLName (const std::string &name, const std::vector< std::string > &known)
 
template<typename T >
static std::string listXMLValues (const std::unordered_map< std::string, T > &values)
 An enumeration's values, sorted, for an error message.
 
static std::string getStringXMLAttributeValue (std::string value)
 
static std::string getFilePathXMLAttributeValue (std::string value)
 

Protected Member Functions

void invalidateImageBounds ()
 
int getImageFlags ()
 
size_t checkCache (const std::string &path)
 
void releaseTexture ()
 Deletes the texture if owned, or hands it back to TextureCache.
 
- Protected Member Functions inherited from aurore::View
NVGcolor a (NVGcolor color)
 Helper functions to apply this view's alpha to a color.
 
NVGpaint a (NVGpaint paint)
 
NVGcolor RGB (unsigned r, unsigned g, unsigned b)
 
NVGcolor RGBA (unsigned r, unsigned g, unsigned b, unsigned a)
 
NVGcolor RGBf (float r, float g, float b)
 
NVGcolor RGBAf (float r, float g, float b, float a)
 
NVGcolor shadowColor (NVGcolor color, float opacity)
 
virtual bool animateHint ()
 
virtual AccessibilityRole getDefaultAccessibilityRole ()
 
virtual std::string getDefaultAccessibilityLabel ()
 
virtual std::string getDefaultAccessibilityValue ()
 
virtual bool getDefaultAccessibilitySelected ()
 
bool transitionStyle (const char *name, const StyleValue &to)
 

Protected Attributes

ImageScalingType scalingType = ImageScalingType::FIT
 
ImageAlignment align = ImageAlignment::CENTER
 
ImageInterpolation interpolation = ImageInterpolation::LINEAR
 
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.
 
- Protected Attributes inherited from aurore::View
Animatable collapseState = 1.0f
 
bool focused = false
 
Activity * parentActivity = nullptr
 
Box * parent = nullptr
 
GenericEvent focusEvent
 
GenericEvent focusLostEvent
 
YGNode * ygNode
 
std::string id = ""
 

Additional Inherited Members

- Public Types inherited from aurore::View
typedef std::vector< std::shared_ptr< Action > >::iterator ActionIterator
 
- Public Attributes inherited from aurore::View
Animatable alpha = 1.0f
 
- Static Public Attributes inherited from aurore::View
static constexpr float AUTO = NAN
 A size or position left to the layout (auto in XML).
 
static std::string CUSTOM_RESOURCES_PATH
 
static std::string currentXMLResource
 

Detailed 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).

Constructor & Destructor Documentation

◆ Image()

aurore::Image::Image ( )

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

◆ ~Image()

aurore::Image::~Image ( )

Member Function Documentation

◆ checkCache()

size_t aurore::Image::checkCache ( const std::string &  path)
protected

◆ clear()

void aurore::Image::clear ( )

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

◆ create()

static View * aurore::Image::create ( )
static

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

◆ draw()

void aurore::Image::draw ( NVGcontext *  vg,
float  x,
float  y,
float  width,
float  height,
Style  style,
FrameContext *  ctx 
)
overridevirtual

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

Implements aurore::View.

◆ getFreeTexture()

bool aurore::Image::getFreeTexture ( )

◆ getImageFlags()

int aurore::Image::getImageFlags ( )
protected

◆ getOriginalImageHeight()

float aurore::Image::getOriginalImageHeight ( )

◆ getOriginalImageWidth()

float aurore::Image::getOriginalImageWidth ( )

The size of the picture shown, in pixels.

◆ getScalingType()

ImageScalingType aurore::Image::getScalingType ( )

◆ getTexture()

int aurore::Image::getTexture ( )

The nanovg image shown, 0 for none.

◆ getThemeImage()

const std::string & aurore::Image::getThemeImage ( ) const
inline

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

◆ innerSetImage()

virtual void aurore::Image::innerSetImage ( int  texture)
virtual

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

◆ invalidateImageBounds()

void aurore::Image::invalidateImageBounds ( )
protected

◆ onLayout()

void aurore::Image::onLayout ( )
overridevirtual

Called when a layout pass ends on that view.

Reimplemented from aurore::View.

◆ releaseTexture()

void aurore::Image::releaseTexture ( )
protected

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

◆ setFreeTexture()

void aurore::Image::setFreeTexture ( bool  value)

Whether to destroy the current texture before updating the image texture

◆ setImageAlign()

void aurore::Image::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.

◆ setImageAsync()

void aurore::Image::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).

◆ setImageFromFile()

void aurore::Image::setImageFromFile ( const std::string &  path)

Sets the image from the given file path.

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

◆ setImageFromFileAsync()

void aurore::Image::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.

◆ setImageFromMem()

void aurore::Image::setImageFromMem ( const unsigned char *  data,
int  size 
)

Sets the image from memory.

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

◆ setImageFromRes()

void aurore::Image::setImageFromRes ( const std::string &  name)

Sets the image from the given resource name.

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

◆ setImageFromRGBA()

void aurore::Image::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.

◆ setInterpolation()

void aurore::Image::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.

◆ setScalingType()

void aurore::Image::setScalingType ( ImageScalingType  scalingType)

Sets the scaling type for this image.

Default is FIT.

◆ setThemeImage()

void aurore::Image::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.

Member Data Documentation

◆ align

ImageAlignment aurore::Image::align = ImageAlignment::CENTER
protected

◆ asyncGeneration

unsigned aurore::Image::asyncGeneration = 0
protected

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

◆ freeTexture

bool aurore::Image::freeTexture = true
protected

◆ imageHeight

float aurore::Image::imageHeight = 0
protected

◆ imageWidth

float aurore::Image::imageWidth = 0
protected

◆ imageX

float aurore::Image::imageX = 0
protected

◆ imageY

float aurore::Image::imageY = 0
protected

◆ interpolation

ImageInterpolation aurore::Image::interpolation = ImageInterpolation::LINEAR
protected

◆ originalImageHeight

float aurore::Image::originalImageHeight = 0
protected

◆ originalImageWidth

float aurore::Image::originalImageWidth = 0
protected

◆ paint

NVGpaint aurore::Image::paint
protected

◆ scalingType

ImageScalingType aurore::Image::scalingType = ImageScalingType::FIT
protected

◆ texture

int aurore::Image::texture = 0
protected

The documentation for this class was generated from the following file: