COIN-OR::LEMON - Graph Library

Changeset 1652:6eb2f0f3bab9 in lemon-0.x


Ignore:
Timestamp:
08/26/05 14:37:34 (19 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2165
Message:

Display the node's coordinates while moving it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas-event.cc

    r1651 r1652  
    8787bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
    8888{
     89  static Gnome::Canvas::Text *coord_text = 0;
    8990  switch(e->type)
    9091  {
     
    113114      break;
    114115    case GDK_BUTTON_RELEASE:
     116      if (coord_text)
     117      {
     118        delete coord_text;
     119        coord_text = 0;
     120      }
    115121      isbutton=0;
    116122      active_item=NULL;
     
    122128      {
    123129        mapstorage.modified = true;
    124         mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
     130
    125131        //new coordinates will be the old values,
    126132        //because the item will be moved to the
     
    139145        nodetextmap[active_node]->move(dx, dy);
    140146
     147        // the new coordinates of the centre of the node
     148        double coord_x = new_x - (clicked_x - mapstorage.coords[active_node].x);
     149        double coord_y = new_y - (clicked_y - mapstorage.coords[active_node].y);
     150
    141151        clicked_x=new_x;
    142152        clicked_y=new_y;
    143153
    144 
     154        // write back the new coordinates to the coords map
     155        mapstorage.coords.set(active_node, xy<double>(coord_x, coord_y));
     156
     157        // reposition the coordinates text
     158        std::ostringstream ostr;
     159        ostr << "(" <<
     160          mapstorage.coords[active_node].x << ", " <<
     161          mapstorage.coords[active_node].y << ")";
     162        if (coord_text)
     163        {
     164          coord_text->property_text().set_value(ostr.str());
     165          coord_text->property_x().set_value(mapstorage.coords[active_node].x +
     166              node_property_defaults[N_RADIUS] + 40);
     167          coord_text->property_y().set_value(mapstorage.coords[active_node].y +
     168              node_property_defaults[N_RADIUS] - 40);
     169        }
     170        else
     171        {
     172          coord_text = new Gnome::Canvas::Text(
     173              displayed_graph,
     174              mapstorage.coords[active_node].x +
     175              node_property_defaults[N_RADIUS] + 40,
     176              mapstorage.coords[active_node].y +
     177              node_property_defaults[N_RADIUS] - 40,
     178              ostr.str());
     179          coord_text->property_fill_color().set_value("black");
     180        }
     181
     182        //all the edges connected to the moved point has to be redrawn
    145183        for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
    146184        {
Note: See TracChangeset for help on using the changeset viewer.