coordinate system context for a drawing area uses (relative to get_allocation)

classic Classic list List threaded Threaded
3 messages Options
dan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

coordinate system context for a drawing area uses (relative to get_allocation)

dan
So it appears that when you draw in a drawing area, using commands
like (cairo_)move_to and (cairo_)line_to, the path is rendered
relative to the top left of the area.

More explicitly, if you try to figure out how far you can draw, the x
and y values from get_allocation(...) are not relevant, only the width
and height.

Or in other words, the location at the top left of the drawing area
has coordinates (0, 0) and at the bottom right has coordinates (width,
height), rather than (x, y) and (x+width, y+height), at least as far
as primitives like move_to and line_to are concerned.

This sure seems to be true on my system (debian stretch) using gtk3,
but if i'm wrong, please correct me.

Also, is this documented anywhere, or am i the only person clueless
enough to try to get to the top left by going to the x,y returned by
get_allocation, instead of to (0,0)?

dan
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: coordinate system context for a drawing area uses (relative to get_allocation)

Tadej Borovšak
On Sat, May 13, 2017 at 05:00:43PM -0700, Dan Hitt wrote:

> So it appears that when you draw in a drawing area, using commands
> like (cairo_)move_to and (cairo_)line_to, the path is rendered
> relative to the top left of the area.
>
> More explicitly, if you try to figure out how far you can draw, the x
> and y values from get_allocation(...) are not relevant, only the width
> and height.
>
> Or in other words, the location at the top left of the drawing area
> has coordinates (0, 0) and at the bottom right has coordinates (width,
> height), rather than (x, y) and (x+width, y+height), at least as far
> as primitives like move_to and line_to are concerned.
>
> This sure seems to be true on my system (debian stretch) using gtk3,
> but if i'm wrong, please correct me.

Yes, you are correct, things do work this way.

> Also, is this documented anywhere, or am i the only person clueless
> enough to try to get to the top left by going to the x,y returned by
> get_allocation, instead of to (0,0)?

This is documented in the draw signal docs [1].

Cheers,
Tadej


[1] https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw

--
Tadej Borovšak
[hidden email]
[hidden email]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
dan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: coordinate system context for a drawing area uses (relative to get_allocation)

dan
Thanks Tadej.

That's a very good reference.

(Also, thanks for creating a tutorial on using glade some years back,
which i found useful.)

dan

On Mon, May 15, 2017 at 12:25 AM, Tadej Borovšak <[hidden email]> wrote:

> On Sat, May 13, 2017 at 05:00:43PM -0700, Dan Hitt wrote:
>> So it appears that when you draw in a drawing area, using commands
>> like (cairo_)move_to and (cairo_)line_to, the path is rendered
>> relative to the top left of the area.
>>
>> More explicitly, if you try to figure out how far you can draw, the x
>> and y values from get_allocation(...) are not relevant, only the width
>> and height.
>>
>> Or in other words, the location at the top left of the drawing area
>> has coordinates (0, 0) and at the bottom right has coordinates (width,
>> height), rather than (x, y) and (x+width, y+height), at least as far
>> as primitives like move_to and line_to are concerned.
>>
>> This sure seems to be true on my system (debian stretch) using gtk3,
>> but if i'm wrong, please correct me.
>
> Yes, you are correct, things do work this way.
>
>> Also, is this documented anywhere, or am i the only person clueless
>> enough to try to get to the top left by going to the x,y returned by
>> get_allocation, instead of to (0,0)?
>
> This is documented in the draw signal docs [1].
>
> Cheers,
> Tadej
>
>
> [1] https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw
>
> --
> Tadej Borovšak
> [hidden email]
> [hidden email]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Loading...