1 /* zoom.c  */
2 /* COPYRIGHT (C) 2000 THE VICTORIA UNIVERSITY OF MANCHESTER and John Levon
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15  * Place - Suite 330, Boston, MA 02111-1307, USA.
16  */
17 /*
18  * $Log: zoom.c,v $
19  * Revision 1.2  2000/12/06 20:56:07  moz
20  * GPL stuff.
21  *
22  * Revision 1.1.1.1  2000/08/21 01:05:31  moz
23  *
24  *
25  * Revision 1.1.1.1  2000/07/19 22:45:31  moz
26  * CVS Import
27  *
28  * Revision 1.13  2000/03/14 22:42:53  moz
29  * Fix for droppings when editing_object (see edit_ob.c)
30  *
31  * Revision 1.12  2000/03/14 02:48:48  moz
32  * Slight xor improvement.
33  *
34  * Revision 1.11  2000/03/14 01:09:36  moz
35  * Remove non-working xor stuff.
36  *
37  * Revision 1.10  2000/03/13 17:35:03  moz
38  * Only leaves edit object droppings when zooming *in* now.
39  *
40  * Revision 1.9  2000/03/08 22:15:02  moz
41  * Compile fixes.
42  *
43  * Revision 1.8  2000/02/27 21:28:32  moz
44  * Movee zoom_levels to here.
45  *
46  * Revision 1.7  2000/01/30 17:23:45  moz
47  * no_desert unused.
48  *
49  * Revision 1.6  1999/11/15 02:00:20  moz
50  * Name change.
51  *
52  * Revision 1.5  1999/07/04 02:04:33  moz
53  * Back to REDRAW_ALL_WINDOW(v->draw_window) to fix some rubber band droppings.
54  *
55  * Revision 1.4  1999/07/03 21:35:13  moz
56  * If from a button, don't resize, and zoom from/to centre of figure.
57  *
58  * Revision 1.3  1999/06/30 14:28:06  moz
59  * Redraw the window if the resizing has no effect.
60  *
61  * Revision 1.2  1999/04/23 00:40:26  moz
62  * redraw_view_window change.
63  *
64  * Revision 1.1  1999/03/30 00:07:13  moz
65  * Initial revision
66  *
67  */
68 
69 #include "include/figurine.h"
70 #include "include/extern.h"
71 
72 static double zoom_levels[] =
73         { 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.7, 2.0, 3.0, 4.0,
74 	          5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 15.0,17.0, 20.0, };
75 static int no_zoom_levels = sizeof(zoom_levels)/sizeof(double);
76 
77 extern int disable_motion;
78 
79 Boolean just_resized=FALSE;
80 
81 void
zoom_in(View * v,Boolean button)82 zoom_in(View *v,Boolean button)
83 {
84 	long x, y;
85 	ulong vw, vh;
86 	Boolean growx=FALSE, growy=FALSE;
87 	char a[850];
88 	char a2[10];
89 
90 	if (v->zoom_level>=no_zoom_levels-1)
91 		return;
92 
93 	x = XP2D(mouse_x,v);
94 	y = YP2D(mouse_y,v);
95 
96 	v->zoom_factor = zoom_levels[++v->zoom_level];
97 
98 	vw = v->window.w;
99 	vh = v->window.h;
100 
101 	if (strlen(v->doc->pathname)<400)
102 		strncpy(a, v->doc->pathname,400);
103 	strncat(a,v->doc->filename,400);
104 	strcat(a," (");
105 	sprintf(a2,"%.1f",v->zoom_factor*100);
106 	strcat(a,a2);
107 	strcat(a,"%)");
108 
109 	strcpy(v->wname,a);
110 	set_window_name(&(v->window),v->wname);
111 
112 	if (!button)
113 		{
114 		XEvent xev;
115 
116 		growx = (RULER_PIXEL_SIZE + I2P(v->doc->width_in_inches,v))  < (7.0*DisplayWidth(display,screen)/10.0);
117 		growy = (VIEW_ICON_SIZE + RULER_PIXEL_SIZE + I2P(v->doc->height_in_inches,v)) < (7.0*DisplayHeight(display,screen)/10.0);
118 
119 		v->x_inches_offset = D2I(x,v) - (P2I(v->draw_window->w,v)/2.0);
120 		v->y_inches_offset = D2I(y,v) - (P2I(v->draw_window->h,v)/2.0);
121 		XWarpPointer(display, None, v->draw_window->win, 0, 0, 1, 1,
122 				 (int)v->draw_window->w/2, (int)v->draw_window->h/2);
123 		mouse_x = v->draw_window->w/2;
124 		mouse_y = v->draw_window->h/2;
125 		XSync(display,False);
126 		while (XCheckTypedWindowEvent(display, v->draw_window->win, MotionNotify, &xev))
127 			;
128 
129 		if (growx)
130 			{
131 			vw = I2P(v->doc->width_in_inches,v) + 1 + RULER_PIXEL_SIZE;
132 			v->x_inches_offset = 0;
133 			};
134 
135 		if (growy)
136 			{
137 			vh = I2P(v->doc->height_in_inches,v) + 1 + RULER_PIXEL_SIZE + VIEW_ICON_SIZE;
138 			v->y_inches_offset = 0;
139 			};
140 
141 		if (growx || growy)
142 			XResizeWindow(display, v->window.win, vw, vh);
143 		}
144 	else
145 		{
146 		v->x_inches_offset = (v->doc->width_in_inches - P2I(v->draw_window->w,v))/2.0;
147 		v->y_inches_offset = (v->doc->height_in_inches - P2I(v->draw_window->h,v))/2.0;
148 		};
149 
150 	/* bitmap fonts don't scale linearly  */
151 	recalc_text_boxes(v);
152 
153 	disable_motion=4;
154 	just_resized=TRUE;
155 	if (button || (!growx && !growy) || (vw==v->window.w && vh==v->window.h))
156 		{
157  		REDRAW_ALL_WINDOW(v->draw_window);
158 		REDRAW_ALL_WINDOW(v->ruler_x_window);
159 		REDRAW_ALL_WINDOW(v->ruler_y_window);
160 		};
161 }
162 
163 void
zoom_out(View * v,Boolean button)164 zoom_out(View *v,Boolean button)
165 {
166 	long x, y;
167 	ulong vw, vh;
168 	Boolean shrinkx=FALSE, shrinky=FALSE;
169 	char a[850];
170 	char a2[10];
171 
172 	if (v->zoom_level==0)
173 		return;
174 
175 	x = XP2D(mouse_x,v);
176 	y = YP2D(mouse_y,v);
177 
178 	v->zoom_factor = zoom_levels[--v->zoom_level];
179 
180 	shrinkx = (RULER_PIXEL_SIZE + I2P(v->doc->width_in_inches,v))  < (7.0*DisplayWidth(display,screen)/10.0);
181 	shrinky = (RULER_PIXEL_SIZE + VIEW_ICON_SIZE + I2P(v->doc->height_in_inches,v)) < (7.0*DisplayHeight(display,screen)/10.0);
182 
183 	v->x_inches_offset = D2I(x,v) - (P2I(v->draw_window->w,v)/2.0);
184 	v->y_inches_offset = D2I(y,v) - (P2I(v->draw_window->h,v)/2.0);
185 
186 	if (strlen(v->doc->pathname)<400)
187 		strncpy(a, v->doc->pathname,400);
188 	strncat(a,v->doc->filename,400);
189 	strcat(a," (");
190 	sprintf(a2,"%.1f",v->zoom_factor*100);
191 	strcat(a,a2);
192 	strcat(a,"%)");
193 
194 	strcpy(v->wname,a);
195 	set_window_name(&(v->window),v->wname);
196 
197 	vw = v->window.w;
198 	vh = v->window.h;
199 
200 	if (!button)
201 		{
202 		if (shrinkx)
203 			{
204 			vw = I2P(v->doc->width_in_inches,v) + 1 + RULER_PIXEL_SIZE;
205 			v->x_inches_offset = 0;
206 			};
207 
208 		if (shrinky)
209 			{
210 			vh = I2P(v->doc->height_in_inches,v) + 1 + RULER_PIXEL_SIZE + VIEW_ICON_SIZE;
211 			v->y_inches_offset = 0;
212 			};
213 
214 		if (v->x_inches_offset<0)
215 			v->x_inches_offset = 0;
216 		if (v->y_inches_offset<0)
217 			v->y_inches_offset = 0;
218 
219 		if (shrinkx || shrinky)
220 			XResizeWindow(display, v->window.win, vw, vh);
221 		}
222 	else
223 		{
224 		v->x_inches_offset = (v->doc->width_in_inches - P2I(v->draw_window->w,v))/2.0;
225 		v->y_inches_offset = (v->doc->height_in_inches - P2I(v->draw_window->h,v))/2.0;
226 		};
227 
228 
229 	/* bitmap fonts don't scale linearly  */
230 	recalc_text_boxes(v);
231 
232 	disable_motion=4;
233 	just_resized=TRUE;
234 	/* only redraw again if the window hasn't been resized  */
235 	if (button || (!shrinkx && !shrinky) || (vw==v->window.w && vh==v->window.h))
236 		{
237 		REDRAW_ALL_WINDOW(v->draw_window);
238 		REDRAW_ALL_WINDOW(v->ruler_x_window);
239 		REDRAW_ALL_WINDOW(v->ruler_y_window);
240 		};
241 }
242