[Lemon-commits] hegyi: r3150 - glemon/trunk

Lemon SVN svn at lemon.cs.elte.hu
Fri Feb 2 11:13:34 CET 2007


Author: hegyi
Date: Fri Feb  2 11:13:33 2007
New Revision: 3150

Modified:
   glemon/trunk/graph_displayer_canvas-event.cc
   glemon/trunk/graph_displayer_canvas.cc
   glemon/trunk/graph_displayer_canvas.h

Log:
Zoom is now available with mouse-wheel.

Modified: glemon/trunk/graph_displayer_canvas-event.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas-event.cc	(original)
+++ glemon/trunk/graph_displayer_canvas-event.cc	Fri Feb  2 11:13:33 2007
@@ -95,6 +95,45 @@
   return actual_tool;
 }
 
+bool GraphDisplayerCanvas::scrollEventHandler(GdkEvent* e)
+{
+  bool handled=false;
+  if(e->type==GDK_SCROLL)
+    {
+
+      //pointer shows this win point before zoom
+      XY win_coord(((GdkEventScroll*)e)->x, ((GdkEventScroll*)e)->y);
+
+      //the original scroll settings
+      int scroll_offset_x, scroll_offset_y;
+      get_scroll_offsets(scroll_offset_x, scroll_offset_y);
+
+      //pointer shows this canvas point before zoom
+      XY canvas_coord;
+      window_to_world(win_coord.x, win_coord.y, canvas_coord.x, canvas_coord.y);
+
+      if(((GdkEventScroll*)e)->direction) //IN
+	{
+	  zoomIn();
+	}
+      else
+	{
+	  zoomOut();
+	}
+
+      //pointer shows this window point after zoom
+      XY post_win_coord;
+      world_to_window(canvas_coord.x, canvas_coord.y, post_win_coord.x, post_win_coord.y);
+
+      //we have to add the difference between new and old window point to original scroll offset
+      scroll_to(scroll_offset_x+(int)(post_win_coord.x-win_coord.x),scroll_offset_y+(int)(post_win_coord.y-win_coord.y));
+      
+      //no other eventhandler is needed
+      handled=true;
+    }
+  return handled;
+}
+
 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
 {
   static Gnome::Canvas::Text *coord_text = 0;

Modified: glemon/trunk/graph_displayer_canvas.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas.cc	(original)
+++ glemon/trunk/graph_displayer_canvas.cc	Fri Feb  2 11:13:33 2007
@@ -28,10 +28,14 @@
   was_redesigned(false), is_drawn(false), mytab(mainw),
   background_set(false)
 {
+  //add mouse scroll event handler - it won't be changed, it handles zoom
+  signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::scrollEventHandler), false);
+
   //base event handler is move tool
   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
   actual_tool=MOVE;
 
+
   active_node=INVALID;
   active_edge=INVALID;
   forming_edge=INVALID;
@@ -319,6 +323,7 @@
 
 void GraphDisplayerCanvas::reDesignGraph()
 {
+  double max_coord=50000;
   double min_dist=20;
   double init_vector_length=25;
 
@@ -401,6 +406,26 @@
 	}
       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
 	{
+	  if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
+	    {
+	      actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
+	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
+	    }
+	  else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
+	    {
+	      actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
+	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
+	    }
+	  if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
+	    {
+	      actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
+	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
+	    }
+	  else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
+	    {
+	      actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
+	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
+	    }
 	  moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
 	}
     }

Modified: glemon/trunk/graph_displayer_canvas.h
==============================================================================
--- glemon/trunk/graph_displayer_canvas.h	(original)
+++ glemon/trunk/graph_displayer_canvas.h	Fri Feb  2 11:13:33 2007
@@ -288,6 +288,8 @@
   bool eraserEventHandler(GdkEvent*);
   ///event handler for the case when map editor tool is active
   bool mapEditEventHandler(GdkEvent*);
+  ///event handler for the case when user scrolls the mouse
+  bool scrollEventHandler(GdkEvent*);
 
 private:
   ///moves node according to the given parameters



More information about the Lemon-commits mailing list