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: b48853570a09ad1d77cc95cda0c5b04b5028ee80 $
00006  *
00007  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * 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 buttons
00029  */
00030 enum
00031 {
00032     MOUSE_BUTTON_LEFT=0,
00033     MOUSE_BUTTON_CENTER,
00034     MOUSE_BUTTON_RIGHT,
00035     MOUSE_BUTTON_WHEEL_UP,
00036     MOUSE_BUTTON_WHEEL_DOWN,
00037     MOUSE_BUTTON_WHEEL_LEFT,
00038     MOUSE_BUTTON_WHEEL_RIGHT,
00039     MOUSE_BUTTON_MAX
00040 };
00041 
00042 /**
00043  * Mouse state
00044  */
00045 typedef struct
00046 {
00047     /* Coordinate */
00048     int i_x;
00049     int i_y;
00050     /* Mask of pressed button */
00051     int i_pressed;
00052     /* Is double clicked */
00053     bool b_double_click;
00054 } vlc_mouse_t;
00055 
00056 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
00057 {
00058     p_mouse->i_x = 0;
00059     p_mouse->i_y = 0;
00060     p_mouse->i_pressed = 0;
00061     p_mouse->b_double_click = false;
00062 }
00063 
00064 /* */
00065 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
00066                                          int i_button )
00067 {
00068     p_mouse->i_pressed |= 1 << i_button;
00069 }
00070 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
00071                                           int i_button )
00072 {
00073     p_mouse->i_pressed &= ~(1 << i_button);
00074 }
00075 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
00076                                           int i_x, int i_y )
00077 {
00078     p_mouse->i_x = i_x;
00079     p_mouse->i_y = i_y;
00080 }
00081 
00082 /* */
00083 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
00084                                         int i_button )
00085 {
00086     return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
00087 }
00088 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
00089 {
00090     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
00091 }
00092 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
00093 {
00094     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
00095 }
00096 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
00097 {
00098     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
00099 }
00100 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
00101 {
00102     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_UP );
00103 }
00104 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
00105 {
00106     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_DOWN );
00107 }
00108 static inline void vlc_mouse_GetMotion( int *pi_x, int *pi_y,
00109                                         const vlc_mouse_t *p_old,
00110                                         const vlc_mouse_t *p_new )
00111 {
00112     *pi_x = p_new->i_x - p_old->i_x;
00113     *pi_y = p_new->i_y - p_old->i_y;
00114 }
00115 
00116 /* */
00117 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
00118                                          const vlc_mouse_t *p_new )
00119 {
00120     return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y ||
00121            p_old->i_pressed != p_new->i_pressed;
00122 }
00123 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
00124                                        const vlc_mouse_t *p_new )
00125 {
00126     return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
00127 }
00128 static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
00129                                         const vlc_mouse_t *p_new )
00130 {
00131     return p_old->i_pressed != p_new->i_pressed;
00132 }
00133 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
00134                                          const vlc_mouse_t *p_new,
00135                                          int i_button )
00136 {
00137     const int i_mask = 1 << i_button;
00138     return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
00139 }
00140 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
00141                                           const vlc_mouse_t *p_new,
00142                                           int i_button )
00143 {
00144     const int i_mask = 1 << i_button;
00145     return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
00146 }
00147 #endif /* _VLC_MOUSE_H */
00148 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines