Pebble Foundation Classes  0.2.0
C++ for Pebble
Pebble::GRect Struct Reference

#include <pebble_graphics_types.hpp>

Collaboration diagram for Pebble::GRect:

Public Member Functions

 GRect ()
 Constructs an empty GRect.
 
 GRect (const ::GRect &rect)
 Converts from Pebble GRect.
 
 GRect (int16_t x, int16_t y, int16_t w, int16_t h)
 
 GRect (::GPoint origin, ::GSize size)
 
 GRect (GPoint origin, GSize size)
 
 operator::GRect & ()
 Convert to a Pebble GRect.
 
 operator const ::GRect & () const
 Convert to a Pebble GRect.
 
 operator::GRect * ()
 Convert to a Pebble GRect pointer.
 
 operator const ::GRect * () const
 Convert to a Pebble GRect pointer.
 
bool operator== (const ::GRect &rect) const
 
bool operator!= (const ::GRect &rect) const
 
void Align (const ::GRect &inside_rect, const GAlign alignment, const bool clip)
 
GPoint CenterPoint () const
 
GRect Inset (GEdgeInsets insets) const
 
bool IsEmpty ()
 
void Standardize ()
 
void Clip (const GRect &rect_clipper)
 
bool ContainsPoint (const GPoint &point)
 
GRect Crop (int32_t crop_size_px)
 
GPoint FromPolar (GOvalScaleMode scale_mode, int32_t angle)
 
GRect CenterFromPolar (GOvalScaleMode scale_mode, int32_t angle, GSize size)
 

Public Attributes

GPoint origin
 The coordinate of the upper-lefthand corner point of the rectangle.
 
GSize size
 The size of the rectangle.
 

Detailed Description

Represents a rectangle and defining it using the origin of the upper-lefthand corner and its size.

Constructor & Destructor Documentation

◆ GRect() [1/3]

Pebble::GRect::GRect ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h 
)
inline

Constructs from a position and size

Parameters
xThe X coordinate
yThe Y coordinate
wThe width
hThe height

◆ GRect() [2/3]

Pebble::GRect::GRect ( ::GPoint  origin,
::GSize  size 
)
inline

Construct a GRect from a Pebble point and size

Parameters
originOrigin
sizeSize

◆ GRect() [3/3]

Pebble::GRect::GRect ( GPoint  origin,
GSize  size 
)
inline

Construct a GRect from a point and size

Parameters
originOrigin
sizeSize

Member Function Documentation

◆ Align()

void Pebble::GRect::Align ( const ::GRect inside_rect,
const GAlign  alignment,
const bool  clip 
)
inline

Aligns one rectangle within another rectangle, using an alignment parameter. The relative coordinate systems of both rectangles are assumed to be the same. When clip is true, rect is also clipped by the constraint.

Parameters
inside_rectThe rectangle in which to align rect
alignmentDetermines the alignment of rect within inside_rect by specifying what edges of should overlap.
clipDetermines whether rect should be trimmed using the edges of inside_rect in case rect extends outside of the area that inside_rect covers after the alignment.

◆ CenterFromPolar()

GRect Pebble::GRect::CenterFromPolar ( GOvalScaleMode  scale_mode,
int32_t  angle,
GSize  size 
)
inline

Calculates a rectangle centered on the perimeter of a circle at a given angle. Use this to construct rectangles that follow the perimeter of a circle as an input for graphics_fill_radial_internal or graphics_draw_arc_internal, e.g. to draw circles every 30 degrees on a watchface.

Parameters
scale_modeDetermines how rect will be used to derive the circle's center point and radius.
angleThe angle at which the point on the circle's perimeter should be calculated. Use DEG_TO_TRIGANGLE to easily convert degrees to the appropriate value.
sizeWidth and height of the desired rectangle.
Returns
The rectangle centered on the circle's perimeter.

◆ CenterPoint()

GPoint Pebble::GRect::CenterPoint ( ) const
inline

Convenience method to compute the center-point of a given rectangle. This is equal to (rect->x + rect->width / 2, rect->y + rect->height / 2).

Returns
The point at the center of rect

◆ Clip()

void Pebble::GRect::Clip ( const GRect rect_clipper)
inline

Trim one rectangle using the edges of a second rectangle.

Parameters
rect_clipperThe rectangle of which the edges will serve as "scissors" in order to trim rect_to_clip.

◆ ContainsPoint()

bool Pebble::GRect::ContainsPoint ( const GPoint point)
inline

Tests whether a rectangle contains a point.

Parameters
pointThe point
Returns
true if the rectangle contains the point, or false if it does not.

◆ Crop()

GRect Pebble::GRect::Crop ( int32_t  crop_size_px)
inline

Reduce the width and height of a rectangle by insetting each of the edges with a fixed inset. The returned rectangle will be centered relative to the input rectangle.

Note
The function will trip an assertion if the crop yields a rectangle with negative width or height.
Parameters
crop_size_pxThe inset by which each of the rectangle will be inset. A positive inset value results in a smaller rectangle, while negative inset value results in a larger rectangle.
Returns
The cropped rectangle.

◆ FromPolar()

GPoint Pebble::GRect::FromPolar ( GOvalScaleMode  scale_mode,
int32_t  angle 
)
inline

Calculates a GPoint located at the angle provided on the perimeter of a circle defined by the provided GRect.

Parameters
scale_modeDetermines how rect will be used to derive the center point and radius.
angleThe angle at which the point on the circle's perimeter should be calculated. Use DEG_TO_TRIGANGLE to easily convert degrees to the appropriate value.
Returns
The point on the circle's perimeter.

◆ Inset()

GRect Pebble::GRect::Inset ( GEdgeInsets  insets) const
inline

Returns a rectangle that is shrinked or expanded by the given edge insets.

Note
The rectangle is standardized and then the inset parameters are applied. If the resulting rectangle would have a negative height or width, a GRectZero is returned.
Parameters
insetsThe insets that will be applied
Returns
The resulting rectangle
Note
Use this function in together with the GEdgeInsets macro

◆ IsEmpty()

bool Pebble::GRect::IsEmpty ( )
inline

Tests whether the size of the rectangle is (0, 0).

Returns
true if the rectangle its size is (0, 0), or false if not.
Note
If the width and/or height of a rectangle is negative, this function will return true!

◆ operator!=()

bool Pebble::GRect::operator!= ( const ::GRect rect) const
inline

Tests whether 2 rectangles are not equal.

Parameters
rectThe second rectangle
Returns
true if both rectangles are not equal, false if equal.

◆ operator==()

bool Pebble::GRect::operator== ( const ::GRect rect) const
inline

Tests whether 2 rectangles are equal.

Parameters
rectThe second rectangle
Returns
true if both rectangles are equal, false if not.

◆ Standardize()

void Pebble::GRect::Standardize ( )
inline

Converts a rectangle's values so that the components of its size (width and/or height) are both positive. In the width and/or height are negative, the origin will offset, so that the final rectangle overlaps with the original. For example, a GRect with size (-10, -5) and origin (20, 20), will be standardized to size (10, 5) and origin (10, 15).


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