1 /* Copyright (C) 1992-1998 The Geometry Center
2  * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3  *
4  * This file is part of Geomview.
5  *
6  * Geomview is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Geomview is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Geomview; see the file COPYING.  If not, write
18  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19  * USA, or visit http://www.gnu.org.
20  */
21 
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25 
26 #if 0
27 static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
28 Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
29 #endif
30 
31 
32 /* Authors: Stuart Levy, Tamara Munzner, Mark Phillips */
33 
34 /*
35  * mouse.c: mouse computations
36  */
37 
38 #include "window.h"
39 #include "common.h"
40 #include "mouse.h"
41 
42 Event oldmouse;
43 static float olddist = 0;
44 
45 void
mousezero(Event * event,WnPosition * wp)46 mousezero(Event *event,  WnPosition *wp)
47 {
48   oldmouse = *event;
49 }
50 
51 
52 void
mousedisp(Event * event,float * dx,float * dy,unsigned long int * dt,WnPosition * wp)53 mousedisp(Event *event, float *dx, float *dy, unsigned long int *dt, WnPosition *wp)
54 {
55   *dx = 2. * (event->x - oldmouse.x) / (wp->xmax - wp->xmin + 1);
56   *dy = 2. * (event->y - oldmouse.y) / (wp->ymax - wp->ymin + 1);
57   *dt = event->t - oldmouse.t;
58 D1PRINT(("mousedisp: dx <- %10f, dy <- %10f, dt <- %ld\n", *dx, *dy, *dt));
59   mousezero(event, wp);
60 }
61 
62 void
radialmousezero(Event * event,WnPosition * wp)63 radialmousezero(Event *event, WnPosition *wp)
64 {
65   float x,y;
66   float xw = wp->xmax - wp->xmin + 1;
67   float yw = wp->ymax - wp->ymin + 1;
68 
69   x = (event->x - wp->xmin) / xw - 0.5;
70   y = (event->y - wp->ymin) / yw - 0.5;
71   olddist = sqrt( x*x + y*y );
72 }
73 
74 float
radialmousedisp(Event * event,WnPosition * wp)75 radialmousedisp(Event *event, WnPosition *wp)
76 {
77   float x, y, dist, val;
78   float xw = wp->xmax - wp->xmin + 1;
79   float yw = wp->ymax - wp->ymin + 1;
80 
81   x = (event->x - wp->xmin) / xw - 0.5;
82   y = (event->y - wp->ymin) / yw - 0.5;
83 
84   dist = sqrt( x*x + y*y );
85   val = dist - olddist;
86   olddist = dist;
87   return 2 * val;
88 }
89 
90 void
mousemap(int x,int y,float * rx,float * ry,WnPosition * wp)91 mousemap(int x, int y, float *rx, float *ry, WnPosition *wp)
92 {
93   *rx = 2. * (x - wp->xmin) / (wp->xmax - wp->xmin + 1) - 1;
94   *ry = 2. * (y - wp->ymin) / (wp->ymax - wp->ymin + 1) - 1;
95 }
96