cairo::pattern
cairo::pattern_t is the paint with which cairo draws. The primary use of patterns is as the source for all cairo drawing operations, although they can also be used as masks, that is, as the brush too.
A cairo pattern is created by using one of the many constructors, of the form cairo::pattern::create_type() or implicitly through cairo::set_source_type() functions.
Index
Functions
fn add_color_stop_rgb(pattern: *cairo::pattern_t, offset_: f64, red: f64, green: f64, blue: f64) (void | cairo::error);
fn add_color_stop_rgba(pattern: *cairo::pattern_t, offset_: f64, red: f64, green: f64, blue: f64, alpha: f64) (void | cairo::error);
fn create_for_surface(surface: *cairo::surface_t) (*cairo::pattern_t | cairo::error);
fn create_linear(x0: f64, y0: f64, x1: f64, y1: f64) (*cairo::pattern_t | cairo::error);
fn create_mesh() *cairo::pattern_t;
fn create_radial(cx0: f64, cy0: f64, radius0: f64, cx1: f64, cy1: f64, radius1: f64) (*cairo::pattern_t | cairo::error);
fn create_rgb(red: f64, green: f64, blue: f64) (*cairo::pattern_t | cairo::error);
fn create_rgba(red: f64, green: f64, blue: f64, alpha: f64) (*cairo::pattern_t | cairo::error);
fn destroy(pattern: *cairo::pattern_t) void;
fn get_color_stop_count(pattern: *cairo::pattern_t, count: *int) cairo::status_t;
fn get_color_stop_rgba(pattern: *cairo::pattern_t, index: int, offset_: *f64, red: *f64, green: *f64, blue: *f64, alpha: *f64) cairo::status_t;
fn get_extend(pattern: *cairo::pattern_t) cairo::extend_t;
fn get_filter(pattern: *cairo::pattern_t) cairo::filter_t;
fn get_linear_points(pattern: *cairo::pattern_t, x0: *f64, y0: *f64, x1: *f64, y1: *f64) cairo::status_t;
fn get_matrix(pattern: *cairo::pattern_t, matrix: *cairo::matrix_t) void;
fn get_radial_circles(pattern: *cairo::pattern_t, x0: *f64, y0: *f64, r0: *f64, x1: *f64, y1: *f64, r1: *f64) cairo::status_t;
fn get_reference_count(pattern: *cairo::pattern_t) uint;
fn get_rgba(pattern: *cairo::pattern_t, red: *f64, green: *f64, blue: *f64, alpha: *f64) cairo::status_t;
fn get_surface(pattern: *cairo::pattern_t, surface: *cairo::surface_t) cairo::status_t;
fn get_type(pattern: *cairo::pattern_t) cairo::pattern_type_t;
fn reference(pattern: *cairo::pattern_t) *cairo::pattern_t;
fn set_extend(pattern: *cairo::pattern_t, extend: cairo::extend_t) void;
fn set_filter(pattern: *cairo::pattern_t, filter: cairo::filter_t) void;
fn set_matrix(pattern: *cairo::pattern_t, matrix: *const cairo::matrix_t) void;
fn status(pattern: *cairo::pattern_t) cairo::status_t;
Functions
fn add_color_stop_rgb
fn add_color_stop_rgb(pattern: *cairo::pattern_t, offset_: f64, red: f64, green: f64, blue: f64) (void | cairo::error);
Adds an opaque color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (x0,y0) to (x1,y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.
The color is specified in the same way as in cairo::set_source_rgb.
If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.
Parameters
- pattern: a cairo::pattern_t
- offset: an offset in the range [0.0 .. 1.0]
- red: red component of color
- green: green component of color
- blue: blue component of color
fn add_color_stop_rgba
fn add_color_stop_rgba(pattern: *cairo::pattern_t, offset_: f64, red: f64, green: f64, blue: f64, alpha: f64) (void | cairo::error);
Adds a translucent color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (x0,y0) to (x1,y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.
The color is specified in the same way as in cairo::set_source_rgba.
If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.
Parameters
- pattern: a cairo::pattern_t
- offset: an offset in the range [0.0 .. 1.0]
- red: red component of color
- green: green component of color
- blue: blue component of color
- alpha: alpha component of color
fn create_for_surface
fn create_for_surface(surface: *cairo::surface_t) (*cairo::pattern_t | cairo::error);
Creates a new cairo::pattern_t for the given surface.
Returns the newly created cairo::pattern_t if successful, or an cairo::error in case of no memory. The caller owns the returned object and should call cairo::pattern_destroy when finished with it.
fn create_linear
fn create_linear(x0: f64, y0: f64, x1: f64, y1: f64) (*cairo::pattern_t | cairo::error);
Creates a new linear gradient cairo::pattern_t along the line defined by (x0, y0) and (x1, y1). Before using the gradient pattern, a number of color stops should be defined using cairo::pattern::add_color_stop_rgb or cairo::pattern::add_color_stop_rgba.
Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with cairo::pattern::set_matrix.
Parameters
- x0: x coordinate of the start point
- y0: y coordinate of the start point
- x1: x coordinate of the end point
- y1: y coordinate of the end point
Returns the newly created cairo::pattern_t if successful, or an cairo::error in case of no memory. The caller owns the returned object and should call cairo::pattern_destroy when finished with it.
fn create_mesh
fn create_mesh() *cairo::pattern_t;
XXX: Creates a new mesh pattern.
fn create_radial
fn create_radial(cx0: f64, cy0: f64, radius0: f64, cx1: f64, cy1: f64, radius1: f64) (*cairo::pattern_t | cairo::error);
Creates a new radial gradient cairo::pattern_t between the two circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). Before using the gradient pattern, a number of color stops should be defined using cairo::pattern::add_color_stop_rgb or cairo::pattern::add_color_stop_rgba.
Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with cairo::pattern::set_matrix.
Parameters
- cx0: x coordinate for the center of the start circle
- cy0: y coordinate for the center of the start circle
- radius0: radius of the start circle
- cx1: x coordinate for the center of the end circle
- cy1: y coordinate for the center of the end circle
- radius1: radius of the end circle
Returns the newly created cairo::pattern_t if successful, or an cairo::error in case of no memory. The caller owns the returned object and should call cairo::pattern_destroy when finished with it.
fn create_rgb
fn create_rgb(red: f64, green: f64, blue: f64) (*cairo::pattern_t | cairo::error);
Creates a new cairo::pattern_t corresponding to an opaque color. The color components are floating point numbers in the range 0.0 to 1.0. If the values passed in are outside that range, they will be clamped.
Parameters
- red: red component of the color
- green: green component of the color
- blue: blue component of the color
Returns the newly created cairo::pattern_t if successful, or an cairo::error in case of no memory. The caller owns the returned object and should call cairo::pattern_destroy when finished with it.
fn create_rgba
fn create_rgba(red: f64, green: f64, blue: f64, alpha: f64) (*cairo::pattern_t | cairo::error);
Creates a new cairo::pattern_t corresponding to a translucent color. The color components are floating point numbers in the range 0.0 to 1.0 If the values passed in are outside that range, they will be clamped.
Parameters
- red: red component of the color
- green: green component of the color
- blue: blue component of the color
- alpha: alpha component of the color
Returns the newly created cairo::pattern_t if successful, or an cairo::error in case of no memory. The caller owns the returned object and should call cairo::pattern_destroy when finished with it.
fn destroy
fn destroy(pattern: *cairo::pattern_t) void;
Decreases the reference count on pattern by one. If the result is zero, then pattern and all associated resources are freed. See cairo::pattern::reference.
fn get_color_stop_count
fn get_color_stop_count(pattern: *cairo::pattern_t, count: *int) cairo::status_t;
XXX: HAREFY Gets the number of color stops specified in the given gradient pattern.
Parameters
- pattern: a cairo::pattern_t
- count: return value for the number of color stops, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_PATTERN_TYPE_MISMATCH if pattern is not a gradient pattern.
fn get_color_stop_rgba
fn get_color_stop_rgba(pattern: *cairo::pattern_t, index: int, offset_: *f64, red: *f64, green: *f64, blue: *f64, alpha: *f64) cairo::status_t;
XXX: HAREFY Gets the color and offset information at the given index for a gradient pattern. Values of index range from 0 to n-1 where n is the number returned by cairo::pattern::get_color_stop_count.
Parameters
- pattern: a cairo::pattern_t
- index: index of the stop to return data for
- offset: return value for the offset of the stop, or NULL
- red: return value for red component of color, or NULL
- green: return value for green component of color, or NULL
- blue: return value for blue component of color, or NULL
- alpha: return value for alpha component of color, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_INVALID_INDEX if index is not valid for the given pattern. If the pattern is not a gradient pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH is returned.
fn get_extend
fn get_extend(pattern: *cairo::pattern_t) cairo::extend_t;
Gets the current extend mode for a pattern. See cairo::extend_t for details on the semantics of each extend strategy.
fn get_filter
fn get_filter(pattern: *cairo::pattern_t) cairo::filter_t;
Gets the current filter for a pattern. See cairo::filter_t for details on each filter.
fn get_linear_points
fn get_linear_points(pattern: *cairo::pattern_t, x0: *f64, y0: *f64, x1: *f64, y1: *f64) cairo::status_t;
XXX: HAREFY Gets the gradient endpoints for a linear gradient.
Parameters
- pattern: a cairo::pattern_t
- x0: return value for the x coordinate of the first point, or NULL
- y0: return value for the y coordinate of the first point, or NULL
- x1: return value for the x coordinate of the second point, or NULL
- y1: return value for the y coordinate of the second point, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_PATTERN_TYPE_MISMATCH if pattern is not a linear gradient pattern.
fn get_matrix
fn get_matrix(pattern: *cairo::pattern_t, matrix: *cairo::matrix_t) void;
XXX: HAREFY Stores the pattern's transformation matrix into matrix.
fn get_radial_circles
fn get_radial_circles(pattern: *cairo::pattern_t, x0: *f64, y0: *f64, r0: *f64, x1: *f64, y1: *f64, r1: *f64) cairo::status_t;
XXX: HAREFY Gets the gradient endpoint circles for a radial gradient, each specified as a center coordinate and a radius.
Parameters
- pattern: a cairo::pattern_t
- x0: return value for the x coordinate of the center of the first circle, or NULL
- y0: return value for the y coordinate of the center of the first circle, or NULL
- r0: return value for the radius of the first circle, or NULL
- x1: return value for the x coordinate of the center of the second circle, or NULL
- y1: return value for the y coordinate of the center of the second circle, or NULL
- r1: return value for the radius of the second circle, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_PATTERN_TYPE_MISMATCH if pattern is not a radial gradient pattern.
fn get_reference_count
fn get_reference_count(pattern: *cairo::pattern_t) uint;
Returns the current reference count of pattern. If the object is a nil object, 0 will be returned.
fn get_rgba
fn get_rgba(pattern: *cairo::pattern_t, red: *f64, green: *f64, blue: *f64, alpha: *f64) cairo::status_t;
XXX: HAREFY Gets the solid color for a solid color pattern.
Parameters
- pattern: a cairo::pattern_t
- red: return value for red component of color, or NULL
- green: return value for green component of color, or NULL
- blue: return value for blue component of color, or NULL
- alpha: return value for alpha component of color, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a solid color pattern.
fn get_surface
fn get_surface(pattern: *cairo::pattern_t, surface: *cairo::surface_t) cairo::status_t;
XXX: HAREFY Gets the surface of a surface pattern. The reference returned in surface is owned by the pattern; the caller should call cairo::surface::reference if the surface is to be retained.
Parameters
- pattern: a cairo::pattern_t
- surface: return value for surface of pattern, or NULL
Returns CAIRO_STATUS_SUCCESS, or CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a surface pattern.
fn get_type
fn get_type(pattern: *cairo::pattern_t) cairo::pattern_type_t;
Get the pattern's type. See cairo::pattern_type_t for available types.
fn reference
fn reference(pattern: *cairo::pattern_t) *cairo::pattern_t;
Increases the reference count on pattern by one. This prevents pattern from being destroyed until a matching call to cairo::pattern::destroy is made.
Use cairo::pattern::get_reference_count to get the number of references to a cairo::pattern_t.
Returns the referenced cairo::pattern_t.
fn set_extend
fn set_extend(pattern: *cairo::pattern_t, extend: cairo::extend_t) void;
Sets the mode to be used for drawing outside the area of a pattern. See cairo::extend_t for details on the semantics of each extend strategy.
The default extend mode is cairo::extend_t::NONE for surface patterns and cairo::extend_t::PAD for gradient patterns.
fn set_filter
fn set_filter(pattern: *cairo::pattern_t, filter: cairo::filter_t) void;
Sets the filter to be used for resizing when using this pattern. See cairo::filter_t for details on each filter.
Note that you might want to control filtering even when you do not have an explicit cairo::pattern_t object, (for example when using cairo::set_source_surface). In these cases, it is convenient to use cairo::get_source to get access to the pattern that cairo creates implicitly. For example:
cairo::set_source_surface(cr, image, x, y); cairo::pattern::set_filter(cairo::get_source(cr), cairo::filter_t::NEAREST);
fn set_matrix
fn set_matrix(pattern: *cairo::pattern_t, matrix: *const cairo::matrix_t) void;
XXX: HAREFY Sets the pattern's transformation matrix to matrix. This matrix is a transformation from user space to pattern space.
When a pattern is first created it always has the identity matrix for its transformation matrix, which means that pattern space is initially identical to user space.
Important: Please note that the direction of this transformation matrix is from user space to pattern space. This means that if you imagine the flow from a pattern to user space (and on to device space), then coordinates in that flow will be transformed by the inverse of the pattern matrix.
For example, if you want to make a pattern appear twice as large as it does by default the correct code to use is:
cairo::matrix::init_scale(&matrix, 0.5, 0.5); cairo::pattern::set_matrix(pattern, &matrix);
Meanwhile, using values of 2.0 rather than 0.5 in the code above would cause the pattern to appear at half of its default size.
Also, please note the discussion of the user-space locking semantics of cairo::set_source.
fn status
fn status(pattern: *cairo::pattern_t) cairo::status_t;
Checks whether an error has previously occurred for this pattern.