Re: GTK+3 - A common event handler - possible?





On Wed, May 22, 2013 at 11:00 AM, Donn <donn ingle gmail com> wrote:
On 22/05/2013 09:29, Bernhard Schuster wrote:
In general factoring code is good (at least that's my opinion) - what
you are trying to do is the reverse and will give you one very big
function, hardly readable.

I take your very good point.

I really suggest you to go with seperate handlers. If you need cross
handler information, then you should create yourself a context object
and store desired information into that and obtain it from that, you can
simply pass the context object as the user_data gpointer.

I will attempt grokkage of this user_data thing. I've seen it in the C docs, but I'm newly into Vala, and it looks ... weird:
https://live.gnome.org/Vala/SignalsAndCallbacks (at end)


Never really got into vala, and I currently lack the time to give it a whirl.

Why do you want to disabel doublebuffering in the first case?

Two zones of reasons, both hopefully full of fail and new hope! :P

A:
As it seems now , in order to discover whether the cursor in inside a shape, I have to draw a path and use cr_in_fill(). This can only happen when I have a Cairo context! That only happens in the draw() signal handler!

If you compose your stuff of polygons (which I am pretty sure you do), there is pretty neat math to check if your cursor is in or outside of a polygon (for low vertex count polygons, for greater numbers you need to calculate a boundingbox that is fixed for at least a few frames). This actually detaches the position-checks from the drawing event. A somewhat-model-view approach.

Correct me if I misunderstod something.

There are a lot of approaches on how to actually get dirty regions (moved items + bounding boxes + tree walk). Also be aware that this whole thing also depends on your backend. If you got a decent ( OpenGL 2.1 or newer ) video card it is not really sane to calculate dirty regions and redraw them (especially if you got a lot of items floating/hanging around).

So, in order to simply discover this fact, I have to force a complete redraw (queue_draw()) and this then draws *all* my canvas objects again, from scratch. A very heavy burden for one mouse motion event.

(Add to this that the object which I am motioning over may be under several transforms. i.e. I have to transform several times before I get to draw that path in order to test in_fill)

B:
Also, I'm still struggling with the various options - I can draw every object from bottom to top, on every draw(). I can draw each object to a memory surface (cairo pattern) and then compose them all, back to front, every draw().

The thing is - *if* the canvas has *not* changed, *but* I have a tool or icon on the topmost layer that moves (I call it a sprite) by a few pixels, then it makes more sense to do a small blit of the old background and draw the sprite in a new position - rather than drawing all my canvas objects again just so I can draw the sprite in a new position.


That means you need to walk your tree, check all items bounding boxes and redraw all which intersect with the boundingbox of the item moved (in the old and new position, otherwise you'd get artifacts)

Thus, the double-buffering that blanks the canvas screws the pooch ;)


See first answer chunk.

In case that is not really important to you, you could have a look at
goocanvas..

I guess I'm just keen to see if I can do this (a canvas vector art zui draggy thing) on my own. I have the Goo source but it's just as confusing to me as the Inkscape source. Still, I do try.


Keep trying, there is always that "reading-foreign-code" barrier - at first it sometimes looks all gibberish :) . But goocanvas (as far as I can say from reading a few specific pieces of code) is pretty well documented, so it should not take too long until the first chunks start making sense - a good editor also helps.

Best
\B



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