Display the node's coordinates while moving it.
authorladanyi
Fri, 26 Aug 2005 12:37:34 +0000
changeset 16526eb2f0f3bab9
parent 1651 e40c41eae31f
child 1653 9955e7ec7e89
Display the node's coordinates while moving it.
gui/graph_displayer_canvas-event.cc
     1.1 --- a/gui/graph_displayer_canvas-event.cc	Fri Aug 26 11:37:41 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas-event.cc	Fri Aug 26 12:37:34 2005 +0000
     1.3 @@ -86,6 +86,7 @@
     1.4  
     1.5  bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
     1.6  {
     1.7 +  static Gnome::Canvas::Text *coord_text = 0;
     1.8    switch(e->type)
     1.9    {
    1.10      case GDK_BUTTON_PRESS:
    1.11 @@ -112,6 +113,11 @@
    1.12  	}
    1.13        break;
    1.14      case GDK_BUTTON_RELEASE:
    1.15 +      if (coord_text)
    1.16 +      {
    1.17 +        delete coord_text;
    1.18 +        coord_text = 0;
    1.19 +      }
    1.20        isbutton=0;
    1.21        active_item=NULL;
    1.22        active_node=INVALID;
    1.23 @@ -121,7 +127,7 @@
    1.24        if(active_node!=INVALID)
    1.25        {
    1.26          mapstorage.modified = true;
    1.27 -        mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
    1.28 +
    1.29  	//new coordinates will be the old values,
    1.30  	//because the item will be moved to the
    1.31  	//new coordinate therefore the new movement
    1.32 @@ -138,10 +144,42 @@
    1.33          active_item->move(dx, dy);
    1.34  	nodetextmap[active_node]->move(dx, dy);
    1.35  
    1.36 +        // the new coordinates of the centre of the node 
    1.37 +        double coord_x = new_x - (clicked_x - mapstorage.coords[active_node].x);
    1.38 +        double coord_y = new_y - (clicked_y - mapstorage.coords[active_node].y);
    1.39 +
    1.40          clicked_x=new_x;
    1.41          clicked_y=new_y;
    1.42  
    1.43 +        // write back the new coordinates to the coords map
    1.44 +        mapstorage.coords.set(active_node, xy<double>(coord_x, coord_y));
    1.45  
    1.46 +        // reposition the coordinates text
    1.47 +        std::ostringstream ostr;
    1.48 +        ostr << "(" <<
    1.49 +          mapstorage.coords[active_node].x << ", " <<
    1.50 +          mapstorage.coords[active_node].y << ")";
    1.51 +        if (coord_text)
    1.52 +        {
    1.53 +          coord_text->property_text().set_value(ostr.str());
    1.54 +          coord_text->property_x().set_value(mapstorage.coords[active_node].x +
    1.55 +              node_property_defaults[N_RADIUS] + 40);
    1.56 +          coord_text->property_y().set_value(mapstorage.coords[active_node].y +
    1.57 +              node_property_defaults[N_RADIUS] - 40);
    1.58 +        }
    1.59 +        else
    1.60 +        {
    1.61 +          coord_text = new Gnome::Canvas::Text(
    1.62 +              displayed_graph,
    1.63 +              mapstorage.coords[active_node].x +
    1.64 +              node_property_defaults[N_RADIUS] + 40,
    1.65 +              mapstorage.coords[active_node].y +
    1.66 +              node_property_defaults[N_RADIUS] - 40,
    1.67 +              ostr.str());
    1.68 +          coord_text->property_fill_color().set_value("black");
    1.69 +        }
    1.70 +
    1.71 +	//all the edges connected to the moved point has to be redrawn
    1.72          for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
    1.73          {
    1.74              Gnome::Canvas::Points coos;