1 /*****************************************************************************
2 * vlc_mouse.h: mouse related structures and functions
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
24 #define _VLC_MOUSE_H 1
34 MOUSE_BUTTON_WHEEL_UP
,
35 MOUSE_BUTTON_WHEEL_DOWN
,
36 MOUSE_BUTTON_WHEEL_LEFT
,
37 MOUSE_BUTTON_WHEEL_RIGHT
,
44 typedef struct vlc_mouse_t
49 /* Mask of pressed button */
51 /* Is double clicked */
56 * Mouse event callback
57 * @param mouse new mouse event to process, can be NULL for an invalidate state
58 * (a new vout is created or restarted).
61 typedef void (*vlc_mouse_event
)(const vlc_mouse_t
*mouse
, void *user_data
);
63 static inline void vlc_mouse_Init( vlc_mouse_t
*p_mouse
)
67 p_mouse
->i_pressed
= 0;
68 p_mouse
->b_double_click
= false;
72 static inline void vlc_mouse_SetPressed( vlc_mouse_t
*p_mouse
,
75 p_mouse
->i_pressed
|= 1 << i_button
;
77 static inline void vlc_mouse_SetReleased( vlc_mouse_t
*p_mouse
,
80 p_mouse
->i_pressed
&= ~(1 << i_button
);
82 static inline void vlc_mouse_SetPosition( vlc_mouse_t
*p_mouse
,
90 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t
*p_mouse
,
93 return ( p_mouse
->i_pressed
& (1 << i_button
) ) != 0;
95 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t
*p_mouse
)
97 return vlc_mouse_IsPressed( p_mouse
, MOUSE_BUTTON_LEFT
);
99 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t
*p_mouse
)
101 return vlc_mouse_IsPressed( p_mouse
, MOUSE_BUTTON_CENTER
);
103 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t
*p_mouse
)
105 return vlc_mouse_IsPressed( p_mouse
, MOUSE_BUTTON_RIGHT
);
107 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t
*p_mouse
)
109 return vlc_mouse_IsPressed( p_mouse
, MOUSE_BUTTON_WHEEL_UP
);
111 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t
*p_mouse
)
113 return vlc_mouse_IsPressed( p_mouse
, MOUSE_BUTTON_WHEEL_DOWN
);
115 static inline void vlc_mouse_GetMotion( int *pi_x
, int *pi_y
,
116 const vlc_mouse_t
*p_old
,
117 const vlc_mouse_t
*p_new
)
119 *pi_x
= p_new
->i_x
- p_old
->i_x
;
120 *pi_y
= p_new
->i_y
- p_old
->i_y
;
124 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t
*p_old
,
125 const vlc_mouse_t
*p_new
)
127 return p_old
->i_x
!= p_new
->i_x
|| p_old
->i_y
!= p_new
->i_y
||
128 p_old
->i_pressed
!= p_new
->i_pressed
;
130 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t
*p_old
,
131 const vlc_mouse_t
*p_new
)
133 return p_old
->i_x
!= p_new
->i_x
|| p_old
->i_y
!= p_new
->i_y
;
135 static inline bool vlc_mouse_HasButton( const vlc_mouse_t
*p_old
,
136 const vlc_mouse_t
*p_new
)
138 return p_old
->i_pressed
!= p_new
->i_pressed
;
140 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t
*p_old
,
141 const vlc_mouse_t
*p_new
,
144 const int i_mask
= 1 << i_button
;
145 return (p_old
->i_pressed
& i_mask
) == 0 && (p_new
->i_pressed
& i_mask
);
147 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t
*p_old
,
148 const vlc_mouse_t
*p_new
,
151 const int i_mask
= 1 << i_button
;
152 return (p_old
->i_pressed
& i_mask
) && (p_new
->i_pressed
& i_mask
) == 0;
154 #endif /* _VLC_MOUSE_H */