lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hello Hakki,

Thanks for your answer, and for your bindings !

The way I've done it in python, with pyCairo is like that :

    for type, points in ctx.copy_path():
        if type == cairo.PATH_MOVE_TO:
            if first:
                first = False
            x, y = function(*points)
            ctx.move_to(x, y)

        elif type == cairo.PATH_LINE_TO:
            x, y = function(*points)
            ctx.line_to(x, y)

        elif type == cairo.PATH_CURVE_TO:
            x1, y1, x2, y2, x3, y3 = points
            x1, y1 = function(x1, y1)
            x2, y2 = function(x2, y2)
            x3, y3 = function(x3, y3)
            ctx.curve_to(x1, y1, x2, y2, x3, y3)

        elif type == cairo.PATH_CLOSE_PATH:

It's inspired from this file :

For the previous script, it doesn't work! I think it's because I run it from conky (not with the lua command),so maybe some implementations are missing in conky.

I've got errors at this line (attempt to index global 'cairo' (a nil value)) :
local headertype = cairo.path_data_header_type(path, i)

or with this
local headertype = cairo_path_data_header_type(path, i)

And the beginnig of the script is  :
local i = 0
local numdata = path.num_data

while i < numdata do
    -- data = "">    local headertype = cairo_path_data_header_type(path, i)

As I said, I run it from conky so the problem can be here . I will try to run it directly with lua next week!
thanks again!

De : Hakki Dogusan <>
À :
Envoyé le : Mer 20 octobre 2010, 9h 57min 13s
Objet : Re: loop through cairo_path_data_t


(Small modification in previous example)

20/10/2010 10:37, Hakki Dogusan wrote:
> Hi,
> [snip]
> Will something like as follows work for you?
> -------------------------------------------------------------------------

-- cairo_path_t *path;
-- cairo_path_data_t *data;

local path = cairo.copy_path (cr);

local i = 0
local numdata = cairo.path_num_data(path)

while i < numdata do
    -- data = "">    local headertype = cairo.path_data_header_type(path, i)

    if headertype == CAIRO.PATH_MOVE_TO then

        local x,y = cairo.path_data_point(path, i, 1)

        do_move_to_things (x, y);

    elseif headertype == CAIRO.PATH_LINE_TO then

        local x,y = cairo.path_data_point(path, i, 1)

        do_line_to_things (x, y);

    elseif headertype == CAIRO.PATH_CURVE_TO then

        local x1,y1 = cairo.path_data_point(path, i, 1)
        local x2,y2 = cairo.path_data_point(path, i, 2)
        local x3,y3 = cairo.path_data_point(path, i, 3)

        do_curve_to_things (x1, y1, x2, y2, x3, y3);

    elseif headertype == CAIRO.PATH_CLOSE_PATH then

        do_close_path_things ();


    local headerlength = cairo.path_data_header_length(path, i)
    i = i + headerlength

cairo.path_destroy (path);

> -------------------------------------------------------------------------

Hakki Dogusan