Louvre v2.16.0-1
C++ library for Wayland compositors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
LNinePatchView Class Reference

Nine-Patch Texture View. More...

#include <LNinePatchView.h>

+ Inheritance diagram for LNinePatchView:

Public Member Functions

 LNinePatchView (LView *parent=nullptr) noexcept
 Creates an empty nine-patch view.
 
 LNinePatchView (LTexture *texture, Float32 bufferScale, const LRectF &center, LView *parent=nullptr) noexcept
 Creates a nine-patch view with a specified texture.
 
 ~LNinePatchView () noexcept
 Destructor for LNinePatchView.
 
void setPos (Int32 x, Int32 y) noexcept
 Sets the position of the view.
 
void setPos (const LPoint &pos) noexcept
 Sets the position of the view.
 
void setSize (Int32 width, Int32 height) noexcept
 Sets the size of the view.
 
void setSize (const LSize &size) noexcept
 Sets the size of the view.
 
const LSizeminSize () const noexcept
 Returns the minimum size of the view.
 
LTexturetexture () const noexcept
 Returns the current nine-patch texture.
 
void setTexture (LTexture *texture, Float32 bufferScale, const LRectF &center) noexcept
 Sets the nine-patch texture.
 
const LRectFcenter () const noexcept
 Returns the texture subrect for the central view in surface coordinates.
 
LTextureViewgetSubView (LBitset< LEdge > edge) noexcept
 Retrieves one of the nine sub texture views.
 
std::array< LTextureView, 9 > & subViews () noexcept
 Array of the 9 sub-views.
 
bool nativeMapped () const noexcept override
 Tells whether the view should be rendered.
 
const LPointnativePos () const noexcept override
 Gets the position of the view without any transformations applied.
 
const LSizenativeSize () const noexcept override
 Gets the size of the view without any transformations applied.
 
Float32 bufferScale () const noexcept override
 Gets the scale of the view buffer content.
 
void enteredOutput (LOutput *output) noexcept override
 Notifies that portion of the view is visible on the given output.
 
void leftOutput (LOutput *output) noexcept override
 Notifies that the view is no longer visible on the given output.
 
const std::vector< LOutput * > & outputs () const noexcept override
 Gets a vector of output pointers on which the view is currently visible.
 
void requestNextFrame (LOutput *output) noexcept override
 Notifies that the view has been rendered on the given output.
 
const LRegiondamage () const noexcept override
 Gets the region within the view rect that needs to be repainted.
 
const LRegiontranslucentRegion () const noexcept override
 Gets the current translucent region.
 
const LRegionopaqueRegion () const noexcept override
 Gets the current opaque region.
 
const LRegioninputRegion () const noexcept override
 Gets the current input region.
 
void paintEvent (const PaintEventParams &params) noexcept override
 Requests to paint a region of the view to the current framebuffer.
 
- Public Member Functions inherited from LView
 LView (UInt32 type, bool renderable, LView *parent) noexcept
 Construct an LView object.
 
 ~LView () noexcept
 Destructor for the LView class.
 
void enablePointerEvents (bool enabled) noexcept
 Toggles pointer events.
 
bool pointerEventsEnabled () const noexcept
 Checks if pointer events are enabled.
 
bool pointerIsOver () const noexcept
 Checks if the view has pointer focus.
 
void enableBlockPointer (bool enabled) noexcept
 Toggles blocking pointer events to views behind the view's input region.
 
bool blockPointerEnabled () const noexcept
 Checks if blocking of pointer events is enabled.
 
void enableKeyboardEvents (bool enabled) noexcept
 Toggles keyboard events.
 
bool keyboardEventsEnabled () const noexcept
 Checks if keyboard events are enabled.
 
void enableTouchEvents (bool enabled) noexcept
 Toggles touch events.
 
bool touchEventsEnabled () const noexcept
 Checks if touch events are enabled.
 
void enableBlockTouch (bool enabled) noexcept
 Toggles blocking touch events to views behind the view's input region.
 
bool blockTouchEnabled () const noexcept
 Checks if blocking of touch events to views behind the view's input region is enabled.
 
void damageAll () noexcept
 Forces a complete repaint of the view in the next rendering frame.
 
LScenescene () const noexcept
 Gets the scene in which this view is currently embedded.
 
bool isLScene () const noexcept
 Checks if the view is an LScene::mainView().
 
LSceneViewparentSceneView () const noexcept
 Gets the closest parent LSceneView.
 
