| 1 | /* -*- C++ -*- |
|---|
| 2 | * |
|---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2003-2006 |
|---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
|---|
| 8 | * |
|---|
| 9 | * Permission to use, modify and distribute this software is granted |
|---|
| 10 | * provided that this copyright notice appears in all copies. For |
|---|
| 11 | * precise terms see the accompanying LICENSE file. |
|---|
| 12 | * |
|---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
|---|
| 14 | * express or implied, and with no claim as to its suitability for any |
|---|
| 15 | * purpose. |
|---|
| 16 | * |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include "graph_displayer_canvas.h" |
|---|
| 20 | #include <cmath> |
|---|
| 21 | |
|---|
| 22 | void GraphDisplayerCanvas::zoomIn() |
|---|
| 23 | { |
|---|
| 24 | set_pixels_per_unit( |
|---|
| 25 | (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); |
|---|
| 26 | if(zoomtrack) |
|---|
| 27 | { |
|---|
| 28 | propertyChange(false, N_RADIUS); |
|---|
| 29 | propertyChange(true, E_WIDTH); |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | void GraphDisplayerCanvas::zoomOut() |
|---|
| 34 | { |
|---|
| 35 | set_pixels_per_unit( |
|---|
| 36 | (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); |
|---|
| 37 | if(zoomtrack) |
|---|
| 38 | { |
|---|
| 39 | propertyChange(true, E_WIDTH); |
|---|
| 40 | propertyChange(false, N_RADIUS); |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void GraphDisplayerCanvas::zoomFit() |
|---|
| 45 | { |
|---|
| 46 | updateScrollRegion(); |
|---|
| 47 | |
|---|
| 48 | // get the height and width of the canvas |
|---|
| 49 | Gtk::Allocation a = get_allocation(); |
|---|
| 50 | int aw = a.get_width(); |
|---|
| 51 | int ah = a.get_height(); |
|---|
| 52 | |
|---|
| 53 | // get the bounding box of the graph |
|---|
| 54 | update_now(); |
|---|
| 55 | double x1, y1, x2, y2; |
|---|
| 56 | root()->get_bounds(x1, y1, x2, y2); |
|---|
| 57 | |
|---|
| 58 | // fit the graph to the window |
|---|
| 59 | double ppu1 = (double) aw / fabs(x2 - x1); |
|---|
| 60 | double ppu2 = (double) ah / fabs(y2 - y1); |
|---|
| 61 | set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
|---|
| 62 | |
|---|
| 63 | if(zoomtrack) |
|---|
| 64 | { |
|---|
| 65 | propertyChange(true, E_WIDTH); |
|---|
| 66 | propertyChange(false, N_RADIUS); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void GraphDisplayerCanvas::zoom100() |
|---|
| 71 | { |
|---|
| 72 | updateScrollRegion(); |
|---|
| 73 | set_pixels_per_unit(1.0); |
|---|
| 74 | |
|---|
| 75 | if(zoomtrack) |
|---|
| 76 | { |
|---|
| 77 | propertyChange(true, E_WIDTH); |
|---|
| 78 | propertyChange(false, N_RADIUS); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void GraphDisplayerCanvas::updateScrollRegion() |
|---|
| 83 | { |
|---|
| 84 | // get_bounds() yields something sane only when no updates are pending |
|---|
| 85 | // and it returns a sufficient, not an exact bounding box |
|---|
| 86 | update_now(); |
|---|
| 87 | double x1, y1, x2, y2; |
|---|
| 88 | root()->get_bounds(x1, y1, x2, y2); |
|---|
| 89 | set_scroll_region(x1, y1, x2, y2); |
|---|
| 90 | } |
|---|