VLC 4.0.0-dev
Loading...
Searching...
No Matches
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 */
41/**
42 * Mouse state
43 */
44typedef 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 /* Has filter listening to mouse events */
54 bool b_mouse_filter;
57/**
58 * Mouse event callback
59 * @param mouse new mouse event to process, can be NULL for an invalidate state
60 * (a new vout is created or restarted).
61 * @param user_data
62 */
63typedef void (*vlc_mouse_event)(const vlc_mouse_t *mouse, void *user_data);
65static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
67 p_mouse->i_x = 0;
68 p_mouse->i_y = 0;
69 p_mouse->i_pressed = 0;
70 p_mouse->b_double_click = false;
71 p_mouse->b_mouse_filter = false;
72}
73
74/* */
75static inline void vlc_mouse_SetPressed( vlc_mouse_t *p_mouse,
76 int i_button )
77{
78 p_mouse->i_pressed |= 1 << i_button;
79}
80static inline void vlc_mouse_SetReleased( vlc_mouse_t *p_mouse,
81 int i_button )
82{
83 p_mouse->i_pressed &= ~(1 << i_button);
84}
85static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
86 int i_x, int i_y )
87{
88 p_mouse->i_x = i_x;
89 p_mouse->i_y = i_y;
90}
91
92static inline void vlc_mouse_SetMouseFilter( vlc_mouse_t *p_mouse,
93 bool mouse_filter )
94{
95 p_mouse->b_mouse_filter = mouse_filter;
96}
97
98/* */
99static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
100 int i_button )
101{
102 return ( p_mouse->i_pressed & (1 << i_button) ) != 0;
103}
104static inline bool vlc_mouse_IsLeftPressed( const vlc_mouse_t *p_mouse )
106 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_LEFT );
107}
108static inline bool vlc_mouse_IsCenterPressed( const vlc_mouse_t *p_mouse )
110 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_CENTER );
111}
112static inline bool vlc_mouse_IsRightPressed( const vlc_mouse_t *p_mouse )
114 return vlc_mouse_IsPressed( p_mouse, MOUSE_BUTTON_RIGHT );
115}
116static inline bool vlc_mouse_IsWheelUpPressed( const vlc_mouse_t *p_mouse )
119}
120static inline bool vlc_mouse_IsWheelDownPressed( const vlc_mouse_t *p_mouse )
123}
124static inline void vlc_mouse_GetMotion( int *pi_x, int *pi_y,
125 const vlc_mouse_t *p_old,
126 const vlc_mouse_t *p_new )
127{
128 *pi_x = p_new->i_x - p_old->i_x;
129 *pi_y = p_new->i_y - p_old->i_y;
130}
131
132/* */
133static inline bool vlc_mouse_HasChanged( const vlc_mouse_t *p_old,
134 const vlc_mouse_t *p_new )
135{
136 return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y ||
137 p_old->i_pressed != p_new->i_pressed;
138}
139static inline bool vlc_mouse_HasMoved( const vlc_mouse_t *p_old,
140 const vlc_mouse_t *p_new )
141{
142 return p_old->i_x != p_new->i_x || p_old->i_y != p_new->i_y;
143}
144static inline bool vlc_mouse_HasButton( const vlc_mouse_t *p_old,
145 const vlc_mouse_t *p_new )
146{
147 return p_old->i_pressed != p_new->i_pressed;
148}
149static inline bool vlc_mouse_HasPressed( const vlc_mouse_t *p_old,
150 const vlc_mouse_t *p_new,
151 int i_button )
152{
153 const int i_mask = 1 << i_button;
154 return (p_old->i_pressed & i_mask) == 0 && (p_new->i_pressed & i_mask);
155}
156static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
157 const vlc_mouse_t *p_new,
158 int i_button )
159{
160 const int i_mask = 1 << i_button;
161 return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
162}
163static inline bool vlc_mouse_HasMouseFilter( const vlc_mouse_t *p_mouse )
165 return p_mouse->b_mouse_filter;
166}
167#endif /* _VLC_MOUSE_H */
168
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
bool b_mouse_filter
Definition vlc_mouse.h:55
This file is a collection of common definitions and types.
static void vlc_mouse_SetReleased(vlc_mouse_t *p_mouse, int i_button)
Definition vlc_mouse.h:81
static bool vlc_mouse_IsWheelDownPressed(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:121
static bool vlc_mouse_IsRightPressed(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:113
static bool vlc_mouse_IsLeftPressed(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:105
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 bool vlc_mouse_HasMouseFilter(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:164
static void vlc_mouse_Init(vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:66
static bool vlc_mouse_IsPressed(const vlc_mouse_t *p_mouse, int i_button)
Definition vlc_mouse.h:100
static bool vlc_mouse_IsCenterPressed(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:109
static bool vlc_mouse_HasReleased(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new, int i_button)
Definition vlc_mouse.h:157
static bool vlc_mouse_HasPressed(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new, int i_button)
Definition vlc_mouse.h:150
static bool vlc_mouse_IsWheelUpPressed(const vlc_mouse_t *p_mouse)
Definition vlc_mouse.h:117
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:125
void(* vlc_mouse_event)(const vlc_mouse_t *mouse, void *user_data)
Mouse event callback.
Definition vlc_mouse.h:64
static bool vlc_mouse_HasButton(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition vlc_mouse.h:145
static void vlc_mouse_SetPressed(vlc_mouse_t *p_mouse, int i_button)
Definition vlc_mouse.h:76
static bool vlc_mouse_HasChanged(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition vlc_mouse.h:134
static void vlc_mouse_SetPosition(vlc_mouse_t *p_mouse, int i_x, int i_y)
Definition vlc_mouse.h:86
static void vlc_mouse_SetMouseFilter(vlc_mouse_t *p_mouse, bool mouse_filter)
Definition vlc_mouse.h:93
static bool vlc_mouse_HasMoved(const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
Definition vlc_mouse.h:140