|
| 1 | +// Copyright (c) Amer Koleci and Contributors. |
| 2 | +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. |
| 3 | + |
| 4 | +using System.Diagnostics.CodeAnalysis; |
| 5 | +using System.Runtime.CompilerServices; |
| 6 | +using System.Runtime.InteropServices; |
| 7 | +using Alimer.Input; |
| 8 | + |
| 9 | +namespace Alimer; |
| 10 | + |
| 11 | +partial class AlimerApi |
| 12 | +{ |
| 13 | + #region Enums |
| 14 | + public enum EventType |
| 15 | + { |
| 16 | + Unknown = 0, |
| 17 | + Quit, |
| 18 | + Terminating, |
| 19 | + LowMemory, |
| 20 | + WillEnterBackground, |
| 21 | + DidEnterBackground, |
| 22 | + WillEnterForeground, |
| 23 | + DidEnterForeground, |
| 24 | + LocaleChanged, |
| 25 | + SystemThemeChanged, |
| 26 | + |
| 27 | + Window, |
| 28 | + KeyDown, |
| 29 | + KeyUp, |
| 30 | + TextInput, |
| 31 | + |
| 32 | + MouseMotion, |
| 33 | + MouseButtonDown, |
| 34 | + MouseButtonUp, |
| 35 | + MouseWheel, |
| 36 | + MouseAdded, |
| 37 | + MouseRemoved, |
| 38 | + |
| 39 | + ClipboardUpdate, |
| 40 | + |
| 41 | + Count, |
| 42 | + } |
| 43 | + |
| 44 | + public enum WindowEventType |
| 45 | + { |
| 46 | + None = 0, |
| 47 | + Shown, |
| 48 | + Hidden, |
| 49 | + Exposed, |
| 50 | + Moved, |
| 51 | + Resized, |
| 52 | + SizeChanged, |
| 53 | + Minimized, |
| 54 | + Maximized, |
| 55 | + Restored, |
| 56 | + Enter, |
| 57 | + Leave, |
| 58 | + FocusGained, |
| 59 | + FocusLost, |
| 60 | + CloseRequested, |
| 61 | + |
| 62 | + Count, |
| 63 | + } |
| 64 | + #endregion |
| 65 | + |
| 66 | + #region Structs |
| 67 | + public struct WindowIcon |
| 68 | + { |
| 69 | + public uint width; |
| 70 | + public uint height; |
| 71 | + public unsafe byte* data; |
| 72 | + } |
| 73 | + |
| 74 | + public struct WindowDesc |
| 75 | + { |
| 76 | + public unsafe byte* title; |
| 77 | + public uint width; |
| 78 | + public uint height; |
| 79 | + public WindowFlags flags; |
| 80 | + public WindowIcon icon; |
| 81 | + } |
| 82 | + |
| 83 | + public struct WindowEvent |
| 84 | + { |
| 85 | + public WindowEventType type; |
| 86 | + public uint windowID; |
| 87 | + public int data1; |
| 88 | + public int data2; |
| 89 | + } |
| 90 | + |
| 91 | + public struct KeyEvent |
| 92 | + { |
| 93 | + public uint windowID; |
| 94 | + public Keys key; |
| 95 | + public Bool8 alt; |
| 96 | + public Bool8 ctrl; |
| 97 | + public Bool8 shift; |
| 98 | + public Bool8 system; |
| 99 | + } |
| 100 | + |
| 101 | + public struct TextInputEvent |
| 102 | + { |
| 103 | + public uint windowID; |
| 104 | + public unsafe byte* text; |
| 105 | + } |
| 106 | + |
| 107 | + public struct MouseMotionEvent |
| 108 | + { |
| 109 | + public uint windowID; |
| 110 | + public float x; |
| 111 | + public float y; |
| 112 | + public float xRelative; |
| 113 | + public float yRelative; |
| 114 | + } |
| 115 | + |
| 116 | + public struct MouseButtonEvent |
| 117 | + { |
| 118 | + public uint windowID; |
| 119 | + public float x; |
| 120 | + public float y; |
| 121 | + public MouseButton button; |
| 122 | + } |
| 123 | + |
| 124 | + public struct MouseWheelEvent |
| 125 | + { |
| 126 | + public uint windowID; |
| 127 | + public float x; |
| 128 | + public float y; |
| 129 | + } |
| 130 | + |
| 131 | + public struct PlatformEvent |
| 132 | + { |
| 133 | + public EventType type; |
| 134 | + |
| 135 | + private Union _union; |
| 136 | + |
| 137 | + [UnscopedRef] |
| 138 | + public ref WindowEvent window |
| 139 | + { |
| 140 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 141 | + get => ref _union.window; |
| 142 | + } |
| 143 | + |
| 144 | + [UnscopedRef] |
| 145 | + public ref KeyEvent key |
| 146 | + { |
| 147 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 148 | + get => ref _union.key; |
| 149 | + } |
| 150 | + |
| 151 | + [UnscopedRef] |
| 152 | + public ref TextInputEvent text |
| 153 | + { |
| 154 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 155 | + get => ref _union.text; |
| 156 | + } |
| 157 | + |
| 158 | + [UnscopedRef] |
| 159 | + public ref MouseMotionEvent motion |
| 160 | + { |
| 161 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 162 | + get => ref _union.motion; |
| 163 | + } |
| 164 | + |
| 165 | + [UnscopedRef] |
| 166 | + public ref MouseButtonEvent button |
| 167 | + { |
| 168 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 169 | + get => ref _union.button; |
| 170 | + } |
| 171 | + |
| 172 | + [UnscopedRef] |
| 173 | + public ref MouseWheelEvent wheel |
| 174 | + { |
| 175 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 176 | + get => ref _union.wheel; |
| 177 | + } |
| 178 | + |
| 179 | + [StructLayout(LayoutKind.Explicit)] |
| 180 | + public partial struct Union |
| 181 | + { |
| 182 | + [FieldOffset(0)] |
| 183 | + public WindowEvent window; |
| 184 | + |
| 185 | + [FieldOffset(0)] |
| 186 | + public KeyEvent key; |
| 187 | + |
| 188 | + [FieldOffset(0)] |
| 189 | + public TextInputEvent text; |
| 190 | + |
| 191 | + [FieldOffset(0)] |
| 192 | + public MouseMotionEvent motion; |
| 193 | + |
| 194 | + [FieldOffset(0)] |
| 195 | + public MouseButtonEvent button; |
| 196 | + |
| 197 | + [FieldOffset(0)] |
| 198 | + public MouseWheelEvent wheel; |
| 199 | + } |
| 200 | + } |
| 201 | + #endregion |
| 202 | + |
| 203 | + [LibraryImport(LibraryName)] |
| 204 | + [return: MarshalAs(UnmanagedType.U1)] |
| 205 | + public static partial bool alimerPlatformInit(); |
| 206 | + [LibraryImport(LibraryName)] |
| 207 | + public static partial void alimerPlatformShutdown(); |
| 208 | + |
| 209 | + [LibraryImport(LibraryName)] |
| 210 | + [return: MarshalAs(UnmanagedType.U1)] |
| 211 | + public static unsafe partial bool alimerPlatformPollEvent(PlatformEvent* evt); |
| 212 | + |
| 213 | + #region Window |
| 214 | + [LibraryImport(LibraryName)] |
| 215 | + public static partial nint alimerWindowCreate(in WindowDesc desc); |
| 216 | + |
| 217 | + [LibraryImport(LibraryName)] |
| 218 | + public static partial void alimerWindowDestroy(nint window); |
| 219 | + [LibraryImport(LibraryName)] |
| 220 | + public static partial uint alimerWindowGetID(nint window); |
| 221 | + [LibraryImport(LibraryName)] |
| 222 | + [return: MarshalAs(UnmanagedType.U1)] |
| 223 | + public static partial bool alimerWindowIsOpen(nint window); |
| 224 | + [LibraryImport(LibraryName)] |
| 225 | + public static partial void alimerWindowSetPosition(nint window, int x, int y); |
| 226 | + [LibraryImport(LibraryName)] |
| 227 | + public static partial void alimerWindowGetPosition(nint window, out int x, out int y); |
| 228 | + [LibraryImport(LibraryName)] |
| 229 | + public static partial void alimerWindowSetCentered(nint window); |
| 230 | + [LibraryImport(LibraryName)] |
| 231 | + public static partial void alimerWindowSetSize(nint window, int width, int height); |
| 232 | + [LibraryImport(LibraryName)] |
| 233 | + public static partial void alimerWindowGetSize(nint window, out int width, out int height); |
| 234 | + [LibraryImport(LibraryName)] |
| 235 | + public static partial void alimerWindowGetSizeInPixels(nint window, out int width, out int height); |
| 236 | + [LibraryImport(LibraryName, StringMarshalling = StringMarshalling.Utf8)] |
| 237 | + public static partial void alimerWindowSetTitle(nint window, string title); |
| 238 | + [LibraryImport(LibraryName, StringMarshalling = StringMarshalling.Utf8)] |
| 239 | + public static partial string? alimerWindowGetTitle(nint window); |
| 240 | + |
| 241 | + [LibraryImport(LibraryName)] |
| 242 | + [return: MarshalAs(UnmanagedType.U1)] |
| 243 | + public static partial bool alimerWindowIsMinimized(nint window); |
| 244 | + |
| 245 | + [LibraryImport(LibraryName)] |
| 246 | + [return: MarshalAs(UnmanagedType.U1)] |
| 247 | + public static partial bool alimerWindowIsMaximized(nint window); |
| 248 | + |
| 249 | + [LibraryImport(LibraryName)] |
| 250 | + [return: MarshalAs(UnmanagedType.U1)] |
| 251 | + public static partial bool alimerWindowIsFullscreen(nint window); |
| 252 | + |
| 253 | + [LibraryImport(LibraryName)] |
| 254 | + public static partial void alimerWindowSetFullscreen(nint window, [MarshalAs(UnmanagedType.U1)] bool value); |
| 255 | + |
| 256 | + [LibraryImport(LibraryName)] |
| 257 | + [return: MarshalAs(UnmanagedType.U1)] |
| 258 | + public static partial bool alimerWindowHasFocus(nint window); |
| 259 | + [LibraryImport(LibraryName)] |
| 260 | + public static partial void alimerWindowShow(nint window); |
| 261 | + [LibraryImport(LibraryName)] |
| 262 | + public static partial void alimerWindowHide(nint window); |
| 263 | + [LibraryImport(LibraryName)] |
| 264 | + public static partial void alimerWindowMaximize(nint window); |
| 265 | + [LibraryImport(LibraryName)] |
| 266 | + public static partial void alimerWindowMinimize(nint window); |
| 267 | + [LibraryImport(LibraryName)] |
| 268 | + public static partial void alimerWindowRestore(nint window); |
| 269 | + [LibraryImport(LibraryName)] |
| 270 | + public static partial void alimerWindowFocus(nint window); |
| 271 | + |
| 272 | + [LibraryImport(LibraryName)] |
| 273 | + public static partial nint alimerGetWin32Window(nint window); |
| 274 | + |
| 275 | + [LibraryImport(LibraryName)] |
| 276 | + public static partial nint alimerGetCocoaWindow(nint window); |
| 277 | + [LibraryImport(LibraryName)] |
| 278 | + public static partial nint alimerGetWaylandDisplay(nint window); |
| 279 | + [LibraryImport(LibraryName)] |
| 280 | + public static partial nint alimerGetWaylandSurface(nint window); |
| 281 | + [LibraryImport(LibraryName)] |
| 282 | + public static partial nint alimerGetX11Display(nint window); |
| 283 | + [LibraryImport(LibraryName)] |
| 284 | + public static partial ulong alimerGetX11Window(nint window); |
| 285 | + #endregion |
| 286 | + |
| 287 | + #region Clipboard |
| 288 | + [LibraryImport(LibraryName)] |
| 289 | + [return: MarshalAs(UnmanagedType.U1)] |
| 290 | + public static partial bool alimerHasClipboardText(); |
| 291 | + |
| 292 | + [LibraryImport(LibraryName, StringMarshalling = StringMarshalling.Utf8)] |
| 293 | + public static partial void alimerClipboardSetText(string? text); |
| 294 | + |
| 295 | + [LibraryImport(LibraryName, StringMarshalling = StringMarshalling.Utf8)] |
| 296 | + public static partial string? alimerClipboardGetText(); |
| 297 | + #endregion |
| 298 | +} |
0 commit comments