]> git.sesse.net Git - vlc/blob - include/vlc_mouse.h
Merge branch 'master' into lpcm_encoder
[vlc] / include / vlc_mouse.h
1 /*****************************************************************************
2  * vlc_mouse.h: mouse related structures and functions
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_MOUSE_H
25 #define _VLC_MOUSE_H 1
26
27 /**
28  * Mouse button
29  */
30 enum
31 {
32         MOUSE_BUTTON_LEFT,
33         MOUSE_BUTTON_CENTER,
34         MOUSE_BUTTON_RIGHT,
35         MOUSE_BUTTON_WHEEL_UP,
36         MOUSE_BUTTON_WHEEL_DOWN,
37 };
38
39 /**
40  * Mouse state
41  */
42 typedef struct
43 {
44     /* Coordinate */
45     int i_x;
46     int i_y;
47     /* Mask of pressed button */
48     int i_pressed;
49     /* Is double clicked */
50     bool b_double_click;
51 } vlc_mouse_t;
52
53 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
54 {
55     p_mouse->i_x = 0;
56     p_mouse->i_y = 0;
57     p_mouse->i_pressed = 0;
58     p_mouse->b_double_click = false;
59 }
60
61 /* */
62 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
63                                          int i_button )
64 {
65     p_mouse->i_pressed |= 1 << i_button;
66 }
67 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
68                                           int i_button )
69 {
70     p_mouse->i_pressed &= ~(1 << i_button);
71 }
72 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
73                                           int i_x, int i_y )
74 {
75     p_mouse->i_x = i_x;
76     p_mouse->i_y = i_y;
77 }
78
79 /* */
80 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
81                                         int i_button )
82 {
83     return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
84 }
85 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
86 {
87     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
88 }
89 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
90 {
91     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
92 }
93 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
94 {
95     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
96 }
97 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
98 {
99     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_UP );
100 }
101 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
102 {
103     return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_DOWN );
104 }
105 static inline void vlc_mouse_GetMotion( int *pi_x, int *pi_y,
106                                         const vlc_mouse_t *p_old,
107                                         const vlc_mouse_t *p_new )
108 {
109     *pi_x = p_new->i_x - p_old->i_x;
110     *pi_y = p_new->i_y - p_old->i_y;
111 }
112
113 /* */
114 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
115                                          const vlc_mouse_t *p_new )
116 {
117     return p_old->i_x != p_new->i_x || p_old->i_x != p_new->i_x ||
118            p_old->i_pressed != p_new->i_pressed;
119 }
120 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
121                                        const vlc_mouse_t *p_new )
122 {
123     return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
124 }
125 static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
126                                         const vlc_mouse_t *p_new )
127 {
128     return p_old->i_pressed != p_new->i_pressed;
129 }
130 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
131                                          const vlc_mouse_t *p_new,
132                                          int i_button )
133 {
134     const int i_mask = 1 << i_button;
135     return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
136 }
137 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
138                                           const vlc_mouse_t *p_new,
139                                           int i_button )
140 {
141     const int i_mask = 1 << i_button;
142     return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
143 }
144 #endif /* _VLC_MOUSE_H */
145