# HG changeset patch # User hegyi # Date 1170411213 0 # Node ID b465e2c34f2335cc52eb22c96df16bbb82f07c33 # Parent 013afe9ee040344a24a4a45715bcdcaefc4f6826 Zoom is now available with mouse-wheel. diff -r 013afe9ee040 -r b465e2c34f23 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Wed Jan 10 14:56:16 2007 +0000 +++ b/graph_displayer_canvas-event.cc Fri Feb 02 10:13:33 2007 +0000 @@ -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; diff -r 013afe9ee040 -r b465e2c34f23 graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Wed Jan 10 14:56:16 2007 +0000 +++ b/graph_displayer_canvas.cc Fri Feb 02 10:13:33 2007 +0000 @@ -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); } } diff -r 013afe9ee040 -r b465e2c34f23 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Wed Jan 10 14:56:16 2007 +0000 +++ b/graph_displayer_canvas.h Fri Feb 02 10:13:33 2007 +0000 @@ -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