diff -r 3d2e3cfb2a6c -r fd4b6f6d592a gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Fri May 27 10:34:20 2005 +0000 +++ b/gui/graph_displayer_canvas.cc Wed Jun 01 23:30:13 2005 +0000 @@ -3,6 +3,7 @@ GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL) { + //set_center_scroll_region(true); //first edges are drawn, to hide joining with nodes later @@ -50,6 +51,7 @@ (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); } +/* //setting zoom to be able to see the whole graph on the canvas double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); @@ -59,7 +61,8 @@ std::cout<get_bounds(x1, y1, x2, y2); - - x=(int)((x1+x2)/2); - y=(int)((y1+y2)/2); - - int maxx=0, maxy=0, minx=(int)x, miny=(int)y; - - for (; i!=INVALID; ++i) - { - nodesmap[i]->get_bounds(x1, y1, x2, y2); - - x=(int)((x1+x2)/2); - y=(int)((y1+y2)/2); - - if(x>maxx)maxx=x; - if(y>maxy)maxy=y; - if(xabs(minx))?(abs(maxx)+80):(abs(minx)+80); - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); - - set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); - return 0; -}; - - bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) { switch(e->type) @@ -300,3 +261,61 @@ //rezoom(); return true; } + +void GraphDisplayerCanvas::zoomIn() +{ + set_pixels_per_unit( + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); +} + +void GraphDisplayerCanvas::zoomOut() +{ + set_pixels_per_unit( + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); +} + +void GraphDisplayerCanvas::zoomFit() +{ + // get the height and width of the canvas + Gtk::Allocation a = get_allocation(); + int aw = a.get_width(); + int ah = a.get_height(); + // add some space + aw -= 5; if (aw < 0) aw = 0; + ah -= 5; if (ah < 0) ah = 0; + //std::cout << "aw=" << aw << " ah=" << ah << std::endl; + + // get the bounding box of the graph + set_pixels_per_unit(1.0); // I don't really understand why this is necessary + double wx1, wy1, wx2, wy2; + double cx1, cy1, cx2, cy2; + Gnome::Canvas::Item* pCanvasItem = root(); + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); + //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl; + w2c(wx1, wy1, cx1, cy1); + w2c(wx2, wy2, cx2, cy2); + //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl; + //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl; + + // fit the graph to the window + double ppu1 = (double) aw / fabs(cx2 - cx1); + double ppu2 = (double) ah / fabs(cy2 - cy1); + //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl; + (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2); +} + +void GraphDisplayerCanvas::zoom100() +{ + set_pixels_per_unit(1.0); +} + +void GraphDisplayerCanvas::updateScrollRegion() +{ + double wx1, wy1, wx2, wy2; + int cx1, cy1, cx2, cy2; + Gnome::Canvas::Item* pCanvasItem = root(); + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); + w2c(wx1, wy1, cx1, cy1); + w2c(wx2, wy2, cx2, cy2); + set_scroll_region(cx1, cy1, cx2, cy2); +}