GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Dec 20, 2014 3:05 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Reccomendation for drawing movable lines
PostPosted: Mon Jan 16, 2012 8:36 pm 
Offline

Joined: Mon Jan 16, 2012 8:04 pm
Posts: 2
Hi,

I am a newbie with respect to GTK and I could not find an answer using Google.

Basically I am wondering if there is a recommended way of drawing lines that can be adjusted (dragged) by the user.

Use-Case:
- User opens an image which gets displayed in an GtkImage or GtkImageView (have not decided which yet)
- Then the user adds straight lines to the image.
so far no problem but when user needs to adjust a drawn line I currently need to reload the whole image and then redraw all the lines in the list (every line is in a list)

I am hoping there is a smarter way of handling this, e.g. in addition to the user drawn line also create a corresponding line that consists of the original image data which then can be used to redraw the line during the adjustment.
One note is that the user do not want the original image to be destroyed during the draw line operation. The drawn lines are only there to extract coordinates from the original image.

I program in C using gtk 2.20.1 (Ubuntu 10.04) if that matters.

thanks for reading.


Top
 Profile  
 
 Post subject: Re: Reccomendation for drawing movable lines
PostPosted: Mon Jan 16, 2012 11:14 pm 
Offline
Familiar Face

Joined: Mon Jan 16, 2012 9:26 pm
Posts: 5
Sorry, I'm not a big pro to give an advice, but maybe you could look towards Cairo library. I heard they achieve good results when using it for drawing in GTK+ programs in C.

http://cairographics.org/samples
http://zetcode.com/tutorials/cairographicstutorial/


Top
 Profile  
 
 Post subject: Re: Reccomendation for drawing movable lines
PostPosted: Tue Jan 17, 2012 8:04 pm 
Offline

Joined: Mon Jan 16, 2012 8:04 pm
Posts: 2
Thanks, I might end up using Cairo but do not see an advantage at this point.
I am only loading an image file into a buffer and then modifying the displayed image by using plain draw lines functions.
And I do think the same problem will appear using Cairo as well unless one can use several canvases on top of each other where the canvases for lines would be transparent except for lines... I'll have a look into this.


Top
 Profile  
 
 Post subject: Re: Reccomendation for drawing movable lines
PostPosted: Thu Jan 19, 2012 11:03 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums!

Have you thought about using real canvas to do this? You gain quite a lot by using something like GooCanvas (now lines are distinct objects that can be manipulated with ease).

Another option would be to simply draw all of the stuff manually using cairo on GtkDrawingArea. If done properly, this can be very efficient and powerful way of doing things, but you'll need to learn how to use cairo. And yes, cairo does support stuff like layers.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Reccomendation for drawing movable lines
PostPosted: Thu Jan 19, 2012 11:58 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Well GTK is the toolkit used by GIMP and GIMP already implements all the stuff that you want so if you're fine with licencing it under GPL you can just nick the code from them.
Learning how to program in Cairo is pretty straightforward and its the same kind of thing no matter what vector graphics you're doing (e.g. SVG format). The click drag move can be the difficult bit as you need to know a bit about the way signalling works and potentially how to create you're own widget. Either way there's tutorials out there on the GTK site which'll help along the way. but either way yes what you are trying to do is possible so you don't have to worry about learning a lot of stuff to only find out it's to no avail.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group