Louvre  v1.2.1-2
C++ library for Wayland compositors
List of all members | Public Member Functions
LTextureView Class Reference

#include <LTextureView.h>

View for displaying textures. More...

Detailed Description

View for displaying textures.

The LTextureView class enables you to use an LTexture as a view within a scene.
You can set the view's texture using setTexture(), and passing nullptr unsets the texture, effectively unmapping the view.
Multiple views can share the same LTexture, and if the texture is destroyed, their texture() property is automatically set to nullptr.

Texture views can also have a custom destination size, which may differ from their buffer size. In such cases, regions for damage, input, translucent, and opaque must be defined based on the destination size.
To enable a custom destination size, use the enableDstSize() and setDstSize() methods.

Note
Using a custom destination size is recommended instead of relying on the scalingVector() option, as it allows for continued damage tracking within the scene.

When destination size is disabled, the view size is by default equal to the texture size divided by its buffer scale if no other transformations are applied.

As of Louvre version 1.2.0, you can define a source rect with applied transformations, adhering to the behavior outlined in the Viewporter protocol.

For additional methods and properties available, please refer to the documentation of the LView class.

Public Member Functions

 LTextureView (LTexture *texture=nullptr, LView *parent=nullptr)
 Construct an LTextureView with an optional LTexture and parent LView. More...
 
 ~LTextureView ()
 Destructor for the LTextureView. More...
 
virtual void setPos (Int32 x, Int32 y)
 Set the position of the LTextureView. More...
 
void setPos (const LPoint &pos)
 Set the position of the LTextureView using an LPoint object. More...
 
virtual void setInputRegion (const LRegion *region)
 Set the input region of the LTextureView. More...
 
virtual void setTranslucentRegion (const LRegion *region)
 Set the translucent region of the LTextureView. More...
 
virtual void setBufferScale (Float32 scale)
 Set the buffer scale of the LTextureView. More...
 
void setTexture (LTexture *texture)
 Set the LTexture for the LTextureView. More...
 
virtual LTexturetexture () const
 Get the current LTexture used by the LTextureView. More...
 
virtual void enableDstSize (bool enabled)
 Enable or disable the custom destination size for the LTextureView. More...
 
virtual bool dstSizeEnabled () const
 Check if the custom destination size is enabled for the LTextureView. More...
 
virtual void setDstSize (Int32 w, Int32 h)
 Set the custom destination size of the LTextureView. More...
 
void setDstSize (const LSize &dstSize)
 Set the custom destination size of the LTextureView using an LSize object. More...
 
void enableCustomColor (bool enabled)
 Enable or disable custom coloring for texture rendering. More...
 
bool customColorEnabled () const
 Check if custom coloring for texture rendering is enabled. More...
 
void setCustomColor (Float32 r, Float32 g, Float32 b)
 Set a custom color for texture rendering while preserving the texture's alpha channel. More...
 
void setCustomColor (const LRGBF &color)
 Set a custom color for texture rendering using an LRGBF object. More...
 
const LRGBFcustomColor () const
 Get the current custom color used for texture rendering. More...
 
void enableSrcRect (bool enabled)
 Enables or disables the use of a custom source rect. More...
 
bool srcRectEnabled () const
 Checks if the use of the source rect (srcRect()) is enabled. More...
 
void setSrcRect (const LRectF &srcRect)
 Sets the source rect of the texture to use. More...
 
const LRectFsrcRect () const
 Gets the source rect set with setSrcRect(). More...
 
void setTransform (LFramebuffer::Transform transform)
 Sets the transform of the texture. More...
 
LFramebuffer::Transform transform () const
 Gets the transform set with setTransform(). More...
 
virtual bool nativeMapped () const override
 Tells whether the view should be rendered. More...
 
virtual const LPointnativePos () const override
 Get the position of the view without any transformations applied. More...
 
virtual const LSizenativeSize () const override
 Get the size of the view without any transformations applied. More...
 
virtual Float32 bufferScale () const override
 Get the scale of the view buffer content. More...
 
virtual void enteredOutput (LOutput *output) override
 Indicate that the view is visible on the given output. More...
 
virtual void leftOutput (LOutput *output) override
 Indicate that the view is no longer visible on the given output. More...
 
virtual const std::vector< LOutput * > & outputs () const override
 Get a vector of output pointers on which the view is currently visible. More...
 
virtual bool isRenderable () const override
 Check if the view is itself renderable. More...
 
