preliminary mouse support
This commit is contained in:
parent
5d0d9216de
commit
1571c54733
46
photon/mouse.py
Normal file
46
photon/mouse.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import ctypes
|
||||||
|
from .internal import _SDL, errcheck
|
||||||
|
from .enum import CEnum
|
||||||
|
|
||||||
|
def get_mouse_state():
|
||||||
|
x = ctypes.c_int()
|
||||||
|
y = ctypes.c_int()
|
||||||
|
buttons = _SDL.SDL_GetMouseState(ctypes.byref(x), ctypes.byref(y))
|
||||||
|
return x.value, y.value, buttons
|
||||||
|
|
||||||
|
def get_relative_mouse_state():
|
||||||
|
x = ctypes.c_int()
|
||||||
|
y = ctypes.c_int()
|
||||||
|
buttons = _SDL.SDL_GetRelativeMouseState(ctypes.byref(x), ctypes.byref(y))
|
||||||
|
return x.value, y.value, buttons
|
||||||
|
|
||||||
|
def get_relative_mouse_mode():
|
||||||
|
return _SDL.SDL_GetRelativeMouseMode() == 1
|
||||||
|
|
||||||
|
def set_relative_mouse_mode(enabled):
|
||||||
|
errcheck(_SDL.SDL_SetRelativeMouseMode(enabled))
|
||||||
|
|
||||||
|
def set_cursor_visibility(visible):
|
||||||
|
errcheck(_SDL.SDL_ShowCursor(visible))
|
||||||
|
|
||||||
|
def is_cursor_visible():
|
||||||
|
return errcheck(_SDL.SDL_ShowCursor(-1)) == 1
|
||||||
|
|
||||||
|
def warp_mouse_in_window(x, y, window=0):
|
||||||
|
if window:
|
||||||
|
window = window._handle
|
||||||
|
_SDL.SDL_WarpMouseInWindow(window, x, y)
|
||||||
|
|
||||||
|
class Button(CEnum):
|
||||||
|
LEFT = 1
|
||||||
|
MIDDLE = 2
|
||||||
|
RIGHT = 3
|
||||||
|
X1 = 4
|
||||||
|
X2 = 5
|
||||||
|
|
||||||
|
# masks for comparison against get_mouse_state return values
|
||||||
|
LMASK = 1
|
||||||
|
MMASK = 2
|
||||||
|
RMASK = 4
|
||||||
|
X1MASK = 8
|
||||||
|
X2MASK = 16
|
27
photon/tests/test_mouse.py
Normal file
27
photon/tests/test_mouse.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from .. import init, InitFlags
|
||||||
|
from ..internal import SDLError
|
||||||
|
from ..mouse import (get_relative_mouse_mode, set_relative_mouse_mode,
|
||||||
|
set_cursor_visibility, is_cursor_visible)
|
||||||
|
from nose.tools import with_setup
|
||||||
|
|
||||||
|
def init_everything():
|
||||||
|
init(InitFlags.EVERYTHING)
|
||||||
|
|
||||||
|
@with_setup(init_everything)
|
||||||
|
def test_relative_mouse_mode():
|
||||||
|
try:
|
||||||
|
set_relative_mouse_mode(True)
|
||||||
|
assert get_relative_mouse_mode() == True
|
||||||
|
set_relative_mouse_mode(False)
|
||||||
|
assert get_relative_mouse_mode() == False
|
||||||
|
except SDLError:
|
||||||
|
pass # sometimes this method isn't supported
|
||||||
|
|
||||||
|
@with_setup(init_everything)
|
||||||
|
def test_cursor_visiblity():
|
||||||
|
assert is_cursor_visible() == True
|
||||||
|
set_cursor_visibility(False)
|
||||||
|
assert is_cursor_visible() == False
|
||||||
|
set_cursor_visibility(True)
|
||||||
|
assert is_cursor_visible() == True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user