gui/graph_displayer_canvas-event.cc
changeset 1653 9955e7ec7e89
parent 1651 e40c41eae31f
child 1654 0917756ba533
equal deleted inserted replaced
25:e73ededfe3ff 26:dc21f95d51c6
    84   return actual_tool;
    84   return actual_tool;
    85 }
    85 }
    86 
    86 
    87 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
    87 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
    88 {
    88 {
       
    89   static Gnome::Canvas::Text *coord_text = 0;
    89   switch(e->type)
    90   switch(e->type)
    90   {
    91   {
    91     case GDK_BUTTON_PRESS:
    92     case GDK_BUTTON_PRESS:
    92       //we mark the location of the event to be able to calculate parameters of dragging
    93       //we mark the location of the event to be able to calculate parameters of dragging
    93       window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    94       window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   110 	  isbutton=1;
   111 	  isbutton=1;
   111 	  break;
   112 	  break;
   112 	}
   113 	}
   113       break;
   114       break;
   114     case GDK_BUTTON_RELEASE:
   115     case GDK_BUTTON_RELEASE:
       
   116       if (coord_text)
       
   117       {
       
   118         delete coord_text;
       
   119         coord_text = 0;
       
   120       }
   115       isbutton=0;
   121       isbutton=0;
   116       active_item=NULL;
   122       active_item=NULL;
   117       active_node=INVALID;
   123       active_node=INVALID;
   118       break;
   124       break;
   119     case GDK_MOTION_NOTIFY:
   125     case GDK_MOTION_NOTIFY:
   120       //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
   126       //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
   121       if(active_node!=INVALID)
   127       if(active_node!=INVALID)
   122       {
   128       {
   123         mapstorage.modified = true;
   129         mapstorage.modified = true;
   124         mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
   130 
   125 	//new coordinates will be the old values,
   131 	//new coordinates will be the old values,
   126 	//because the item will be moved to the
   132 	//because the item will be moved to the
   127 	//new coordinate therefore the new movement
   133 	//new coordinate therefore the new movement
   128 	//has to be calculated from here
   134 	//has to be calculated from here
   129 
   135 
   136 
   142 
   137 	//repositioning node and its text
   143 	//repositioning node and its text
   138         active_item->move(dx, dy);
   144         active_item->move(dx, dy);
   139 	nodetextmap[active_node]->move(dx, dy);
   145 	nodetextmap[active_node]->move(dx, dy);
   140 
   146 
       
   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 
   141         clicked_x=new_x;
   151         clicked_x=new_x;
   142         clicked_y=new_y;
   152         clicked_y=new_y;
   143 
   153 
   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
   145         for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
   183         for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
   146         {
   184         {
   147             Gnome::Canvas::Points coos;
   185             Gnome::Canvas::Points coos;
   148             double x1, x2, y1, y2;
   186             double x1, x2, y1, y2;
   149 
   187