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



On 16 May 2018 at 18:22, Compro Prasad <comproprasad gmail com> wrote:
On Wed, May 16, 2018 at 10:47 PM, Daniel Boles <dboles src gmail com> 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.



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