Basic graphics types (point, rect, size, color, bitmaps, etc.) and utility functions.
Create a new GBitmap on the heap as a sub-bitmap of a 'base' GBitmap, using a GRect to indicate what portion of the base to use. The sub-bitmap will just reference the image data of the base bitmap. No deep-copying occurs as a result of calling this function, thus the caller is responsible for making sure the base bitmap will remain available when using the sub-bitmap.
[in] | base_bitmap | The bitmap that the sub-bitmap of which the image data will be used by the sub-bitmap |
sub_rect | The rectangle within the image data of the base bitmap. The bounds of the base bitmap will be used to clip sub_rect . |
GBitmap* gbitmap_create_with_data | ( | const uint8_t * | data | ) |
Creates a new GBitmap on the heap initialized with a Pebble image file data (.pbi), as output by bitmapgen.py.
data | The Pebble image file data. Must not be NULL. The function assumes the data to be correct; there are no sanity checks performed on the data. |
void gbitmap_destroy | ( | GBitmap * | bitmap | ) |
Tests whether 2 points are equal.
point_a | Pointer to the first point |
point_b | Pointer to the second point |
true
if both points are equal, false
if not. void grect_align | ( | GRect * | rect, |
const GRect * | inside_rect, | ||
const GAlign | alignment, | ||
const bool | clip | ||
) |
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.
[in] | rect | The rectangle to align (in place) |
[out] | rect | The aligned and optionally clipped rectangle |
inside_rect | The rectangle in which to align rect | |
alignment | Determines the alignment of rect within inside_rect by specifying what edges of should overlap. | |
clip | Determines 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. |
Convenience function to compute the center-point of a given rectangle. This is equal to (rect->x + rect->width / 2, rect->y + rect->height / 2)
.
rect | The rectangle for which to calculate the center point. |
rect
Trim one rectangle using the edges of a second rectangle.
[in] | rect_to_clip | The rectangle that needs to be clipped (in place). |
[out] | rect_to_clip | The clipped rectangle. |
rect_clipper | The rectangle of which the edges will serve as "scissors" in order to trim rect_to_clip . |
Tests whether a rectangle contains a point.
rect | The rectangle |
point | The point |
true
if the rectangle contains the point, or false
if it does not. 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.
rect | The rectangle that will be inset |
crop_size_px | The 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. |
Tests whether 2 rectangles are equal.
rect_a | Pointer to the first rectangle |
rect_b | Pointer to the second rectangle |
true
if both rectangles are equal, false
if not. bool grect_is_empty | ( | const GRect *const | rect | ) |
Tests whether the size of the rectangle is (0, 0).
rect | Pointer to the rectangle |
true
if the rectangle its size is (0, 0), or false
if not. true
! void grect_standardize | ( | GRect * | rect | ) |
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).
[in] | rect | The rectangle to convert. |
[out] | rect | The standardized rectangle. |
Tests whether 2 sizes are equal.
size_a | Pointer to the first size |
size_b | Pointer to the second size |
true
if both sizes are equal, false
if not. struct GBitmap |
Structure containing the metadata of a bitmap image.
Note that this structure does NOT contain any pixel data; it only has a pointer to a buffer containing the pixels (the addr
field). The metadata describes how long each row of pixels is in the buffer (the stride). Each row must be a multiple of 32 pixels (4 bytes). Using the bounds
field, the area that is actually relevant can be specified.
For example, when the image is 29 by 5 pixels (width by height) and the first bit of image data is the pixel at (0, 0), then the bounds.size would be GSize(29, 5)
and bounds.origin would be GPoint(0, 0)
.
In the illustration each pixel is a representated as a square. The white squares are the bits that are used, the gray squares are the padding bits, because each row of image data has to be a multiple of 4 bytes (32 bits). The numbers in the column in the left are the offsets (in bytes) from the *addr
field of the GBitmap.
Each pixel in a bitmap is represented by 1 bit. If a bit is set (1
or true
), it will result in a white pixel, and vice versa, if a bit is cleared (0
or false
), it will result in a black pixel.
Data Fields | ||
---|---|---|
union GBitmap | __unnamed__ | This union is here to make it easy to copy in a full uint16_t of flags from the binary format. |
void * | addr | Pointer to the address where the image data lives. |
GRect | bounds |
The box of bits that the addr field is pointing to, that contains the actual image data to use. Note that this may be a subsection of the data with padding on all sides. |
uint16_t | row_size_bytes |
|
union GBitmap.__unnamed__ |
This union is here to make it easy to copy in a full uint16_t of flags from the binary format.
Data Fields | ||
---|---|---|
__unnamed__ | __unnamed__ | |
uint16_t | info_flags | Bitfields of metadata flags. |
struct GPoint |
Represents a point in a 2-dimensional coordinate system.
Data Fields | ||
---|---|---|
int16_t | x | The x-coordinate. |
int16_t | y | The y-coordinate. |
struct GRect |
struct GSize |
enum GAlign |
Values to specify how two things should be aligned relative to each other.
enum GColor |
enum GCompOp |
Values to specify how the source image should be composited onto the destination image.
There is no notion of "transparency" in the graphics system. However, the effect of transparency can be created by masking and using compositing modes.
Contrived example of how the different compositing modes affect drawing. Often, the "destination image" is the render buffer and thus contains the image of what has been drawn before or "underneath".