gui/graph_displayer_canvas.cc
changeset 1448 0274acee0e35
parent 1442 1e3c69aa035b
child 1468 d0ccb2fdeeff
equal deleted inserted replaced
3:5e0000835d9f 4:d213cffb85da
   188       isbutton=true;
   188       isbutton=true;
   189       break;
   189       break;
   190     case GDK_BUTTON_RELEASE:
   190     case GDK_BUTTON_RELEASE:
   191       isbutton=false;
   191       isbutton=false;
   192       active_item=NULL;
   192       active_item=NULL;
       
   193       updateScrollRegion();
   193       break;
   194       break;
   194     case GDK_MOTION_NOTIFY:
   195     case GDK_MOTION_NOTIFY:
   195       //we only have to do sg. if the mouse button is pressed
   196       //we only have to do sg. if the mouse button is pressed
   196       if(isbutton)
   197       if(isbutton)
   197       {
   198       {
   281   int aw = a.get_width();
   282   int aw = a.get_width();
   282   int ah = a.get_height();
   283   int ah = a.get_height();
   283   // add some space
   284   // add some space
   284   aw -= 5; if (aw < 0) aw = 0;
   285   aw -= 5; if (aw < 0) aw = 0;
   285   ah -= 5; if (ah < 0) ah = 0;
   286   ah -= 5; if (ah < 0) ah = 0;
   286   //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
       
   287 
   287 
   288   // get the bounding box of the graph
   288   // get the bounding box of the graph
   289   set_pixels_per_unit(1.0); // I don't really understand why this is necessary
       
   290   double wx1, wy1, wx2, wy2;
   289   double wx1, wy1, wx2, wy2;
   291   double cx1, cy1, cx2, cy2;
       
   292   Gnome::Canvas::Item* pCanvasItem = root();
   290   Gnome::Canvas::Item* pCanvasItem = root();
   293   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   291   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   294   //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
       
   295   w2c(wx1, wy1, cx1, cy1);
       
   296   w2c(wx2, wy2, cx2, cy2);
       
   297   //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
       
   298   //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
       
   299 
   292 
   300   // fit the graph to the window
   293   // fit the graph to the window
   301   double ppu1 = (double) aw / fabs(cx2 - cx1);
   294   double ppu1 = (double) aw / fabs(wx2 - wx1);
   302   double ppu2 = (double) ah / fabs(cy2 - cy1);
   295   double ppu2 = (double) ah / fabs(wy2 - wy1);
   303   //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
   296   set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
   304   (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
       
   305 }
   297 }
   306 
   298 
   307 void GraphDisplayerCanvas::zoom100()
   299 void GraphDisplayerCanvas::zoom100()
   308 {
   300 {
   309   set_pixels_per_unit(1.0);
   301   set_pixels_per_unit(1.0);
   310 }
   302 }
   311 
   303 
   312 void GraphDisplayerCanvas::updateScrollRegion()
   304 void GraphDisplayerCanvas::updateScrollRegion()
   313 {
   305 {
   314   double wx1, wy1, wx2, wy2;
   306   double wx1, wy1, wx2, wy2;
   315   int cx1, cy1, cx2, cy2;
       
   316   Gnome::Canvas::Item* pCanvasItem = root();
   307   Gnome::Canvas::Item* pCanvasItem = root();
   317   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   308   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   318   w2c(wx1, wy1, cx1, cy1);
   309   set_scroll_region(wx1, wy1, wx2, wy2);
   319   w2c(wx2, wy2, cx2, cy2);
   310 }
   320   set_scroll_region(cx1, cy1, cx2, cy2);
       
   321 }