[174] | 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 | |
---|
[53] | 19 | #include "graph_displayer_canvas.h" |
---|
[59] | 20 | #include <cmath> |
---|
[27] | 21 | |
---|
| 22 | void GraphDisplayerCanvas::zoomIn() |
---|
| 23 | { |
---|
| 24 | set_pixels_per_unit( |
---|
| 25 | (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); |
---|
[156] | 26 | if(zoomtrack) |
---|
| 27 | { |
---|
| 28 | propertyChange(false, N_RADIUS); |
---|
[157] | 29 | propertyChange(true, E_WIDTH); |
---|
[156] | 30 | } |
---|
[27] | 31 | } |
---|
| 32 | |
---|
| 33 | void GraphDisplayerCanvas::zoomOut() |
---|
| 34 | { |
---|
| 35 | set_pixels_per_unit( |
---|
| 36 | (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); |
---|
[156] | 37 | if(zoomtrack) |
---|
| 38 | { |
---|
[157] | 39 | propertyChange(true, E_WIDTH); |
---|
[156] | 40 | propertyChange(false, N_RADIUS); |
---|
| 41 | } |
---|
[27] | 42 | } |
---|
| 43 | |
---|
| 44 | void GraphDisplayerCanvas::zoomFit() |
---|
| 45 | { |
---|
[87] | 46 | updateScrollRegion(); |
---|
| 47 | |
---|
[27] | 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 |
---|
[87] | 54 | update_now(); |
---|
| 55 | double x1, y1, x2, y2; |
---|
| 56 | root()->get_bounds(x1, y1, x2, y2); |
---|
[27] | 57 | |
---|
| 58 | // fit the graph to the window |
---|
[87] | 59 | double ppu1 = (double) aw / fabs(x2 - x1); |
---|
| 60 | double ppu2 = (double) ah / fabs(y2 - y1); |
---|
[27] | 61 | set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
---|
[156] | 62 | |
---|
| 63 | if(zoomtrack) |
---|
| 64 | { |
---|
[157] | 65 | propertyChange(true, E_WIDTH); |
---|
[156] | 66 | propertyChange(false, N_RADIUS); |
---|
| 67 | } |
---|
[27] | 68 | } |
---|
| 69 | |
---|
| 70 | void GraphDisplayerCanvas::zoom100() |
---|
| 71 | { |
---|
[87] | 72 | updateScrollRegion(); |
---|
[27] | 73 | set_pixels_per_unit(1.0); |
---|
[156] | 74 | |
---|
| 75 | if(zoomtrack) |
---|
| 76 | { |
---|
[157] | 77 | propertyChange(true, E_WIDTH); |
---|
[156] | 78 | propertyChange(false, N_RADIUS); |
---|
| 79 | } |
---|
[27] | 80 | } |
---|
| 81 | |
---|
| 82 | void GraphDisplayerCanvas::updateScrollRegion() |
---|
| 83 | { |
---|
[87] | 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); |
---|
[27] | 90 | } |
---|