input: add input_SetProgramId
[vlc.git] / include / vlc_mouse.h
blob870f27ffb521167acadca872e1bf7661c3a7026f
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 *****************************************************************************/
23 #ifndef _VLC_MOUSE_H
24 #define _VLC_MOUSE_H 1
26 /**
27 * Mouse buttons
29 enum vlc_mouse_button
31 MOUSE_BUTTON_LEFT=0,
32 MOUSE_BUTTON_CENTER,
33 MOUSE_BUTTON_RIGHT,
34 MOUSE_BUTTON_WHEEL_UP,
35 MOUSE_BUTTON_WHEEL_DOWN,
36 MOUSE_BUTTON_WHEEL_LEFT,
37 MOUSE_BUTTON_WHEEL_RIGHT,
38 MOUSE_BUTTON_MAX
41 /**
42 * Mouse state
44 typedef struct vlc_mouse_t
46 /* Coordinate */
47 int i_x;
48 int i_y;
49 /* Mask of pressed button */
50 int i_pressed;
51 /* Is double clicked */
52 bool b_double_click;
53 } vlc_mouse_t;
55 /**
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).
59 * @param user_data
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 )
65 p_mouse->i_x = 0;
66 p_mouse->i_y = 0;
67 p_mouse->i_pressed = 0;
68 p_mouse->b_double_click = false;
71 /* */
72 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
73 int i_button )
75 p_mouse->i_pressed |= 1 << i_button;
77 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
78 int i_button )
80 p_mouse->i_pressed &= ~(1 << i_button);
82 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
83 int i_x, int i_y )
85 p_mouse->i_x = i_x;
86 p_mouse->i_y = i_y;
89 /* */
90 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
91 int i_button )
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;
123 /* */
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,
142 int i_button )
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,
149 int i_button )
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 */