1 
2 //          Copyright 2018 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.sdl.bind.sdlmouse;
8 
9 import bindbc.sdl.config;
10 import bindbc.sdl.bind.sdlstdinc : SDL_bool;
11 import bindbc.sdl.bind.sdlsurface : SDL_Surface;
12 import bindbc.sdl.bind.sdlvideo : SDL_Window;
13 
14 struct SDL_Cursor;
15 
16 enum SDL_SystemCursor {
17     SDL_SYSTEM_CURSOR_ARROW,
18     SDL_SYSTEM_CURSOR_IBEAM,
19     SDL_SYSTEM_CURSOR_WAIT,
20     SDL_SYSTEM_CURSOR_CROSSHAIR,
21     SDL_SYSTEM_CURSOR_WAITARROW,
22     SDL_SYSTEM_CURSOR_SIZENWSE,
23     SDL_SYSTEM_CURSOR_SIZENESW,
24     SDL_SYSTEM_CURSOR_SIZEWE,
25     SDL_SYSTEM_CURSOR_SIZENS,
26     SDL_SYSTEM_CURSOR_SIZEALL,
27     SDL_SYSTEM_CURSOR_NO,
28     SDL_SYSTEM_CURSOR_HAND,
29     SDL_NUM_SYSTEM_CURSORS
30 }
31 mixin(expandEnum!SDL_SystemCursor);
32 
33 enum SDL_BUTTON(ubyte x) = 1 << (x-1);
34 
35 enum : ubyte {
36     SDL_BUTTON_LEFT = 1,
37     SDL_BUTTON_MIDDLE = 2,
38     SDL_BUTTON_RIGHT = 3,
39     SDL_BUTTON_X1 = 4,
40     SDL_BUTTON_X2 = 5,
41     SDL_BUTTON_LMASK = SDL_BUTTON!(SDL_BUTTON_LEFT),
42     SDL_BUTTON_MMASK = SDL_BUTTON!(SDL_BUTTON_MIDDLE),
43     SDL_BUTTON_RMASK = SDL_BUTTON!(SDL_BUTTON_RIGHT),
44     SDL_BUTTON_X1MASK = SDL_BUTTON!(SDL_BUTTON_X1),
45     SDL_BUTTON_X2MASK = SDL_BUTTON!(SDL_BUTTON_X2),
46 }
47 
48 static if(sdlSupport >= SDLSupport.sdl204) {
49     enum SDL_MouseWheelDirection {
50         SDL_MOUSEWHEEL_NORMAL,
51         SDL_MOUSEWHEEL_FLIPPED,
52     }
53     mixin(expandEnum!SDL_MouseWheelDirection);
54 }
55 
56 static if(staticBinding) {
57     extern(C) @nogc nothrow {
58         SDL_Window* SDL_GetMouseFocus();
59         uint SDL_GetMouseState(int* x, int* y);
60         uint SDL_GetRelativeMouseState(int* x, int* y);
61         void SDL_WarpMouseInWindow(SDL_Window* window, int x, int y);
62         int SDL_SetRelativeMouseMode(SDL_bool enabled);
63         SDL_bool SDL_GetRelativeMouseMode();
64         SDL_Cursor* SDL_CreateCursor(const(ubyte)* data, const(ubyte)* mask, int w, int h, int hot_x, int hot_y);
65         SDL_Cursor* SDL_CreateColorCursor(SDL_Surface* surface, int hot_x, int hot_y);
66         SDL_Cursor* SDL_CreateSystemCursor(SDL_SystemCursor id);
67         void SDL_SetCursor(SDL_Cursor* cursor);
68         SDL_Cursor* SDL_GetCursor();
69         SDL_Cursor* SDL_GetDefaultCursor();
70         void SDL_FreeCursor(SDL_Cursor* cursor);
71         int SDL_ShowCursor(int toggle);
72 
73         static if(sdlSupport >= SDLSupport.sdl204) {
74             int SDL_CaptureMouse(SDL_bool enabled);
75             uint SDL_GetGlobalMouseState(int* x, int* y);
76             void SDL_WarpMouseGlobal(int x, int y);
77         }
78     }
79 }
80 else {
81     extern(C) @nogc nothrow {
82         alias pSDL_GetMouseFocus = SDL_Window* function();
83         alias pSDL_GetMouseState = uint function(int* x, int* y);
84         alias pSDL_GetRelativeMouseState = uint function(int* x, int* y);
85         alias pSDL_WarpMouseInWindow = void function(SDL_Window* window, int x, int y);
86         alias pSDL_SetRelativeMouseMode = int function(SDL_bool enabled);
87         alias pSDL_GetRelativeMouseMode = SDL_bool function();
88         alias pSDL_CreateCursor = SDL_Cursor* function(const(ubyte)* data, const(ubyte)* mask, int w, int h, int hot_x, int hot_y);
89         alias pSDL_CreateColorCursor = SDL_Cursor* function(SDL_Surface* surface, int hot_x, int hot_y);
90         alias pSDL_CreateSystemCursor = SDL_Cursor* function(SDL_SystemCursor id);
91         alias pSDL_SetCursor = void function(SDL_Cursor* cursor);
92         alias pSDL_GetCursor = SDL_Cursor* function();
93         alias pSDL_GetDefaultCursor = SDL_Cursor* function();
94         alias pSDL_FreeCursor = void function(SDL_Cursor* cursor);
95         alias pSDL_ShowCursor = int function(int toggle);
96     }
97 
98     __gshared {
99         pSDL_GetMouseFocus SDL_GetMouseFocus;
100         pSDL_GetMouseState SDL_GetMouseState;
101         pSDL_GetRelativeMouseState SDL_GetRelativeMouseState;
102         pSDL_WarpMouseInWindow SDL_WarpMouseInWindow;
103         pSDL_SetRelativeMouseMode SDL_SetRelativeMouseMode;
104         pSDL_GetRelativeMouseMode SDL_GetRelativeMouseMode;
105         pSDL_CreateCursor SDL_CreateCursor;
106         pSDL_CreateColorCursor SDL_CreateColorCursor;
107         pSDL_CreateSystemCursor SDL_CreateSystemCursor;
108         pSDL_SetCursor SDL_SetCursor;
109         pSDL_GetCursor SDL_GetCursor;
110         pSDL_GetDefaultCursor SDL_GetDefaultCursor;
111         pSDL_FreeCursor SDL_FreeCursor;
112         pSDL_ShowCursor SDL_ShowCursor;
113     }
114 
115     static if(sdlSupport >= SDLSupport.sdl204) {
116         extern(C) @nogc nothrow {
117             alias pSDL_CaptureMouse = int function(SDL_bool enabled);
118             alias pSDL_GetGlobalMouseState = uint function(int* x, int* y);
119             alias pSDL_WarpMouseGlobal = void function(int x, int y);
120         }
121 
122         __gshared {
123             pSDL_CaptureMouse SDL_CaptureMouse;
124             pSDL_GetGlobalMouseState SDL_GetGlobalMouseState;
125             pSDL_WarpMouseGlobal SDL_WarpMouseGlobal;
126         }
127     }
128 }