UInt32 type () const noexcept
 Gets the identifier for the type of view.
 
bool isRenderable () const noexcept
 Checks if the view is renderable.
 
void repaint () const noexcept
 Schedules a repaint for all outputs where this view is currently visible.
 
LViewparent () const noexcept
 Gets the parent of the view.
 
void setParent (LView *view) noexcept
 Sets the new parent for the view and insert it at the end of its children list.
 
void insertAfter (LView *prev) noexcept
 Inserts the view after the specified 'prev' view.
 
const std::list< LView * > & children () const noexcept
 Children views.
 
void enableParentOffset (bool enabled) noexcept
 Toggles the parent position offset.
 
bool parentOffsetEnabled () const noexcept
 Checks if pos() includes the parent's position.
 
const LPointpos () const noexcept
 Gets the current position of the view with applied transformations.
 
const LSizesize () const noexcept
 Gets the current size of the view with applied transformations.
 
void enableClipping (bool enabled) noexcept
 Toggles the use of the clippingRect() property.
 
bool clippingEnabled () const noexcept
 Checks if the view is currently being clipped to the clippingRect() property.
 
void setClippingRect (const LRect &rect) noexcept
 Sets a custom clipping rect.
 
const LRectclippingRect () const noexcept
 Gets the clipping rect set with setClippingRect().
 
void enableParentClipping (bool enabled) noexcept
 Toggles parent clipping.
 
bool parentClippingEnabled () const noexcept
 Checks if the view is clipped to the parent view rect.
 
void enableScaling (bool enabled) noexcept
 Toggles the use of the scalingVector().
 
bool scalingEnabled () const noexcept
 Checks if the scalingVector() is enabled.
 
void setScalingVector (const LSizeF &scalingVector) noexcept
 Sets the scalingVector() property.
 
const LSizeFscalingVector (bool forceIgnoreParent=false) const noexcept
 Gets the scaling vector.
 
void enableParentScaling (bool enabled) noexcept
 Toggles the scaling of size and position by the parent's scaling vector.
 
bool parentScalingEnabled () const noexcept
 Checks if the size and position are scaled by the parent's scalingVector().
 
void setVisible (bool visible) noexcept
 Toggles the view visibility.
 
bool visible () const noexcept
 Checks if the view is marked as visible.
 
bool mapped () const noexcept
 Checks if the view should be rendered, taking into consideration several conditions.
 
void setOpacity (Float32 opacity) noexcept
 Set the view opacity.
 
Float32 opacity (bool forceIgnoreParent=false) const noexcept
 Gets the view opacity.
 
void enableParentOpacity (bool enabled) noexcept
 Toggles the use of the parent's opacity.
 
bool parentOpacityEnabled () const noexcept
 Checks if the view's opacity is multiplied by its parent's opacity.
 
void enableForceRequestNextFrame (bool enabled) noexcept
 Toggles forcing triggering the requestNextFrame() event.
 
bool forceRequestNextFrameEnabled () const noexcept
 Checks if forcing requestNextFrame() is enabled.
 
void setBlendFunc (const LBlendFunc &blendFunc) noexcept
 Sets a custom alpha/color blending function for the view.
 
const LBlendFuncblendFunc () const noexcept
 Gets the blending function set with setBlendFunc().
 
void enableAutoBlendFunc (bool enabled) noexcept
 Toggles the automatic blend function adjustment.
 
bool autoBlendFuncEnabled () const noexcept
 Checks whether the automatic blend function adjustment is enabled.
 
void setColorFactor (const LRGBAF &colorFactor) noexcept
 Set the color factor.
 
const LRGBAFcolorFactor () const noexcept
 Gets the color factor.
 
LBox boundingBox () const noexcept
 Gets the bounding box of the view and all its mapped children.
 
virtual void pointerEnterEvent (const LPointerEnterEvent &event)
 Handles a pointer enter event within the view.
 
virtual void pointerMoveEvent (const LPointerMoveEvent &event)
 Handle a pointer move event within the view.
 
virtual void pointerLeaveEvent (const LPointerLeaveEvent &event)
 Handle a pointer leave event within the view.
 
virtual void pointerButtonEvent (const LPointerButtonEvent &event)
 Handle a pointer button event within the view.
 
virtual void pointerScrollEvent (const LPointerScrollEvent &event)
 Handle a pointer scroll event within the view.
 
