Re: Re-drawing GtkDrawingArea surface on motion-notify-event
- From: rbd <rbd soest hawaii edu>
- To: gtk-app-devel-list gnome org, marcin kolny gmail com
- Subject: Re: Re-drawing GtkDrawingArea surface on motion-notify-event
- Date: Mon, 20 Mar 2017 14:51:23 -1000 (HST)
Hello Marcin,
I have written a number of gtk3 apps that perform the type of rubberband
line drawing you have described. Although I was originally porting apps
from an Xlib drawing environment where XOR was available to do
lightning-fast 'undraws' of existing line segments and was skeptical of
Cairo performance possibilities due to its lack of an XOR drawing op, I
was very pleasantly surprised by its rendering speed (as Eric noted). In
one of my apps, for instance, on a 2009 Macbook Pro laptop I can drag a
wireframe with a dozen line segments around on a full-screen background
field with only barely noticeable lag.
My suggestion to you would be to do the very easiest thing first and see
if performance is acceptable -- if not, then do as Dov suggested and try
redrawing only the smallest rectangle that encloses your line segment. You
could also try using Cairo's clipping path, although I have no experience
with that performance-wise.
Roger Davis
Univ. of Hawaii
From: Marcin Kolny <marcin kolny gmail com>
To: gtk-app-devel-list gnome org
Subject: Re-drawing GtkDrawingArea surface on motion-notify-event
Message-ID:
<CAHVGj5HM4=AGi2Yqn_7TkYYfMtbipwq5ig9oCSRMMuQtV6bgWw mail gmail com>
Content-Type: text/plain; charset=UTF-8
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]