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

Linux Cross Reference
Tina6/tina-tools/tinatool/gphx/gdk2/gphxGdk_mousestate.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/gphx/gdk2/gphxGdk_mousestate.c,v $
 37  * Date    :  $Date: 2009/03/24 12:58:52 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: gphxGdk_mousestate.c,v 1.4 2009/03/24 12:58:52 paul Exp $
 40  *
 41  * Author  :  giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  gphxGdk_mousestate.c
 47  *  @brief Simple description of current mouse event.
 48  *
 49  *  Turns a GDK mouse state description into a Tina mouse state decription for subsequent handling. 
 50  *
 51  *  Note: the functions in this file are duplicated for each graphics lib (x11, GDK, etc ...).
 52  *
 53  */
 54 
 55 
 56 #include "gphxGdk_mousestate.h"
 57 
 58 #if HAVE_CONFIG_H
 59   #include <config.h>
 60 #endif
 61 
 62 #include <gtk/gtk.h>
 63 
 64 /**
 65  * @brief  Show current mouse state on the main tinaTool text subwindow.  
 66  * @param  state   Integer descriptor of current mouse state (see draw_TvDef.h).
 67  *
 68  * Debug aid.
 69  */
 70 void    format_mousestate(int state)
 71 {
 72     switch (state)
 73     {
 74         case LEFT_DOWN:
 75         format("LEFT_DOWN\n");
 76         break;
 77     case LEFT_DRAG:
 78         format("LEFT_DRAG\n");
 79         break;
 80     case LEFT_UP:
 81         format("LEFT_UP\n");
 82         break;
 83     case MIDDLE_DOWN:
 84         format("MIDDLE_DOWN\n");
 85         break;
 86     case MIDDLE_DRAG:
 87         format("MIDDLE_DRAG\n");
 88         break;
 89     case MIDDLE_UP:
 90         format("MIDDLE_UP\n");
 91         break;
 92     case RIGHT_DOWN:
 93         format("RIGHT_DOWN\n");
 94         break;
 95     case RIGHT_DRAG:
 96         format("RIGHT_DRAG\n");
 97         break;
 98     case RIGHT_UP:
 99         format("RIGHT_UP\n");
100         break;
101     case WAIT_STATE:
102         format("WAIT_STATE\n");
103         break;
104     case BAD_STATE:
105         format("BAD_STATE\n");
106         break;
107     default:
108         format("STRANGE_STATE\n");
109         break;
110     }
111 }
112 
113 /**
114  * @brief  Set the Tina mouse state descriptor and location, based on the current mouse event.  
115  * @param  event  Pointer to GdkEvent struct for the current mouse event.
116  * @param  pos    Pointer to storage for current mouse location.
117  * @return int  Integer descriptor of current mouse state (see draw_TvDef.h).
118  */
119 int   mouse_get_state(GdkEvent *event, Ipos *pos)
120 {
121   static int mouse_state = BAD_STATE;
122 
123   switch (event->type)
124   {
125     case GDK_BUTTON_PRESS:
126       switch (((GdkEventButton *)event)->button)
127       {
128         case 1:
129           mouse_state = LEFT_DOWN;
130           break;
131         case 2:
132           mouse_state = MIDDLE_DOWN;
133           break;
134         case 3:
135           mouse_state = RIGHT_DOWN;
136           break;
137         default:
138           return (BAD_STATE);
139       }
140       break;
141 
142     case GDK_MOTION_NOTIFY:
143 
144       /* Check for motion hints: if the image display is slow (e.g. with large stereo datasets in the threed
145          tv) then buffered events are issued as hints and not processed.  The next block of code ensures that 
146          the final mouse position is always implemented i.e. the image will jump to the final mouse position.
147          However, this will only occur in general in tv's that are not using gdk double buffering so, if such
148          jumps are observed, ensure that tv_screen_double_buffer_start and tv_screen_double_buffer_start are
149          wrapped around the skeldraw function for the tv. PAB 23/03/2009 */
150 
151       if (event->motion.is_hint)
152       {
153         GdkModifierType state;
154         int x, y;
155 
156         gdk_window_get_pointer(event->motion.window, &x, &y, &state);
157         event->motion.x_root = x;
158         event->motion.y_root = y; 
159       }
160 
161       switch (mouse_state)
162       {
163         case LEFT_DOWN:
164         case LEFT_DRAG:
165           mouse_state = LEFT_DRAG;
166           break;
167         case MIDDLE_DOWN:
168         case MIDDLE_DRAG:
169           mouse_state = MIDDLE_DRAG;
170           break;
171         case RIGHT_DOWN:
172         case RIGHT_DRAG:
173           mouse_state = RIGHT_DRAG;
174           break;
175         default:
176           return (BAD_STATE);
177       }
178       break;
179 
180     case GDK_BUTTON_RELEASE:
181       switch (((GdkEventButton *)event)->button)
182       {
183         case 1:
184           mouse_state = LEFT_UP;
185           break;
186         case 2:
187           mouse_state = MIDDLE_UP;
188           break;
189         case 3:
190           mouse_state = RIGHT_UP;
191           break;
192         default:
193           return (BAD_STATE);
194       }
195       break;
196 
197     default:
198       return (BAD_STATE);
199   }
200 
201   switch (event->type)
202   {
203     case GDK_BUTTON_PRESS:
204     case GDK_BUTTON_RELEASE:
205       pos->x = (int) (((GdkEventButton *)event)->x);
206       pos->y = (int) (((GdkEventButton *)event)->y);
207       break;
208    case GDK_MOTION_NOTIFY:
209       pos->x = (int) (((GdkEventMotion *)event)->x);
210       pos->y = (int) (((GdkEventMotion *)event)->y);
211       break;
212   }
213 
214   return (mouse_state);
215 }
216 

~ [ 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.