Gtkmm draw line with mouse events



I wish to draw a line using mouseevents on Gtk::DrawableArea. What I
want is something like:

#1: Click on Line Button to activate line event
#2: Select first point(already drawn) in the drawingarea
#3: Now Select second point(again already drawn) in the drawingarea
#4: line should be drawn between two points

What I already have:

#1: Gtk::DrawingArea
#2: 2 points(manual circles) drawn using cairo, needed to create the line

The follwing is my constructor that calls the on_draw function.

 drawingArea:: drawingArea()
 {
    signal_draw().connect(sigc::mem_fun(*this, &drawingArea::on_draw), false);
 }

And the on_draw function draws the background:

bool drawingArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
    cr->set_source_rgb(1.0, 1.0, 1.0);   // white background
    cr->paint();

    cr->save();
    cr->arc(10.0, 10.0, 1.0, 0.0, 2 * M_PI); // full circle
    cr->set_source_rgba(0.0, 0.0, 0.8, 0.6); // partially translucent
    cr->fill_preserve();
    cr->restore();
    cr->stroke();

    return true;
}

Any guidance how to achieve that?

-- 
Gurjot Singh
Blog: http://bhattigurjot.wordpress.com

"It takes a person who is wide awake to make his dream come true." ~
Roger Babson


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