vlc_mouse.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_mouse.h: mouse related structures and functions
00003  *****************************************************************************
00004  * Copyright (C) 2009 Laurent Aimar
00005  * $Id: dff2129424d7f9c8f5c342f175572058d8b002f9 $
00006  *
00007  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef _VLC_MOUSE_H
00025 #define _VLC_MOUSE_H 1
00026 
00027 /**
00028  * Mouse button
00029  */
00030 enum
00031 {
00032     MOUSE_BUTTON_LEFT,
00033     MOUSE_BUTTON_CENTER,
00034     MOUSE_BUTTON_RIGHT,
00035     MOUSE_BUTTON_WHEEL_UP,
00036     MOUSE_BUTTON_WHEEL_DOWN,
00037 };
00038 
00039 /**
00040  * Mouse state
00041  */
00042 typedef struct
00043 {
00044     /* Coordinate */
00045     int i_x;
00046     int i_y;
00047     /* Mask of pressed button */
00048     int i_pressed;
00049     /* Is double clicked */
00050     bool b_double_click;
00051 } vlc_mouse_t;
00052 
00053 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
00054 {
00055     p_mouse->i_x = 0;
00056     p_mouse->i_y = 0;
00057     p_mouse->i_pressed = 0;
00058     p_mouse->b_double_click = false;
00059 }
00060 
00061 /* */
00062 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
00063                                          int i_button )
00064 {
00065     p_mouse->i_pressed |= 1 << i_button;
00066 }
00067 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
00068                                           int i_button )
00069 {
00070     p_mouse->i_pressed &= ~(1 << i_button);
00071 }
00072 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
00073                                           int i_x, int i_y )
00074 {
00075     p_mouse->i_x = i_x;
00076     p_mouse->i_y = i_y;
00077 }
00078 
00079 /* */
00080 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
00081                                         int i_button )
00082 {
00083     return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
00084 }
00085 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
00086 {
00087     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
00088 }
00089 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
00090 {
00091     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
00092 }
00093 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
00094 {
00095     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
00096 }
00097 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
00098 {
00099     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_UP );
00100 }
00101 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
00102 {
00103     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_DOWN );
00104 }
00105 static inline void vlc_mouse_GetMotion( int *pi_x, int *pi_y,
00106                                         const vlc_mouse_t *p_old,
00107                                         const vlc_mouse_t *p_new )
00108 {
00109     *pi_x = p_new->i_x - p_old->i_x;
00110     *pi_y = p_new->i_y - p_old->i_y;
00111 }
00112 
00113 /* */
00114 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
00115                                          const vlc_mouse_t *p_new )
00116 {
00117     return p_old->i_x != p_new->i_x || p_old->i_x != p_new->i_x ||
00118            p_old->i_pressed != p_new->i_pressed;
00119 }
00120 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
00121                                        const vlc_mouse_t *p_new )
00122 {
00123     return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
00124 }
00125 static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
00126                                         const vlc_mouse_t *p_new )
00127 {
00128     return p_old->i_pressed != p_new->i_pressed;
00129 }
00130 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
00131                                          const vlc_mouse_t *p_new,
00132                                          int i_button )
00133 {
00134     const int i_mask = 1 << i_button;
00135     return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
00136 }
00137 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
00138                                           const vlc_mouse_t *p_new,
00139                                           int i_button )
00140 {
00141     const int i_mask = 1 << i_button;
00142     return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
00143 }
00144 #endif /* _VLC_MOUSE_H */
00145 

Generated on Mon Nov 22 07:55:20 2010 for VLC by  doxygen 1.5.6