Re: drawing GtkDrawingArea surface on motion-notify-event




Hi Marcin,

One approach is to use a GtkOverlay. Draw the shape on the top and then save the coordinates of the shape if 
it is what you want. Then you can draw the saved shapes on the lower drawing area. 

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/draw_rectangle1.c

Cairo is pretty fast drawing. It take quite a bit to slow it down. 

Eric
 

 

 

-----Original Message-----
From: Marcin Kolny <marcin kolny gmail com>
To: gtk-app-devel-list <gtk-app-devel-list gnome org>
Sent: Mon, Mar 20, 2017 1:25 pm
Subject: 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
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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