1 /+
2 +            Copyright 2022 – 2023 Aya Partridge
3 +          Copyright 2018 - 2022 Michael D. Parker
4 + Distributed under the Boost Software License, Version 1.0.
5 +     (See accompanying file LICENSE_1_0.txt or copy at
6 +           http://www.boost.org/LICENSE_1_0.txt)
7 +/
8 module sdl.mouse;
9 
10 import bindbc.sdl.config;
11 import bindbc.sdl.codegen;
12 
13 import sdl.stdinc: SDL_bool;
14 import sdl.surface: SDL_Surface;
15 import sdl.video: SDL_Window;
16 
17 struct SDL_Cursor;
18 
19 alias SDL_SystemCursor = uint;
20 enum: SDL_SystemCursor{
21 	SDL_SYSTEM_CURSOR_ARROW        = 0,
22 	SDL_SYSTEM_CURSOR_IBEAM        = 1,
23 	SDL_SYSTEM_CURSOR_WAIT         = 2,
24 	SDL_SYSTEM_CURSOR_CROSSHAIR    = 3,
25 	SDL_SYSTEM_CURSOR_WAITARROW    = 4,
26 	SDL_SYSTEM_CURSOR_SIZENWSE     = 5,
27 	SDL_SYSTEM_CURSOR_SIZENESW     = 6,
28 	SDL_SYSTEM_CURSOR_SIZEWE       = 7,
29 	SDL_SYSTEM_CURSOR_SIZENS       = 8,
30 	SDL_SYSTEM_CURSOR_SIZEALL      = 9,
31 	SDL_SYSTEM_CURSOR_NO           = 10,
32 	SDL_SYSTEM_CURSOR_HAND         = 11,
33 	SDL_NUM_SYSTEM_CURSORS         = 12,
34 }
35 
36 static if(sdlSupport >= SDLSupport.v2_0_4){
37 	alias SDL_MouseWheelDirection = uint;
38 	enum: SDL_MouseWheelDirection{
39 		SDL_MOUSEWHEEL_NORMAL   = 0,
40 		SDL_MOUSEWHEEL_FLIPPED  = 1,
41 	}
42 }
43 
44 pragma(inline, true) nothrow @nogc pure @safe{
45 	uint SDL_BUTTON(ubyte x){ return 1 << (x-1); }
46 }
47 deprecated("Please use the non-template version instead"){
48 	enum SDL_BUTTON(ubyte x) = 1 << (x-1);
49 }
50 enum: ubyte{
51 	SDL_BUTTON_LEFT      = 1,
52 	SDL_BUTTON_MIDDLE    = 2,
53 	SDL_BUTTON_RIGHT     = 3,
54 	SDL_BUTTON_X1        = 4,
55 	SDL_BUTTON_X2        = 5,
56 	SDL_BUTTON_LMASK     = SDL_BUTTON(SDL_BUTTON_LEFT),
57 	SDL_BUTTON_MMASK     = SDL_BUTTON(SDL_BUTTON_MIDDLE),
58 	SDL_BUTTON_RMASK     = SDL_BUTTON(SDL_BUTTON_RIGHT),
59 	SDL_BUTTON_X1MASK    = SDL_BUTTON(SDL_BUTTON_X1),
60 	SDL_BUTTON_X2MASK    = SDL_BUTTON(SDL_BUTTON_X2),
61 }
62 
63 mixin(joinFnBinds((){
64 	string[][] ret;
65 	ret ~= makeFnBinds([
66 		[q{SDL_Window*}, q{SDL_GetMouseFocus}, q{}],
67 		[q{uint}, q{SDL_GetMouseState}, q{int* x, int* y}],
68 		[q{uint}, q{SDL_GetRelativeMouseState}, q{int* x, int* y}],
69 		[q{void}, q{SDL_WarpMouseInWindow}, q{SDL_Window* window, int x, int y}],
70 		[q{int}, q{SDL_SetRelativeMouseMode}, q{SDL_bool enabled}],
71 		[q{SDL_bool}, q{SDL_GetRelativeMouseMode}, q{}],
72 		[q{SDL_Cursor*}, q{SDL_CreateCursor}, q{const(ubyte)* data, const(ubyte)* mask, int w, int h, int hot_x, int hot_y}],
73 		[q{SDL_Cursor*}, q{SDL_CreateColorCursor}, q{SDL_Surface* surface, int hot_x, int hot_y}],
74 		[q{SDL_Cursor*}, q{SDL_CreateSystemCursor}, q{SDL_SystemCursor id}],
75 		[q{void}, q{SDL_SetCursor}, q{SDL_Cursor* cursor}],
76 		[q{SDL_Cursor*}, q{SDL_GetCursor}, q{}],
77 		[q{SDL_Cursor*}, q{SDL_GetDefaultCursor}, q{}],
78 		[q{void}, q{SDL_FreeCursor}, q{SDL_Cursor* cursor}],
79 		[q{int}, q{SDL_ShowCursor}, q{int toggle}],
80 	]);
81 	static if(sdlSupport >= SDLSupport.v2_0_4){
82 		ret ~= makeFnBinds([
83 			[q{int}, q{SDL_CaptureMouse}, q{SDL_bool enabled}],
84 			[q{uint}, q{SDL_GetGlobalMouseState}, q{int* x, int* y}],
85 			[q{void}, q{SDL_WarpMouseGlobal}, q{int x, int y}],
86 		]);
87 	}
88 	return ret;
89 }()));
90 
91 alias SDL_CreateColourCursor = SDL_CreateColorCursor;