COIN-OR::LEMON - Graph Library

Changeset 187:b465e2c34f23 in glemon-0.x


Ignore:
Timestamp:
02/02/07 11:13:33 (13 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3150
Message:

Zoom is now available with mouse-wheel.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r179 r187  
    9494{
    9595  return actual_tool;
     96}
     97
     98bool GraphDisplayerCanvas::scrollEventHandler(GdkEvent* e)
     99{
     100  bool handled=false;
     101  if(e->type==GDK_SCROLL)
     102    {
     103
     104      //pointer shows this win point before zoom
     105      XY win_coord(((GdkEventScroll*)e)->x, ((GdkEventScroll*)e)->y);
     106
     107      //the original scroll settings
     108      int scroll_offset_x, scroll_offset_y;
     109      get_scroll_offsets(scroll_offset_x, scroll_offset_y);
     110
     111      //pointer shows this canvas point before zoom
     112      XY canvas_coord;
     113      window_to_world(win_coord.x, win_coord.y, canvas_coord.x, canvas_coord.y);
     114
     115      if(((GdkEventScroll*)e)->direction) //IN
     116        {
     117          zoomIn();
     118        }
     119      else
     120        {
     121          zoomOut();
     122        }
     123
     124      //pointer shows this window point after zoom
     125      XY post_win_coord;
     126      world_to_window(canvas_coord.x, canvas_coord.y, post_win_coord.x, post_win_coord.y);
     127
     128      //we have to add the difference between new and old window point to original scroll offset
     129      scroll_to(scroll_offset_x+(int)(post_win_coord.x-win_coord.x),scroll_offset_y+(int)(post_win_coord.y-win_coord.y));
     130     
     131      //no other eventhandler is needed
     132      handled=true;
     133    }
     134  return handled;
    96135}
    97136
  • graph_displayer_canvas.cc

    r184 r187  
    2929  background_set(false)
    3030{
     31  //add mouse scroll event handler - it won't be changed, it handles zoom
     32  signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::scrollEventHandler), false);
     33
    3134  //base event handler is move tool
    3235  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    3336  actual_tool=MOVE;
     37
    3438
    3539  active_node=INVALID;
     
    320324void GraphDisplayerCanvas::reDesignGraph()
    321325{
     326  double max_coord=50000;
    322327  double min_dist=20;
    323328  double init_vector_length=25;
     
    402407      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    403408        {
     409          if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
     410            {
     411              actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
     412              std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
     413            }
     414          else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
     415            {
     416              actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
     417              std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
     418            }
     419          if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
     420            {
     421              actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
     422              std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
     423            }
     424          else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
     425            {
     426              actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
     427              std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
     428            }
    404429          moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
    405430        }
  • graph_displayer_canvas.h

    r184 r187  
    289289  ///event handler for the case when map editor tool is active
    290290  bool mapEditEventHandler(GdkEvent*);
     291  ///event handler for the case when user scrolls the mouse
     292  bool scrollEventHandler(GdkEvent*);
    291293
    292294private:
Note: See TracChangeset for help on using the changeset viewer.