5
5
using System . Collections . Generic ;
6
6
using System . Diagnostics ;
7
7
using System . Drawing ;
8
+ using System . Threading ;
8
9
using osu . Framework . Bindables ;
9
10
using osu . Framework . Configuration ;
10
11
using osu . Framework . Extensions . EnumExtensions ;
@@ -151,11 +152,12 @@ private void enqueueJoystickButtonInput(JoystickButton button, bool isPressed)
151
152
152
153
private PointF previousPolledPoint = PointF . Empty ;
153
154
154
- private SDL_MouseButtonFlags pressedButtons ;
155
+ private volatile uint pressedButtons ;
155
156
156
157
private void pollMouse ( )
157
158
{
158
159
float x , y ;
160
+ var pressed = ( SDL_MouseButtonFlags ) pressedButtons ;
159
161
SDL_MouseButtonFlags globalButtons = SDL_GetGlobalMouseState ( & x , & y ) ;
160
162
161
163
if ( previousPolledPoint . X != x || previousPolledPoint . Y != y )
@@ -170,18 +172,18 @@ private void pollMouse()
170
172
}
171
173
172
174
// a button should be released if it was pressed and its current global state differs (its bit in globalButtons is set to 0)
173
- SDL_MouseButtonFlags buttonsToRelease = pressedButtons & ( globalButtons ^ pressedButtons ) ;
175
+ SDL_MouseButtonFlags buttonsToRelease = pressed & ( globalButtons ^ pressed ) ;
174
176
175
177
// the outer if just optimises for the common case that there are no buttons to release.
176
178
if ( buttonsToRelease != 0 )
177
179
{
180
+ Interlocked . And ( ref pressedButtons , ( uint ) ~ buttonsToRelease ) ;
181
+
178
182
if ( buttonsToRelease . HasFlagFast ( SDL_MouseButtonFlags . SDL_BUTTON_LMASK ) ) MouseUp ? . Invoke ( MouseButton . Left ) ;
179
183
if ( buttonsToRelease . HasFlagFast ( SDL_MouseButtonFlags . SDL_BUTTON_MMASK ) ) MouseUp ? . Invoke ( MouseButton . Middle ) ;
180
184
if ( buttonsToRelease . HasFlagFast ( SDL_MouseButtonFlags . SDL_BUTTON_RMASK ) ) MouseUp ? . Invoke ( MouseButton . Right ) ;
181
185
if ( buttonsToRelease . HasFlagFast ( SDL_MouseButtonFlags . SDL_BUTTON_X1MASK ) ) MouseUp ? . Invoke ( MouseButton . Button1 ) ;
182
186
if ( buttonsToRelease . HasFlagFast ( SDL_MouseButtonFlags . SDL_BUTTON_X2MASK ) ) MouseUp ? . Invoke ( MouseButton . Button2 ) ;
183
-
184
- pressedButtons &= ~ buttonsToRelease ;
185
187
}
186
188
}
187
189
@@ -465,12 +467,12 @@ private void handleMouseButtonEvent(SDL_MouseButtonEvent evtButton)
465
467
switch ( evtButton . type )
466
468
{
467
469
case SDL_EventType . SDL_EVENT_MOUSE_BUTTON_DOWN :
468
- pressedButtons |= mask ;
469
470
MouseDown ? . Invoke ( button ) ;
471
+ Interlocked . Or ( ref pressedButtons , ( uint ) mask ) ;
470
472
break ;
471
473
472
474
case SDL_EventType . SDL_EVENT_MOUSE_BUTTON_UP :
473
- pressedButtons &= ~ mask ;
475
+ Interlocked . And ( ref pressedButtons , ( uint ) ~ mask ) ;
474
476
MouseUp ? . Invoke ( button ) ;
475
477
break ;
476
478
}
0 commit comments