1 /*****************************************************************************
2 * vlc_mouse.h: mouse related structures and functions
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #define _VLC_MOUSE_H 1
35 MOUSE_BUTTON_WHEEL_UP,
36 MOUSE_BUTTON_WHEEL_DOWN,
37 MOUSE_BUTTON_WHEEL_LEFT,
38 MOUSE_BUTTON_WHEEL_RIGHT,
52 /* Mask of pressed button */
54 /* Is double clicked */
58 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
62 p_mouse->i_pressed = 0;
63 p_mouse->b_double_click = false;
67 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
70 p_mouse->i_pressed |= 1 << i_button;
72 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
75 p_mouse->i_pressed &= ~(1 << i_button);
77 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
85 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
88 return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
90 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
92 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
94 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
96 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
98 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
100 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
102 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
104 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_UP );
106 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
108 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_DOWN );
110 static inline void vlc_mouse_GetMotion( int *pi_x, int *pi_y,
111 const vlc_mouse_t *p_old,
112 const vlc_mouse_t *p_new )
114 *pi_x = p_new->i_x - p_old->i_x;
115 *pi_y = p_new->i_y - p_old->i_y;
119 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
120 const vlc_mouse_t *p_new )
122 return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y ||
123 p_old->i_pressed != p_new->i_pressed;
125 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
126 const vlc_mouse_t *p_new )
128 return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
130 static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
131 const vlc_mouse_t *p_new )
133 return p_old->i_pressed != p_new->i_pressed;
135 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
136 const vlc_mouse_t *p_new,
139 const int i_mask = 1 << i_button;
140 return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
142 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
143 const vlc_mouse_t *p_new,
146 const int i_mask = 1 << i_button;
147 return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
149 #endif /* _VLC_MOUSE_H */