VLC  4.0.0-dev
vlc_mouse.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_mouse.h: mouse related structures and functions
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  *
6  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7  *
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.
12  *
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.
17  *
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  *****************************************************************************/
22 
23 #ifndef _VLC_MOUSE_H
24 #define _VLC_MOUSE_H 1
25 
26 /**
27  * Mouse buttons
28  */
30 {
39 };
40 
41 /**
42  * Mouse state
43  */
44 typedef struct vlc_mouse_t
45 {
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;
54 
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
60  */
61 typedef void (*vlc_mouse_event)(const vlc_mouse_t *mouse, void *user_data);
62 
63 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
64 {
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;
69 }
70 
71 /* */
72 static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
73  int i_button )
74 {
75  p_mouse->i_pressed |= 1 << i_button;
76 }
77 static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
78  int i_button )
79 {
80  p_mouse->i_pressed &= ~(1 << i_button);
81 }
82 static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
83  int i_x, int i_y )
84 {
85  p_mouse->i_x = i_x;
86  p_mouse->i_y = i_y;
87 }
88 
89 /* */
90 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
91  int i_button )
92 {
93  return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
94 }
95 static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
96 {
97  return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
98 }
99 static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
100 {
101  return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
102 }
103 static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
104 {
105  return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
106 }
107 static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
108 {
109  return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_UP );
110 }
111 static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
112 {
113  return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_WHEEL_DOWN );
114 }
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 )
118 {
119  *pi_x = p_new->i_x - p_old->i_x;
120  *pi_y = p_new->i_y - p_old->i_y;
121 }
122 
123 /* */
124 static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
125  const vlc_mouse_t *p_new )
126 {
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;
129 }
130 static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
131  const vlc_mouse_t *p_new )
132 {
133  return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
134 }
135 static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
136  const vlc_mouse_t *p_new )
137 {
138  return p_old->i_pressed != p_new->i_pressed;
139 }
140 static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
141  const vlc_mouse_t *p_new,
142  int i_button )
143 {
144  const int i_mask = 1 << i_button;
145  return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
146 }
147 static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
148  const vlc_mouse_t *p_new,
149  int i_button )
150 {
151  const int i_mask = 1 << i_button;
152  return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
153 }
154 #endif /* _VLC_MOUSE_H */
155 
Mouse state.
Definition: vlc_mouse.h:46
bool b_double_click
Definition: vlc_mouse.h:53
int i_pressed
Definition: vlc_mouse.h:51
int i_x
Definition: vlc_mouse.h:48
int i_y
Definition: vlc_mouse.h:49
struct vlc_mouse_t vlc_mouse_t
Mouse state.
static void vlc_mouse_SetReleased(vlc_mouse_t *p_mouse, int i_button)
Definition: vlc_mouse.h:78
static bool vlc_mouse_IsWheelDownPressed(const vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:112
static bool vlc_mouse_IsRightPressed(const vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:104
static bool vlc_mouse_IsLeftPressed(const vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:96
vlc_mouse_button
Mouse buttons.
Definition: vlc_mouse.h:31
@ MOUSE_BUTTON_LEFT
Definition: vlc_mouse.h:32
@ MOUSE_BUTTON_WHEEL_LEFT
Definition: vlc_mouse.h:37
@ MOUSE_BUTTON_WHEEL_UP
Definition: vlc_mouse.h:35
@ MOUSE_BUTTON_RIGHT
Definition: vlc_mouse.h:34
@ MOUSE_BUTTON_WHEEL_DOWN
Definition: vlc_mouse.h:36
@ MOUSE_BUTTON_WHEEL_RIGHT
Definition: vlc_mouse.h:38
@ MOUSE_BUTTON_CENTER
Definition: vlc_mouse.h:33
@ MOUSE_BUTTON_MAX
Definition: vlc_mouse.h:39
static void vlc_mouse_Init(vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:64
static bool vlc_mouse_IsPressed(const vlc_mouse_t *p_mouse, int i_button)
Definition: vlc_mouse.h:91
static bool vlc_mouse_IsCenterPressed(const vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:100
static bool vlc_mouse_HasReleased(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new, int i_button)
Definition: vlc_mouse.h:148
static bool vlc_mouse_HasPressed(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new, int i_button)
Definition: vlc_mouse.h:141
static bool vlc_mouse_IsWheelUpPressed(const vlc_mouse_t *p_mouse)
Definition: vlc_mouse.h:108
static void vlc_mouse_GetMotion(int *pi_x, int *pi_y, const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition: vlc_mouse.h:116
void(* vlc_mouse_event)(const vlc_mouse_t *mouse, void *user_data)
Mouse event callback.
Definition: vlc_mouse.h:62
static bool vlc_mouse_HasButton(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition: vlc_mouse.h:136
static void vlc_mouse_SetPressed(vlc_mouse_t *p_mouse, int i_button)
Definition: vlc_mouse.h:73
static bool vlc_mouse_HasChanged(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition: vlc_mouse.h:125
static void vlc_mouse_SetPosition(vlc_mouse_t *p_mouse, int i_x, int i_y)
Definition: vlc_mouse.h:83
static bool vlc_mouse_HasMoved(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition: vlc_mouse.h:131