gtkmm 4.23.0
Gdk::Graphene::Rect Class Reference

The location and size of a rectangle region. More...

#include <gdkmm/graphene_rect.h>

Public Member Functions

 Rect ()
 Constructs an invalid object.
 Rect (graphene_rect_t * castitem, bool make_a_copy=false)
 Rect (const Rect & src)
Rectoperator= (const Rect & src)
 Rect (Rect && other) noexcept
Rectoperator= (Rect && other) noexcept
 ~Rect () noexcept
void swap (Rect & other) noexcept
graphene_rect_t * gobj ()
const graphene_rect_t * gobj () const
graphene_rect_t * gobj_copy () const
 Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
 Rect (float x, float y, float width, float height)
 operator bool () const
 Checks if this instance is valid.
Point get_origin () const
void set_origin (const Point & value)
Size get_size () const
void set_size (const Size & value)
Point get_center () const
 Retrieves the coordinates of the center of the given rectangle.
Point get_top_left () const
 Retrieves the coordinates of the top-left corner of the given rectangle.
Point get_top_right () const
 Retrieves the coordinates of the top-right corner of the given rectangle.
Point get_bottom_right () const
 Retrieves the coordinates of the bottom-right corner of the given rectangle.
Point get_bottom_left () const
 Retrieves the coordinates of the bottom-left corner of the given rectangle.
std::array< Vec2, 4 > get_vertices () const
 Computes the four vertices of this Rect.
bool equal (const Rect & b) const
 Checks whether the two given rectangle are equal.
void normalize ()
 Normalizes the passed rectangle.
float get_x () const
 Retrieves the normalized X coordinate of the origin of the given rectangle.
float get_y () const
 Retrieves the normalized Y coordinate of the origin of the given rectangle.
float get_width () const
 Retrieves the normalized width of the given rectangle.
float get_height () const
 Retrieves the normalized height of the given rectangle.
float get_area () const
 Compute the area of given normalized rectangle.
Rect join (const Rect & b) const
 Computes the union of the two rectangles.
std::optional< Rectintersection (const Rect & b) const
 Computes the intersection of the two given rectangles.
bool contains_point (const Point & p) const
 Checks whether a #graphene_rect_t contains the given coordinates.
bool contains_rect (const Rect & b) const
 Checks whether a #graphene_rect_t fully contains the given rectangle.
void offset (float d_x, float d_y)
 Offsets the origin by d_x and d_y.
void inset (float d_x, float d_y)
 Changes the given rectangle to be smaller, or larger depending on the given inset parameters.
Rect round_extents () const
 Rounds the origin of this rectangle to its nearest integer value and recomputes the size so that the rectangle is large enough to contain all the corners of the original rectangle.
Rect interpolate (const Rect & b, double factor) const
 Linearly interpolates the origin and size of this rectangle and rectangle b.
Rect expand (const Point & p) const
 Expands this rectangle to contain the given point.
Rect scale (float s_h, float s_v) const
 Scales the size and origin of this rectangle horizontally by s_h, and vertically by s_v.

Protected Attributes

graphene_rect_t * gobject_

(Note that these are not member symbols.)

void swap (Rect & lhs, Rect & rhs) noexcept
Gdk::Graphene::Rect wrap (graphene_rect_t * object, bool take_copy=false)
 A Glib::wrap() method for this object.

Detailed Description

The location and size of a rectangle region.

The width and height of a Gdk::Graphene::Rect can be negative; for instance, a Gdk::Graphene::Rect with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is equivalent to a Gdk::Graphene::Rect with an origin of [ 10, 10 ] and a size of [ -10, -10 ].

Application code can normalize rectangles using normalize(); this function will ensure that the width and height of a rectangle are positive values. All functions taking a Gdk::Graphene::Rect as an argument will internally operate on a normalized copy; all functions returning a Gdk::Graphene::Rect will always return a normalized rectangle.

Since gtkmm 4.12

Constructor & Destructor Documentation

◆ Rect() [1/5]

Gdk::Graphene::Rect::Rect ( )

Constructs an invalid object.

E.g. for output arguments to methods. There is not much you can do with the object before it has been assigned a valid value.

◆ Rect() [2/5]

Gdk::Graphene::Rect::Rect ( graphene_rect_t * castitem,
bool make_a_copy = false )
explicit