virtual void requestNextFrame (LOutput *output) override
 Notify that the view has been rendered on the given output. More...
 
virtual const LRegiondamage () const override
 Get the region within the view rect that needs to be repainted. More...
 
virtual const LRegiontranslucentRegion () const override
 Returns the translucent region within the view rectangle. More...
 
virtual const LRegionopaqueRegion () const override
 Returns the opaque region within the view rectangle. More...
 
virtual const LRegioninputRegion () const override
 Region within the view rect that can receive input events (when the inputEnabled() property is enabled). More...
 
virtual void paintEvent (const PaintEventParams &params) override
 Request to paint a region of the view to the current framebuffer. More...
 
- Public Member Functions inherited from LView
 LView (UInt32 type, LView *parent=nullptr)
 Construct an LView object. More...
 
virtual ~LView ()
 Destructor for the LView class. More...
 
void damageAll ()
 Forces a complete repaint of the view in the next rendering frame. More...
 
LScenescene () const
 Get the scene in which this view is currently embedded. More...
 
LSceneViewparentSceneView () const
 Get the LSceneView in which this view is currently embedded. More...
 
UInt32 type () const
 Get the identifier for the type of view. More...
 
void repaint ()
 Schedule a repaint for all outputs where this view is currently visible. More...
 
LViewparent () const
 Get the parent of the view. More...
 
void setParent (LView *view)
 Set the new parent for the view and insert it at the end of its children list. More...
 
void insertAfter (LView *prev, bool switchParent=true)
 Insert the view after the 'prev' view. More...
 
std::list< LView * > & children () const
 Get the list of child views. More...
 
bool parentOffsetEnabled () const
 Check if the parent's offset is applied to the view position. More...
 
void enableParentOffset (bool enabled)
 Enable or disable the parent's offset for the view position. More...
 
const LPointpos () const
 Get the current position of the view with applied transformations. More...
 
const LSizesize () const
 Get the current size of the view with applied transformations. More...
 
bool clippingEnabled () const
 Check if the view is currently being clipped to the clippingRect() property. More...
 
void enableClipping (bool enabled)
 Enable or disable clipping of the view to the clippingRect() property. More...
 
const LRectclippingRect () const
 Get the current clipping rectangle defined by the clippingRect() property. More...
 
void setClippingRect (const LRect &rect)
 Set the clipping rectangle for the view using the clippingRect() property. More...
 
bool parentClippingEnabled () const
 Check if the view clipping to the current parent view rect is enabled. More...
 
void enableParentClipping (bool enabled)
 Enable or disable clipping of the view to the current parent view rect. More...
 
bool inputEnabled () const
 Check if the view receives pointer and touch events. More...
 
void enableInput (bool enabled)
 Enable or disable pointer and touch events for the view. More...
 
bool scalingEnabled () const
 Check if scaling is enabled for the view's size. More...
 
void enableScaling (bool enabled)
 Enable or disable scaling for the view's size. More...
 
bool parentScalingEnabled () const
 Check if the size and position are scaled by the parent scaling vector. More...
 
void enableParentScaling (bool enabled)
 Enable or disable scaling of the size and position by the parent's scaling vector. More...
 
const LSizeFscalingVector (bool forceIgnoreParent=false) const
 Get the scaling vector for the view's size. More...
 
void setScalingVector (const LSizeF &scalingVector)
 Set the scaling vector for the view's size. More...
 
bool visible () const
 Check if the view is marked as visible. More...
 
void setVisible (bool visible)
 Toggle the view visibility. More...
 
bool mapped () const
 Check if the view should be rendered, taking into consideration several conditions. More...
 
Float32 opacity (bool forceIgnoreParent=false) const
 Get the current view opacity. More...
 
void setOpacity (Float32 opacity)
 Set the view opacity. More...
 
bool parentOpacityEnabled () const
 Check if the view's opacity is multiplied by its parent's opacity. More...
 
void enableParentOpacity (bool enabled)
 Enable or disable the view's opacity being multiplied by its parent's opacity. More...
 
bool forceRequestNextFrameEnabled () const
 Check if the requestNextFrame() is enabled. More...
 
void enableForceRequestNextFrame (bool enabled) const
 Enable or disable the requestNextFrame() to be called always. More...
 
void setBlendFunc (GLenum sRGBFactor, GLenum dRGBFactor, GLenum sAlphaFactor, GLenum dAlphaFactor)
 Set the alpha blending function for the view. More...
 
