Re: Drawing a line



>    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=20
>    later.  It can be saw on many graphics software.
>
>    With Gtkmm, how do I do it?  Thanks for your help.

First things first, please do not send HTML-formatted email to mailing
lists. EVER.

Secondly, as a rough hint at how to do this:

	  Gtk::DrawingArea foo;

	  foo.on_expose_event.connect (bind (slot (expose_handler), &foo));
	  foo.on_button_press_event.connect (bind (slot (press_handler), &foo));
	  
	  gint press_handler (GdkEventButton* ev, Gtk::DrawingArea* foo)
	  {
	       ... change your own data structures ....

	       /* ask for an expose event */
	       foo->queue_draw ();
          }

	  gint expose_handler (GtkEventExpose* ev, Gtk::DrawingArea* foo) 
	  {
	        ... compute line coordinates from your own data structures ...

		/* now draw it */
		foo->get_window().draw_line (...);
		return true;
          }

there are more C++-ish ways to do this, but thats a basic guide to the
salient points.

--p



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