◆ Rect() [3/5]

Gdk::Graphene::Rect::Rect ( const Rect & src)

◆ Rect() [4/5]

Gdk::Graphene::Rect::Rect ( Rect && other)
noexcept

◆ ~Rect()

Gdk::Graphene::Rect::~Rect ( )
noexcept

◆ Rect() [5/5]

Gdk::Graphene::Rect::Rect ( float x,
float y,
float width,
float height )

Member Function Documentation

◆ contains_point()

bool Gdk::Graphene::Rect::contains_point ( const Point & p) const

Checks whether a #graphene_rect_t contains the given coordinates.

Since gtkmm 4.12
Parameters
pA #graphene_point_t.
Returns
true if the rectangle contains the point.

◆ contains_rect()

bool Gdk::Graphene::Rect::contains_rect ( const Rect & b) const

Checks whether a #graphene_rect_t fully contains the given rectangle.

Since gtkmm 4.12
Parameters
bA #graphene_rect_t.
Returns
true if the rectangle a fully contains b.

◆ equal()

bool Gdk::Graphene::Rect::equal ( const Rect & b) const

Checks whether the two given rectangle are equal.

Since gtkmm 4.12
Parameters
bA #graphene_rect_t.
Returns
true if the rectangles are equal.

◆ expand()

Rect Gdk::Graphene::Rect::expand ( const Point & p) const

Expands this rectangle to contain the given point.

Since gtkmm 4.24
Parameters
pA Gdk::Graphene::Point.
Returns
The expanded rectangle.

◆ get_area()

float Gdk::Graphene::Rect::get_area ( ) const

Compute the area of given normalized rectangle.

Since gtkmm 4.12
Returns
The area of the normalized rectangle.

◆ get_bottom_left()

Point Gdk::Graphene::Rect::get_bottom_left ( ) const

Retrieves the coordinates of the bottom-left corner of the given rectangle.

◆ get_bottom_right()

Point Gdk::Graphene::Rect::get_bottom_right ( ) const

Retrieves the coordinates of the bottom-right corner of the given rectangle.

◆ get_center()

Point Gdk::Graphene::Rect::get_center ( ) const

Retrieves the coordinates of the center of the given rectangle.

◆ get_height()

float Gdk::Graphene::Rect::get_height ( ) const

Retrieves the normalized height of the given rectangle.

Since gtkmm 4.12
Returns
The normalized height of the rectangle.

◆ get_origin()

Point Gdk::Graphene::Rect::get_origin ( ) const

◆ get_size()

Size Gdk::Graphene::Rect::get_size ( ) const

◆ get_top_left()

Point Gdk::Graphene::Rect::get_top_left ( ) const

Retrieves the coordinates of the top-left corner of the given rectangle.

◆ get_top_right()

Point Gdk::Graphene::Rect::get_top_right ( ) const

Retrieves the coordinates of the top-right corner of the given rectangle.

◆ get_vertices()

std::array< Vec2, 4 > Gdk::Graphene::Rect::get_vertices ( ) const

Computes the four vertices of this Rect.

Since gtkmm 4.24
Returns
Array of the 4 vertices.

◆ get_width()

float Gdk::Graphene::Rect::get_width ( ) const

Retrieves the normalized width of the given rectangle.

Since gtkmm 4.12
Returns
The normalized width of the rectangle.

◆ get_x()

float Gdk::Graphene::Rect::get_x ( ) const

Retrieves the normalized X coordinate of the origin of the given rectangle.

Since gtkmm 4.12
Returns
The normalized X coordinate of the rectangle.

◆ get_y()

float Gdk::Graphene::Rect::get_y ( ) const

Retrieves the normalized Y coordinate of the origin of the given rectangle.

Since gtkmm 4.12
Returns
The normalized Y coordinate of the rectangle.

◆ gobj() [1/2]

graphene_rect_t * Gdk::Graphene::Rect::gobj ( )
inline

◆ gobj() [2/2]

const graphene_rect_t * Gdk::Graphene::Rect::gobj ( ) const
inline

◆ gobj_copy()

graphene_rect_t * Gdk::Graphene::Rect::gobj_copy ( ) const

Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.

◆ inset()

void Gdk::Graphene::Rect::inset ( float d_x,
float d_y )

Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

