Get width and height of a Cairo::Context

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Get width and height of a Cairo::Context

Compro Prasad
I have a function that is run when drawing in a Gtk::DrawingArea.
Signal:
paintarea.signal_draw().connect(sigc::ptr_fun(draw_thing));
draw_thing prototype:
int draw_thing(const Cairo::RefPtr<Cairo::Context> cr)
I want to get height and width of the drawing area. How can I obtain them?
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Get width and height of a Cairo::Context

Daniel Boles
I think all the DrawingArea tutorials I saw mentioned this, but anyway, you just get the width/height of the allocation, so

drawingArea.get_allocation() and then get_(width|height)() on that

or

drawingArea.get_allocated_(width|height)()


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Get width and height of a Cairo::Context

Daniel Boles
also, you should take the RefPtr by const& to avoid pointlessly incrementing and decrementing the refcount within the function


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Get width and height of a Cairo::Context

Compro Prasad
In reply to this post by Daniel Boles
On Wed, May 16, 2018 at 10:47 PM, Daniel Boles <[hidden email]> wrote:
> I think all the DrawingArea tutorials I saw mentioned this, but anyway, you
> just get the width/height of the allocation, so
>
> drawingArea.get_allocation() and then get_(width|height)() on that
That is IMO for drawing area and not cairo context. I want to get
width and hright
inside "draw_thing" function where I don't think drawing area is available.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Get width and height of a Cairo::Context

Daniel Boles
On 16 May 2018 at 18:22, Compro Prasad <[hidden email]> wrote:
On Wed, May 16, 2018 at 10:47 PM, Daniel Boles <[hidden email]> wrote:
> I think all the DrawingArea tutorials I saw mentioned this, but anyway, you
> just get the width/height of the allocation, so
>
> drawingArea.get_allocation() and then get_(width|height)() on that
That is IMO for drawing area and not cairo context. I want to get
width and hright
inside "draw_thing" function where I don't think drawing area is available.


So you just use a lambda or some bind() function to capture a reference to the DrawingArea in the handler, so it is available. My point is that you need to scale/draw within the allocation of the widget. The context itself doesn't really have any meaningful dimensions, on its own.

GTK+ always passes signal handlers the instance as 1st argument (unless connected swapped), but gtkmm doesn't, so capture/binding a reference to the instance while connecting the handler is standard practice.

That, or you connect ::draw to an instance method of some containing class, which also contains the DrawingArea as a member, and thus binds it that way.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list