~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tv/tv_zoom.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <math.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 #include <tina/tv.h>
 10 #include <tina/tvfuncs.h>
 11 
 12 Ipos    ipos();
 13 void    tv_erase();
 14 void    tv_orient2();
 15 void    tv_orient3();
 16 void    tv_line();
 17 void    tv_text();
 18 
 19 void    tv_shift(Tv * tv, double dx, double dy)
 20 {
 21     tv->cx += (float)dx;
 22     tv->cy += (float)dy;
 23 }
 24 
 25 void    tv_zoom(Tv * tv, double zoom)
 26 {
 27     double  x = (tv->width / 2 - tv->cx) / tv->scalex;
 28     double  y = (tv->height / 2 - tv->cy) / tv->scaley;
 29 
 30     tv->scalex *= (float)zoom;
 31     tv->scaley *= (float)zoom;
 32     tv->cx = (float)(tv->width / 2 - x * tv->scalex);
 33     tv->cy = (float)(tv->height / 2 - y * tv->scaley);
 34 }
 35 
 36 void    tv_zoomx(Tv * tv, double zoom)
 37 {
 38     double  x = (tv->width / 2 - tv->cx) / tv->scalex;
 39 
 40     tv->scalex *= (float)zoom;
 41     tv->cx = (float)(tv->width / 2 - x * tv->scalex);
 42 }
 43 
 44 void    tv_zoomy(Tv * tv, double zoom)
 45 {
 46     double  y = (tv->height / 2 - tv->cy) / tv->scaley;
 47 
 48     tv->scaley *= (float)zoom;
 49     tv->cy = (float)(tv->height / 2 - y * tv->scaley);
 50 }
 51 
 52 void    tv_rot(Tv * tv, double theta)
 53 {
 54     Vec2    down2 = {Vec2_id};
 55     Vec3    down3 = {Vec3_id};
 56 
 57     down2 = mat2_vprod(rot2(theta), tv->ey2);
 58     tv_orient2(tv, down2);
 59     down3 = mat3_vprod(rot3(theta, tv->ez3), tv->ey3);
 60     tv_orient3(tv, tv->ez3, down3);
 61 }
 62 
 63 void    tv_rot2(Tv * tv, double theta)
 64 {
 65     Vec2    down2 = {Vec2_id};
 66 
 67     down2 = mat2_vprod(rot2(theta), tv->ey2);
 68     tv_orient2(tv, down2);
 69 }
 70 
 71 void    tv_rot3(Tv * tv, double theta)
 72 {
 73     Vec2    down2 = {Vec2_id};
 74     Vec3    down3 = {Vec3_id};
 75 
 76     down3 = mat3_vprod(rot3(theta, tv->ez3), tv->ey3);
 77     tv_orient3(tv, tv->ez3, down3);
 78 }
 79 
 80 void    tv_twist(Tv * tv, double theta, Vec3 axis)
 81 {
 82     Mat3    rot = {Mat3_id};
 83     Vec3    aim = {Vec3_id};
 84     Vec3    down = {Vec3_id};
 85 
 86     rot = rot3(theta, axis);
 87     aim = mat3_vprod(rot, tv->ez3);
 88     down = mat3_vprod(rot, tv->ey3);
 89     tv_orient3(tv, aim, down);
 90 }
 91 
 92 void    tv_fly(Tv * tv, Vec3 v, Vec3 down)
 93 {
 94     Vec3    aim = {Vec3_id};
 95 
 96     aim = vec3_unit(vec3_sum(tv->ez3, v));
 97     tv_orient3(tv, aim, down);
 98 }
 99 