To create an inset rectangle, use positive d_x or d_y values; to create a larger, encompassing rectangle, use negative d_x or d_y values.

The origin of the rectangle is offset by d_x and d_y, while the size is adjusted by (2 * @a d_x, 2 * @a d_y). If d_x and d_y are positive values, the size of the rectangle is decreased; if d_x and d_y are negative values, the size of the rectangle is increased.

If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

Since gtkmm 4.24
Parameters
d_xThe horizontal inset.
d_yThe vertical inset.

◆ interpolate()

Rect Gdk::Graphene::Rect::interpolate ( const Rect & b,
double factor ) const

Linearly interpolates the origin and size of this rectangle and rectangle b.

Since gtkmm 4.24
Parameters
bA Gdk::Graphene::Rect.
factorThe linear interpolation factor.
Returns
The interpolated rectangle.

◆ intersection()

std::optional< Rect > Gdk::Graphene::Rect::intersection ( const Rect & b) const

Computes the intersection of the two given rectangles.

If the two rectangles do not intersect, no value is returned.

Since gtkmm 4.24
Parameters
bA Gdk::Graphene::Rect.
Returns
The intersection of this rectangle and b, if any.

◆ join()

Rect Gdk::Graphene::Rect::join ( const Rect & b) const

Computes the union of the two rectangles.

Since gtkmm 4.24
Parameters
bA Gdk::Graphene::Rect.
Returns
The union of this rectangle and b.

◆ normalize()

void Gdk::Graphene::Rect::normalize ( )

Normalizes the passed rectangle.

This function ensures that the size of the rectangle is made of positive values, and that the origin is the top-left corner of the rectangle.

Since gtkmm 4.12

◆ offset()

void Gdk::Graphene::Rect::offset ( float d_x,
float d_y )

Offsets the origin by d_x and d_y.

The size of the rectangle is unchanged.

Since gtkmm 4.24
Parameters
d_xThe horizontal offset.
d_yThe vertical offset.

◆ operator bool()

Gdk::Graphene::Rect::operator bool ( ) const
explicit

Checks if this instance is valid.

It is valid if and only if it contains a value. For instance,

if (rect)
do_something()

◆ operator=() [1/2]

Rect & Gdk::Graphene::Rect::operator= ( const Rect & src)

◆ operator=() [2/2]

Rect & Gdk::Graphene::Rect::operator= ( Rect && other)
noexcept

◆ round_extents()

Rect Gdk::Graphene::Rect::round_extents ( ) const

Rounds the origin of this rectangle to its nearest integer value and recomputes the size so that the rectangle is large enough to contain all the corners of the original rectangle.

This function is the equivalent of calling floor on the coordinates of the origin, and recomputing the size calling ceil on the bottom-right coordinates.

If you want to be sure that the rounded rectangle completely covers the area that was covered by the original rectangle — i.e. you want to cover the area including all its corners — this function will make sure that the size is recomputed taking into account the ceiling of the coordinates of the bottom-right corner. If the difference between the original coordinates and the coordinates of the rounded rectangle is greater than the difference between the original size and the rounded size, then the move of the origin would not be compensated by a move in the anti-origin, leaving the corners of the original rectangle outside the rounded one.

Since gtkmm 4.24
Returns
The rectangle with rounded extents.

◆ scale()

Rect Gdk::Graphene::Rect::scale ( float s_h,
float s_v ) const

Scales the size and origin of this rectangle horizontally by s_h, and vertically by s_v.

Since gtkmm 4.24
Parameters
s_hHorizontal scale factor.
s_vVertical scale factor.
Returns
The scaled and normalized rectangle.

◆ set_origin()

void Gdk::Graphene::Rect::set_origin ( const Point & value)

◆ set_size()

void Gdk::Graphene::Rect::set_size ( const Size & value)

◆ swap()

void Gdk::Graphene::Rect::swap ( Rect & other)
noexcept

◆ swap()

void swap ( Rect & lhs,
Rect & rhs )
related
Parameters
lhsThe left-hand side
rhsThe right-hand side

◆ wrap()

Gdk::Graphene::Rect wrap ( graphene_rect_t * object,
bool take_copy = false )
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.

Member Data Documentation

◆ gobject_

graphene_rect_t* Gdk::Graphene::Rect::gobject_
protected