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