void enableAutoBlendFunc (bool enabled)
 Enable or disable automatic blend function adjustment. More...
 
bool autoBlendFuncEnabled () const
 Check whether the automatic blend function adjustment is enabled. More...
 
void setColorFactor (Float32 r, Float32 g, Float32 b, Float32 a)
 Set the color factor. More...
 
const LRGBAFcolorFactor ()
 Get the color factor. More...
 
bool pointerIsOver () const
 Checks if the pointer/cursor is inside the view's input region. More...
 
void enableBlockPointer (bool enabled)
 Enable or disable blocking of pointer or touch events to views behind the view's input region. More...
 
bool blockPointerEnabled () const
 Checks if blocking of pointer or touch events to views behind the view's input region is enabled. More...
 
LBox boundingBox () const
 Get the bounding box of the view and all its mapped children. More...
 
virtual void pointerEnterEvent (const LPoint &localPos)
 Handle the pointer enter event within the view. More...
 
virtual void pointerMoveEvent (const LPoint &localPos)
 Handle the pointer move event within the view. More...
 
virtual void pointerLeaveEvent ()
 Handle the pointer leave event within the view. More...
 
virtual void pointerButtonEvent (LPointer::Button button, LPointer::ButtonState state)
 Handle the pointer button event within the view. More...
 
virtual void pointerAxisEvent (Float64 axisX, Float64 axisY, Int32 discreteX, Int32 discreteY, UInt32 source)
 Handle the pointer axis event within the view. More...
 
virtual void keyModifiersEvent (UInt32 depressed, UInt32 latched, UInt32 locked, UInt32 group)
 Handle the key modifiers event within the view. More...
 
virtual void keyEvent (UInt32 keyCode, UInt32 keyState)
 Handle the key event within the view. More...
 
- Public Member Functions inherited from LObject
 LObject ()=default
 Constructor of the LObject class. More...
 
 ~LObject ()
 Destructor of the LObject class. More...
 
std::shared_ptr< const bool > isAlive () const
 Object's liveness status. More...
 

Additional Inherited Members

- Public Types inherited from LView
enum  Type : UInt32
 Types of views included with Louvre. More...
 
- Static Public Member Functions inherited from LObject
static LCompositorcompositor ()
 Quick access to the global compositor instance. More...
 
static LSeatseat ()
 Quick access to the global seat instance. More...
 
static LCursorcursor ()
 Quick access to the global cursor instance. More...
 

Constructor & Destructor Documentation

◆ LTextureView()

LTextureView ( LTexture texture = nullptr,
LView parent = nullptr 
)

Construct an LTextureView with an optional LTexture and parent LView.

Parameters
textureThe LTexture to be used as the view's texture. Default is nullptr.
parentThe parent LView of the LTextureView. Default is nullptr.

◆ ~LTextureView()

Destructor for the LTextureView.

Member Function Documentation

◆ setPos() [1/2]

void setPos ( Int32  x,
Int32  y 
)
virtual

Set the position of the LTextureView.

Parameters
xThe x-coordinate of the position.
yThe y-coordinate of the position.

◆ setPos() [2/2]

void setPos ( const LPoint pos)

Set the position of the LTextureView using an LPoint object.

Parameters
posThe position as an LPoint object.

◆ setInputRegion()

void setInputRegion ( const LRegion region)
virtual

Set the input region of the LTextureView.

Parameters
regionThe input region as an LRegion object.

◆ setTranslucentRegion()

void setTranslucentRegion ( const LRegion region)
virtual

Set the translucent region of the LTextureView.

Passing nullptr as the region means that the entire view is considered translucent, which is the default value. Passing an empty LRegion (not nullptr), on the other hand, means the entire view is opaque.

Parameters
regionThe translucent region as an LRegion object.

◆ setBufferScale()

void setBufferScale ( Float32  scale)
virtual

Set the buffer scale of the LTextureView.

Parameters
scaleThe buffer scale factor.

◆ setTexture()

void setTexture ( LTexture texture)

Set the LTexture for the LTextureView.

Note
If the current texture is destroyed, this property is automatically set to nullptr.
Parameters
textureThe LTexture to be used as the view's texture.

◆ texture()

LTexture * texture ( ) const
virtual

Get the current LTexture used by the LTextureView.

Returns
A pointer to the current LTexture used by the view.

◆ enableDstSize()

void enableDstSize ( bool  enabled)
virtual

