1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
8 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
11 This file is part of gpiv.
13 Gpiv is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ----------------------------------------------------------------------*/
31 #include "display_zoom.h"
35 set__canvas_size (Display
*disp
39 set__adjusters (Display
*disp
43 canvas_display_button_scroll (GtkWidget
*widget
,
44 GdkEventScroll
*event
,
47 /*-----------------------------------------------------------------------------
50 Display
* disp
= gtk_object_get_data(GTK_OBJECT(widget
), "disp");
51 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
54 if (event
->direction
== 0) {
55 disp
->zoom_factor
*= DISPLAY_ZOOMFACTOR_STEP
;
58 if (event
->direction
== 1) {
59 disp
->zoom_factor
/= DISPLAY_ZOOMFACTOR_STEP
;
62 check__zoom_factor (&disp
->zoom_factor
);
63 set__canvas_size (disp
);
64 if (gpiv_par
->display__stretch_auto
== TRUE
) {
65 stretch_window (disp
);
67 set__adjusters (disp
);
68 set__hrulerscale (disp
);
69 set__vrulerscale (disp
);
74 check__zoom_factor (gfloat
*factor
76 /*-----------------------------------------------------------------------------
79 if (*factor
< DISPLAY_ZOOMFACTOR_MIN
) {
80 *factor
= DISPLAY_ZOOMFACTOR_MIN
;
83 if (*factor
> DISPLAY_ZOOMFACTOR_MAX
) {
84 *factor
= DISPLAY_ZOOMFACTOR_MAX
;
90 set__canvas_size (Display
*disp
92 /*-----------------------------------------------------------------------------
95 gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (disp
->canvas
),
97 /* gnome_canvas_set_center_scroll_region (GNOME_CANVAS(disp->canvas), TRUE); */
99 if (disp
->zoom_factor
< disp
->zoom_factor_old
) {
100 gtk_widget_set_size_request (disp
->canvas
,
101 (gint
) (disp
->zoom_factor
*
102 disp
->img
->image
->header
->ncolumns
),
103 (gint
) (disp
->zoom_factor
*
104 disp
->img
->image
->header
->nrows
));
106 disp
->zoom_factor_old
= disp
->zoom_factor
;
113 set__hrulerscale (Display
*disp
115 /*-----------------------------------------------------------------------------
121 if (disp
->pida
->exist_piv
&& display_act
->pida
->scaled_piv
) {
122 x_start
= (gfloat
) (disp
->x_adj_value
- 1)
123 / (gfloat
) disp
->zoom_factor
124 * disp
->img
->image
->header
->s_scale
126 + disp
->img
->image
->header
->z_off_x
129 x_end
= (gfloat
) x_start
130 + (disp
->img
->image
->header
->s_scale
* (gfloat
) disp
->x_page_size
131 / (gfloat
) disp
->zoom_factor
)
135 x_start
= (gfloat
) (disp
->x_adj_value
- 1) / (gfloat
) disp
->zoom_factor
;
136 x_end
= (gfloat
) x_start
137 + (gfloat
) disp
->x_page_size
/ (gfloat
) disp
->zoom_factor
;
141 /* g_message ("set__hrulerscale:: s_scale = %f z_off_x = %f x_start = %f x_end = %f", */
142 /* disp->img->image->header->s_scale, */
143 /* disp->img->image->header->z_off_x, */
146 gtk_ruler_set_range (GTK_RULER (disp
->hruler
),
155 set__vrulerscale (Display
*disp
157 /*-----------------------------------------------------------------------------
158 * Identic to display.c: on_adj_changed__adapt_vruler
164 if (disp
->pida
->exist_piv
&& display_act
->pida
->scaled_piv
) {
165 y_start
= (gfloat
) (disp
->y_adj_value
- 1)
166 / (gfloat
) disp
->zoom_factor
167 * disp
->img
->image
->header
->s_scale
169 + disp
->img
->image
->header
->z_off_y
172 y_end
= (gfloat
) y_start
173 + (disp
->img
->image
->header
->s_scale
* (gfloat
) disp
->y_page_size
174 / (gfloat
) disp
->zoom_factor
)
178 y_start
= (gfloat
) (disp
->y_adj_value
- 1) / (gfloat
) disp
->zoom_factor
;
179 y_end
= (gfloat
) y_start
180 + (gfloat
) disp
->y_page_size
/(gfloat
) disp
->zoom_factor
;
183 gtk_ruler_set_range (GTK_RULER (disp
->vruler
),
192 set__adjusters (Display
*disp
194 /*-----------------------------------------------------------------------------
197 GtkAdjustment
* hadj
= GTK_ADJUSTMENT (disp
->hadj
);
198 GtkAdjustment
* vadj
= GTK_ADJUSTMENT (disp
->vadj
) ;
201 vadj
->upper
= (gdouble
) (disp
->img
->image
->header
->nrows
)
202 * disp
->zoom_factor
- 1.0;
203 vadj
->page_size
= (gdouble
) (disp
->img
->image
->header
->nrows
)
204 * disp
->zoom_factor_old
;
205 gtk_adjustment_set_value( GTK_ADJUSTMENT (vadj
),
206 (vadj
->lower
+ vadj
->upper
- vadj
->page_size
)
211 hadj
->upper
= (gdouble
) (disp
->img
->image
->header
->ncolumns
)
212 * disp
->zoom_factor
- 1.0;
213 hadj
->page_size
= (gdouble
) (disp
->img
->image
->header
->ncolumns
)
214 * disp
->zoom_factor_old
;
215 gtk_adjustment_set_value (GTK_ADJUSTMENT (hadj
),
216 (hadj
->lower
+ hadj
->upper
- hadj
->page_size
)
219 /* g_message ("set__adjusters:: HOR: lower = %f upper = %f size = %f", */
220 /* hadj->lower, hadj->upper, hadj->page_size); */
222 g_signal_emit_by_name (G_OBJECT (hadj
), "changed");
223 g_signal_emit_by_name (G_OBJECT (vadj
), "changed");
229 stretch_window (Display
*disp
231 /*-----------------------------------------------------------------------------
234 GtkAdjustment
* hadj
= GTK_ADJUSTMENT (disp
->hadj
);
235 GtkAdjustment
* vadj
= GTK_ADJUSTMENT (disp
->vadj
);
236 gint screen_width
= gdk_screen_width();
237 gint screen_height
= gdk_screen_height();
239 gint display_width
= (gint
) (disp
->zoom_factor
*
240 disp
->img
->image
->header
->ncolumns
243 gint display_height
= (gint
) (disp
->zoom_factor
*
244 disp
->img
->image
->header
->nrows
248 if (display_width
>= screen_width
/* - VIEW_HMARGE */) {
249 display_width
= screen_width
- VIEW_HMARGE
;
252 if (display_height
>= screen_height
- VIEW_VMARGE
) {
253 display_height
= screen_height
/* - VIEW_VMARGE */;
257 gtk_widget_set_size_request (disp
->canvas
,
258 (gint
) display_width
/* - VIEW_HMARGE */,
259 (gint
) display_height
/* - VIEW_VMARGE */);
261 disp
->zoom_factor_old
= disp
->zoom_factor
;
264 vadj
->upper
= (gdouble
) disp
->img
->image
->header
->nrows
- 1;
265 vadj
->page_size
= (gdouble
) (disp
->img
->image
->header
->nrows
);
268 hadj
->upper
= (gdouble
) disp
->img
->image
->header
->ncolumns
- 1;
269 hadj
->page_size
= (gdouble
) (disp
->img
->image
->header
->ncolumns
);
271 g_signal_emit_by_name (G_OBJECT (hadj
), "changed");
272 g_signal_emit_by_name (G_OBJECT (vadj
), "changed");
277 zoom_display (Display
*disp
,
280 /*-----------------------------------------------------------------------------
283 gint width
= 0, height
= 0;
284 gint new_width
= 0, new_height
= 0;
287 disp
->zoom_factor
= zfactor
[zoom_index
];
288 check__zoom_factor (&disp
->zoom_factor
);
289 set__canvas_size (disp
);
290 if (gpiv_par
->display__stretch_auto
== TRUE
) {
291 stretch_window (disp
);
293 set__adjusters (disp
);
294 set__hrulerscale (disp
);
295 set__vrulerscale (disp
);