Module cairo_helpers

Cairo helper functions

Functions

create_cr(conky_window) Get a new drawing context for the given conky window.
polygon(cr, coordinates) Draw a polygon with the given vertices.
show_point(cr, x, y[, size=4[, r=1[, g=0[, b=0[, a=0.7]]]]]) Draw a little cross where a given point is.
alpha_gradient(cr, x1, y1, x2, y2, r, g, b, stops) Set a single color gradient with varying opacity on the given cairo drawing context.
alpha_gradient_radial(cr, x1, y1, inner_radius, x2, y2, outer_radius, r, g, b, stops) Set a radial single color gradient with varying opacity on the given cairo drawing context.
set_font(cr, font_family, font_size[, font_slant[, font_weight]]) Select font settings for given cairo drawing context
font_extents(font_family, font_size[, font_slant[, font_weight]]) Get cairo_font_extents_t for a given font with size.
write_left(cr, x, y, text) Write text left-aligned (to the right of given x).
write_right(cr, x, y, text) Write text right-aligned (to the left of given x).
write_centered(cr, mx, y, text) Write text centered (spread evenly towards both sides of mx).
write_middle(cr, mx, my, text) Write text centered horizontally and vertically on the given point mx, my.

Local Functions

text_extents(cr, text) Get cairo_text_extents_t for given text on given cairo drawing surface with its currently set font.
round_coords(cr, x, y) Round coordinates to even pixel values See https://www.cairographics.org/FAQ/#sharp_lines See https://scriptinghelpers.org/questions/4850/how-do-i-round-numbers-in-lua-answered


Functions

create_cr(conky_window)
Get a new drawing context for the given conky window. Be sure to call cairo_destroy(cr) when you're done.

Parameters:

  • conky_window global conky_window

Returns:

    cairo_t
polygon(cr, coordinates)
Draw a polygon with the given vertices.

Parameters:

  • cr cairo_t
  • coordinates {number,...} of vertices (x1, y1, x2, y2, ...)
show_point(cr, x, y[, size=4[, r=1[, g=0[, b=0[, a=0.7]]]]])
Draw a little cross where a given point is. Useful for debugging. By default the cross is red.

Parameters:

  • cr cairo_t
  • x number x coordinate of point
  • y number y coordinate of point
  • size number line length of cross (default 4)
  • r number red color component (default 1)
  • g number green color component (default 0)
  • b number blue color component (default 0)
  • a number alpha color compnent (transparency) (default 0.7)
alpha_gradient(cr, x1, y1, x2, y2, r, g, b, stops)
Set a single color gradient with varying opacity on the given cairo drawing context.

Parameters:

  • cr cairo_t
  • x1 number x coordinate of gradient start
  • y1 number y coordinate of gradient start
  • x2 number x coordinate of gradient end
  • y2 number y coordinate of gradient end
  • r number red color component
  • g number green color component
  • b number blue color component
  • stops {number,...} list of offset & alpha value pairs offset between 0 and 1 describes position in the gradient alpha between 0 and 1 describes opacity at given offset. Note: For high/low alpha values the brightness may be emphasized by color variation.
alpha_gradient_radial(cr, x1, y1, inner_radius, x2, y2, outer_radius, r, g, b, stops)
Set a radial single color gradient with varying opacity on the given cairo drawing context.

Parameters:

  • cr cairo_t
  • x1 number x coordinate of inner circle center point
  • y1 number y coordinate of inner circle center point
  • inner_radius number
  • x2 number x coordinate of outer circle center point
  • y2 number y coordinate of outer circle center point
  • outer_radius number
  • r number red color component
  • g number green color component
  • b number blue color component
  • stops {number,...} list of offset & alpha value pairs offset between 0 and 1 describes position in the gradient alpha between 0 and 1 describes opacity at given offset. Note: For high/low alpha values the brightness may be emphasized by color variation.
set_font(cr, font_family, font_size[, font_slant[, font_weight]])
Select font settings for given cairo drawing context

Parameters:

  • cr cairo_t
  • font_family string
  • font_size int
  • font_slant optional cairo_font_slant_t (default: CAIRO_FONT_SLANT_NORMAL) (optional)
  • font_weight optional cairo_font_weight_t (default: CAIRO_FONT_WEIGHT_NORMAL) (optional)
font_extents(font_family, font_size[, font_slant[, font_weight]])
Get cairo_font_extents_t for a given font with size. Use this, for example, to determine line-height. see https://cairographics.org/manual/cairo-cairo-scaled-font-t.html#cairo-font-extents-t

Parameters:

  • font_family string
  • font_size int
  • font_slant optional cairo_font_slant_t (default: CAIRO_FONT_SLANT_NORMAL) (optional)
  • font_weight optional cairo_font_weight_t (default: CAIRO_FONT_WEIGHT_NORMAL) (optional)

Returns:

    cairo_font_extents_t
write_left(cr, x, y, text)
Write text left-aligned (to the right of given x).

Parameters:

  • cr cairo_t
  • x number start of the written text
  • y number coordinate of the baseline on top of which the text will be written
  • text string
write_right(cr, x, y, text)
Write text right-aligned (to the left of given x).

Parameters:

  • cr cairo_t
  • x number end of the written text
  • y number coordinate of the baseline on top of which the text will be written
  • text string
write_centered(cr, mx, y, text)
Write text centered (spread evenly towards both sides of mx).

Parameters:

  • cr cairo_t
  • mx number horizontal center of the written text
  • y number coordinate of the baseline on top of which the text will be written
  • text string
write_middle(cr, mx, my, text)
Write text centered horizontally and vertically on the given point mx, my.

Parameters:

  • cr cairo_t
  • mx number horizontal center of the written text
  • my number vertical center of the written text
  • text string

Local Functions

text_extents(cr, text)
Get cairo_text_extents_t for given text on given cairo drawing surface with its currently set font. See https://cairographics.org/manual/cairo-cairo-scaled-font-t.html#cairo-text-extents-t

Parameters:

  • cr cairo_t
  • text string

Returns:

    cairo_text_extents_t
round_coords(cr, x, y)
Round coordinates to even pixel values See https://www.cairographics.org/FAQ/#sharp_lines See https://scriptinghelpers.org/questions/4850/how-do-i-round-numbers-in-lua-answered

Parameters:

  • cr cairo_t
  • x number horizontal pixel coord value
  • y number vertical pixel coord value
generated by LDoc 1.4.6 Last updated 2023-03-26 23:57:51