1 /+ 2 + Copyright 2022 – 2024 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.system; 9 10 import bindbc.sdl.config; 11 import bindbc.sdl.codegen; 12 13 import sdl.render; 14 import sdl.stdinc: SDL_bool; 15 import sdl.video; 16 17 version(Windows) version = Win32_GDK; 18 version(WinGDK) version = Win32_GDK; 19 20 version(Win32_GDK){ 21 static if(sdlSupport >= SDLSupport.v2_0_1): 22 struct IDirect3DDevice9; 23 24 static if(sdlSupport >= SDLSupport.v2_0_4): 25 alias SDL_WindowsMessageHook = extern(C) void function(void* userData, void* hWnd, uint message, ulong wParam, long lParam) nothrow; 26 27 static if(sdlSupport >= SDLSupport.v2_0_16): 28 struct ID3D11Device; 29 30 static if(sdlSupport >= SDLSupport.v2_24): 31 struct ID3D12Device; 32 } 33 version(Android){ 34 enum: int{ 35 SDL_ANDROID_EXTERNAL_STORAGE_READ = 0x01, 36 SDL_ANDROID_EXTERNAL_STORAGE_WRITE = 0x02, 37 } 38 } 39 version(WinRT){ 40 static if(sdlSupport >= SDLSupport.v2_0_3): 41 alias SDL_WinRT_Path = int; 42 enum: SDL_WinRT_Path{ 43 SDL_WINRT_PATH_INSTALLED_LOCATION, 44 SDL_WINRT_PATH_LOCAL_FOLDER, 45 SDL_WINRT_PATH_ROAMING_FOLDER, 46 SDL_WINRT_PATH_TEMP_FOLDER, 47 } 48 49 static if(sdlSupport >= SDLSupport.v2_0_8): 50 alias SDL_WinRT_DeviceFamily = int; 51 enum: SDL_WinRT_DeviceFamily{ 52 SDL_WINRT_DEVICEFAMILY_UNKNOWN, 53 SDL_WINRT_DEVICEFAMILY_DESKTOP, 54 SDL_WINRT_DEVICEFAMILY_MOBILE, 55 SDL_WINRT_DEVICEFAMILY_XBOX, 56 } 57 } 58 version(WinGDK){ 59 static if(sdlSupport >= SDLSupport.v2_24): 60 private struct XTaskQueueObject; 61 alias XTaskQueueHandle = XTaskQueueObject*; 62 private struct XUser; 63 alias XUserHandle = XUser*; 64 } 65 66 mixin(joinFnBinds((){ 67 FnBind[] ret; 68 if(sdlSupport >= SDLSupport.v2_0_9){ 69 FnBind[] add = [ 70 {q{SDL_bool}, q{SDL_IsTablet}, q{}}, 71 ]; 72 ret ~= add; 73 } 74 if(sdlSupport >= SDLSupport.v2_0_12){ 75 FnBind[] add = [ 76 {q{void}, q{SDL_OnApplicationWillTerminate}, q{}}, 77 {q{void}, q{SDL_OnApplicationDidReceiveMemoryWarning}, q{}}, 78 {q{void}, q{SDL_OnApplicationWillResignActive}, q{}}, 79 {q{void}, q{SDL_OnApplicationDidEnterBackground}, q{}}, 80 {q{void}, q{SDL_OnApplicationWillEnterForeground}, q{}}, 81 {q{void}, q{SDL_OnApplicationDidBecomeActive}, q{}}, 82 ]; 83 ret ~= add; 84 } 85 version(Win32_GDK){ 86 if(sdlSupport >= SDLSupport.v2_0_1){ 87 FnBind[] add = [ 88 {q{int}, q{SDL_Direct3D9GetAdapterIndex}, q{int displayIndex}}, 89 {q{IDirect3DDevice9*}, q{SDL_RenderGetD3D9Device}, q{SDL_Renderer* renderer}}, 90 ]; 91 ret ~= add; 92 } 93 if(sdlSupport >= SDLSupport.v2_0_2){ 94 FnBind[] add = [ 95 {q{SDL_bool}, q{SDL_DXGIGetOutputInfo}, q{int displayIndex, int* adapterIndex, int* outputIndex}}, 96 ]; 97 ret ~= add; 98 } 99 if(sdlSupport >= SDLSupport.v2_0_4){ 100 FnBind[] add = [ 101 {q{void}, q{SDL_SetWindowsMessageHook}, q{SDL_WindowsMessageHook callback, void* userData}}, 102 ]; 103 ret ~= add; 104 } 105 if(sdlSupport >= SDLSupport.v2_0_16){ 106 FnBind[] add = [ 107 {q{void}, q{SDL_RenderGetD3D11Device}, q{SDL_Renderer* renderer}}, 108 ]; 109 ret ~= add; 110 } 111 } 112 version(linux){ 113 if(sdlSupport >= SDLSupport.v2_0_9){ 114 FnBind[] add = [ 115 {q{int}, q{SDL_LinuxSetThreadPriority}, q{long threadID, int priority}}, 116 ]; 117 ret ~= add; 118 } 119 if(sdlSupport >= SDLSupport.v2_0_18){ 120 FnBind[] add = [ 121 {q{int}, q{SDL_LinuxSetThreadPriorityAndPolicy}, q{long threadID, int sdlPriority, int schedPolicy}}, 122 ]; 123 ret ~= add; 124 } 125 } 126 version(iOS){ 127 { 128 FnBind[] add = [ 129 {q{int}, q{SDL_iPhoneSetAnimationCallback}, q{SDL_Window* window, int interval, void function(void*) callback, void* callbackParam}}, 130 {q{void}, q{SDL_iPhoneSetEventPump}, q{SDL_bool enabled}}, 131 ]; 132 ret ~= add; 133 } 134 if(sdlSupport >= SDLSupport.v2_0_12){ 135 FnBind[] add = [ 136 {q{void}, q{SDL_OnApplicationDidChangeStatusBarOrientation}, q{}}, 137 ]; 138 ret ~= add; 139 } 140 } 141 version(Android){ 142 { 143 FnBind[] add = [ 144 {q{void*}, q{SDL_AndroidGetJNIEnv}, q{}}, 145 {q{void*}, q{SDL_AndroidGetActivity}, q{}}, 146 {q{const(char)*}, q{SDL_AndroidGetInternalStoragePath}, q{}}, 147 {q{int}, q{SDL_AndroidGetExternalStorageState}, q{}}, 148 {q{const(char)*}, q{SDL_AndroidGetExternalStoragePath}, q{}}, 149 ]; 150 ret ~= add; 151 } 152 if(sdlSupport >= SDLSupport.v2_0_8){ 153 FnBind[] add = [ 154 {q{SDL_bool}, q{SDL_IsAndroidTV}, q{}}, 155 ]; 156 ret ~= add; 157 } 158 if(sdlSupport >= SDLSupport.v2_0_9){ 159 FnBind[] add = [ 160 {q{SDL_bool}, q{SDL_IsChromebook}, q{}}, 161 {q{SDL_bool}, q{SDL_IsDeXMode}, q{}}, 162 {q{void}, q{SDL_AndroidBackButton}, q{}}, 163 ]; 164 ret ~= add; 165 } 166 if(sdlSupport >= SDLSupport.v2_0_12){ 167 FnBind[] add = [ 168 {q{int}, q{SDL_GetAndroidSDKVersion}, q{}}, 169 ]; 170 ret ~= add; 171 } 172 if(sdlSupport >= SDLSupport.v2_0_14){ 173 FnBind[] add = [ 174 {q{SDL_bool}, q{SDL_AndroidRequestPermission}, q{const(char)* permission}}, 175 ]; 176 ret ~= add; 177 } 178 if(sdlSupport >= SDLSupport.v2_0_16){ 179 FnBind[] add = [ 180 {q{int}, q{SDL_AndroidShowToast}, q{const(char)* message, int duration, int gravity, int xOffset, int yOffset}}, 181 ]; 182 ret ~= add; 183 } 184 if(sdlSupport >= SDLSupport.v2_0_22){ 185 FnBind[] add = [ 186 {q{int}, q{SDL_AndroidSendMessage}, q{uint command, int param}}, 187 ]; 188 ret ~= add; 189 } 190 } 191 version(WinRT){ 192 if(sdlSupport >= SDLSupport.v2_0_3){ 193 FnBind[] add = [ 194 {q{wchar_t*}, q{SDL_WinRTGetFSPathUNICODE}, q{SDL_WinRT_Path pathType}}, 195 {q{const(char)*}, q{SDL_WinRTGetFSPathUTF8}, q{SDL_WinRT_Path pathType}}, 196 ]; 197 ret ~= add; 198 } 199 if(sdlSupport >= SDLSupport.v2_0_8){ 200 FnBind[] add = [ 201 {q{SDL_WinRT_DeviceFamily}, q{SDL_WinRTGetDeviceFamily}, q{}}, 202 ]; 203 ret ~= add; 204 } 205 } 206 version(WinGDK){ 207 if(sdlSupport >= SDLSupport.v2_24){ 208 FnBind[] add = [ 209 {q{int}, q{SDL_GDKGetTaskQueue}, q{XTaskQueueHandle* outTaskQueue}}, 210 ]; 211 ret ~= add; 212 } 213 if(sdlSupport >= SDLSupport.v2_30){ 214 FnBind[] add = [ 215 {q{int}, q{SDL_GDKGetDefaultUser}, q{XUserHandle* outUserHandle}}, 216 ]; 217 ret ~= add; 218 } 219 } 220 return ret; 221 }())); 222 223 version(iOS){ 224 static if(sdlSupport >= SDLSupport.v2_0_4): 225 alias SDL_iOSSetAnimationCallback = SDL_iPhoneSetAnimationCallback; 226 alias SDL_iOSSetEventPump = SDL_iPhoneSetEventPump; 227 }