Re: Drawing a line



On Wed, 22 Dec 2004 21:14:42 +0800, Victor Hsieh <victor csie org> wrote:
> Hi,
>     I want to connect a line between two points.  When the user click on
>     one point and start to move the cursor, there will be a line from
>     where the user clicked first to the cursor.  And there should be a
>     static line from that point to the position where the user click
>     later.  It can be saw on many graphics software.
> 
>     With Gtkmm, how do I do it?  Thanks for your help.
> 
> Best,
> Victor
> 

As far as Gtkmm's part in your program, I would use a DrawingArea. 
Check out http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch14.html.
 You will need to use the DrawingArea's add_events(Gdk::EventMask
events) method to have it detect mouse clicks.  Use
Gdk::BUTTON_PRESS_MASK and Gdk::BUTTON_RELEASE_MASK, for example:

add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);

See http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#a52
and
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/group__gdkmmEnums.html#ga97

Of course you'll also have to set up a signal handler for the button
pressed/released events, i.e. overriding
DrawingArea;:on_button_press_event(Gtk::EventButton *event)...

DrawingArea area;
area.signal_button_press_event().connect(sigc::mem_fun(*this,
&WhateverClassThisIs::on_button_press_event));

Look to the Gtkmm tutorial for more clarity on that.  As far as the
actual behavior you're looking for, well hopefully you can figure that
out since its more to do with your program logic than Gtkmm itself.

> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 
> 
> 
>



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