Enable or disable the custom destination size for the LTextureView.

Parameters
enabledTrue to enable custom destination size, false to disable.

◆ dstSizeEnabled()

bool dstSizeEnabled ( ) const
virtual

Check if the custom destination size is enabled for the LTextureView.

Returns
True if custom destination size is enabled, false otherwise.

◆ setDstSize() [1/2]

void setDstSize ( Int32  w,
Int32  h 
)
virtual

Set the custom destination size of the LTextureView.

Parameters
wThe width of the custom destination size.
hThe height of the custom destination size.

◆ setDstSize() [2/2]

void setDstSize ( const LSize dstSize)

Set the custom destination size of the LTextureView using an LSize object.

Parameters
dstSizeThe custom destination size as an LSize object.

◆ enableCustomColor()

void enableCustomColor ( bool  enabled)

Enable or disable custom coloring for texture rendering.

This method enables or disables custom coloring for the texture rendering process. When custom coloring is enabled, the texture color is replaced by a custom color while preserving the texture's alpha channel.

Parameters
enabledA boolean value indicating whether custom coloring should be enabled (true) or disabled (false).

◆ customColorEnabled()

bool customColorEnabled ( ) const

Check if custom coloring for texture rendering is enabled.

This method returns a boolean value indicating whether custom coloring is currently enabled for the texture rendering process.

Returns
true if custom coloring is enabled, false otherwise.

◆ setCustomColor() [1/2]

void setCustomColor ( Float32  r,
Float32  g,
Float32  b 
)

Set a custom color for texture rendering while preserving the texture's alpha channel.

This method sets a custom color for the texture rendering process, replacing the original texture color while keeping the texture's alpha channel intact.

Parameters
rThe red component of the custom color (0.0 to 1.0).
gThe green component of the custom color (0.0 to 1.0).
bThe blue component of the custom color (0.0 to 1.0).

◆ setCustomColor() [2/2]

void setCustomColor ( const LRGBF color)

Set a custom color for texture rendering using an LRGBF object.

This method sets a custom color for the texture rendering process, replacing the original texture color while keeping the texture's alpha channel intact.

Parameters
colorThe LRGBF object representing the custom color.

◆ customColor()

const LRGBF & customColor ( ) const

Get the current custom color used for texture rendering.

This method retrieves the current custom color that is being used for the texture rendering process. The custom color replaces the original texture color while keeping the texture's alpha channel intact.

Returns
A constant reference to the LRGBF object representing the current custom color.

◆ enableSrcRect()

void enableSrcRect ( bool  enabled)

Enables or disables the use of a custom source rect.

Enabling this feature allows you to specify a custom source rectangle using setSrcRect().

Note
When disabled, the entire texture is used as the source.
Parameters
enabledIf true, the custom source rectangle is enabled; if false, the entire texture is used as the source.

◆ srcRectEnabled()

bool srcRectEnabled ( ) const

Checks if the use of the source rect (srcRect()) is enabled.

Disabled by default.

Returns
true if enabled, false otherwise.
See also
enableSrcRect()
setSrcRect()

◆ setSrcRect()

void setSrcRect ( const LRectF srcRect)

Sets the source rect of the texture to use.

The source rect must be specified in surface coordinates, taking into account the space generated after the inverse transform() (from transform() to LFramebuffer::Normal) is applied.

Note
The source rect is used only if srcRectEnabled() is set to true.
Parameters
srcRectThe source rect in surface coordinates.

◆ srcRect()

const LRectF & srcRect ( ) const

Gets the source rect set with setSrcRect().

Note
When srcRectEnabled() returns false the rect covers the entire texture.
Returns
A constant reference to the source rect specified using setSrcRect().

◆ setTransform()

void setTransform ( LFramebuffer::Transform  transform)

Sets the transform of the texture.

Use this method to tell the scene the transformation that the texture's content ALREADY HAS and not the transformation you want to apply.

For example, pass LFramebuffer::Rotated90 if the texture's content is rotated 90 degrees counter-clockwise, and the scene (if the current LOutput has a normal transform) will apply a 90-degree clockwise rotation to display it normally.

Changing the transform affects how the source rectangle is defined and may also swap the original width and height of the view when using transforms with 90 or 270 degrees rotation.

Parameters
transformThe transform to be applied for proper display.

◆ transform()

LFramebuffer::Transform transform ( ) const

Gets the transform set with setTransform().