virtual void pointerSwipeBeginEvent (const LPointerSwipeBeginEvent &event)
 Handle a pointer swipe begin event within the view.
 
virtual void pointerSwipeUpdateEvent (const LPointerSwipeUpdateEvent &event)
 Handle a pointer swipe update event within the view.
 
virtual void pointerSwipeEndEvent (const LPointerSwipeEndEvent &event)
 Handle a pointer swipe end event within the view.
 
virtual void pointerPinchBeginEvent (const LPointerPinchBeginEvent &event)
 Handle a pointer pinch begin event within the view.
 
virtual void pointerPinchUpdateEvent (const LPointerPinchUpdateEvent &event)
 Handle a pointer pinch update event within the view.
 
virtual void pointerPinchEndEvent (const LPointerPinchEndEvent &event)
 Handle a pointer pinch end event within the view.
 
virtual void pointerHoldBeginEvent (const LPointerHoldBeginEvent &event)
 Handle a pointer hold begin event within the view.
 
virtual void pointerHoldEndEvent (const LPointerHoldEndEvent &event)
 Handle a pointer hold end event within the view.
 
virtual void keyEvent (const LKeyboardKeyEvent &event)
 Handle the key event within the view.
 
virtual void touchDownEvent (const LTouchDownEvent &event)
 Handle a touch down event within the view.
 
virtual void touchMoveEvent (const LTouchMoveEvent &event)
 Handle a touch move event within the view.
 
virtual void touchUpEvent (const LTouchUpEvent &event)
 Handle a touch up event within the view.
 
virtual void touchFrameEvent (const LTouchFrameEvent &event)
 Handle a touch frame event within the view.
 
virtual void touchCancelEvent (const LTouchCancelEvent &event)
 Handle a touch cancel event within the view.
 
- Public Member Functions inherited from LObject
 LObject (const LObject &) noexcept
 Copy constructor.
 
LObjectoperator= (const LObject &) noexcept
 Assignment operator (each object has its own individual LWeak reference count).
 
void setUserData (UIntPtr data) const noexcept
 Store an unsigned integer value/pointer.
 
UIntPtr userData () const noexcept
 Retrieves the stored unsigned integer value/pointer.
 

Additional Inherited Members

- Public Types inherited from LView
enum  Type : UInt8
 Types of views included with Louvre. More...
 
- Protected Member Functions inherited from LObject
 LObject () noexcept=default
 Constructor of the LObject class.
 
virtual ~LObject () noexcept
 Destructor of the LObject class.
 
void notifyDestruction () noexcept
 Notifies the object destruction.
 

Detailed Description

Nine-Patch Texture View.

The LNinePatchView class is useful for implementing buttons, containers, borders, etc. in an efficient way. It consists of 9 sub LTextureView s arranged as shown below:

The portion of the texture, position and size of each subview is automatically calculated from the provided center() (E) and the dimensions set with setSize().

For more information about the nine-patch technique, check out this link.

Subviews can be accessed directly via subViews() or getSubView(), for example, to toggle the visibility of a specific one, change its color, etc.

Warning
If used as borders (with an invisible center), remember to hide the central view, otherwise, the scene will unnecessarily paint invisible pixels.

Constructor & Destructor Documentation

◆ LNinePatchView() [1/2]

LNinePatchView ( LView parent = nullptr)
inlinenoexcept

Creates an empty nine-patch view.

◆ LNinePatchView() [2/2]

LNinePatchView ( LTexture texture,
Float32  bufferScale,
const LRectF center,
LView parent = nullptr 
)
inlinenoexcept

Creates a nine-patch view with a specified texture.

Parameters
textureThe texture, or nullptr (unmapped).
bufferScaleThe scaling factor of the texture.
centerThe subrect of the texture corresponding to the central view in surface coordinates. If extended beyond the texture bounds, it will be clipped.
parentThe parent view, or nullptr if there is no parent. Defaults to nullptr.

◆ ~LNinePatchView()

~LNinePatchView ( )
inlinenoexcept

Destructor for LNinePatchView.

Member Function Documentation

◆ setPos() [1/2]

void setPos ( Int32  x,
Int32  y 
)
noexcept

Sets the position of the view.

Parameters
xThe x-coordinate in surface coordinates.
yThe y-coordinate in surface coordinates.

◆ setPos() [2/2]

void setPos ( const LPoint pos)
inlinenoexcept

Sets the position of the view.

Parameters
posThe position in surface coordinates.

