Re-drawing GtkDrawingArea surface on motion-notify-event



Hi everyone,
I'd like to write very simple application for drawing lines.
 1) User press button - app saves x and y coordinates
 2) User moves the mouse - app dynamically draws potential line on each
mouse move event
 3) User releases button - app "saves" the line on the canvas.

I've tried to modify slightly the GTK example drawing application [1].
 1) On button press event I paint the current state to the "base_surface"
surface.
 2) On each mouse move I paint to the "tmp_surface" surface "base_surface"
and after that the actual line, so I avoid multiple lines on mouse move.
 3) On mouse release event I paint "tmp_surface" surface to "base_surface".

This works, and full code can be found on my gist [2]. However, I don't
think it's the right approach, since I have to re-paint a whole image for
each mouse-move, and latter on, on "draw" event application is doing almost
the same, so I'm doing the re-paint twice per each mouse move. I'm afraid
that for huge surfaces it might be very inefficient.

Do you know what would be the right approach to solve this sort of problems?

Thank you for help,
Marcin

[1] https://developer.gnome.org/gtk3/stable/ch01s05.html
[2] https://gist.github.com/loganek/156b6b9ce2333fd7d389f74c093a92b4


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