The default value is LFramebuffer::Normal.

◆ nativeMapped()

bool nativeMapped ( ) const
overridevirtual

Tells whether the view should be rendered.

Returns
true if the view should be rendered without considering visible(), otherwise false.

Implements LView.

◆ nativePos()

const LPoint & nativePos ( ) const
overridevirtual

Get the position of the view without any transformations applied.

Must return the position of the view in surface coordinates.

Returns
The position of the view as an LPoint object.

Implements LView.

◆ nativeSize()

const LSize & nativeSize ( ) const
overridevirtual

Get the size of the view without any transformations applied.

Must return the size of the view in surface coordinates.

Returns
The size of the view as an LSize object.

Implements LView.

◆ bufferScale()

Float32 bufferScale ( ) const
overridevirtual

Get the scale of the view buffer content.

This property is primarily used by views that contain a buffer like for example the LSceneView, LSurfaceView and LTextureView types.

Returns
The buffer scale as an Int32 value.

Implements LView.

◆ enteredOutput()

void enteredOutput ( LOutput output)
overridevirtual

Indicate that the view is visible on the given output.

This method is invoked by a LScene when the view's rect intersects an output.

Parameters
outputThe LOutput where the view is visible.

Implements LView.

◆ leftOutput()

void leftOutput ( LOutput output)
overridevirtual

Indicate that the view is no longer visible on the given output.

This method is invoked by a LScene when the view's rect no longer intersects an output.

Parameters
outputThe LOutput from which the view is no longer visible.

Implements LView.

◆ outputs()

const std::vector< LOutput * > & outputs ( ) const
overridevirtual

Get a vector of output pointers on which the view is currently visible.

Must return a vector of output pointers where the view is currently visible. Use the enteredOutput() and leftOutput() methods to update the vector.

Returns
A reference to a vector of LOutput pointers representing the outputs where the view is visible.

Implements LView.

◆ isRenderable()

bool isRenderable ( ) const
overridevirtual

Check if the view is itself renderable.

This property indicates whether the view is capable of rendering its content (check paintEvent()). For example, all view types included in Louvre are renderable, except for LLayerView, which serves as a container for other views but does not produce any output by itself.

Returns
true if the view is renderable; otherwise, false.

Implements LView.

◆ requestNextFrame()

void requestNextFrame ( LOutput output)
overridevirtual

Notify that the view has been rendered on the given output.

This method is called by LScene and should be used to clear the previous view damage or update its content. If forceRequestNextFrameEnabled() is true, this method is always called.

Parameters
outputThe LOutput on which the view is rendered.

Implements LView.

◆ damage()

const LRegion * damage ( ) const
overridevirtual

Get the region within the view rect that needs to be repainted.

The region rects are specified in surface coordinates within the view, without any scaling, clipping, or offset transformations applied. The damage may be cleared after requestNextFrame() is called. If nullptr is returned, the entire view rect will be considered damaged. If the view has no damage, simply pass an empty LRegion (not nullptr).

Returns
A pointer to the LRegion specifying the damaged area within the view, or nullptr if the entire view rect is damaged.

Implements LView.

◆ translucentRegion()

const LRegion * translucentRegion ( ) const
overridevirtual

Returns the translucent region within the view rectangle.


The region rects are specified in surface coordinates within the view, without any scaling, clipping, or offset transformations.
If nullptr is returned, the entire view rect will be considered translucent.

Implements LView.

◆ opaqueRegion()

const LRegion * opaqueRegion ( ) const
overridevirtual

Returns the opaque region within the view rectangle.

The region rects are specified in surface coordinates within the view, without any scaling, clipping, or offset transformations.
If nullptr is returned, the inverse of the translucent region will be considered opaque.

Implements LView.

◆ inputRegion()

const LRegion * inputRegion ( ) const
overridevirtual

Region within the view rect that can receive input events (when the inputEnabled() property is enabled).


The region rects are specified in surface coordinates within the view, without any scaling, clipping, or offset transformations.
If nullptr is returned, the entire view rect will receive input.

Implements LView.

◆ paintEvent()

void paintEvent ( const PaintEventParams params)
overridevirtual

Request to paint a region of the view to the current framebuffer.

This method is used by LSceneView to request the view to paint a specified region on the current framebuffer. The painting is performed using the provided LPainter object.

Note
Alternatively, you have the option to use your own custom OpenGL shaders/program for rendering, in place of the provided LPainter.

Implements LView.