◆ setSize() [1/2]

void setSize ( Int32  width,
Int32  height 
)
noexcept

Sets the size of the view.

Note
The size is constrained by minSize()
Parameters
widthThe width in surface coordinates.
heightThe height in surface coordinates.

◆ setSize() [2/2]

void setSize ( const LSize size)
inlinenoexcept

Sets the size of the view.

Note
The size is constrained by minSize()
Parameters
sizeThe size in surface coordinates.

◆ minSize()

const LSize & minSize ( ) const
inlinenoexcept

Returns the minimum size of the view.

The minimum size is equal to the texture's size in surface coordinates (the buffer size divided by the buffer scale) minus the center rect size.

If no texture is set the minimum size is (0, 0).

◆ texture()

LTexture * texture ( ) const
inlinenoexcept

Returns the current nine-patch texture.

See also
setTexture()
Returns
A pointer to the texture, or nullptr if no texture is set.

◆ setTexture()

void setTexture ( LTexture texture,
Float32  bufferScale,
const LRectF center 
)
noexcept

Sets the nine-patch texture.

Parameters
textureThe texture, or nullptr to unset.
bufferScaleThe scaling factor of the texture.
centerThe subrect of the texture corresponding to the central view in surface coordinates. If extended beyond the texture bounds, it will be clipped.

◆ center()

const LRectF & center ( ) const
inlinenoexcept

Returns the texture subrect for the central view in surface coordinates.

See also
setTexture()

If no texture is set (0, 0, 0, 0) is returned.

◆ getSubView()

LTextureView * getSubView ( LBitset< LEdge edge)
noexcept

Retrieves one of the nine sub texture views.

Example:

ninePatchView->getSubView(LEdgeTop | LEdgeLeft) // Returns the top-left sub-view
@ LEdgeLeft
The left edge.
Definition LEdge.h:17
@ LEdgeTop
The top edge.
Definition LEdge.h:15
Parameters
edgeThe edge or corner to retrieve. Passing LEdgeNone (or a value that is not a corner or edge) returns the central view.
Returns
A pointer to the requested LTextureView.

◆ subViews()

std::array< LTextureView, 9 > & subViews ( )
inlinenoexcept

Array of the 9 sub-views.

The order of the views is L, T, R, B, TL, TR, BR, BL, and Center.

If a specific view needs to be retrieved, consider using getSubView() instead.

Returns
A reference to the vector of sub-views.

◆ nativeMapped()

bool nativeMapped ( ) const
overridevirtualnoexcept

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
overridevirtualnoexcept

Gets the position of the view without any transformations applied.

Must return the position of the view in compositor-global coordinates.

Returns
The position of the view as an LPoint object.

Implements LView.

◆ nativeSize()

const LSize & nativeSize ( ) const
overridevirtualnoexcept

Gets 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
overridevirtualnoexcept

Gets 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)
overridevirtualnoexcept

Notifies that portion of 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)
overridevirtualnoexcept

Notifies 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
overridevirtualnoexcept

Gets 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.

◆ requestNextFrame()

void requestNextFrame ( LOutput output)
overridevirtualnoexcept

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

This method is called by the closest parent scene view 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
overridevirtualnoexcept

Gets 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.

It should 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
overridevirtualnoexcept

Gets the current translucent region.

The region must be specified in surface-local coordinates, without any scaling, clipping, or offset transformations applied.

If nullptr is returned, the entire view rect will be considered translucent.

Implements LView.

◆ opaqueRegion()

const LRegion * opaqueRegion ( ) const
overridevirtualnoexcept

Gets the current opaque region.

The region must be specified in surface-local coordinates without any scaling, clipping, or offset transformations applied.

If nullptr is returned, the inverse of the translucent region will be considered opaque.

Note
You could only specify the translucent region.

Implements LView.

◆ inputRegion()

const LRegion * inputRegion ( ) const
overridevirtualnoexcept

Gets the current input region.

Region within the view rect that can receive pointer and touch events.

The region must be specified in surface-local coordinates without any scaling, clipping, or offset transformations applied.

If nullptr is returned, the entire view will receive input.

Implements LView.

◆ paintEvent()

void paintEvent ( const PaintEventParams params)
overridevirtualnoexcept

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

This method is used by the closest parent LSceneView to request the view to paint a specified region on the current framebuffer. Painting can be performed using the provided LPainter object.

Note
Using LPainter is optional.

Implements LView.