100 static void centredot(Tv * tv)
101 {
102     tv_save_draw(tv);
103     (void) tv_set_op(tv, rop_copy);
104     tv_set_color(tv, black);
105     tv_dot(tv, ipos(tv->width / 2, tv->height / 2));
106     tv_reset_draw(tv);
107 }
108 
109 void    tv_imzoom_proc(Tv * tv, int state, Ipos pos)
110 {
111     double  x, y, dx, dy;
112     static double oldx, oldy;
113     static Vec2 p1 = {Vec2_id};
114     static Vec2 p2 = {Vec2_id};
115     Imregion roi = {Imregion_id};
116 
117     x = pos.x;
118     y = pos.y;
119     switch (state)
120     {
121     case LEFT_DOWN:
122     case MIDDLE_DOWN:
123     case RIGHT_DOWN:
124         tv_set_overlay(tv);     /* also calls tv_save_draw */
125         break;
126     case LEFT_UP:
127     case MIDDLE_UP:
128     case RIGHT_UP:
129         tv_reset_draw(tv);
130         break;
131     }
132 
133 
134     switch (state)
135     {
136     case LEFT_DOWN:
137         oldx = x;
138         oldy = y;
139         tv_erase(tv);
140         centredot(tv);
141         tv->skeldraw(tv);
142         break;
143     case MIDDLE_DOWN:
144         oldx = x;
145         oldy = y;
146         tv_erase(tv);
147         tv->skeldraw(tv);
148         break;
149     case LEFT_DRAG:
150         tv->skeldraw(tv);
151         tv_shift(tv, x - oldx, y - oldy);
152         tv->skeldraw(tv);
153         oldx = x;
154         oldy = y;
155         break;
156     case MIDDLE_DRAG:
157         tv->skeldraw(tv);
158         dx = x - oldx;
159         dy = y - oldy;
160         if (fabs(dx) > fabs(dy))
161             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
162         else
163             tv_rot3(tv,-dy / tv->height);
164         tv->skeldraw(tv);
165         oldx = x;
166         oldy = y;
167         break;
168     case RIGHT_DOWN:
169         p1 = p2 = tv_backproj2(tv, pos);
170         tv_rect2(tv, p1, p2);
171         break;
172     case RIGHT_DRAG:
173         tv_rect2(tv, p1, p2);
174         p2 = tv_backproj2(tv, pos);
175         tv_rect2(tv, p1, p2);
176         break;
177     case RIGHT_UP:
178         tv_rect2(tv, p1, p2);
179         if (vec2_x(p1) > vec2_x(p2))
180             SWAP(double, (float)vec2_x(p1), (float)vec2_x(p2));
181         if (vec2_y(p1) > vec2_y(p2))
182             SWAP(double, (float)vec2_y(p1), (float)vec2_y(p2));
183         roi_fill(&roi, (int) vec2_x(p1), (int) vec2_y(p1),
184                  (int) vec2_x(p2), (int) vec2_y(p2));
185         tv_camera2_roi(tv, &roi);
186     case LEFT_UP:
187     case MIDDLE_UP:
188         tv_free_background(tv);
189         tv_repaint(tv);
190         break;
191     default:
192         break;
193     }
194 }
195 
196 void    tv_zoom2_proc(Tv * tv, int state, Ipos pos)
197 {
198     double  x, y, dx, dy;
199     static double oldx, oldy;
200 
201     x = pos.x;
202     y = pos.y;
203     switch (state)
204     {
205     case LEFT_DOWN:
206     case MIDDLE_DOWN:
207     case RIGHT_DOWN:
208         tv_set_overlay(tv);     /* also calls tv_save_draw */
209         break;
210     case LEFT_UP:
211     case MIDDLE_UP:
212     case RIGHT_UP:
213         tv_reset_draw(tv);
214         break;
215     }
216     switch (state)
217     {
218     case LEFT_DOWN:
219         oldx = x;
220         oldy = y;
221         tv_erase(tv);
222         centredot(tv);
223         tv->skeldraw(tv);
224         break;
225     case MIDDLE_DOWN:
226         oldx = x;
227         oldy = y;
228         tv_erase(tv);
229         tv->skeldraw(tv);
230         break;
231     case LEFT_DRAG:
232         tv->skeldraw(tv);
233         tv_shift(tv, x - oldx, y - oldy);
234         tv->skeldraw(tv);
235         oldx = x;
236         oldy = y;
237         break;
238     case MIDDLE_DRAG:
239         tv->skeldraw(tv);
240         dx = x - oldx;
241         dy = y - oldy;
242         if (fabs(dx) > fabs(dy))
243             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
244         else
245             tv_rot(tv, -dy / tv->height);
246         tv->skeldraw(tv);
247         oldx = x;
248         oldy = y;
249         break;
250     case LEFT_UP:
251     case MIDDLE_UP:
252         tv_free_background(tv);
253         tv_repaint(tv);
254         break;
255     default:
256         break;
257     }
258 }
259 
260 void    tv_zoomaf_proc(Tv * tv, int state, Ipos pos)
261 {
262     double  x, y, dx, dy;
263     static double oldx, oldy;
264 
265     x = pos.x;
266     y = pos.y;
267     switch (state)
268     {
269     case LEFT_DOWN:
270     case MIDDLE_DOWN:
271     case RIGHT_DOWN:
272         tv_set_overlay(tv);     /* also calls tv_save_draw */
273         break;
274     case LEFT_UP:
275     case MIDDLE_UP:
276     case RIGHT_UP:
277         tv_reset_draw(tv);
278         break;
279     }
280     switch (state)
281     {
282     case LEFT_DOWN:
283         oldx = x;
284         oldy = y;
285         tv_erase(tv);
286         centredot(tv);
287         tv->skeldraw(tv);
288         break;
289     case MIDDLE_DOWN:
290         oldx = x;
291         oldy = y;
292         tv_erase(tv);
293         tv->skeldraw(tv);
294         break;
295     case LEFT_DRAG:
296         tv->skeldraw(tv);
297         tv_shift(tv, x - oldx, y - oldy);
298         tv->skeldraw(tv);
299         oldx = x;
300         oldy = y;
301         break;
302     case MIDDLE_DRAG:
303         tv->skeldraw(tv);
304         dx = x - oldx;
305         dy = y - oldy;
306         if (fabs(dx) > fabs(dy))
307             tv_zoomx(tv, (1.0 + x) / (1.0 + oldx));
308         else
309             tv_zoomy(tv, (1.0 + y) / (1.0 + oldy));
310         tv->skeldraw(tv);
311         oldx = x;
312         oldy = y;
313         break;
314     case LEFT_UP:
315     case MIDDLE_UP:
316         tv_free_background(tv);
317         tv_repaint(tv);
318         break;
319     default:
320         break;
321     }
322 }
323 
324 void    tv_zoom3_proc(Tv * tv, int state, Ipos pos)
325 {
326     double  x, y, dx, dy;
327     static double oldx, oldy;
328 
329     x = pos.x;
330     y = pos.y;
331     switch (state)
332     {
333     case LEFT_DOWN:
334     case MIDDLE_DOWN:
335     case RIGHT_DOWN:
336         tv_set_overlay(tv);     /* also calls tv_save_draw */
337         break;
338     case LEFT_UP:
339     case MIDDLE_UP:
340     case RIGHT_UP:
341         tv_reset_draw(tv);
342         break;
343     }
344     switch (state)
345     {
346     case LEFT_DOWN:
347         oldx = x;
348         oldy = y;
349         tv_erase(tv);
350         centredot(tv);
351         tv->skeldraw(tv);
352         break;
353     case MIDDLE_DOWN:
354     case RIGHT_DOWN:
355         oldx = x;
356         oldy = y;
357         tv_erase(tv);
358         tv->skeldraw(tv);
359         break;
360     case LEFT_DRAG:
361         tv->skeldraw(tv);
362         tv_shift(tv, x - oldx, y - oldy);
363         tv->skeldraw(tv);
364         oldx = x;
365         oldy = y;
366         break;
367     case MIDDLE_DRAG:
368         tv->skeldraw(tv);
369         dx = x - oldx;
370         dy = y - oldy;
371         if (fabs(dx) > fabs(dy))
372             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
373         else
374             tv_rot(tv, -dy / tv->height);
375         tv->skeldraw(tv);
376         oldx = x;
377         oldy = y;
378         break;
379     case RIGHT_DRAG:
380         tv->skeldraw(tv);
381         dx = x - oldx;
382         dy = y - oldy;
383         if (fabs(dx) > fabs(dy))
384         {
385             if (tv->axis_set)
386                 tv_twist(tv, dx / tv->width, tv->axis);
387             else
388                 tv_twist(tv, dx / tv->width, tv->ey3);
389         } else
390             tv_twist(tv, -dy / tv->height, tv->ex3);
391         tv->skeldraw(tv);
392         oldx = x;
393         oldy = y;
394         break;
395     case LEFT_UP:
396     case MIDDLE_UP:
397     case RIGHT_UP:
398         tv_free_background(tv);
399         tv_repaint(tv);
400         break;
401     default:
402         break;
403     }
404 }
405 
406 void    tv_zoomgr_proc(Tv * tv, int state, Ipos pos)
407 {
408     double  x, y, dx, dy;
409     static double oldx, oldy;
410 
411     x = pos.x;
412     y = pos.y;
413     switch (state)
414     {
415     case LEFT_DOWN:
416     case MIDDLE_DOWN:
417     case RIGHT_DOWN:
418         tv_set_overlay(tv);     /* also calls tv_save_draw */
419         break;
420     case LEFT_UP:
421     case MIDDLE_UP:
422     case RIGHT_UP:
423         tv_reset_draw(tv);
424         break;
425     }
426     switch (state)
427     {
428     case LEFT_DOWN:
429         oldx = x;
430         oldy = y;
431         tv_erase(tv);
432         centredot(tv);
433         tv->skeldraw(tv);
434         break;
435     case MIDDLE_DOWN:
436     case RIGHT_DOWN:
437         oldx = x;
438         oldy = y;
439         tv_erase(tv);
440         tv->skeldraw(tv);
441         break;
442     case LEFT_DRAG:
443         tv->skeldraw(tv);
444         tv_shift(tv, x - oldx, y - oldy);
445         tv->skeldraw(tv);
446         oldx = x;
447         oldy = y;
448         break;
449     case MIDDLE_DRAG:
450         tv->skeldraw(tv);
451         dx = x - oldx;
452         dy = y - oldy;
453         if (fabs(dx) > fabs(dy))
454             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
455         tv->skeldraw(tv);
456         oldx = x;
457         oldy = y;
458         break;
459     case RIGHT_DRAG:
460         tv->skeldraw(tv);
461         dx = x - oldx;
462         dy = y - oldy;
463         if (fabs(dx) > fabs(dy))
464         {
465             Vec3    v = {Vec3_id};
466 
467             v = vec3_times(dx / tv->width, tv->ex3);
468             tv_fly(tv, v, tv->axis);
469         } else
470         {
471             Vec3    v = {Vec3_id};
472 
473             v = vec3_times(dy / tv->height, tv->ey3);
474             tv_fly(tv, v, tv->axis);
475         }
476         tv->skeldraw(tv);
477         oldx = x;
478         oldy = y;
479         break;
480     case LEFT_UP:
481     case MIDDLE_UP:
482     case RIGHT_UP:
483         tv_free_background(tv);
484         tv_repaint(tv);
485         break;
486     default:
487         break;
488     }
489 }
490 
491 void    tv_zoom_proc(Tv * tv, int state, Ipos pos)
492 {
493     switch (tv->zoomlevel)
494     {
495         case NULL:
496         return;
497     case IMZOOM:
498         tv_imzoom_proc(tv, state, pos);
499         break;
500     case ZOOMAF:
501         tv_zoomaf_proc(tv, state, pos);
502         break;
503     case ZOOM2:
504         tv_zoom2_proc(tv, state, pos);
505         break;
506     case ZOOM3:
507         tv_zoom3_proc(tv, state, pos);
508         break;
509     case ZOOMGR:
510         tv_zoomgr_proc(tv, state, pos);
511         break;
512     }
513 }
514 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.