Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-26 Thread Marcin Kolny
Thanks everyone,
I'll try all the suggested solutions and pick best that works for me.

2017-03-21 11:20 GMT+00:00 Joël Krähemann :

> Hi
>
> If you do it using cairo you might be interested in the following function.
>
> cairo_image_surface_get_data()
>
> You get the pixels stored in your picture. It can be restored using
> memcpy()
> what is actually quiet fast.
>
> Bests,
> Joël
>
>
> On Tue, Mar 21, 2017 at 8:26 AM, F.Reiter 
> wrote:
> > Hallo,
> > for lightning-fast, xor, rubberbanding, zooming, clipping ..
> > why not consider Open-GL ?
> > Franz
> > (https://github.com/gcad3d/gcad3d)
> >
> > ___
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>



-- 
Pozdrawiam
Marcin Kolny
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-22 Thread Stefan Salewski
On Sun, 2017-03-19 at 22:12 +, Marcin Kolny wrote:
> I'd like to write very simple application for drawing lines.

You can restrict all drawing operations to a rectangle enclosing your
line. For each move with button pressed, fill that rectangle with
background color and then draw the line with foreground color. Or, you
may save the old line start and end points and paint that old line with
background color before drawing the new line. I think there is not much
benefit for using an temporary surface for this use case.

For more complicated graphics it can become a bit slow indeed -- I once
tried it for my schematics editor -- there I used a bounding box for
all the graphical elements, when one element is moved, I had to draw
its background and then all other elements overlapping with that
background element. Using OpenGl may be faster and easier, because you
can fast just redraw all. I think GTK3 now has a gl-area widget. The
problem with Gl is that it is basically more for drawing triangles than
for drawing lines... 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-22 Thread Marcin Kolny
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


Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-21 Thread Joël Krähemann
Hi

If you do it using cairo you might be interested in the following function.

cairo_image_surface_get_data()

You get the pixels stored in your picture. It can be restored using memcpy()
what is actually quiet fast.

Bests,
Joël


On Tue, Mar 21, 2017 at 8:26 AM, F.Reiter  wrote:
> Hallo,
> for lightning-fast, xor, rubberbanding, zooming, clipping ..
> why not consider Open-GL ?
> Franz
> (https://github.com/gcad3d/gcad3d)
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-21 Thread F.Reiter
Hallo,
for lightning-fast, xor, rubberbanding, zooming, clipping .. 
why not consider Open-GL ?
Franz
(https://github.com/gcad3d/gcad3d)

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-20 Thread rbd


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.ko...@gmail.com>
To: gtk-app-devel-list@gnome.org
Subject: Re-drawing GtkDrawingArea surface on motion-notify-event
Message-ID:

Re: drawing GtkDrawingArea surface on motion-notify-event

2017-03-20 Thread Eric Cashon via gtk-app-devel-list

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.ko...@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

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-20 Thread Dov Grobgeld
The key is to not draw directly, but to invalidate one or more rectangles
needed to for changing the image from the old to the new one.

I worked on this problem some years ago and I think my solution is very
relevant to your question.

See the gtk3 branch at: https://github.com/dov/dovtk-lasso .

Regards,
Dov

On Mon, Mar 20, 2017 at 9:25 PM, Marcin Kolny 
wrote:

> 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
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re-drawing GtkDrawingArea surface on motion-notify-event

2017-03-20 Thread Marcin Kolny
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