├── .gitignore ├── LICENSE-MIT.txt ├── LICENSE-NCSA.txt ├── LICENSE-Zlib.txt ├── Makefile ├── README.md ├── config.nims ├── examples ├── checkerboard.nim ├── config.nims ├── displays.nim ├── draw.nim ├── joysticks.nim ├── randomlines.nim ├── randompixels.nim ├── randomrects.nim ├── touchdevices.nim └── version.nim ├── nsdl3.nimble ├── src ├── nsdl3.nim └── nsdl3 │ ├── config.nim │ ├── extra │ ├── desktop.nim │ └── messagebox.nim │ ├── libsdl3.nim │ ├── sdl3inc │ ├── sdl3audio.nim │ ├── sdl3blendmode.nim │ ├── sdl3camera.nim │ ├── sdl3clipboard.nim │ ├── sdl3dialog.nim │ ├── sdl3events.nim │ ├── sdl3filesystem.nim │ ├── sdl3gamepad.nim │ ├── sdl3hints.nim │ ├── sdl3init.nim │ ├── sdl3iostream.nim │ ├── sdl3joystick.nim │ ├── sdl3keyboard.nim │ ├── sdl3keycode.nim │ ├── sdl3log.nim │ ├── sdl3main.nim │ ├── sdl3messagebox.nim │ ├── sdl3mouse.nim │ ├── sdl3pen.nim │ ├── sdl3pixels.nim │ ├── sdl3power.nim │ ├── sdl3properties.nim │ ├── sdl3rect.nim │ ├── sdl3render.nim │ ├── sdl3scancode.nim │ ├── sdl3sensor.nim │ ├── sdl3storage.nim │ ├── sdl3surface.nim │ ├── sdl3timer.nim │ ├── sdl3touch.nim │ ├── sdl3video.nim │ └── sdl3video_capture.nim │ └── utils.nim └── tests ├── config.nims ├── test_libsdl3.nim └── test_nsdl3.nim /.gitignore: -------------------------------------------------------------------------------- 1 | # Doc. 2 | htmldocs/ 3 | 4 | # Source. 5 | src/**/*.js 6 | 7 | # Examples. 8 | examples/** 9 | !examples/**/config.nims 10 | !examples/**/*.nim 11 | !examples/config.nims 12 | !examples/*.nim 13 | 14 | # Tests. 15 | tests/**/test_* 16 | !tests/**/test_*.nim 17 | !tests/**/test_*.nims 18 | 19 | # Testament. 20 | nimcache/ 21 | testresults/ 22 | outputExpected.txt 23 | outputGotten.txt 24 | testresults.html 25 | tests/megatest 26 | tests/megatest.nim 27 | 28 | # Temp. 29 | *~ 30 | tmp/ 31 | 32 | # vim: set sts=2 et sw=2: 33 | -------------------------------------------------------------------------------- /LICENSE-MIT.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022-2023 Amun-Ra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE-NCSA.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022-2023 Amun-Ra. All rights reserved. 2 | 3 | Developed by: Amun-Ra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal with 7 | the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to 10 | do so, subject to the following conditions: 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimers. 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimers in the documentation 15 | and/or other materials provided with the distribution. 16 | * Neither the names of Amun-Ra nor the names of its contributors may be used 17 | to endorse or promote products derived from this Software without specific 18 | prior written permission. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 26 | SOFTWARE. 27 | -------------------------------------------------------------------------------- /LICENSE-Zlib.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 1997-2023 Sam Lantinga 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Nim project (2023-12-09). 2 | 3 | NIM ?= nim 4 | NIMBLE ?= nimble 5 | TESTAMENT ?= testament 6 | RMDIR ?= rmdir 7 | PYTHON ?= python3 8 | 9 | PACKAGE_NAME = $(basename $(wildcard *.nimble)) 10 | 11 | EXAMPLES ?= $(patsubst %.nim, %, $(wildcard examples/*.nim)) 12 | 13 | ifeq ($(VERBOSE),1) 14 | V := 15 | else 16 | V := @ 17 | endif 18 | 19 | .DEFAULT_GOAL := help 20 | 21 | all: 22 | 23 | .PHONY: help 24 | help: 25 | @echo "Usage: $(MAKE) " 26 | @echo 27 | @echo "Targets:" 28 | @grep -E '^[a-z]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \ 29 | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' 30 | 31 | .PHONY: check 32 | check: ## verify nimble package 33 | $(V)$(NIMBLE) check 34 | $(V)$(NIM) check --hint:name:off --styleCheck=hint src/$(PACKAGE_NAME).nim 35 | 36 | .PHONY: examples 37 | examples: 38 | $(V)$(NIMBLE) $@ 39 | 40 | .PHONY: check 41 | test: ## run tests 42 | $(V)$(TESTAMENT) all 43 | 44 | .PHONY: doc 45 | doc: ## generate package documentation 46 | $(V)$(NIMBLE) gendoc 47 | 48 | .PHONY: install 49 | install: ## install the package 50 | $(V)$(NIMBLE) install 51 | 52 | .PHONY: force-install 53 | force-install: ## force install the package 54 | $(V)$(NIMBLE) install -y 55 | 56 | .PHONY: uninstall 57 | uninstall: ## uninstall the package 58 | -$(V)$(NIMBLE) uninstall $(PACKAGE_NAME) 59 | 60 | .PHONY: uninstall 61 | force-uninstall: ## force uninstall the package 62 | -$(V)$(NIMBLE) -y uninstall $(PACKAGE_NAME) 63 | 64 | .PHONY: reinstall 65 | reinstall: uninstall install ## reinstall the package 66 | 67 | .PHONY: force-reinstall 68 | force-reinstall: force-uninstall install ## force reinstall the package 69 | 70 | .PHONY: clean 71 | clean: 72 | -$(V)$(RM) $(basename $(wildcard tests/*/test_*.nim)) 73 | -$(V)$(RM) tests/megatest.nim tests/megatest 74 | 75 | .PHONY: distclean 76 | distclean: clean 77 | -$(V)$(RM) -rf nimcache/ 78 | -$(V)$(RM) -rf testresults/ 79 | -$(V)$(RM) outputExpected.txt outputGotten.txt testresults.html 80 | 81 | .PHONY: watchdoc 82 | watchdoc: 83 | $(MAKE) doc 84 | $(V)inotifywait -e close_write --recursive --monitor --format '%e %w%f' src | \ 85 | while read change; do \ 86 | $(MAKE) doc; \ 87 | done 88 | 89 | .PHONY: 90 | serve: 91 | $(V)$(PYTHON) -m http.server -d /tmp/nimdoc 92 | 93 | arch: clean 94 | $(V)set -e; \ 95 | project=`basename \`pwd\``; \ 96 | timestamp=`date '+%Y-%m-%d-%H%M%S'`; \ 97 | destfile=../$$project-$$timestamp.tar.zst; \ 98 | tar -C .. -caf $$destfile $$project && chmod 444 $$destfile; \ 99 | echo -n "$$destfile" | xclip -selection clipboard -i; \ 100 | echo "Archive is $$destfile" 101 | 102 | # vim: set ts=8 noet sts=8: 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # High level SDL 3.0 shared library wrapper for Nim 2 | 3 | **nsdl3** is a high level **SDL 3.0** shared library wrapper for Nim. 4 | 5 | ## Features 6 | 7 | - Tries to hide as many C types from the user as possible. 8 | - Replaces generic C types with Nim distinct ones. 9 | - Does not require **SDL 3.0** library headers during build process. 10 | - The executable is not linked again a specific **SDL 3.0** library version. 11 | - Loads **SDL 3.0** library only when you need it (via `dynlib` module). 12 | - Single external dependency: [dlutils](https://github.com/amnr/dlutils). 13 | 14 | > **_WARNING:_** Keep in mind SDL3 API is not yet stable. 15 | 16 | > **_NOTE:_** Not everything is implemented yet. 17 | 18 | > **_NOTE:_** This is a mirror of my local git repository. 19 | 20 | ## API 21 | 22 | Original C `SDL_` prefix is dropped: 23 | 24 | - `SDL_INIT_VIDEO` becomes `INIT_VIDEO` 25 | - `SDL_GetTicks` becomes `GetTicks` 26 | - etc. 27 | 28 | Refer to the [documentation](https://amnr.github.io/nsdl3/) for the complete 29 | list of changes. 30 | 31 | ## Installation 32 | 33 | ```sh 34 | git clone https://github.com/amnr/nsdl3/ 35 | cd nsdl3 36 | nimble install 37 | ``` 38 | 39 | ## Configuration 40 | 41 | You can disable functions you don't use. 42 | All function groups are enabled by default. 43 | 44 | | Group | Define | Functions Defined In | 45 | | ----------- | ------------------- | --------------------------- | 46 | | Audio | `sdl3.audio=0` | ```` | 47 | | Blend Mode | `sdl3.blendmode=0` | ```` | 48 | | Clipboard | `sdl3.clipboard=0` | ```` | 49 | | Gamepad | `sdl3.gamepad=0` | ```` | 50 | | Gesture | `sdl3.gesture=0` | ```` | 51 | | Haptic | `sdl3.haptic=0` | ```` | 52 | | HID API | `sdl3.hidapi=0` | ```` | 53 | | Hints | `sdl3.hints=0` | ```` | 54 | | Joystick | `sdl3.joystick=0` | ```` | 55 | | Keyboard | `sdl3.keyboard=0` | ```` | 56 | | Message Box | `sdl3.messagebox=0` | ```` | 57 | | Mouse | `sdl3.mouse=0` | ```` | 58 | | Pen | `sdl3.pen=0` | ```` | 59 | | Properties | `sdl3.mouse=0` | ```` | 60 | | Sensor | `sdl3.properties=0` | ```` | 61 | | Touch | `sdl3.touch=0` | ```` | 62 | | Vulkan | `sdl3.vulkan=0` | ```` | 63 | 64 | For example if you don't need audio functions compile with: 65 | 66 | ```sh 67 | nim c -d=sdl3.audio=0 file(s) 68 | ``` 69 | 70 | ## Basic Usage 71 | 72 | ```nim 73 | import nsdl3 74 | 75 | proc main() = 76 | # Load all symbols from SDL3 shared library. 77 | # This must be the first proc called. 78 | if not open_sdl3_library(): 79 | echo "Failed to load SDL3 library: ", last_sdl3_error() 80 | quit QuitFailure 81 | defer: 82 | close_sdl3_library() 83 | 84 | # Initialize the library. 85 | if not Init INIT_VIDEO: 86 | echo "Error initializing SDL3: ", GetError() 87 | quit QuitFailure 88 | defer: 89 | Quit() 90 | 91 | # Create the window. 92 | let window = CreateWindow("Test Window", 640, 480) 93 | if window == nil: 94 | echo "Error creating window: ", GetError() 95 | quit QuitFailure 96 | defer: 97 | DestroyWindow window 98 | 99 | # Create window renderer. 100 | let renderer = CreateRenderer window 101 | if renderer == nil: 102 | echo "Error creating renderer: ", GetError() 103 | quit QuitFailure 104 | defer: 105 | DestroyRenderer renderer 106 | 107 | # Clear the window. 108 | discard RenderClear renderer 109 | RenderPresent renderer 110 | 111 | # Basic event loop. 112 | var event: Event 113 | while true: 114 | while PollEvent event: 115 | case event.typ 116 | of EVENT_QUIT: 117 | return 118 | else: 119 | discard 120 | Delay 100 121 | 122 | when isMainModule: 123 | main() 124 | ``` 125 | 126 | You can find more examples [here](examples/). 127 | 128 | ## Author 129 | 130 | - [Amun](https://github.com/amnr/) 131 | 132 | ## License 133 | 134 | `nlibsdl2` is released under: 135 | 136 | - [**MIT**](LICENSE-MIT.txt) — Nim license 137 | - [**NCSA**](LICENSE-NCSA.txt) — author's license of choice 138 | - [**Zlib**](LICENSE-Zlib.txt) — SDL 3.0 license 139 | 140 | Pick the one you prefer (or all). 141 | -------------------------------------------------------------------------------- /config.nims: -------------------------------------------------------------------------------- 1 | # config.nims. 2 | 3 | switch "hint", "name:off" 4 | switch "spellSuggest", "auto" 5 | switch "styleCheck", "hint" 6 | 7 | when defined mingw32: 8 | switch "define", "windows" 9 | 10 | switch "cpu", "i386" 11 | switch "os", "windows" 12 | 13 | switch "i386.windows.gcc.exe", "i686-w64-mingw32-gcc" 14 | switch "i386.windows.cpp.exe", "i686-w64-mingw32-g++" 15 | switch "i386.windows.gcc.linkerexe", "i686-w64-mingw32-gcc" 16 | switch "i386.windows.cpp.linkerexe", "i686-w64-mingw32-g++" 17 | 18 | # No -ldl. 19 | switch "gcc.options.linker", "-Wl,-Bstatic -lpthread" 20 | switch "gcc.cpp.options.linker", "" 21 | elif defined mingw64: 22 | switch "define", "windows" 23 | 24 | switch "cpu", "amd64" 25 | switch "os", "windows" 26 | 27 | switch "amd64.windows.gcc.exe", "x86_64-w64-mingw32-gcc" 28 | switch "amd64.windows.cpp.exe", "x86_64-w64-mingw32-g++" 29 | switch "amd64.windows.gcc.linkerexe", "x86_64-w64-mingw32-gcc" 30 | switch "amd64.windows.cpp.linkerexe", "x86_64-w64-mingw32-g++" 31 | 32 | # No -ldl. 33 | switch "gcc.options.linker", "-Wl,-Bstatic -lpthread" 34 | switch "gcc.cpp.options.linker", "" 35 | 36 | when defined sanitize: 37 | switch "passc", "-fsanitize=address,undefined" 38 | switch "passl", "-lasan -lubsan" 39 | 40 | # vim: set sts=2 et sw=2: 41 | -------------------------------------------------------------------------------- /examples/checkerboard.nim: -------------------------------------------------------------------------------- 1 | ## Checkerboard. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | when defined nimPreviewSlimSystem: 9 | import std/assertions 10 | 11 | import nsdl3 12 | 13 | const 14 | win_width = 800 15 | win_height = 600 16 | 17 | proc draw_checkerboard(texture: Texture) = 18 | var format: PixelFormatEnum 19 | var access, width, height: int 20 | assert QueryTexture(texture, format, access, width, height) 21 | echo format, ' ', access, ' ', width, " x ", height 22 | 23 | var buf = newSeqUninitialized[byte](width * height * uint32.sizeof) 24 | 25 | const components = [0x99'u8, 0x66'u8] 26 | 27 | var pos = 0 28 | for y in 0 ..< height: 29 | for x in 0 ..< width: 30 | let comp = components[((x xor y) div 8) and 1] 31 | buf[pos + 0] = comp 32 | buf[pos + 1] = comp 33 | buf[pos + 2] = comp 34 | buf[pos + 3] = comp 35 | pos += 4 36 | 37 | let pitch = width * uint32.sizeof 38 | assert UpdateTexture(texture, buf[0].addr, pitch) 39 | 40 | proc main_test() = 41 | # Create the window screen. 42 | let win = CreateWindow("Checkerboard", win_width, win_height) 43 | if win == nil: 44 | echo "Failed to create window: ", GetError() 45 | quit QuitFailure 46 | defer: 47 | DestroyWindow win 48 | 49 | let renderer = CreateRenderer win 50 | if renderer == nil: 51 | echo "Failed to create renderer: ", GetError() 52 | quit QuitFailure 53 | defer: 54 | DestroyRenderer renderer 55 | 56 | #var info: RendererInfo 57 | #renderer.get_renderer_info info 58 | #echo info 59 | 60 | let texture = CreateTexture(renderer, PIXELFORMAT_RGBA8888, TEXTUREACCESS_STATIC, win_width, win_height) 61 | if texture == nil: 62 | echo "Failed to create texture: ", GetError() 63 | quit QuitFailure 64 | defer: 65 | DestroyTexture texture 66 | 67 | draw_checkerboard texture 68 | 69 | discard RenderClear renderer 70 | discard RenderTexture(renderer, texture) 71 | RenderPresent renderer 72 | 73 | # Wait for events. 74 | var event: Event 75 | while true: 76 | if PollEvent event: 77 | # echo event 78 | case event.typ 79 | of EVENT_KEY_DOWN: 80 | case event.key.key 81 | of SDLK_ESCAPE, SDLK_q: 82 | break 83 | else: 84 | discard 85 | of EVENT_QUIT: 86 | break 87 | else: 88 | discard 89 | else: 90 | Delay 20 91 | 92 | proc main() = 93 | # Load library. 94 | if not open_sdl3_library(): 95 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 96 | quit QuitFailure 97 | defer: 98 | close_sdl3_library() 99 | 100 | if not Init INIT_VIDEO: 101 | echo "Failed to initialize SDL3: ", GetError() 102 | quit QuitFailure 103 | defer: 104 | Quit() 105 | 106 | main_test() 107 | 108 | when isMainModule: 109 | main() 110 | 111 | # vim: set sts=2 et sw=2: 112 | -------------------------------------------------------------------------------- /examples/config.nims: -------------------------------------------------------------------------------- 1 | switch "path", "$projectDir/../src" 2 | -------------------------------------------------------------------------------- /examples/displays.nim: -------------------------------------------------------------------------------- 1 | ## Displays. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import std/strformat 9 | 10 | import nsdl3 11 | 12 | proc list_displays() {.raises: ValueError.} = 13 | # if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) { 14 | for disp_id in GetDisplays(): 15 | let name = GetDisplayName disp_id 16 | 17 | # SDL_Log("Display %" SDL_PRIu32 ": %s\n", instance_id, name ? name : "Unknown"); 18 | let outname = if name != "": name else: "Unknown" 19 | echo &"Display {disp_id.uint32}: {outname}" 20 | # SDL_QuitSubSystem(SDL_INIT_VIDEO); 21 | 22 | proc list_fullscreen_display_modes() {.raises: ValueError.} = 23 | let display = GetPrimaryDisplay() 24 | var i = 0 25 | for mode in GetFullscreenDisplayModes display: 26 | # SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gx %gHz\n", 27 | # display, i, mode->w, mode->h, mode->pixel_density, mode->refresh_rate); 28 | echo &"Display {display.uint32} mode {i}: {mode.w}x{mode.h}@{mode.pixel_density:g}x {mode.refresh_rate:g}Hz" 29 | inc i 30 | 31 | proc main() = 32 | # Load library. 33 | if not open_sdl3_library(): 34 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 35 | quit QuitFailure 36 | defer: 37 | close_sdl3_library() 38 | 39 | if not Init INIT_VIDEO: 40 | echo "Failed to initialize SDL3: ", GetError() 41 | quit QuitFailure 42 | defer: 43 | Quit() 44 | 45 | try: 46 | list_displays() 47 | except ValueError as e: 48 | echo "ValueError: ", e.msg 49 | 50 | try: 51 | list_fullscreen_display_modes() 52 | except ValueError as e: 53 | echo "ValueError: ", e.msg 54 | 55 | when isMainModule: 56 | main() 57 | 58 | # vim: set sts=2 et sw=2: 59 | -------------------------------------------------------------------------------- /examples/draw.nim: -------------------------------------------------------------------------------- 1 | ## Draw on window. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | import nsdl2 7 | 8 | const 9 | WindowTitle = "Pixel Draw" 10 | Width = 320 # Texture width. 11 | Height = 240 # Texture height. 12 | Scale = 4 # Window pixel scale. 13 | 14 | proc loop(renderer: Renderer, texture: Texture) = 15 | var 16 | pixels: array[Width * Height, uint32] 17 | event = Event() 18 | lmb = false 19 | 20 | while true: 21 | # Wait for events. 22 | assert WaitEvent event 23 | 24 | # Update the texture with new pixel data. 25 | assert UpdateTexture(texture, pixels, Width * uint32.sizeof) 26 | 27 | case event.typ 28 | of EVENT_MOUSEBUTTONDOWN: 29 | if event.button.button == BUTTON_LEFT: 30 | lmb = true 31 | of EVENT_MOUSEBUTTONUP: 32 | if event.button.button == BUTTON_LEFT: 33 | lmb = false 34 | of EVENT_MOUSEMOTION: 35 | if lmb: 36 | let x = event.motion.x div Scale 37 | let y = event.motion.y div Scale 38 | pixels[Width * y + x] = 0x00ffffff 39 | of EVENT_QUIT: 40 | return 41 | else: 42 | discard 43 | 44 | # Render the texture. 45 | assert RenderClear renderer 46 | assert RenderCopy(renderer, texture) 47 | RenderPresent renderer 48 | 49 | 50 | proc main() = 51 | # Load library. 52 | if not open_sdl2_library(): 53 | echo "Failed to load SDL 2.0 library: ", last_sdl2_error() 54 | quit QuitFailure 55 | defer: 56 | close_sdl2_library() 57 | 58 | # Initialize SDL. 59 | if not Init INIT_VIDEO: 60 | echo "Failed to initialize SDL 2.0: ", GetError() 61 | quit QuitFailure 62 | defer: 63 | Quit() 64 | 65 | # Create window. 66 | let win = CreateWindow(WindowTitle, Scale * Width, Scale * Height) 67 | if win == nil: 68 | echo "Failed to create window: ", GetError() 69 | quit QuitFailure 70 | defer: 71 | DestroyWindow win 72 | 73 | # Create window renderer. 74 | let renderer = CreateRenderer win 75 | if renderer == nil: 76 | echo "Failed to create renderer: ", GetError() 77 | quit QuitFailure 78 | defer: 79 | DestroyRenderer renderer 80 | 81 | # Create renderer texture. 82 | let texture = CreateTexture(renderer, PIXELFORMAT_ARGB8888, 83 | TEXTUREACCESS_STATIC, Width, Height) 84 | if texture == nil: 85 | echo "Failed to create texture: ", GetError() 86 | quit QuitFailure 87 | defer: 88 | DestroyTexture texture 89 | 90 | loop renderer, texture 91 | 92 | when isMainModule: 93 | main() 94 | 95 | # vim: set sts=2 et sw=2: 96 | -------------------------------------------------------------------------------- /examples/joysticks.nim: -------------------------------------------------------------------------------- 1 | ## Display information about all connected joysticks. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import std/enumerate 9 | import std/strformat 10 | 11 | import nsdl3 12 | 13 | proc main() = 14 | # Load library. 15 | if not open_sdl3_library(): 16 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 17 | quit QuitFailure 18 | defer: 19 | close_sdl3_library() 20 | 21 | # Initialize SDL. 22 | if not Init INIT_JOYSTICK: 23 | echo "Failed to initialize SDL 3.0: ", GetError() 24 | quit QuitFailure 25 | defer: 26 | Quit() 27 | 28 | let joysticks = GetJoysticks() 29 | 30 | if joysticks.len == 0: 31 | echo "No joysticks found." 32 | return 33 | 34 | for i, joy_id in enumerate joysticks: 35 | echo "Joystick #", i, ':' 36 | let joy = OpenJoystick joy_id 37 | if joy == nil: 38 | echo "Failed to open joystick #", i 39 | continue 40 | defer: 41 | CloseJoystick joy 42 | 43 | #let guid = joy.get_guid_string 44 | 45 | #echo " type . . : ", joy.get_type 46 | echo " name . . : ", GetJoystickName joy 47 | echo " path . . : ", GetJoystickPath joy 48 | #echo " serial . : ", joy.get_serial 49 | #echo " GUID . . : ", joy.get_guid_string 50 | #echo " GUID . . : ", guid[0..7], '-', guid[8..11], '-', guid[12..15], 51 | # '-', guid[16..19], '-', guid[20..^1] 52 | try: 53 | echo &" USB . . : {GetJoystickVendor joy:04x}:{GetJoystickProduct joy:04x}" 54 | except ValueError: 55 | discard 56 | echo " details : ", GetNumJoystickAxes joy, " axes, ", 57 | GetNumJoystickButtons joy, " buttons, ", 58 | GetNumJoystickHats joy, " hats" 59 | echo " features : ", 60 | " rumble: ", JoystickHasRumble joy, 61 | " rumble triggers: ", JoystickHasRumbleTriggers joy 62 | 63 | when isMainModule: 64 | main() 65 | 66 | # vim: set sts=2 et sw=2: 67 | -------------------------------------------------------------------------------- /examples/randomlines.nim: -------------------------------------------------------------------------------- 1 | ## Random lines. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | when NimMajor >= 2 or defined nimPreviewSlimSystem: 9 | import std/assertions 10 | import std/random 11 | 12 | import nsdl3 13 | 14 | const 15 | WindowTitle = "Random Lines" 16 | Width = 320 # Texture width. 17 | Height = 240 # Texture height. 18 | Scale = 3 # Window pixel scale. 19 | MaxLines = 100 20 | DrawDelay = 10 21 | 22 | proc loop(renderer: Renderer, texture: Texture) = 23 | var 24 | event: Event 25 | cnt = 0 26 | force_clear = false 27 | 28 | # Randomize RNG for the loop. 29 | randomize() 30 | 31 | RenderPresent renderer 32 | 33 | assert RenderClear renderer 34 | 35 | while true: 36 | while PollEvent event: 37 | case event.typ 38 | of EVENT_KEYDOWN: 39 | case event.key.key 40 | of SDLK_ESCAPE, SDLK_q: 41 | return 42 | of SDLK_SPACE: 43 | # assert renderer.set_draw_color(0x00, 0x00, 0x00) 44 | # assert RenderClear renderer 45 | force_clear = true 46 | else: 47 | discard 48 | of EVENT_QUIT: 49 | return 50 | else: 51 | discard 52 | 53 | assert SetRenderTarget(renderer, texture) 54 | 55 | if cnt >= MaxLines: 56 | force_clear = true 57 | cnt = 0 58 | 59 | if force_clear: 60 | assert SetRenderDrawColor(renderer, 0x00, 0x00, 0x00) 61 | assert RenderClear renderer 62 | force_clear = false 63 | 64 | # Set random pixel with random color. 65 | let 66 | x1 = float rand Width - 1 67 | y1 = float rand Height - 1 68 | x2 = float rand Width - 1 69 | y2 = float rand Height - 1 70 | color = rand 0x00ffffff 71 | 72 | assert SetRenderDrawColor(renderer, byte (color shr 16) and 0xff, 73 | byte (color shr 8) and 0xff, 74 | byte color and 0xff) 75 | assert RenderLine(renderer, x1, y1, x2, y2) 76 | inc cnt 77 | 78 | assert SetRenderTarget renderer 79 | 80 | # Render the texture. 81 | assert RenderTexture(renderer, texture) 82 | RenderPresent renderer 83 | 84 | Delay DrawDelay 85 | 86 | proc main() = 87 | # Load library. 88 | if not open_sdl3_library(): 89 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 90 | quit QuitFailure 91 | defer: 92 | close_sdl3_library() 93 | 94 | # Initialize SDL. 95 | if not Init INIT_VIDEO: 96 | echo "Failed to initialize SDL3: ", GetError() 97 | quit QuitFailure 98 | defer: 99 | Quit() 100 | 101 | echo "Press to clear the window." 102 | echo "Press or to exit." 103 | 104 | # discard set_hint(HINT_VIDEO_DOUBLE_BUFFER, "0") 105 | 106 | # Create window. 107 | let win = CreateWindow(WindowTitle, Scale * Width, Scale * Height) 108 | if win == nil: 109 | echo "Failed to create window: ", GetError() 110 | quit QuitFailure 111 | defer: 112 | DestroyWindow win 113 | 114 | # Create window renderer. 115 | let renderer = CreateRenderer win 116 | if renderer == nil: 117 | echo "Failed to create renderer: ", GetError() 118 | quit QuitFailure 119 | defer: 120 | DestroyRenderer renderer 121 | 122 | # Create renderer texture. 123 | let texture = CreateTexture(renderer, PIXELFORMAT_ARGB8888, 124 | TEXTUREACCESS_TARGET, Width, Height) 125 | if texture == nil: 126 | echo "Failed to create texture: ", GetError() 127 | quit QuitFailure 128 | defer: 129 | DestroyTexture texture 130 | 131 | assert SetTextureScaleMode(texture, SCALEMODE_NEAREST) 132 | 133 | # SDL_TEXTUREACCESS_TARGET 134 | # SDL_SetRenderTarget(SDL_Renderer *renderer,SDL_Texture *texture) 135 | 136 | loop renderer, texture 137 | 138 | when isMainModule: 139 | main() 140 | 141 | # vim: set sts=2 et sw=2: 142 | -------------------------------------------------------------------------------- /examples/randompixels.nim: -------------------------------------------------------------------------------- 1 | ## Random pixels. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import std/random 9 | 10 | import nsdl3 11 | 12 | const 13 | WindowTitle = "Random Pixels" 14 | Width = 320 # Texture width. 15 | Height = 240 # Texture height. 16 | Scale = 3 # Window pixel scale. 17 | MaxPixels = 1000 18 | DrawDelay = 10 19 | 20 | proc loop(renderer: Renderer, texture: Texture) = 21 | var 22 | surface: SurfacePtr = nil 23 | event: Event 24 | cnt = 0 25 | 26 | # Randomize RNG for the loop. 27 | randomize() 28 | 29 | while true: 30 | while PollEvent event: 31 | case event.typ 32 | of EVENT_KEY_DOWN: 33 | case event.key.key 34 | of SDLK_ESCAPE, SDLK_q: 35 | return 36 | else: 37 | discard 38 | of EVENT_QUIT: 39 | return 40 | else: 41 | discard 42 | 43 | if cnt < MaxPixels: 44 | # Set random pixel with random color. 45 | let 46 | x = rand Width - 1 47 | y = rand Height - 1 48 | r = byte rand 0xff 49 | g = byte rand 0xff 50 | b = byte rand 0xff 51 | 52 | if LockTextureToSurface(texture, surface): 53 | # pixels[(pitch div 4) * y + x] = uint32 color 54 | discard WriteSurfacePixel(surface, x, y, r, g, b, 0xff) 55 | UnlockTexture texture 56 | inc cnt 57 | else: 58 | # Clear the pixmap if max number of pixels were drawn. 59 | assert SetRenderDrawColor(renderer, 0x00, 0x00, 0x00) 60 | assert RenderClear renderer 61 | cnt = 0 62 | 63 | # Update the texture with new pixel data. 64 | # discard UpdateTexture(texture, pixels[0].addr, Width * uint32.sizeof) 65 | 66 | # Render the texture. 67 | discard RenderClear renderer 68 | discard RenderTexture(renderer, texture) 69 | RenderPresent renderer 70 | 71 | Delay DrawDelay 72 | 73 | proc main() = 74 | # Load library. 75 | if not open_sdl3_library(): 76 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 77 | quit QuitFailure 78 | defer: 79 | close_sdl3_library() 80 | 81 | if not Init INIT_VIDEO: 82 | echo "Failed to initialize SDL3: ", GetError() 83 | quit QuitFailure 84 | defer: 85 | Quit() 86 | 87 | # Create window. 88 | let win = CreateWindow(WindowTitle, Scale * Width, Scale * Height) 89 | if win == nil: 90 | echo "Failed to create window: ", GetError() 91 | quit QuitFailure 92 | defer: 93 | DestroyWindow win 94 | 95 | # Create window renderer. 96 | let renderer = CreateRenderer win 97 | if renderer == nil: 98 | echo "Failed to create renderer: ", GetError() 99 | quit QuitFailure 100 | defer: 101 | DestroyRenderer renderer 102 | 103 | # Create renderer texture. 104 | let texture = CreateTexture(renderer, PIXELFORMAT_ARGB8888, 105 | # TEXTUREACCESS_STATIC, Width, Height) 106 | TEXTUREACCESS_STREAMING, Width, Height) 107 | if texture == nil: 108 | echo "Failed to create texture: ", GetError() 109 | quit QuitFailure 110 | defer: 111 | DestroyTexture texture 112 | 113 | assert SetTextureScaleMode(texture, SCALEMODE_NEAREST) 114 | 115 | loop renderer, texture 116 | 117 | when isMainModule: 118 | main() 119 | 120 | # vim: set sts=2 et sw=2: 121 | -------------------------------------------------------------------------------- /examples/randomrects.nim: -------------------------------------------------------------------------------- 1 | ## Random rectangles. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | when NimMajor >= 2 or defined nimPreviewSlimSystem: 9 | import std/assertions 10 | import std/random 11 | 12 | import nsdl3 13 | 14 | const 15 | WindowTitle = "Random Rectangles" 16 | Width = 320 # Texture width. 17 | Height = 240 # Texture height. 18 | Scale = 3 # Window pixel scale. 19 | MaxRects = 200 20 | DrawDelay = 10 21 | 22 | proc loop(window: Window, renderer: Renderer, texture: Texture) = 23 | var 24 | event: Event 25 | cnt = 0 26 | fill_mode = false 27 | force_clear = false 28 | 29 | # Randomize RNG for the loop. 30 | randomize() 31 | 32 | assert RenderClear renderer 33 | 34 | while true: 35 | while PollEvent event: 36 | case event.typ 37 | of EVENT_KEYDOWN: 38 | case event.key.key 39 | of SDLK_ESCAPE, SDLK_q: 40 | return 41 | of SDLK_SPACE: 42 | fill_mode = not fill_mode 43 | force_clear = true 44 | else: 45 | discard 46 | of EVENT_QUIT: 47 | return 48 | #of EVENT_WINDOW_CLOSE_REQUESTED: 49 | # if event.window.window_id == get_window_id window: 50 | # return 51 | else: 52 | discard 53 | 54 | assert SetRenderTarget(renderer, texture) 55 | 56 | if cnt >= MaxRects: 57 | fill_mode = not fill_mode 58 | force_clear = true 59 | cnt = 0 60 | 61 | if force_clear: 62 | assert SetRenderDrawColor(renderer, 0x00, 0x00, 0x00) 63 | assert RenderClear renderer 64 | force_clear = false 65 | 66 | # Set random pixel with random color. 67 | let 68 | x1 = rand Scale * Width - 1 69 | y1 = rand Scale * Height - 1 70 | x2 = rand Scale * Width - 1 71 | y2 = rand Scale * Height - 1 72 | color = rand 0x00ffffff 73 | 74 | let 75 | x = float min(x1, x2) 76 | y = float min(y1, y2) 77 | w = max(x1, x2).float - x 78 | h = max(y1, y2).float - y 79 | 80 | assert SetRenderDrawColor(renderer, byte (color shr 16) and 0xff, 81 | byte (color shr 8) and 0xff, 82 | byte color and 0xff) 83 | if fill_mode: 84 | assert RenderFillRect(renderer, x, y, w, h) 85 | else: 86 | assert RenderRect(renderer, x, y, w, h) 87 | inc cnt 88 | 89 | assert SetRenderTarget renderer 90 | 91 | # Render the texture. 92 | assert RenderTexture(renderer, texture) 93 | RenderPresent renderer 94 | 95 | Delay DrawDelay 96 | 97 | proc main() = 98 | # Load library. 99 | if not open_sdl3_library(): 100 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 101 | quit QuitFailure 102 | defer: 103 | close_sdl3_library() 104 | 105 | # Initialize SDL. 106 | if not Init INIT_VIDEO: 107 | echo "Failed to initialize SDL3: ", GetError() 108 | quit QuitFailure 109 | defer: 110 | Quit() 111 | 112 | echo "Press to clear the window." 113 | echo "Press or to exit." 114 | 115 | # Create window. 116 | let window = CreateWindow(WindowTitle, Scale * Width, Scale * Height) 117 | if window == nil: 118 | echo "Failed to create window: ", GetError() 119 | quit QuitFailure 120 | defer: 121 | DestroyWindow window 122 | 123 | # Create window renderer. 124 | let renderer = CreateRenderer window 125 | if renderer == nil: 126 | echo "Failed to create renderer: ", GetError() 127 | quit QuitFailure 128 | defer: 129 | DestroyRenderer renderer 130 | 131 | # Create renderer texture. 132 | let texture = CreateTexture(renderer, PIXELFORMAT_ARGB8888, 133 | TEXTUREACCESS_TARGET, 134 | Scale * Width, Scale * Height) 135 | if texture == nil: 136 | echo "Failed to create texture: ", GetError() 137 | quit QuitFailure 138 | defer: 139 | DestroyTexture texture 140 | 141 | assert SetTextureScaleMode(texture, SCALEMODE_NEAREST) 142 | 143 | loop window, renderer, texture 144 | 145 | when isMainModule: 146 | main() 147 | 148 | # vim: set sts=2 et sw=2: 149 | -------------------------------------------------------------------------------- /examples/touchdevices.nim: -------------------------------------------------------------------------------- 1 | ## List touch devices. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import nsdl2 9 | 10 | proc main() = 11 | # Load library. 12 | if not open_sdl2_library(): 13 | echo "Failed to load SDL 2.0 library: ", last_sdl2_error() 14 | quit QuitFailure 15 | defer: 16 | close_sdl2_library() 17 | 18 | # Initialize SDL. 19 | if not Init INIT_SENSOR: 20 | echo "Failed to initialize SDL 2.0: ", GetError() 21 | quit QuitFailure 22 | defer: 23 | Quit() 24 | 25 | let num_devices = GetNumTouchDevices() 26 | 27 | echo "Touch devices : ", num_devices 28 | 29 | when isMainModule: 30 | main() 31 | 32 | # vim: set sts=2 et sw=2: 33 | -------------------------------------------------------------------------------- /examples/version.nim: -------------------------------------------------------------------------------- 1 | ## Test version. 2 | #[ 3 | SPDX-License-Identifier: NCSA 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import nsdl3 9 | 10 | proc main() = 11 | # Load library. 12 | if not open_sdl3_library(): 13 | echo "Failed to load SDL 3.0 library: ", last_sdl3_error() 14 | quit QuitFailure 15 | defer: 16 | close_sdl3_library() 17 | 18 | if not Init(): 19 | echo "Failed to initialize SDL3: ", GetError() 20 | quit QuitFailure 21 | defer: 22 | Quit() 23 | 24 | let vernum = GetVersion() 25 | 26 | let major = vernum div 1000_000 27 | let minor = (vernum div 1000) mod 1000 28 | let patch = vernum mod 1000 29 | let version = $major & '.' & $minor & '.' & $patch 30 | 31 | echo "Version ", version 32 | echo "Revision ", GetRevision() 33 | 34 | 35 | let title = "SDL" & version 36 | let message = "Nim " & NimVersion & '\n' & 37 | "SDL " & version 38 | 39 | discard ShowSimpleMessageBox(MESSAGEBOX_INFORMATION, title, message) 40 | 41 | when isMainModule: 42 | main() 43 | 44 | # vim: set sts=2 et sw=2: 45 | -------------------------------------------------------------------------------- /nsdl3.nimble: -------------------------------------------------------------------------------- 1 | # Package info. 2 | version = "0.9.12" 3 | author = "Amun" 4 | description = "High level SDL 3.0 shared library wrapper" 5 | license = "NCSA OR MIT OR Zlib" 6 | srcDir = "src" 7 | 8 | # Dependencies. 9 | # requires "https://github.com/amnr/dlutils" 10 | requires "dlutils >= 2.0.0" 11 | 12 | import std/os 13 | import std/strformat 14 | from std/algorithm import sorted 15 | from std/sequtils import toSeq 16 | 17 | task examples, "build examples": 18 | const optflags = when defined release: " -d=release --opt=speed" else: "" 19 | for entry in (thisDir() / "examples").walkDir.toSeq.sorted: 20 | if entry.kind == pcFile and entry.path.endswith ".nim": 21 | # exec "nimble" & optflags & " --silent c " & entry.path 22 | exec "nimble" & optflags & " c " & entry.path 23 | 24 | task gendoc, "build documentation": 25 | const 26 | project = projectName() 27 | docdir = "/tmp/nimdoc/" & project 28 | docopts = "--hint=Conf=off --hint=SuccessX=off --github.commit=master" 29 | var ghopts = "" 30 | if "GITHUB_BASEURL".getEnv != "": 31 | ghopts = &" --github.url=" & "GITHUB_BASEURL".getEnv & "/{project}" 32 | let mainfile = thisDir() / srcDir / &"{project}.nim" 33 | if not docdir.dirExists: 34 | mkDir docdir 35 | exec &"nim doc {docopts} {ghopts} --index=on --project -o={docdir} {mainfile}" 36 | if "rrep".findExe != "": 37 | exec &"mv -f '{docdir}/{project}.html' '{docdir}/index.html'" 38 | # Remove src prefix. 39 | exec &"rrep -rq src/ '' {docdir}" 40 | # Fix searchbox link in main module. 41 | exec &"rrep -rq '{project}.html#' '#' {docdir}" 42 | # Fix main module link in theindex.html. 43 | exec &"rrep -rq '\"{project}.html\"' index.html {docdir}" 44 | else: 45 | echo "Warning: rrep not installed; patching not peformed" 46 | 47 | # vim: set sts=2 et sw=2: 48 | -------------------------------------------------------------------------------- /src/nsdl3/config.nim: -------------------------------------------------------------------------------- 1 | ## SDL3 config. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | const 10 | ndoc = defined nimdoc 11 | 12 | const 13 | use_audio* {.booldefine: "sdl3.audio" .} = true or ndoc 14 | ## Include audio functions. 15 | 16 | use_blendmode* {.booldefine: "sdl3.blendmode" .} = true or ndoc 17 | ## Include blend mode functions. 18 | 19 | use_clipboard* {.booldefine: "sdl3.clipboard" .} = true or ndoc 20 | ## Include clipboard functions. 21 | 22 | use_dialog* {.booldefine: "sdl3.dialog" .} = true or ndoc 23 | ## Include dialog functions. 24 | 25 | use_filesystem* {.booldefine: "sdl3.filesystem" .} = true or ndoc 26 | ## Include filesystem functions. 27 | 28 | use_gamepad* {.booldefine: "sdl3.gamepad" .} = true or ndoc 29 | ## Include gamepad functions. 30 | 31 | use_haptic* {.booldefine: "sdl3.haptic" .} = true or ndoc 32 | ## Include haptic functions. 33 | 34 | use_hidapi* {.booldefine: "sdl3.hidapi" .} = true or ndoc 35 | ## Include HID API functions. 36 | 37 | use_hints* {.booldefine: "sdl3.hints" .} = true or ndoc 38 | ## Include hits functions. 39 | 40 | use_joystick* {.booldefine: "sdl3.joystick" .} = true or ndoc 41 | ## Include joystick functions. 42 | 43 | use_keyboard* {.booldefine: "sdl3.keyboard" .} = true or ndoc 44 | ## Include keyboard functions. 45 | 46 | use_messagebox* {.booldefine: "sdl3.messagebox" .} = true or ndoc 47 | ## Include message box functions. 48 | 49 | use_mouse* {.booldefine: "sdl3.mouse" .} = true or ndoc 50 | ## Include mouse functions. 51 | 52 | use_pen* {.booldefine: "sdl3.pen" .} = true or ndoc 53 | ## Include pen functions. 54 | 55 | use_properties* {.booldefine: "sdl3.properties" .} = true or ndoc 56 | ## Include properties functions. 57 | 58 | use_sensor* {.booldefine: "sdl3.sensor" .} = true or ndoc 59 | ## Include sensor functions. 60 | 61 | use_touch* {.booldefine: "sdl3.touch" .} = true or ndoc 62 | ## Include touch functions. 63 | 64 | use_vulkan* {.booldefine: "sdl3.vulkan" .} = true or ndoc 65 | ## Include Vulkan functions. 66 | 67 | # vim: set sts=2 et sw=2: 68 | -------------------------------------------------------------------------------- /src/nsdl3/extra/desktop.nim: -------------------------------------------------------------------------------- 1 | ## Desktop related functions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | import ../../nsdl3 10 | 11 | proc get_desktop_size*(width, height: var int, desktop_index = 0): bool = 12 | ## Return usable desktop size. 13 | ## 14 | ## This function return total desktop size prior to SDL 2.0.5. 15 | GetDisplayUsableBounds(desktop_index, width, height) 16 | 17 | # vim: set sts=4 et sw=4: 18 | -------------------------------------------------------------------------------- /src/nsdl3/extra/messagebox.nim: -------------------------------------------------------------------------------- 1 | ## Message box utils. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | import ../../nsdl3 10 | 11 | {.push inline.} 12 | 13 | proc show_error_message_box*(window: Window, 14 | title, message: string): bool {.inline.} = 15 | ShowSimpleMessageBox MESSAGEBOX_ERROR, title, message, window 16 | 17 | proc show_info_message_box*(window: Window, 18 | title, message: string): bool {.inline.} = 19 | ShowSimpleMessageBox MESSAGEBOX_INFORMATION, title, message, window 20 | 21 | proc show_warning_message_box*(window: Window, 22 | title, message: string): bool {.inline.} = 23 | ShowSimpleMessageBox MESSAGEBOX_WARNING, title, message, window 24 | 25 | {.pop.} # inline. 26 | 27 | # vim: set sts=2 et sw=2: 28 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3audio.nim: -------------------------------------------------------------------------------- 1 | ## Audio definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | #type 10 | # AudioFormat* = distinct uint16 11 | # ## Audio format. 12 | 13 | #func `==`*(a, b: AudioFormat): bool {.borrow.} 14 | 15 | type 16 | AudioFormatFlags* = distinct cint 17 | ## Audio format flags. 18 | 19 | func `or`*(x, y: AudioFormatFlags): AudioFormatFlags {.borrow.} 20 | 21 | const 22 | AUDIO_MASK_BITSIZE* = 0xff 23 | AUDIO_MASK_FLOAT* = 1 shl 8 24 | AUDIO_MASK_ENDIAN* = 1 shl 12 25 | AUDIO_MASK_SIGNED* = 1 shl 15 26 | 27 | type 28 | AudioFormat* {.size: cint.sizeof.} = enum 29 | ## Audio format. 30 | AUDIO_UNKNOWN = 0x0000 ## Unspecified audio format. 31 | AUDIO_U8 = 0x0008 ## Unsigned 8-bit samples. 32 | AUDIO_S8 = 0x8008 ## Signed 8-bit samples. 33 | AUDIO_S16LE = 0x8010 ## Signed 16-bit samples (little endian). 34 | AUDIO_S32LE = 0x8020 ## 32-bit integer samples (little endian). 35 | AUDIO_F32LE = 0x8120 ## 32-bit floating point samples (little endian). 36 | AUDIO_S16BE = 0x9010 ## Signed 16-bit samples (big endian). 37 | AUDIO_S32BE = 0x9020 ## 32-bit integer samples (big endian). 38 | AUDIO_F32BE = 0x9120 ## 32-bit floating point samples (end endian). 39 | 40 | when cpuEndian == littleEndian: 41 | const 42 | AUDIO_S16* = AUDIO_S16LE 43 | AUDIO_S32* = AUDIO_S32LE 44 | AUDIO_F32* = AUDIO_F32LE 45 | else: 46 | const 47 | AUDIO_S16* = AUDIO_S16BE 48 | AUDIO_S32* = AUDIO_S32BE 49 | AUDIO_F32* = AUDIO_F32BE 50 | 51 | func audio_bitsize*(x: uint16): uint16 {.inline.} = x and AUDIO_MASK_BITSIZE 52 | func audio_bytesize*(x: uint16): uint16 {.inline.} = audio_bitsize(x) div 8 53 | func audio_isfloat*(x: uint16): bool {.inline.} = (x and AUDIO_MASK_FLOAT) != 0 54 | func audio_isbigendian*(x: uint16): bool {.inline.} = (x and AUDIO_MASK_ENDIAN) != 0 55 | func audio_islittleendian*(x: uint16): bool {.inline.} = not audio_isbigendian x 56 | func audio_issigned*(x: uint16): bool {.inline.} = (x and AUDIO_MASK_SIGNED) != 0 57 | func audio_isint*(x: uint16): bool {.inline.} = not audio_isfloat(x) 58 | func audio_isunsigned*(x: uint16): bool {.inline.} = not audio_issigned(x) 59 | 60 | type 61 | AudioDeviceID* = distinct uint32 62 | ## Audio Device instance IDs. 63 | 64 | const 65 | AUDIO_DEVICE_DEFAULT_OUTPUT* = AudioDeviceID 0xffffffff 66 | AUDIO_DEVICE_DEFAULT_CAPTURE* = AudioDeviceID 0xfffffffe 67 | 68 | type 69 | AudioSpec* {.final, pure.} = object 70 | format* : AudioFormat ## Audio data format. 71 | channels* : cint ## Number of channels. 72 | freq* : cint ## Sample rate (sample frames per second). 73 | 74 | func audio_framesize*(spec: AudioSpec): uint16 {.inline.} = 75 | audio_bytesize(spec.format.uint16 * spec.channels.uint16) 76 | 77 | type 78 | AudioStream* = ptr object 79 | ## Audio stream. 80 | 81 | type 82 | AudioStreamCallback* = proc (userdata: pointer, stream: AudioStream, 83 | additional_amount: cint, 84 | total_amount: cint) {.cdecl, gcsafe, raises: [].} 85 | 86 | AudioPostmixCallback* = proc (userdata: pointer, spec: ptr AudioSpec, 87 | buffer: ptr cfloat, 88 | buflen: cint) {.cdecl, gcsafe, raises: [].} 89 | 90 | # vim: set sts=2 et sw=2: 91 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3blendmode.nim: -------------------------------------------------------------------------------- 1 | ## Blend modes. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | BlendMode* = distinct cint 11 | ## Blend mode. 12 | 13 | func `or`*(a, b: BlendMode): BlendMode {.borrow.} 14 | 15 | const 16 | BLENDMODE_NONE* = BlendMode 0x00000000 17 | BLENDMODE_BLEND* = BlendMode 0x00000001 18 | BLENDMODE_ADD* = BlendMode 0x00000002 19 | BLENDMODE_MOD* = BlendMode 0x00000004 20 | BLENDMODE_MUL* = BlendMode 0x00000008 21 | BLENDMODE_INVALID* = BlendMode 0x7fffffff 22 | 23 | type 24 | BlendOperation* {.size: cint.sizeof.} = enum 25 | ## Blend operation. 26 | BLENDOPERATION_ADD = 0x1 27 | BLENDOPERATION_SUBTRACT = 0x2 28 | BLENDOPERATION_REV_SUBTRACT = 0x3 29 | BLENDOPERATION_MINIMUM = 0x4 30 | BLENDOPERATION_MAXIMUM = 0x5 31 | 32 | type 33 | BlendFactor* {.size: cint.sizeof.} = enum 34 | ## Blend factor. 35 | BLENDFACTOR_ZERO = 0x1 36 | BLENDFACTOR_ONE = 0x2 37 | BLENDFACTOR_SRC_COLOR = 0x3 38 | BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4 39 | BLENDFACTOR_SRC_ALPHA = 0x5 40 | BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6 41 | BLENDFACTOR_DST_COLOR = 0x7 42 | BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8 43 | BLENDFACTOR_DST_ALPHA = 0x9 44 | BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xa 45 | 46 | # vim: set sts=2 et sw=2: 47 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3camera.nim: -------------------------------------------------------------------------------- 1 | ## Viceo capture. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | from sdl3pixels import PixelFormatEnum 8 | 9 | type 10 | CameraDeviceID* = distinct uint32 11 | ## Unique ID for a camera device. 12 | ## 13 | ## The ID starts at 1. The value 0 is an invalid ID. 14 | 15 | Camera* = ptr object 16 | 17 | CameraSpec* {.final, pure.} = object 18 | format* : PixelFormatEnum ## Frame format. 19 | width* : cint ## Frame width. 20 | height* : cint ## Frame height. 21 | interval_numerator* : cint ## Frame rate numerator ((dom / num) == fps, (num / dom) == duration). 22 | interval_denominator* : cint ## Frame rate demoninator ((dom / num) == fps, (num / dom) == duration). 23 | 24 | CameraPosition* {.size: cint.sizeof.} = enum 25 | ## The position of camera in relation to system device. 26 | CAMERA_POSITION_UNKNOWN 27 | CAMERA_POSITION_FRONT_FACING 28 | CAMERA_POSITION_BACK_FACING 29 | 30 | # vim: set sts=2 et sw=2: 31 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3clipboard.nim: -------------------------------------------------------------------------------- 1 | ## Clipboard. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | ClipboardDataCallback* = proc ( 11 | userdata : pointer, 12 | mime_type : cstring, 13 | size : csize_t 14 | ): pointer {.cdecl, raises: [].} 15 | ## Callback function that will be called when data for the specified 16 | ## mime-type is requested by the OS. 17 | ## 18 | ## The callback function is called with NULL as the mime_type when the clipboard 19 | ## is cleared or new data is set. The clipboard is automatically cleared in SDL_Quit(). 20 | 21 | ClipboardCleanupCallback* = proc (userdata: pointer) {.cdecl, raises: [].} 22 | ## Callback function that will be called when the clipboard is cleared, 23 | ## or new data is set. 24 | 25 | # vim: set sts=2 et sw=2: 26 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3dialog.nim: -------------------------------------------------------------------------------- 1 | ## Dialog. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | type 8 | DialogFileFilter* {.final, pure.} = object 9 | name* : cstring 10 | pattern* : cstring 11 | 12 | DialogFileCallback* = proc ( 13 | userdata : pointer, 14 | filelist : cstringArray, 15 | filter : cint 16 | ) {.cdecl, gcsafe, raises: [].} 17 | 18 | type 19 | FileDialogType* {.size: cint.sizeof.} = enum 20 | ## Dialog types. 21 | FILEDIALOG_OPENFILE 22 | FILEDIALOG_SAVEFILE 23 | FILEDIALOG_OPENFOLDER 24 | 25 | const 26 | PROP_FILE_DIALOG_FILTERS_POINTER* = cstring "SDL.filedialog.filters" 27 | PROP_FILE_DIALOG_NFILTERS_NUMBER* = cstring "SDL.filedialog.nfilters" 28 | PROP_FILE_DIALOG_WINDOW_POINTER* = cstring "SDL.filedialog.window" 29 | PROP_FILE_DIALOG_LOCATION_STRING* = cstring "SDL.filedialog.location" 30 | PROP_FILE_DIALOG_MANY_BOOLEAN* = cstring "SDL.filedialog.many" 31 | PROP_FILE_DIALOG_TITLE_STRING* = cstring "SDL.filedialog.title" 32 | PROP_FILE_DIALOG_ACCEPT_STRING* = cstring "SDL.filedialog.accept" 33 | PROP_FILE_DIALOG_CANCEL_STRING* = cstring "SDL.filedialog.cancel" 34 | 35 | # vim: set sts=2 et sw=2: 36 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3events.nim: -------------------------------------------------------------------------------- 1 | ## Event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3audio import AudioDeviceID 10 | from sdl3camera import CameraDeviceID 11 | from sdl3init import cbool 12 | from sdl3joystick import Hat, JoystickID 13 | from sdl3keyboard import KeyboardID 14 | from sdl3keycode import Keycode, Keymod 15 | from sdl3mouse import MouseButtonFlags, MouseID, MouseWheelDirection 16 | from sdl3pen import PenAxis, PenID, PenInputFlags, PEN_AXIS_COUNT 17 | from sdl3power import PowerState 18 | from sdl3scancode import Scancode 19 | from sdl3sensor import SensorID 20 | from sdl3touch import FingerID, TouchID 21 | from sdl3video import DisplayID, WindowID 22 | 23 | type 24 | EventType* {.pure, size: uint32.sizeof.} = enum 25 | ## Event types. 26 | EVENT_FIRST = 0 27 | 28 | # Application events. 29 | EVENT_QUIT = 0x100 30 | 31 | # iOS event types. 32 | EVENT_TERMINATING 33 | EVENT_LOW_MEMORY 34 | EVENT_WILL_ENTER_BACKGROUND 35 | EVENT_DID_ENTER_BACKGROUND 36 | EVENT_WILL_ENTER_FOREGROUND 37 | EVENT_DID_ENTER_FOREGROUND 38 | EVENT_LOCALE_CHANGED 39 | EVENT_SYSTEM_THEME_CHANGED 40 | 41 | # Display events. 42 | EVENT_DISPLAY_ORIENTATION = 0x151 43 | EVENT_DISPLAY_ADDED 44 | EVENT_DISPLAY_REMOVED 45 | EVENT_DISPLAY_MOVED 46 | EVENT_DISPLAY_DESKTOP_MODE_CHANGED 47 | EVENT_DISPLAY_CURRENT_MODE_CHANGED 48 | EVENT_DISPLAY_CONTENT_SCALE_CHANGED 49 | 50 | # Window events. 51 | EVENT_WINDOW_SHOWN = 0x202 52 | EVENT_WINDOW_HIDDEN 53 | EVENT_WINDOW_EXPOSED 54 | EVENT_WINDOW_MOVED 55 | EVENT_WINDOW_RESIZED 56 | EVENT_WINDOW_PIXEL_SIZE_CHANGED 57 | EVENT_WINDOW_METAL_VIEW_RESIZED 58 | EVENT_WINDOW_MINIMIZED 59 | EVENT_WINDOW_MAXIMIZED 60 | EVENT_WINDOW_RESTORED 61 | EVENT_WINDOW_MOUSE_ENTER 62 | EVENT_WINDOW_MOUSE_LEAVE 63 | EVENT_WINDOW_FOCUS_GAINED 64 | EVENT_WINDOW_FOCUS_LOST 65 | EVENT_WINDOW_CLOSE_REQUESTED 66 | EVENT_WINDOW_HIT_TEST 67 | EVENT_WINDOW_ICCPROF_CHANGED 68 | EVENT_WINDOW_DISPLAY_CHANGED 69 | EVENT_WINDOW_DISPLAY_SCALE_CHANGED 70 | EVENT_WINDOW_SAFE_AREA_CHANGED 71 | EVENT_WINDOW_OCCLUDED 72 | EVENT_WINDOW_ENTER_FULLSCREEN 73 | EVENT_WINDOW_LEAVE_FULLSCREEN 74 | EVENT_WINDOW_DESTROYED 75 | EVENT_WINDOW_HDR_STATE_CHANGED 76 | 77 | # Keyboard events. 78 | EVENT_KEY_DOWN = 0x300 79 | EVENT_KEY_UP 80 | EVENT_TEXT_EDITING 81 | EVENT_TEXT_INPUT 82 | EVENT_KEYMAP_CHANGED 83 | EVENT_KEYBOARD_ADDED 84 | EVENT_KEYBOARD_REMOVED 85 | EVENT_TEXT_EDITING_CANDIDATES 86 | 87 | # Mouse events. 88 | EVENT_MOUSE_MOTION = 0x400 89 | EVENT_MOUSE_BUTTON_DOWN 90 | EVENT_MOUSE_BUTTON_UP 91 | EVENT_MOUSE_WHEEL 92 | EVENT_MOUSE_ADDED 93 | EVENT_MOUSE_REMOVED 94 | 95 | # Joystick events. 96 | EVENT_JOYSTICK_AXIS_MOTION = 0x600 97 | EVENT_JOYSTICK_BALL_MOTION 98 | EVENT_JOYSTICK_HAT_MOTION 99 | EVENT_JOYSTICK_BUTTON_DOWN 100 | EVENT_JOYSTICK_BUTTON_UP 101 | EVENT_JOYSTICK_ADDED 102 | EVENT_JOYSTICK_REMOVED 103 | EVENT_JOYSTICK_BATTERY_UPDATED 104 | EVENT_JOYSTICK_UPDATE_COMPLETE 105 | 106 | # Gamepad events. 107 | EVENT_GAMEPAD_AXIS_MOTION = 0x650 108 | EVENT_GAMEPAD_BUTTON_DOWN 109 | EVENT_GAMEPAD_BUTTON_UP 110 | EVENT_GAMEPAD_ADDED 111 | EVENT_GAMEPAD_REMOVED 112 | EVENT_GAMEPAD_REMAPPED 113 | EVENT_GAMEPAD_TOUCHPAD_DOWN 114 | EVENT_GAMEPAD_TOUCHPAD_MOTION 115 | EVENT_GAMEPAD_TOUCHPAD_UP 116 | EVENT_GAMEPAD_SENSOR_UPDATE 117 | EVENT_GAMEPAD_UPDATE_COMPLETE 118 | EVENT_GAMEPAD_STEAM_HANDLE_UPDATED 119 | 120 | # Touch events. 121 | EVENT_FINGER_DOWN = 0x700 122 | EVENT_FINGER_UP 123 | EVENT_FINGER_MOTION 124 | EVENT_FINGER_CANCELED 125 | 126 | # Clipboard events. 127 | EVENT_CLIPBOARD_UPDATE = 0x900 128 | 129 | # Drag and drop events. 130 | EVENT_DROP_FILE = 0x1000 131 | EVENT_DROP_TEXT 132 | EVENT_DROP_BEGIN 133 | EVENT_DROP_COMPLETE 134 | EVENT_DROP_POSITION 135 | 136 | # Audio hotplug events. 137 | EVENT_AUDIO_DEVICE_ADDED = 0x1100 138 | EVENT_AUDIO_DEVICE_REMOVED 139 | EVENT_AUDIO_DEVICE_FORMAT_CHANGED 140 | 141 | # Sensor events. 142 | EVENT_SENSOR_UPDATE = 0x1200 143 | 144 | # Pressure-sensitive pen events. 145 | EVENT_PEN_PROXIMITY_IN = 0x1300 146 | EVENT_PEN_PROXIMITY_OUT 147 | EVENT_PEN_DOWN 148 | EVENT_PEN_UP 149 | EVENT_PEN_BUTTON_DOWN 150 | EVENT_PEN_BUTTON_UP 151 | EVENT_PEN_MOTION 152 | EVENT_PEN_AXIS 153 | 154 | # Camera hotplug events. 155 | EVENT_CAMERA_DEVICE_ADDED = 0x1400 156 | EVENT_CAMERA_DEVICE_REMOVED 157 | EVENT_CAMERA_DEVICE_APPROVED 158 | EVENT_CAMERA_DEVICE_DENIED 159 | 160 | # Render events. 161 | EVENT_RENDER_TARGETS_RESET = 0x2000 162 | EVENT_RENDER_DEVICE_RESET 163 | EVENT_RENDER_DEVICE_LOST 164 | 165 | # Internal events. 166 | EVENT_POLL_SENTINEL = 0x7f00 167 | 168 | # User defined events. To be registered with `register_events()`. 169 | # Nim exclusive defines. 10 custom user events ought to be enough for anyone. 170 | EVENT_USER = 0x8000 171 | EVENT_USER1 = 0x8001 172 | EVENT_USER2 = 0x8002 173 | EVENT_USER3 = 0x8003 174 | EVENT_USER4 = 0x8004 175 | EVENT_USER5 = 0x8005 176 | EVENT_USER6 = 0x8006 177 | EVENT_USER7 = 0x8007 178 | EVENT_USER8 = 0x8008 179 | 180 | EVENT_LAST = 0xffff 181 | 182 | const 183 | EVENT_DISPLAY_FIRST* = EVENT_DISPLAY_ORIENTATION 184 | EVENT_DISPLAY_LAST* = EVENT_DISPLAY_CONTENT_SCALE_CHANGED 185 | 186 | EVENT_WINDOW_FIRST* = EVENT_WINDOW_SHOWN 187 | EVENT_WINDOW_LAST* = EVENT_WINDOW_HDR_STATE_CHANGED 188 | 189 | type 190 | CommonEvent* {.final, pure.} = object 191 | ## Common event. 192 | typ* : EventType 193 | reserved : uint32 194 | timestamp* : uint64 ## Timestamp (ns). 195 | 196 | DisplayEvent* {.final, pure.} = object 197 | ## Display state change event. 198 | typ* : EventType ## `EVENT_DISPLAYEVENT_*`. 199 | reserved : uint32 200 | timestamp* : uint64 ## Timestamp (ns). 201 | display_id* : DisplayID ## Associated display. 202 | data1* : int32 ## Event dependent data. 203 | data2* : int32 ## Event dependent data. 204 | 205 | WindowEvent* {.final, pure.} = object 206 | ## Window state change event. 207 | typ* : EventType ## `EVENT_WINDOW_*`. 208 | reserved : uint32 209 | timestamp* : uint64 ## Timestamp (ns). 210 | window_id* : WindowID ## Associated window. 211 | data1* : int32 ## Event dependent data. 212 | data2* : int32 ## Event dependent data. 213 | 214 | KeyboardDeviceEvent* {.final, pure.} = object 215 | ## Keyboard device event. 216 | typ* : EventType ## `EVENT_KEYBOARD_ADDED` or `EVENT_KEYBOARD_REMOVED`. 217 | reserved : uint32 218 | timestamp* : uint64 ## Timestamp (ns). 219 | which* : KeyboardID ## Keyboard ID. 220 | 221 | KeyboardEvent* {.final, pure.} = object 222 | ## Keyboard button event. 223 | typ* : EventType ## `EVENT_KEY_DOWN` or `EVENT_KEY_UP`. 224 | reserved : uint32 225 | timestamp* : uint64 ## Timestamp (ns). 226 | window_id* : WindowID ## Window with keyboard focus (if any). 227 | which* : KeyboardID ## Keyboard ID. 228 | scancode* : Scancode 229 | key* : Keycode 230 | `mod`* : Keymod 231 | raw* : uint16 232 | down* : cbool ## True if the key is pressed. 233 | repeat* : cbool ## True if this is a key repeat. 234 | 235 | TextEditingEvent* {.final, pure.} = object 236 | ## Keyboard text editing event. 237 | ## 238 | ## .. note:: This event should be cleaned up with `cleanup_event()` after processing. 239 | typ* : EventType ## `EVENT_TEXT_EDITING`. 240 | reserved : uint32 241 | timestamp* : uint64 ## Timestamp (ns). 242 | window_id* : WindowID ## Window with keyboard focus (if any). 243 | text* : cstring ## The editing text. 244 | start* : int32 ## Selected editing text start cursor. 245 | length* : int32 ## Selected editing text length. 246 | 247 | TextEditingCandidatesEvent* {.final, pure.} = object 248 | ## Keyboard IME candidates input event. 249 | typ* : EventType ## `EVENT_TEXT_INPUT`. 250 | reserved : uint32 251 | timestamp* : uint64 ## Timestamp (ns). 252 | window_id* : WindowID ## Window with keyboard focus (if any). 253 | candidates* : cstringArray ## The list of candidates or `nil`. 254 | num_candidates* : int32 255 | selected_candidate* : int32 256 | horizontal* : cbool 257 | padding1 : byte 258 | padding2 : byte 259 | padding3 : byte 260 | 261 | TextInputEvent* {.final, pure.} = object 262 | ## Keyboard text input event. 263 | ## 264 | ## .. note:: This event should be cleaned up with `cleanup_event()` after processing. 265 | typ* : EventType ## `EVENT_TEXT_INPUT`. 266 | reserved : uint32 267 | timestamp* : uint64 ## Timestamp (ns). 268 | window_id* : WindowID ## Window with keyboard focus (if any). 269 | text* : cstring ## The input text. 270 | 271 | MouseDeviceEvent* {.final, pure.} = object 272 | ## Mouse device event. 273 | typ* : EventType ## `EVENT_MOUSE_ADDED` or `EVENT_MOUSE_REMOVED`. 274 | reserved : uint32 275 | timestamp* : uint64 ## Timestamp (ns). 276 | which* : MouseID ## Mouse instance ID. 277 | 278 | MouseMotionEvent* {.final, pure.} = object 279 | ## Mouse motion event. 280 | typ* : EventType ## `EVENT_MOUSE_MOTION`. 281 | reserved : uint32 282 | timestamp* : uint64 ## Timestamp (ns). 283 | window_id* : WindowID ## Window with mouse focus (if any). 284 | which* : MouseID ## Mouse instance ID or `TOUCH_MOUSEID`. 285 | state* : MouseButtonFlags ## Button state. 286 | x* : cfloat ## X position. 287 | y* : cfloat ## Y position. 288 | xrel* : cfloat ## Relative motion (X direction). 289 | yrel* : cfloat ## Relative motion (Y direction). 290 | 291 | MouseButtonEvent* {.final, pure.} = object 292 | ## Mouse button event. 293 | typ* : EventType ## `EVENT_MOUSE_BUTTON_DOWN` or `EVENT_MOUSE_BUTTON_UP`. 294 | reserved : uint32 295 | timestamp* : uint64 ## Timestamp (ns). 296 | window_id* : WindowID ## Window with mouse focus (if any). 297 | which* : MouseID ## Mouse instance ID or `SDL_TOUCH_MOUSEID`. 298 | button* : byte ## Mouse button index. 299 | down* : cbool ## True if the button is pressed. 300 | clicks* : byte ## Single click (1), double click (2), etc. 301 | padding : byte 302 | x* : cfloat ## X position. 303 | y* : cfloat ## Y position. 304 | 305 | MouseWheelEvent* {.final, pure.} = object 306 | ## Mouse wheel event. 307 | typ* : EventType ## `EVENT_MOUSE_WHEEL`. 308 | reserved : uint32 309 | timestamp* : uint64 ## Timestamp (ns). 310 | window_id* : WindowID ## Window with mouse focus (if any). 311 | which* : MouseID ## Mouse instance ID or `SDL_TOUCH_MOUSEID`. 312 | x* : cfloat ## Horizontal scroll amount. Positive to the 313 | ## right. Negative to the left. 314 | y* : cfloat ## Vertical scroll amount. Positive to the 315 | ## user, negative toward the user. 316 | direction* : MouseWheelDirection ## Direction (`MOUSEWHEEL_*`). 317 | mouse_x* : cfloat ## X position. 318 | mouse_y* : cfloat ## Y position. 319 | 320 | JoyAxisEvent* {.final, pure.} = object 321 | ## Joystick axis motion event. 322 | typ* : EventType ## `EVENT_JOYSTICK_AXIS_MOTION`. 323 | reserved : uint32 324 | timestamp* : uint64 ## Timestamp (ns). 325 | which* : JoystickID ## Joystick ID. 326 | axis* : byte ## Joystick axis index. 327 | padding1 : byte 328 | padding2 : byte 329 | padding3 : byte 330 | value* : int16 ## Axis value (range: -32768 to 32767). 331 | padding4 : uint16 332 | 333 | JoyBallEvent* {.final, pure.} = object 334 | ## Joystick trackball motion event. 335 | typ* : EventType ## `EVENT_JOYBALLMOTION`. 336 | reserved : uint32 337 | timestamp* : uint64 ## Timestamp (ns). 338 | which* : JoystickID ## Joystick ID. 339 | ball* : byte ## Joystick trackball index. 340 | padding1 : byte 341 | padding2 : byte 342 | padding3 : byte 343 | xrel* : int16 ## Relative motion (X direction). 344 | yrel* : int16 ## Relative motion (Y direction). 345 | 346 | JoyHatEvent* {.final, pure.} = object 347 | ## Joystick hat position change event. 348 | typ* : EventType ## `EVENT_JOYSTICK_HAT_MOTION`. 349 | reserved : uint32 350 | timestamp* : uint64 ## Timestamp (ns). 351 | which* : JoystickID ## Joystick ID. 352 | hat* : Hat ## Joystick hat index. 353 | value* : byte ## Hat position. 354 | padding1 : byte 355 | padding2 : byte 356 | 357 | JoyButtonEvent* {.final, pure.} = object 358 | ## Joystick button event. 359 | typ* : EventType ## `EVENT_JOYSTICK_BUTTON_DOWN` or `EVENT_JOYSTICK_BUTTON_UP`. 360 | reserved : uint32 361 | timestamp* : uint64 ## Timestamp (ns). 362 | which* : JoystickID ## Joystick ID. 363 | button* : byte ## Joystick button index. 364 | down* : cbool ## True if the button is pressed. 365 | padding1 : byte 366 | padding2 : byte 367 | 368 | JoyDeviceEvent* {.final, pure.} = object 369 | ## Joystick device event. 370 | typ* : EventType ## `EVENT_JOYSTICK_ADDED`, `EVENT_JOYSTICK_REMOVED` or `EVENT_JOYSTICK_UPDATE_COMPLETE`. 371 | reserved : uint32 372 | timestamp* : uint64 ## Timestamp (ns). 373 | which* : JoystickID ## Joystick ID. 374 | 375 | JoyBatteryEvent* {.final, pure.} = object 376 | ## Joystick battery event. 377 | typ* : EventType ## `EVENT_JOYSTICK_BATTERY_UPDATED`. 378 | reserved : uint32 379 | timestamp* : uint64 ## Timestamp (ns). 380 | which* : JoystickID ## Joystick ID. 381 | state* : PowerState ## Joystick battery state. 382 | percent* : cint ## Joystick battery percent charge remaining. 383 | 384 | GamepadAxisEvent* {.final, pure.} = object 385 | ## Gamepad axis motion event. 386 | typ* : EventType ## `EVENT_GAMEPAD_AXIS_MOTION`. 387 | reserved : uint32 388 | timestamp* : uint64 ## Timestamp (ns). 389 | which* : JoystickID ## Joystick ID. 390 | axis* : byte ## Controller axis (`GameControllerAxis`). 391 | padding1 : byte 392 | padding2 : byte 393 | padding3 : byte 394 | value* : int16 ## Axis value (range: -32768 to 32767). 395 | padding4 : uint16 396 | 397 | GamepadButtonEvent* {.final, pure.} = object 398 | ## Gamepad button event. 399 | typ* : EventType ## `EVENT_GAMEPAD_BUTTON_DOWN` or `EVENT_GAMEPAD_BUTTON_UP`. 400 | reserved : uint32 401 | timestamp* : uint64 ## Timestamp (ns). 402 | which* : JoystickID ## Joystick ID. 403 | button* : byte ## Joystick button (`GameControllerButton`). 404 | down* : cbool ## True if the button is pressed. 405 | padding1 : byte 406 | padding2 : byte 407 | 408 | GamepadDeviceEvent* {.final, pure.} = object 409 | ## Gamepad device event. 410 | typ* : EventType ## `EVENT_GAMEPAD_ADDED`, 411 | ## `EVENT_GAMEPAD_REMOVED` 412 | ## `EVENT_GAMEPAD_REMAPPED`, 413 | ## `EVENT_GAMEPAD_UPDATE_COMPLETE` 414 | ## or `EVENT_GAMEPAD_STEAM_HANDLE_UPDATED`. 415 | reserved : uint32 416 | timestamp* : uint64 ## Timestamp (ns). 417 | which* : JoystickID ## Joystick instance ID. 418 | 419 | GamepadTouchpadEvent* {.final, pure.} = object 420 | ## Gamepad touchpad event. 421 | typ* : EventType ## `EVENT_GAMEPAD_TOUCHPAD_DOWN`, 422 | ## `EVENT_GAMEPAD_TOUCHPAD_MOTION` 423 | ## or `EVENT_GAMEPAD_TOUCHPAD_UP`. 424 | reserved : uint32 425 | timestamp* : uint64 ## Timestamp (ns). 426 | which* : JoystickID ## Joystick ID. 427 | touchpad* : int32 ## Touchpad index. 428 | finger* : int32 ## Finger index. 429 | x* : cfloat ## Normalized, range 0 - 1; 0 is left. 430 | y* : cfloat ## Normalized, range 0 - 1; 0 is top. 431 | pressure* : cfloat ## Normalized, range 0 - 1. 432 | 433 | GamepadSensorEvent* {.final, pure.} = object 434 | ## Gamepad sensor event. 435 | typ* : EventType ## `EVENT_GAMEPAD_SENSOR_UPDATE`. 436 | reserved : uint32 437 | timestamp* : uint64 ## In ms, populated using GetTicks(). 438 | which* : JoystickID ## Joystick ID. 439 | sensor* : int32 ## Sensor type (`SensorType`). 440 | data* : array[3, cfloat] ## Sensor values (up to 3). 441 | sensor_timestamp* : uint64 442 | 443 | AudioDeviceEvent* {.final, pure.} = object 444 | ## Audio device event. 445 | typ* : EventType ## `EVENT_AUDIO_DEVICE_ADDED`, `EVENT_AUDIO_DEVICE_REMOVED` or `EVENT_AUDIO_DEVICE_FORMAT_CHANGED`. 446 | reserved : uint32 447 | timestamp* : uint64 ## Timestamp (ns). 448 | which* : AudioDeviceID ## Audio device index for the `ADDED` event. 449 | ## (valid until next `get_num_audio_devices() 450 | ## call) or `AudioDeviceID` for the `REMOVED` event. 451 | recording* : cbool ## Playback device (false) or recording device (true). 452 | padding1 : byte 453 | padding2 : byte 454 | padding3 : byte 455 | 456 | CameraDeviceEvent* {.final, pure.} = object 457 | ## Camera device event. 458 | typ* : EventType ## `EVENT_CAMERA_DEVICE_ADDED`, `EVENT_CAMERA_DEVICE_REMOVED`, `EVENT_CAMERA_DEVICE_APPROVED` or `EVENT_CAMERA_DEVICE_DENIED`. 459 | reserved : uint32 460 | timestamp* : uint64 ## Timestamp (ns). 461 | which* : CameraDeviceID ## Camera device index for the `ADDED`, `REMOVED` or `CHANGING` event. 462 | 463 | RenderEvent* {.final, pure.} = object 464 | ## Render event. 465 | typ* : EventType ## `SDL_EVENT_RENDER_TARGETS_RESET`, `SDL_EVENT_RENDER_DEVICE_RESET`, `SDL_EVENT_RENDER_DEVICE_LOST`. 466 | reserved : uint32 467 | timestamp* : uint64 ## Timestamp (ns). 468 | window_id* : WindowID ## Rendering window. 469 | 470 | TouchFingerEvent* {.final, pure.} = object 471 | ## Touch finger event. 472 | typ* : EventType ## `EVENT_FINGER_MOTION`, `EVENT_FINGER_DOWN` or `EVENT_FINGER_UP`. 473 | reserved : uint32 474 | timestamp* : uint64 ## Timestamp (ns). 475 | touch_id* : TouchID ## Touch ID. 476 | finger_id* : FingerID 477 | x* : cfloat ## Normalized, range 0 - 1. 478 | y* : cfloat ## Normalized, range 0 - 1. 479 | dx* : cfloat ## Normalized, range -1 - 1. 480 | dy* : cfloat ## Normalized, range -1 - 1. 481 | pressure* : cfloat ## Normalized, range 0 - 1. 482 | window_id* : WindowID ## Window underneath the finger (if any). 483 | 484 | PenProximityEvent* {.final, pure.} = object 485 | ## Pressure-sensitive pen proximity event. 486 | typ* : EventType ## `EVENT_PEN_PROXIMITY_IN` or ``SDL_EVENT_PROXIMITY_OUT`. 487 | reserved : uint32 488 | timestamp* : uint64 ## Timestamp (ns). 489 | window_id* : WindowID ## The window with pen focus, if any. 490 | which* : PenID ## The pen instance id. 491 | 492 | PenMotionEvent* {.final, pure.} = object 493 | ## Pressure-sensitive pen motion event. 494 | typ* : EventType ## `EVENT_PEN_MOTION`. 495 | reserved : uint32 496 | timestamp* : uint64 ## Timestamp (ns). 497 | window_id* : WindowID ## The window with pen focus, if any. 498 | which* : PenID ## The pen instance id. 499 | pen_state* : PenInputFlags ## Complete pen input state at time of event. 500 | x* : cfloat ## X position, relative to window. 501 | y* : cfloat ## Y position, relative to window. 502 | 503 | PenTouchEvent* {.final, pure.} = object 504 | ## Pressure-sensitive pen touched event. 505 | typ* : EventType ## `EVENT_PEN_DOWN` or `EVENT_PEN_UP`. 506 | reserved : uint32 507 | timestamp* : uint64 ## Timestamp (ns). 508 | window_id* : WindowID ## The window with pen focus, if any. 509 | which* : PenID ## The pen instance id. 510 | pen_state* : PenInputFlags ## Complete pen input state at time of event. 511 | x* : cfloat ## X position, relative to window. 512 | y* : cfloat ## Y position, relative to window. 513 | eraser* : cbool ## True is eraser end is used. Not supported by all pens. 514 | down* : cbool ## True if the pen is touching or false if the pen is lifted off. 515 | 516 | PenButtonEvent* {.final, pure.} = object 517 | ## Pressure-sensitive pen button event. 518 | typ* : EventType ## `EVENT_PEN_BUTTON_DOWN` or `EVENT_PEN_BUTTON_UP`. 519 | reserved : uint32 520 | timestamp* : uint64 ## Timestamp (ns). 521 | window_id* : WindowID ## The window with pen focus, if any. 522 | which* : PenID ## The pen instance id. 523 | pen_state* : PenInputFlags ## Complete pen input state at time of event. 524 | x* : cfloat ## X position, relative to window. 525 | y* : cfloat ## Y position, relative to window. 526 | button* : byte ## The pen button index (first button is 1). 527 | down* : cbool ## True if the button is pressed. 528 | 529 | PenAxisEvent* {.final, pure.} = object 530 | ## Pressure-sensitive pen pressure / angle event. 531 | typ* : EventType ## `EVENT_PEN_AXIS`. 532 | reserved : uint32 533 | timestamp* : uint64 ## Timestamp (ns). 534 | window_id* : WindowID ## The window with pen focus, if any. 535 | which* : PenID ## The pen instance id. 536 | pen_state* : PenInputFlags ## Complete pen input state at time of event. 537 | x* : cfloat ## X position, relative to window. 538 | y* : cfloat ## Y position, relative to window. 539 | axis* : PenAxis ## Axis that has changed. 540 | value* : cfloat ## New value of axis. 541 | 542 | DropEvent* {.final, pure.} = object 543 | ## An event used to drop text or request a file open by the system. 544 | ## 545 | ## .. note:: This event should be cleaned up with `cleanup_event()` after processing. 546 | typ* : EventType ## `EVENT_DROP_BEGIN`, `EVENT_DROP_FILE`, 547 | ## `EVENT_DROP_TEXT` or `EVENT_DROP_COMPLETE`. 548 | reserved : uint32 549 | timestamp* : uint64 ## Timestamp (ns). 550 | window_id* : WindowID ## Window ID file was dropped on (if any). 551 | x* : cfloat ## X position, relative to window. 552 | y* : cfloat ## Y position, relative to window. 553 | source* : cstring ## The source app that sent this drop event, or `nil` if that isn't available. 554 | dest* : cstring ## The text for `EVENT_DROP_TEXT` and the file name for `EVENT_DROP_FILE`, `nil` for other events. 555 | 556 | ClipboardEvent* {.final, pure.} = object 557 | ## Clipboard contents have changed. 558 | typ* : EventType ## `EVENT_CLIPBOARD_UPDATE`. 559 | reserved : uint32 560 | timestamp* : uint64 ## Timestamp (ns). 561 | owner* : cbool ## Are we owning the clipboard? 562 | num_mime_types* : int32 ## Number of mime types. 563 | mime_types* : cstringArray ## Mime types. 564 | 565 | SensorEvent* {.final, pure.} = object 566 | ## Sensor event. 567 | typ* : EventType ## `EVENT_SENSOR_UPDATE`. 568 | reserved : uint32 569 | timestamp* : uint64 ## Timestamp (ns). 570 | which* : SensorID ## Sensor ID. 571 | data* : array[6, cfloat] ## Sensor values (up to 6). 572 | ## Query additional values with 573 | ## `sensor_get_data()`. 574 | sensor_timestamp* : uint64 575 | 576 | QuitEvent* {.final, pure.} = object 577 | ## The "quit requested" event. 578 | typ* : EventType ## `EVENT_QUIT`. 579 | reserved : uint32 580 | timestamp* : uint64 ## Timestamp (ns). 581 | 582 | UserEvent* {.final, pure.} = object 583 | ## A user-defined event type. 584 | typ* : EventType ## `EVENT_USER` through `EVENT_USER8`. 585 | reserved : uint32 586 | timestamp* : uint64 ## Timestamp (ns). 587 | window_id* : WindowID ## Associated window (if any). 588 | code* : int32 ## User defined code. 589 | data1* : pointer ## User defined data pointer. 590 | data2* : pointer ## User defined data pointer. 591 | 592 | type 593 | Event* {.bycopy, final, pure, union.} = object 594 | ## Event. 595 | typ* : EventType ## Event type. 596 | common* : CommonEvent ## Common event. 597 | display* : DisplayEvent ## Display event. 598 | window* : WindowEvent ## Window event. 599 | kdevice* : KeyboardDeviceEvent ## Keyboard device change event. 600 | key* : KeyboardEvent ## Keyboard event. 601 | edit* : TextEditingEvent ## Text editing event. 602 | edit_candidates* : TextEditingCandidatesEvent ## Text editing candidates event. 603 | text* : TextInputEvent ## Text input event. 604 | mdevice* : MouseDeviceEvent ## Mouse device change event. 605 | motion* : MouseMotionEvent ## Mouse motion event. 606 | button* : MouseButtonEvent ## Mouse button event. 607 | wheel* : MouseWheelEvent ## Mouse wheel event. 608 | jdevice* : JoyDeviceEvent ## Joystick device change event. 609 | jaxis* : JoyAxisEvent ## Joystick axis event. 610 | jball* : JoyBallEvent ## Joystick ball event. 611 | jhat* : JoyHatEvent ## Joystick hat event. 612 | jbutton* : JoyButtonEvent ## Joystick button event. 613 | jbattery* : JoyBatteryEvent ## Joystick battery event. 614 | gdevice* : GamepadDeviceEvent ## Gamepad device event. 615 | gaxis* : GamepadAxisEvent ## Gamepad axis event. 616 | gbutton* : GamepadButtonEvent ## Gamepad button event. 617 | gtouchpad* : GamepadTouchpadEvent ## Gamepad touchpad event. 618 | gsensor* : GamepadSensorEvent ## Gamepad sensor event. 619 | adevice* : AudioDeviceEvent ## Audio device event. 620 | cdevice* : CameraDeviceEvent ## Camera device event. 621 | sensor* : SensorEvent ## Sensor event. 622 | quit* : QuitEvent ## Quit request event. 623 | user* : UserEvent ## Custom event. 624 | tfinger* : TouchFingerEvent ## Touch finger event. 625 | pproximity* : PenProximityEvent ## Pen proximity event. 626 | ptouch* : PenTouchEvent ## Pen tip touching event. 627 | pmotion* : PenMotionEvent ## Pen motion event. 628 | pbutton* : PenButtonEvent ## Pen button event. 629 | paxis* : PenAxisEvent ## Pen axis event. 630 | render* : RenderEvent ## Render event. 631 | drop* : DropEvent ## Drag and drop event. 632 | clipboard* : ClipboardEvent ## Clipboard change event. 633 | padding : array[128, byte] # See `SDL_events.h` for details. 634 | 635 | # Let's make sure we haven't broken binary compatibility. 636 | when Event.sizeof != Event.padding.sizeof: 637 | {.error: "invalid Event size".} 638 | 639 | type 640 | EventAction* {.size: cint.sizeof.} = enum 641 | ## Event action. 642 | ADDEVENT 643 | PEEKEVENT 644 | GETEVENT 645 | 646 | type 647 | EventFilter* = proc (userdata : pointer, 648 | event : ptr Event): cbool {.cdecl, raises: [].} 649 | ## A function pointer used for callbacks that watch the event queue. 650 | 651 | # ============================================================================ # 652 | # == Nim specific == # 653 | # ============================================================================ # 654 | 655 | # Calling default `$` and repr on union in Nim results with: 656 | # SIGSEGV: Illegal storage access. (Attempt to read from nil?) 657 | 658 | when defined release: 659 | func `$`*(event: ptr Event): string {.error: "do not `$` unions in Nim".} 660 | func repr*(event: Event): string {.error: "do not repr unions in Nim".} 661 | else: 662 | func `$`*(event: Event): string = "(typ: " & $event.typ & ", ...)" 663 | func repr*(event: Event): string = "[typ = " & $event.typ & ", ...]" 664 | 665 | func repr*(event: ptr Event): string {.error: "do not repr unions in Nim".} 666 | 667 | # --------------------------------------------------------------------------- # 668 | # Sanity checks # 669 | # --------------------------------------------------------------------------- # 670 | 671 | when hostCPU == "amd64" and defined gcc: 672 | when Event.sizeof != 128: 673 | {.error: "invalid Event size: " & $Event.sizeof.} 674 | 675 | when CommonEvent.sizeof != 16: 676 | {.error: "invalid CommonEvent size: " & $CommonEvent.sizeof.} 677 | when WindowEvent.sizeof != 32: 678 | {.error: "invalid WindowEvent size: " & $WindowEvent.sizeof.} 679 | # XXX: 680 | # when KeyboardEvent.sizeof != 40: 681 | # {.error: "invalid KeyboardEvent size: " & $KeyboardEvent.sizeof.} 682 | when TextEditingEvent.sizeof != 40: 683 | {.error: "invalid TextEditingEvent size: " & $TextEditingEvent.sizeof.} 684 | when TextInputEvent.sizeof != 32: 685 | {.error: "invalid TextInputEvent size: " & $TextInputEvent.sizeof.} 686 | when MouseMotionEvent.sizeof != 48: 687 | {.error: "invalid MouseMotionEvent size: " & $MouseMotionEvent.sizeof.} 688 | when MouseButtonEvent.sizeof != 40: 689 | {.error: "invalid MouseButtonEvent size: " & $MouseButtonEvent.sizeof.} 690 | when MouseWheelEvent.sizeof != 48: 691 | {.error: "invalid MouseWheelEvent size: " & $MouseWheelEvent.sizeof.} 692 | when JoyAxisEvent.sizeof != 32: 693 | {.error: "invalid JoyAxisEvent size: " & $JoyAxisEvent.sizeof.} 694 | when JoyHatEvent.sizeof != 24: 695 | {.error: "invalid JoyHatEvent size: " & $JoyHatEvent.sizeof.} 696 | when JoyButtonEvent.sizeof != 24: 697 | {.error: "invalid JoyButtonEvent size: " & $JoyButtonEvent.sizeof.} 698 | when JoyDeviceEvent.sizeof != 24: 699 | {.error: "invalid JoyDeviceEvent size: " & $JoyDeviceEvent.sizeof.} 700 | # when JoyBatteryEvent.sizeof != 24: 701 | # {.error: "invalid JoyBatteryEvent size: " & $JoyBatteryEvent.sizeof.} 702 | when GamepadAxisEvent.sizeof != 32: 703 | {.error: "invalid GamepadAxisEvent size: " & $GamepadAxisEvent.sizeof.} 704 | when GamepadButtonEvent.sizeof != 24: 705 | {.error: "invalid GamepadButtonEvent size: " & $GamepadButtonEvent.sizeof.} 706 | when GamepadDeviceEvent.sizeof != 24: 707 | {.error: "invalid GamepadDeviceEvent size: " & $GamepadDeviceEvent.sizeof.} 708 | when GamepadTouchpadEvent.sizeof != 40: 709 | {.error: "invalid GamepadTouchpadEvent size: " & $GamepadTouchpadEvent.sizeof.} 710 | when GamepadSensorEvent.sizeof != 48: 711 | {.error: "invalid GamepadSensorEvent size: " & $GamepadSensorEvent.sizeof.} 712 | when AudioDeviceEvent.sizeof != 24: 713 | {.error: "invalid AudioDeviceEvent size: " & $AudioDeviceEvent.sizeof.} 714 | when TouchFingerEvent.sizeof != 56: 715 | {.error: "invalid TouchFingerEvent size: " & $TouchFingerEvent.sizeof.} 716 | # when PenTipEvent.sizeof != 64: 717 | # {.error: "invalid PenTipEvent size: " & $PenTipEvent.sizeof.} 718 | # when PenMotionEvent.sizeof != 64: 719 | # {.error: "invalid PenMotionEvent size: " & $PenMotionEvent.sizeof.} 720 | # when PenButtonEvent.sizeof != 64: 721 | # {.error: "invalid PenButtonEvent size: " & $PenButtonEvent.sizeof.} 722 | when DropEvent.sizeof != 48: 723 | {.error: "invalid DropEvent size: " & $DropEvent.sizeof.} 724 | #when ClipboardEvent.sizeof != 16: 725 | # {.error: "invalid ClipboardEvent size: " & $ClipboardEvent.sizeof.} 726 | when SensorEvent.sizeof != 56: 727 | {.error: "invalid SensorEvent size: " & $SensorEvent.sizeof.} 728 | when QuitEvent.sizeof != 16: 729 | {.error: "invalid QuitEvent size: " & $QuitEvent.sizeof.} 730 | when UserEvent.sizeof != 40: 731 | {.error: "invalid UserEvent size: " & $UserEvent.sizeof.} 732 | 733 | # vim: set sts=2 et sw=2: 734 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3filesystem.nim: -------------------------------------------------------------------------------- 1 | ## Filesystem definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | #[* 10 | * The type of the OS-provided default folder for a specific purpose. 11 | * 12 | * Note that the Trash folder isn't included here, because trashing files 13 | * usually involves extra OS-specific functionality to remember the file's 14 | * original location. 15 | * 16 | * The folders supported per platform are: 17 | * 18 | * | | Windows | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten | 19 | * | ----------- | ------- | --------- | ---- | ---------- | ----- | ---------- | 20 | * | HOME | X | X | | X | X | X | 21 | * | DESKTOP | X | X | | X | X | | 22 | * | DOCUMENTS | X | X | | X | | | 23 | * | DOWNLOADS | Vista+ | X | | X | | | 24 | * | MUSIC | X | X | | X | | | 25 | * | PICTURES | X | X | | X | | | 26 | * | PUBLICSHARE | | X | | X | | | 27 | * | SAVEDGAMES | Vista+ | | | | | | 28 | * | SCREENSHOTS | Vista+ | | | | | | 29 | * | TEMPLATES | X | X | | X | | | 30 | * | VIDEOS | X | X* | | X | | | 31 | * 32 | * Note that on macOS/iOS, the Videos folder is called "Movies". 33 | * 34 | * \since This enum is available since SDL 3.2.0. 35 | * 36 | * \sa SDL_GetUserFolder 37 | ]# 38 | 39 | type 40 | Folder* {.size: cint.sizeof.} = enum 41 | ## OS-provided default folder. 42 | SDL_FOLDER_HOME 43 | SDL_FOLDER_DESKTOP 44 | SDL_FOLDER_DOCUMENTS 45 | SDL_FOLDER_DOWNLOADS 46 | SDL_FOLDER_MUSIC 47 | SDL_FOLDER_PICTURES 48 | SDL_FOLDER_PUBLICSHARE 49 | SDL_FOLDER_SAVEDGAMES 50 | SDL_FOLDER_SCREENSHOTS 51 | SDL_FOLDER_TEMPLATES 52 | SDL_FOLDER_VIDEOS 53 | SDL_FOLDER_COUNT 54 | 55 | type 56 | PathType* {.size: cint.sizeof.} = enum 57 | ## Types of filesystem entries. 58 | PATHTYPE_NONE 59 | PATHTYPE_FILE 60 | PATHTYPE_DIRECTORY 61 | PATHTYPE_OTHER 62 | 63 | type 64 | PathInfo* {.final, pure.} = object 65 | ## Information about a path on the filesystem. 66 | typ : PathType # type; /**< the path type */ 67 | #Uint64 size; #/**< the file size in bytes */ 68 | #SDL_Time create_time; #/**< the time when the path was created */ 69 | #SDL_Time modify_time; #/**< the last time the path was modified */ 70 | #SDL_Time access_time; #/**< the last time the path was read */ 71 | 72 | type 73 | GlobFlags* = distinct uint32 74 | ## Flags for path matching. 75 | 76 | const 77 | GLOB_CASEINSENSITIVE* = GlobFlags 1u32 shl 0 78 | 79 | type 80 | EnumerationResult* {.size: cint.sizeof.} = enum 81 | ## Possible results from an enumeration callback. 82 | ENUM_CONTINUE 83 | ENUM_SUCCESS 84 | ENUM_FAILURE 85 | 86 | type 87 | EnumerateDirectoryCallback* = proc ( 88 | userdata : pointer, 89 | dirname : cstring, 90 | fname : cstring 91 | ): EnumerationResult {.cdecl, gcsafe, raises: [].} 92 | ## Callback for directory enumeration. 93 | 94 | # vim: set sts=2 et sw=2: 95 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3gamepad.nim: -------------------------------------------------------------------------------- 1 | ## Gamepad event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | Gamepad* = ptr object 11 | ## Gamepad. 12 | 13 | GamepadType* {.size: cint.sizeof.} = enum 14 | ## Gamepad type. 15 | GAMEPAD_TYPE_UNKNOWN = 0 16 | GAMEPAD_TYPE_STANDARD 17 | GAMEPAD_TYPE_XBOX360 18 | GAMEPAD_TYPE_XBOXONE 19 | GAMEPAD_TYPE_PS3 20 | GAMEPAD_TYPE_PS4 21 | GAMEPAD_TYPE_PS5 22 | GAMEPAD_TYPE_NINTENDO_SWITCH_PRO 23 | GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT 24 | GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT 25 | GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR 26 | 27 | const 28 | GAMEPAD_TYPE_COUNT* = GamepadType.high.int + 1 29 | 30 | type 31 | GamepadButton* {.size: cint.sizeof.} = enum # XXX: size. 32 | ## The list of buttons available on a gamepad. 33 | GAMEPAD_BUTTON_INVALID = -1 34 | GAMEPAD_BUTTON_SOUTH 35 | GAMEPAD_BUTTON_EAST 36 | GAMEPAD_BUTTON_WEST 37 | GAMEPAD_BUTTON_NORTH 38 | GAMEPAD_BUTTON_BACK 39 | GAMEPAD_BUTTON_GUIDE 40 | GAMEPAD_BUTTON_START 41 | GAMEPAD_BUTTON_LEFT_STICK 42 | GAMEPAD_BUTTON_RIGHT_STICK 43 | GAMEPAD_BUTTON_LEFT_SHOULDER 44 | GAMEPAD_BUTTON_RIGHT_SHOULDER 45 | GAMEPAD_BUTTON_DPAD_UP 46 | GAMEPAD_BUTTON_DPAD_DOWN 47 | GAMEPAD_BUTTON_DPAD_LEFT 48 | GAMEPAD_BUTTON_DPAD_RIGHT 49 | GAMEPAD_BUTTON_MISC1 50 | GAMEPAD_BUTTON_RIGHT_PADDLE1 51 | GAMEPAD_BUTTON_LEFT_PADDLE1 52 | GAMEPAD_BUTTON_RIGHT_PADDLE2 53 | GAMEPAD_BUTTON_LEFT_PADDLE2 54 | GAMEPAD_BUTTON_TOUCHPAD 55 | GAMEPAD_BUTTON_MISC2 56 | GAMEPAD_BUTTON_MISC3 57 | GAMEPAD_BUTTON_MISC4 58 | GAMEPAD_BUTTON_MISC5 59 | GAMEPAD_BUTTON_MISC6 60 | 61 | const 62 | GAMEPAD_BUTTON_COUNT* = GamepadButton.high.int + 1 63 | 64 | type 65 | GamepadButtonLabel* {.size: cint.sizeof.} = enum 66 | ## The set of gamepad button labels. 67 | GAMEPAD_BUTTON_LABEL_UNKNOWN 68 | GAMEPAD_BUTTON_LABEL_A 69 | GAMEPAD_BUTTON_LABEL_B 70 | GAMEPAD_BUTTON_LABEL_X 71 | GAMEPAD_BUTTON_LABEL_Y 72 | GAMEPAD_BUTTON_LABEL_CROSS 73 | GAMEPAD_BUTTON_LABEL_CIRCLE 74 | GAMEPAD_BUTTON_LABEL_SQUARE 75 | GAMEPAD_BUTTON_LABEL_TRIANGLE 76 | 77 | type 78 | GamepadAxis* {.size: cint.sizeof.} = enum 79 | ## The list of axes available on a gamepad. 80 | GAMEPAD_AXIS_INVALID = -1 81 | GAMEPAD_AXIS_LEFTX 82 | GAMEPAD_AXIS_LEFTY 83 | GAMEPAD_AXIS_RIGHTX 84 | GAMEPAD_AXIS_RIGHTY 85 | GAMEPAD_AXIS_LEFT_TRIGGER 86 | GAMEPAD_AXIS_RIGHT_TRIGGER 87 | 88 | const 89 | GAMEPAD_AXIS_COUNT* = GamepadAxis.high.int + 1 90 | 91 | type 92 | GamepadBindingType* {.size: cint.sizeof.} = enum 93 | GAMEPAD_BINDTYPE_NONE = 0 94 | GAMEPAD_BINDTYPE_BUTTON 95 | GAMEPAD_BINDTYPE_AXIS 96 | GAMEPAD_BINDTYPE_HAT 97 | 98 | type 99 | GamepadBinding* {.final, pure.} = object 100 | ## Gamepad binding. 101 | input_type* : GamepadBindingType 102 | input* : GamepadBindingInputUnion 103 | output_type* : GamepadBindingType 104 | output* : GamepadBindingOutputUnion 105 | 106 | GamepadBindingInputUnion* {.final, pure, union.} = object 107 | button* : cint 108 | axis* : GamepadBindingInputUnionAxis 109 | hat* : GamepadBindingInputUnionHat 110 | 111 | GamepadBindingInputUnionAxis* {.final, pure.} = object 112 | axis* : cint 113 | axis_min* : cint 114 | axis_max* : cint 115 | 116 | GamepadBindingInputUnionHat* {.final, pure.} = object 117 | hat* : cint 118 | hat_mask* : cint 119 | 120 | GamepadBindingOutputUnion* {.final, pure, union.} = object 121 | button* : GamepadButton 122 | axis* : GamepadBindingOutputUnionAxis 123 | 124 | GamepadBindingOutputUnionAxis* {.final, pure.} = object 125 | axis* : GamepadAxis 126 | axis_min* : cint 127 | axis_max* : cint 128 | 129 | # vim: set sts=2 et sw=2: 130 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3hints.nim: -------------------------------------------------------------------------------- 1 | ## Hints. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | import std/macros 10 | 11 | macro gen_hint_enum_type(enum_name: string, 12 | values: varargs[string]) = 13 | var fields: seq[NimNode] = @[] 14 | 15 | for val in values: 16 | let hname = newIdentNode "HINT_" & $val 17 | let hval = newStrLitNode "SDL_" & $val 18 | fields.add( 19 | nnkEnumFieldDef.newNimNode.add(hname).add( 20 | nnkCommand.newNimNode.add(newIdentNode "cstring", hval) 21 | ) 22 | ) 23 | 24 | newEnum(ident $enum_name, fields, public = true, pure = false) 25 | 26 | gen_hint_enum_type "HintName", 27 | "ACCELEROMETER_AS_JOYSTICK", 28 | "ALLOW_ALT_TAB_WHILE_GRABBED", 29 | "ALLOW_TOPMOST", 30 | "ANDROID_ALLOW_RECREATE_ACTIVITY", 31 | "ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO", 32 | "ANDROID_BLOCK_ON_PAUSE", 33 | "ANDROID_LOW_LATENCY_AUDIO", 34 | "ANDROID_TRAP_BACK_BUTTON", 35 | "APP_ID", 36 | "APPLE_TV_CONTROLLER_UI_EVENTS", 37 | "APPLE_TV_REMOTE_ALLOW_ROTATION", 38 | "APP_NAME", 39 | "ASSERT", 40 | "AUDIO_ALSA_DEFAULT_DEVICE", 41 | "AUDIO_ALSA_DEFAULT_PLAYBACK_DEVICE", 42 | "AUDIO_ALSA_DEFAULT_RECORDING_DEVICE", 43 | "AUDIO_CATEGORY", 44 | "AUDIO_CHANNELS", 45 | "AUDIO_DEVICE_APP_NAME", 46 | "AUDIO_DEVICE_SAMPLE_FRAMES", 47 | "AUDIO_DEVICE_STREAM_NAME", 48 | "AUDIO_DEVICE_STREAM_ROLE", 49 | "AUDIO_DISK_INPUT_FILE", 50 | "AUDIO_DISK_OUTPUT_FILE", 51 | "AUDIO_DISK_TIMESCALE", 52 | "AUDIO_DRIVER", 53 | "AUDIO_DUMMY_TIMESCALE", 54 | "AUDIO_FORMAT", 55 | "AUDIO_FREQUENCY", 56 | "AUDIO_INCLUDE_MONITORS", 57 | "AUTO_UPDATE_JOYSTICKS", 58 | "AUTO_UPDATE_SENSORS", 59 | "BMP_SAVE_LEGACY_FORMAT", 60 | "CPU_FEATURE_MASK", 61 | "DIRECTINPUT_ENABLED", 62 | "DISPLAY_USABLE_BOUNDS", 63 | "EGL_LIBRARY", 64 | "EMSCRIPTEN_ASYNCIFY", 65 | "EMSCRIPTEN_CANVAS_SELECTOR", 66 | "EMSCRIPTEN_KEYBOARD_ELEMENT", 67 | "ENABLE_SCREEN_KEYBOARD", 68 | "EVDEV_DEVICES", 69 | "EVENT_LOGGING", 70 | "FILE_DIALOG_DRIVER", 71 | "FORCE_RAISEWINDOW", 72 | "FRAMEBUFFER_ACCELERATION", 73 | "GAMECONTROLLERCONFIG_FILE", 74 | "GAMECONTROLLERCONFIG", 75 | "GAMECONTROLLER_IGNORE_DEVICES_EXCEPT", 76 | "GAMECONTROLLER_IGNORE_DEVICES", 77 | "GAMECONTROLLER_SENSOR_FUSION", 78 | "GAMECONTROLLERTYPE", 79 | "GDK_TEXTINPUT_DEFAULT", 80 | "GDK_TEXTINPUT_DESCRIPTION", 81 | "GDK_TEXTINPUT_MAX_LENGTH", 82 | "GDK_TEXTINPUT_SCOPE", 83 | "GDK_TEXTINPUT_TITLE", 84 | "GPU_DRIVER", 85 | "HIDAPI_ENUMERATE_ONLY_CONTROLLERS", 86 | "HIDAPI_IGNORE_DEVICES", 87 | "HIDAPI_LIBUSB", 88 | "HIDAPI_LIBUSB_WHITELIST", 89 | "HIDAPI_UDEV", 90 | "IME_INTERNAL_EDITING", 91 | "IME_SHOW_UI", 92 | "IOS_HIDE_HOME_INDICATOR", 93 | "JOYSTICK_ALLOW_BACKGROUND_EVENTS", 94 | "JOYSTICK_ARCADESTICK_DEVICES", 95 | "JOYSTICK_ARCADESTICK_DEVICES_EXCLUDED", 96 | "JOYSTICK_BLACKLIST_DEVICES", 97 | "JOYSTICK_BLACKLIST_DEVICES_EXCLUDED", 98 | "JOYSTICK_DEVICE", 99 | "JOYSTICK_ENHANCED_REPORTS", 100 | "JOYSTICK_FLIGHTSTICK_DEVICES", 101 | "JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED", 102 | "JOYSTICK_GAMECUBE_DEVICES", 103 | "JOYSTICK_GAMECUBE_DEVICES_EXCLUDED", 104 | "JOYSTICK_GAMECUBE_RUMBLE_BRAKE", 105 | "JOYSTICK_GAMEINPUT", 106 | "JOYSTICK_HAPTIC_AXES", 107 | "JOYSTICK_HIDAPI", 108 | "JOYSTICK_HIDAPI_COMBINE_JOY_CONS", 109 | "JOYSTICK_HIDAPI_GAMECUBE", 110 | "JOYSTICK_HIDAPI_JOYCON_HOME_LED", 111 | "JOYSTICK_HIDAPI_JOY_CONS", 112 | "JOYSTICK_HIDAPI_LUNA", 113 | "JOYSTICK_HIDAPI_NINTENDO_CLASSIC", 114 | "JOYSTICK_HIDAPI_PS3", 115 | "JOYSTICK_HIDAPI_PS3_SIXAXIS_DRIVER", 116 | #"JOYSTICK_HIDAPI_PS4_RUMBLE", 117 | "JOYSTICK_HIDAPI_PS4", 118 | "JOYSTICK_HIDAPI_PS5_PLAYER_LED", 119 | #"JOYSTICK_HIDAPI_PS5_RUMBLE", 120 | "JOYSTICK_HIDAPI_PS5", 121 | "JOYSTICK_HIDAPI_SHIELD", 122 | "JOYSTICK_HIDAPI_STADIA", 123 | "JOYSTICK_HIDAPI_STEAM", 124 | "JOYSTICK_HIDAPI_STEAM_HOME_LED", 125 | "JOYSTICK_HIDAPI_STEAM_HORI", 126 | "JOYSTICK_HIDAPI_STEAMDECK", 127 | "JOYSTICK_HIDAPI_SWITCH_HOME_LED", 128 | "JOYSTICK_HIDAPI_SWITCH_PLAYER_LED", 129 | "JOYSTICK_HIDAPI_SWITCH", 130 | "JOYSTICK_HIDAPI_VERTICAL_JOY_CONS", 131 | "JOYSTICK_HIDAPI_WII_PLAYER_LED", 132 | "JOYSTICK_HIDAPI_WII", 133 | "JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED", 134 | "JOYSTICK_HIDAPI_XBOX_360", 135 | "JOYSTICK_HIDAPI_XBOX_360_WIRELESS", 136 | "JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED", 137 | "JOYSTICK_HIDAPI_XBOX_ONE", 138 | "JOYSTICK_HIDAPI_XBOX", 139 | "JOYSTICK_IOKIT", 140 | "JOYSTICK_MFI", 141 | "JOYSTICK_RAWINPUT_CORRELATE_XINPUT", 142 | "JOYSTICK_RAWINPUT", 143 | "JOYSTICK_ROG_CHAKRAM", 144 | "JOYSTICK_THREAD", 145 | "JOYSTICK_THROTTLE_DEVICES", 146 | "JOYSTICK_THROTTLE_DEVICES_EXCLUDED", 147 | "JOYSTICK_WGI", 148 | "JOYSTICK_WHEEL_DEVICES", 149 | "JOYSTICK_WHEEL_DEVICES_EXCLUDED", 150 | "JOYSTICK_ZERO_CENTERED_DEVICES", 151 | "KMSDRM_DEVICE_INDEX", 152 | "KMSDRM_REQUIRE_DRM_MASTER", 153 | "LINUX_DIGITAL_HATS", 154 | "LINUX_HAT_DEADZONES", 155 | "LINUX_JOYSTICK_CLASSIC", 156 | "LINUX_JOYSTICK_DEADZONES", 157 | "LOGGING", 158 | "MAC_BACKGROUND_APP", 159 | "MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK", 160 | "MAC_OPENGL_ASYNC_DISPATCH", 161 | "MAC_OPTION_AS_ALT", 162 | "MAC_SCROLL_MOMENTUM", 163 | "MAIN_CALLBACK_RATE", 164 | "MUTE_CONSOLE_KEYBOARD", 165 | "MOUSE_AUTO_CAPTURE", 166 | "MOUSE_DEFAULT_SYSTEM_CURSOR", 167 | "MOUSE_DOUBLE_CLICK_RADIUS", 168 | "MOUSE_DOUBLE_CLICK_TIME", 169 | "MOUSE_FOCUS_CLICKTHROUGH", 170 | "MOUSE_NORMAL_SPEED_SCALE", 171 | "MOUSE_RELATIVE_MODE_CENTER", 172 | #"MOUSE_RELATIVE_MODE_WARP", 173 | "MOUSE_RELATIVE_SPEED_SCALE", 174 | "MOUSE_RELATIVE_SYSTEM_SCALE", 175 | "MOUSE_RELATIVE_WARP_MOTION", 176 | "MOUSE_TOUCH_EVENTS", 177 | "NO_SIGNAL_HANDLERS", 178 | "OPENGL_ES_DRIVER", 179 | "OPENGL_LIBRARY", 180 | "OPENVR_LIBRARY", 181 | "ORIENTATIONS", 182 | "PEN_DELAY_MOUSE_BUTTON", 183 | "PEN_MOUSE_EVENTS", 184 | "PEN_TOUCH_EVENTS", 185 | "POLL_SENTINEL", 186 | "PREFERRED_LOCALES", 187 | "PS2_DYNAMIC_VSYNC", 188 | "QTWAYLAND_CONTENT_ORIENTATION", 189 | "QTWAYLAND_WINDOW_FLAGS", 190 | "QUIT_ON_LAST_WINDOW_CLOSE", 191 | "RENDER_DIRECT3D11_DEBUG", 192 | "RENDER_DIRECT3D_THREADSAFE", 193 | "RENDER_DRIVER", 194 | "RENDER_GPU_DEBUG", 195 | "RENDER_GPU_LOW_POWER", 196 | "RENDER_LINE_METHOD", 197 | "RENDER_METAL_PREFER_LOW_POWER_DEVICE", 198 | "RENDER_OPENGL_SHADERS", 199 | "RENDER_SCALE_QUALITY", 200 | "RENDER_VSYNC", 201 | "RETURN_KEY_HIDES_IME", 202 | "ROG_GAMEPAD_MICE", 203 | "ROG_GAMEPAD_MICE_EXCLUDED", 204 | "RPI_VIDEO_LAYER", 205 | "SCREENSAVER_INHIBIT_ACTIVITY_NAME", 206 | "SHUTDOWN_DBUS_ON_QUIT", 207 | "STORAGE_TITLE_DRIVER", 208 | "STORAGE_USER_DRIVER", 209 | "THREAD_FORCE_REALTIME_TIME_CRITICAL", 210 | "THREAD_PRIORITY_POLICY", 211 | "THREAD_STACK_SIZE", 212 | "TIMER_RESOLUTION", 213 | "TOUCH_MOUSE_EVENTS", 214 | "TRACKPAD_IS_TOUCH_ONLY", 215 | "TV_REMOTE_AS_JOYSTICK", 216 | "VIDEO_ALLOW_SCREENSAVER", 217 | "VIDEO_DISPLAY_PRIORITY", 218 | "VIDEO_DOUBLE_BUFFER", 219 | "VIDEO_DRIVER", 220 | "VIDEO_DUMMY_SAVE_FRAMES", 221 | "VIDEO_EGL_ALLOW_GETDISPLAY_FALLBACK", 222 | "VIDEO_EXTERNAL_CONTEXT", 223 | "VIDEO_FORCE_EGL", 224 | "VIDEO_MAC_FULLSCREEN_SPACES", 225 | "VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY", 226 | "VIDEO_MINIMIZE_ON_FOCUS_LOSS", 227 | "VIDEO_OFFSCREEN_SAVE_FRAMES", 228 | "VIDEO_SYNC_WINDOW_OPERATIONS", 229 | "VIDEO_WAYLAND_ALLOW_LIBDECOR", 230 | "VIDEO_WAYLAND_EMULATE_MOUSE_WARP", 231 | "VIDEO_WAYLAND_MODE_EMULATION", 232 | "VIDEO_WAYLAND_MODE_SCALING", 233 | "VIDEO_WAYLAND_PREFER_LIBDECOR", 234 | "VIDEO_WAYLAND_SCALE_TO_DISPLAY", 235 | "VIDEO_WIN_D3DCOMPILER", 236 | "VIDEO_X11_EXTERNAL_WINDOW_INPUT", # 3.2.10+. 237 | "VIDEO_X11_NET_WM_BYPASS_COMPOSITOR", 238 | "VIDEO_X11_NET_WM_PING", 239 | "VIDEO_X11_NODIRECTCOLOR", 240 | "VIDEO_X11_SCALING_FACTOR", 241 | "VIDEO_X11_VISUALID", 242 | "VIDEO_X11_WINDOW_VISUALID", 243 | "VIDEO_X11_XRANDR", 244 | "VITA_ENABLE_BACK_TOUCH", 245 | "VITA_ENABLE_FRONT_TOUCH", 246 | "VITA_MODULE_PATH", 247 | "VITA_PVR_INIT", 248 | "VITA_PVR_OPENGL", 249 | "VITA_RESOLUTION", 250 | "VITA_TOUCH_MOUSE_DEVICE", 251 | "VULKAN_DISPLAY", 252 | "VULKAN_LIBRARY", 253 | "WAVE_CHUNK_LIMIT", 254 | "WAVE_FACT_CHUNK", 255 | "WAVE_RIFF_CHUNK_SIZE", 256 | "WAVE_TRUNCATION", 257 | "WINDOW_ACTIVATE_WHEN_RAISED", 258 | "WINDOW_ACTIVATE_WHEN_SHOWN", 259 | "WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN", 260 | "WINDOWS_CLOSE_ON_ALT_F4", 261 | "WINDOWS_ENABLE_MENU_MNEMONICS", 262 | "WINDOWS_ENABLE_MESSAGELOOP", 263 | "WINDOWS_FORCE_SEMAPHORE_KERNEL", 264 | "WINDOWS_GAMEINPUT", 265 | "WINDOWS_INTRESOURCE_ICON", 266 | "WINDOWS_INTRESOURCE_ICON_SMALL", 267 | "WINDOWS_NO_CLOSE_ON_ALT_F4", 268 | "WINDOWS_RAW_KEYBOARD", 269 | "WINDOWS_USE_D3D9EX", 270 | "WINRT_HANDLE_BACK_BUTTON", 271 | "X11_FORCE_OVERRIDE_REDIRECT", 272 | "X11_WINDOW_TYPE", 273 | "X11_XCB_LIBRARY", 274 | "XINPUT_ENABLED" 275 | 276 | type 277 | HintPriority* {.size: cint.sizeof.} = enum # XXX: size. 278 | ## Hint priorities. 279 | HINT_DEFAULT 280 | HINT_NORMAL 281 | HINT_OVERRIDE 282 | 283 | HintCallback* = proc (userdata: pointer, name: HintName, 284 | old_value, new_value: cstring) {.cdecl, gcsafe, raises: [].} 285 | 286 | # vim: set sts=2 et sw=2: 287 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3init.nim: -------------------------------------------------------------------------------- 1 | ## Init definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | cbool* = distinct byte 11 | 12 | type 13 | InitFlags* = distinct uint32 14 | ## Window flags. 15 | 16 | func `or`*(a, b: InitFlags): InitFlags {.borrow.} 17 | 18 | const 19 | INIT_NONE* = InitFlags 0x0000_0000 ## Nim specific. 20 | INIT_AUDIO* = InitFlags 0x0000_0010 ## Implies `INIT_EVENTS`. 21 | INIT_VIDEO* = InitFlags 0x0000_0020 ## Implies `INIT_EVENTS`. 22 | INIT_JOYSTICK* = InitFlags 0x0000_0200 ## Implies `INIT_EVENTS`. 23 | INIT_HAPTIC* = InitFlags 0x0000_1000 24 | INIT_GAMEPAD* = InitFlags 0x0000_2000 ## Implies `INIT_JOYSTICK`. 25 | INIT_EVENTS* = InitFlags 0x0000_4000 26 | INIT_SENSOR* = InitFlags 0x0000_8000 ## Implies `INIT_EVENTS`. 27 | INIT_CAMERA* = InitFlags 0x0001_0000 ## Implies `INIT_EVENTS`. 28 | 29 | type 30 | AppResult* {.size: cint.sizeof.} = enum 31 | ## Return values for optional main callbacks. 32 | APP_CONTINUE 33 | APP_SUCCESS 34 | APP_FAILURE 35 | 36 | type 37 | AppInit_func* = proc (appstate: ptr pointer, argc: cint, argv: cstringArray): AppResult {.cdecl.} 38 | AppIterate_func* = proc (appstate: pointer): AppResult {.cdecl.} 39 | # XXX: AppEvent_func* = proc (appstate: pointer, event: ptr Event): AppResult {.cdecl.} 40 | AppQuit_func* = proc (appstate: pointer, res: AppResult) {.cdecl.} 41 | 42 | type 43 | MainThreadCallback* = proc (userdata: pointer) {.cdecl.} 44 | 45 | type 46 | AppMetadataProperty* = enum 47 | PROP_APP_METADATA_NAME_STRING = cstring"SDL.app.metadata.name" 48 | PROP_APP_METADATA_VERSION_STRING = cstring"SDL.app.metadata.version" 49 | PROP_APP_METADATA_IDENTIFIER_STRING = cstring"SDL.app.metadata.identifier" 50 | PROP_APP_METADATA_CREATOR_STRING = cstring"SDL.app.metadata.creator" 51 | PROP_APP_METADATA_COPYRIGHT_STRING = cstring"SDL.app.metadata.copyright" 52 | PROP_APP_METADATA_URL_STRING = cstring"SDL.app.metadata.url" 53 | PROP_APP_METADATA_TYPE_STRING = cstring"SDL.app.metadata.type" 54 | 55 | # vim: set sts=2 et sw=2: 56 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3iostream.nim: -------------------------------------------------------------------------------- 1 | ## RWops definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | IOStatus* {.size: cint.sizeof.} = enum 11 | ## IOStream status, set by a read or write operation. 12 | IO_STATUS_READY 13 | IO_STATUS_ERROR 14 | IO_STATUS_EOF 15 | IO_STATUS_NOT_READY 16 | IO_STATUS_READONLY 17 | IO_STATUS_WRITEONLY 18 | 19 | type 20 | IOWhence* {.size: cint.sizeof.} = enum 21 | ## Possible `whence` values for `IOStream` seeking. 22 | IO_SEEK_SET 23 | IO_SEEK_CUR 24 | IO_SEEK_END 25 | 26 | # TODO: IOStreamInterface. 27 | #[ 28 | SDL_COMPILE_TIME_ASSERT(SDL_IOStreamInterface_SIZE, 29 | (sizeof(void *) == 4 && sizeof(SDL_IOStreamInterface) == 28) || 30 | (sizeof(void *) == 8 && sizeof(SDL_IOStreamInterface) == 56)); 31 | ]# 32 | 33 | #define SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER "SDL.iostream.windows.handle" 34 | #define SDL_PROP_IOSTREAM_STDIO_FILE_POINTER "SDL.iostream.stdio.file" 35 | #define SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER "SDL.iostream.file_descriptor" 36 | #define SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER "SDL.iostream.android.aasset" 37 | 38 | #define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base" 39 | #define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size" 40 | 41 | #define SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER "SDL.iostream.dynamic.memory" 42 | #define SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER "SDL.iostream.dynamic.chunksize" 43 | 44 | 45 | type 46 | IOStream* = ptr object 47 | ## The read/write operation structure. 48 | 49 | # vim: set sts=2 et sw=2: 50 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3joystick.nim: -------------------------------------------------------------------------------- 1 | ## Joystick event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3init import cbool 10 | 11 | type 12 | Joystick* = ptr object 13 | ## Joystick. 14 | 15 | JoystickGUID* {.final, pure.} = object 16 | ## Joystick GUID. 17 | data*: array[16, byte] 18 | 19 | JoystickID* = distinct uint32 20 | ## Joystick unique ID. 21 | ## 22 | ## The ID starts at 1. Invalid ID has value 0. 23 | 24 | func `==`*(a: JoystickID, b: uint32): bool {.borrow.} 25 | 26 | type 27 | JoystickType* {.size: cint.sizeof.} = enum 28 | ## Joystick type. 29 | JOYSTICK_TYPE_UNKNOWN 30 | JOYSTICK_TYPE_GAMEPAD 31 | JOYSTICK_TYPE_WHEEL 32 | JOYSTICK_TYPE_ARCADE_STICK 33 | JOYSTICK_TYPE_FLIGHT_STICK 34 | JOYSTICK_TYPE_DANCE_PAD 35 | JOYSTICK_TYPE_GUITAR 36 | JOYSTICK_TYPE_DRUM_KIT 37 | JOYSTICK_TYPE_ARCADE_PAD 38 | JOYSTICK_TYPE_THROTTLE 39 | 40 | const 41 | JOYSTICK_TYPE_COUNT* = JoystickType.high.int + 1 42 | 43 | type 44 | JoystickConnectionState* {.size: cint.sizeof.} = enum 45 | ## Joystick connection state. 46 | JOYSTICK_CONNECTION_INVALID = -1 47 | JOYSTICK_CONNECTION_UNKNOWN 48 | JOYSTICK_CONNECTION_WIRED 49 | JOYSTICK_CONNECTION_WIRELESS 50 | 51 | const 52 | JOYSTICK_AXIS_MAX* = 32767 53 | JOYSTICK_AXIS_MIN* = -32768 54 | 55 | type 56 | VirtualJoystickDesc* {.final, pure.} = object 57 | ## Extended virtual joystick description. 58 | version* : uint32 ## `VIRTUAL_JOYSTICK_DESC_VERSION`. 59 | `type`* : uint16 ## `JoystickType`. 60 | naxes* : uint16 ## The number of axes. 61 | nbuttons* : uint16 ## The number of buttons. 62 | nhats* : uint16 ## The number of hats. 63 | vendor_id* : uint16 ## USB vendor ID. 64 | product_id* : uint16 ## USB product ID. 65 | padding : uint16 66 | button_mask* : uint32 ## Valid buttons mask. 67 | axis_mask* : uint32 ## Valid axes mask. 68 | name* : cstring ## Joystick name. 69 | touchpads : pointer # XXX: ptr SDL_VirtualJoystickTouchpadDesc. 70 | sensors : pointer # XXX: ptr SDL_VirtualJoystickSensorDesc. 71 | 72 | userdata : pointer ## User data pointer. 73 | Update : proc (userdata: pointer) {.cdecl, gcsafe, raises: [].} 74 | SetPlayerIndex : proc (userdata: pointer, player_index: cint) {.cdecl, gcsafe, raises: [].} 75 | Rumble : proc (userdata: pointer, low_frequency_rumble, high_frequency_rumble: uint16): cbool {.cdecl, gcsafe, raises: [].} 76 | RumbleTriggers : proc (userdata: pointer, left_rumble, right_rumble: uint16): cbool {.cdecl, gcsafe, raises: [].} 77 | SetLED : proc (userdata: pointer, red, green, blue: byte): cbool {.cdecl, gcsafe, raises: [].} 78 | SendEffect : proc (userdata: pointer, data: pointer, size: cint): cbool {.cdecl, gcsafe, raises: [].} 79 | SetSensorsEnabled : proc (userdata: pointer, enabled: cbool): cbool {.cdecl, gcsafe, raises: [].} 80 | Cleanup : proc (userdata: pointer) {.cdecl, gcsafe, raises: [].} 81 | 82 | #[ 83 | XXX: SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE, 84 | (sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) || 85 | (sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136)); 86 | ]# 87 | 88 | const 89 | VIRTUAL_JOYSTICK_DESC_VERSION* = 1 90 | 91 | type 92 | PropJoystickCap* = enum 93 | PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN = cstring"SDL.joystick.cap.mono_led" 94 | PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN = cstring"SDL.joystick.cap.rgb_led" 95 | PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN = cstring"SDL.joystick.cap.player_led" 96 | PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN = cstring"SDL.joystick.cap.rumble" 97 | PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN = cstring"SDL.joystick.cap.trigger_rumble" 98 | 99 | type 100 | Hat* = distinct byte 101 | ## Hat positions. 102 | 103 | func `==`*(a, b: Hat): bool {.borrow.} 104 | func `and`*(a, b: Hat): Hat {.borrow.} 105 | func `or`(a, b: Hat): Hat {.borrow.} 106 | 107 | const 108 | HAT_CENTERED* = Hat 0x00 109 | HAT_UP* = Hat 0x01 110 | HAT_RIGHT* = Hat 0x02 111 | HAT_DOWN* = Hat 0x04 112 | HAT_LEFT* = Hat 0x08 113 | HAT_RIGHTUP* = HAT_RIGHT or HAT_UP 114 | HAT_RIGHTDOWN* = HAT_RIGHT or HAT_DOWN 115 | HAT_LEFTUP* = HAT_LEFT or HAT_UP 116 | HAT_LEFTDOWN* = HAT_LEFT or HAT_DOWN 117 | 118 | # vim: set sts=2 et sw=2: 119 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3keyboard.nim: -------------------------------------------------------------------------------- 1 | ## Keyboard event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | KeyboardID* = distinct uint32 11 | ## Keyboard ID. 12 | 13 | type 14 | TextInputType* {.size: cint.sizeof.} = enum 15 | ## Text input type. 16 | TEXTINPUT_TYPE_TEXT 17 | TEXTINPUT_TYPE_TEXT_NAME 18 | TEXTINPUT_TYPE_TEXT_EMAIL 19 | TEXTINPUT_TYPE_TEXT_USERNAME 20 | TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN 21 | TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE 22 | TEXTINPUT_TYPE_NUMBER 23 | TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN 24 | TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE 25 | 26 | Capitalization* {.size: cint.sizeof.} = enum 27 | ## Auto capitalization type. 28 | CAPITALIZE_NONE 29 | CAPITALIZE_SENTENCES 30 | CAPITALIZE_WORDS 31 | CAPITALIZE_LETTERS 32 | 33 | PropTextInput* = enum 34 | ## Text input property. 35 | PROP_TEXTINPUT_TYPE_NUMBER = cstring"SDL.textinput.type" 36 | PROP_TEXTINPUT_CAPITALIZATION_NUMBER = cstring"SDL.textinput.capitalization" 37 | PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN = cstring"SDL.textinput.autocorrect" 38 | PROP_TEXTINPUT_MULTILINE_BOOLEAN = cstring"SDL.textinput.multiline" 39 | PROP_TEXTINPUT_ANDROID_INPUTTYPE_NUMBER = cstring"SDL.textinput.android.inputtype" 40 | 41 | # vim: set sts=2 et sw=2: 42 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3keycode.nim: -------------------------------------------------------------------------------- 1 | ## Keyboard keys and modifiers definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | Keycode* = distinct cint 11 | ## Virtual key representation. 12 | 13 | func `==`*(x, y: Keycode): bool {.borrow.} 14 | 15 | #const 16 | # EXTENDED_MASK = 1'u32 shl 29 17 | # SCANCODE_MASK = 1'u32 shl 30 18 | 19 | const 20 | SDLK_UNKNOWN* = Keycode 0x00000000 21 | SDLK_RETURN* = Keycode 0x0000000d 22 | SDLK_ESCAPE* = Keycode 0x0000001b 23 | SDLK_BACKSPACE* = Keycode 0x00000008 24 | SDLK_TAB* = Keycode 0x00000009 25 | SDLK_SPACE* = Keycode 0x00000020 26 | SDLK_EXCLAIM* = Keycode 0x00000021 27 | SDLK_DBLAPOSTROPHE* = Keycode 0x00000022 28 | SDLK_HASH* = Keycode 0x00000023 29 | SDLK_DOLLAR* = Keycode 0x00000024 30 | SDLK_PERCENT* = Keycode 0x00000025 31 | SDLK_AMPERSAND* = Keycode 0x00000026 32 | SDLK_APOSTROPHE* = Keycode 0x00000027 33 | SDLK_LEFTPAREN* = Keycode 0x00000028 34 | SDLK_RIGHTPAREN* = Keycode 0x00000029 35 | SDLK_ASTERISK* = Keycode 0x0000002a 36 | SDLK_PLUS* = Keycode 0x0000002b 37 | SDLK_COMMA* = Keycode 0x0000002c 38 | SDLK_MINUS* = Keycode 0x0000002d 39 | SDLK_PERIOD* = Keycode 0x0000002e 40 | SDLK_SLASH* = Keycode 0x0000002f 41 | SDLK_0* = Keycode 0x00000030 42 | SDLK_1* = Keycode 0x00000031 43 | SDLK_2* = Keycode 0x00000032 44 | SDLK_3* = Keycode 0x00000033 45 | SDLK_4* = Keycode 0x00000034 46 | SDLK_5* = Keycode 0x00000035 47 | SDLK_6* = Keycode 0x00000036 48 | SDLK_7* = Keycode 0x00000037 49 | SDLK_8* = Keycode 0x00000038 50 | SDLK_9* = Keycode 0x00000039 51 | SDLK_COLON* = Keycode 0x0000003a 52 | SDLK_SEMICOLON* = Keycode 0x0000003b 53 | SDLK_LESS* = Keycode 0x0000003c 54 | SDLK_EQUALS* = Keycode 0x0000003d 55 | SDLK_GREATER* = Keycode 0x0000003e 56 | SDLK_QUESTION* = Keycode 0x0000003f 57 | SDLK_AT* = Keycode 0x00000040 58 | SDLK_LEFTBRACKET* = Keycode 0x0000005b 59 | SDLK_BACKSLASH* = Keycode 0x0000005c 60 | SDLK_RIGHTBRACKET* = Keycode 0x0000005d 61 | SDLK_CARET* = Keycode 0x0000005e 62 | SDLK_UNDERSCORE* = Keycode 0x0000005f 63 | SDLK_GRAVE* = Keycode 0x00000060 64 | SDLK_A* = Keycode 0x00000061 65 | SDLK_B* = Keycode 0x00000062 66 | SDLK_C* = Keycode 0x00000063 67 | SDLK_D* = Keycode 0x00000064 68 | SDLK_E* = Keycode 0x00000065 69 | SDLK_F* = Keycode 0x00000066 70 | SDLK_G* = Keycode 0x00000067 71 | SDLK_H* = Keycode 0x00000068 72 | SDLK_I* = Keycode 0x00000069 73 | SDLK_J* = Keycode 0x0000006a 74 | SDLK_K* = Keycode 0x0000006b 75 | SDLK_L* = Keycode 0x0000006c 76 | SDLK_M* = Keycode 0x0000006d 77 | SDLK_N* = Keycode 0x0000006e 78 | SDLK_O* = Keycode 0x0000006f 79 | SDLK_P* = Keycode 0x00000070 80 | SDLK_Q* = Keycode 0x00000071 81 | SDLK_R* = Keycode 0x00000072 82 | SDLK_S* = Keycode 0x00000073 83 | SDLK_T* = Keycode 0x00000074 84 | SDLK_U* = Keycode 0x00000075 85 | SDLK_V* = Keycode 0x00000076 86 | SDLK_W* = Keycode 0x00000077 87 | SDLK_X* = Keycode 0x00000078 88 | SDLK_Y* = Keycode 0x00000079 89 | SDLK_Z* = Keycode 0x0000007a 90 | SDLK_LEFTBRACE* = Keycode 0x0000007b 91 | SDLK_PIPE* = Keycode 0x0000007c 92 | SDLK_RIGHTBRACE* = Keycode 0x0000007d 93 | SDLK_TILDE* = Keycode 0x0000007e 94 | SDLK_DELETE* = Keycode 0x0000007f 95 | SDLK_PLUSMINUS* = Keycode 0x000000b1 96 | SDLK_CAPSLOCK* = Keycode 0x40000039 97 | SDLK_F1* = Keycode 0x4000003a 98 | SDLK_F2* = Keycode 0x4000003b 99 | SDLK_F3* = Keycode 0x4000003c 100 | SDLK_F4* = Keycode 0x4000003d 101 | SDLK_F5* = Keycode 0x4000003e 102 | SDLK_F6* = Keycode 0x4000003f 103 | SDLK_F7* = Keycode 0x40000040 104 | SDLK_F8* = Keycode 0x40000041 105 | SDLK_F9* = Keycode 0x40000042 106 | SDLK_F10* = Keycode 0x40000043 107 | SDLK_F11* = Keycode 0x40000044 108 | SDLK_F12* = Keycode 0x40000045 109 | SDLK_PRINTSCREEN* = Keycode 0x40000046 110 | SDLK_SCROLLLOCK* = Keycode 0x40000047 111 | SDLK_PAUSE* = Keycode 0x40000048 112 | SDLK_INSERT* = Keycode 0x40000049 113 | SDLK_HOME* = Keycode 0x4000004a 114 | SDLK_PAGEUP* = Keycode 0x4000004b 115 | SDLK_END* = Keycode 0x4000004d 116 | SDLK_PAGEDOWN* = Keycode 0x4000004e 117 | SDLK_RIGHT* = Keycode 0x4000004f 118 | SDLK_LEFT* = Keycode 0x40000050 119 | SDLK_DOWN* = Keycode 0x40000051 120 | SDLK_UP* = Keycode 0x40000052 121 | SDLK_NUMLOCKCLEAR* = Keycode 0x40000053 122 | SDLK_KP_DIVIDE* = Keycode 0x40000054 123 | SDLK_KP_MULTIPLY* = Keycode 0x40000055 124 | SDLK_KP_MINUS* = Keycode 0x40000056 125 | SDLK_KP_PLUS* = Keycode 0x40000057 126 | SDLK_KP_ENTER* = Keycode 0x40000058 127 | SDLK_KP_1* = Keycode 0x40000059 128 | SDLK_KP_2* = Keycode 0x4000005a 129 | SDLK_KP_3* = Keycode 0x4000005b 130 | SDLK_KP_4* = Keycode 0x4000005c 131 | SDLK_KP_5* = Keycode 0x4000005d 132 | SDLK_KP_6* = Keycode 0x4000005e 133 | SDLK_KP_7* = Keycode 0x4000005f 134 | SDLK_KP_8* = Keycode 0x40000060 135 | SDLK_KP_9* = Keycode 0x40000061 136 | SDLK_KP_0* = Keycode 0x40000062 137 | SDLK_KP_PERIOD* = Keycode 0x40000063 138 | SDLK_APPLICATION* = Keycode 0x40000065 139 | SDLK_POWER* = Keycode 0x40000066 140 | SDLK_KP_EQUALS* = Keycode 0x40000067 141 | SDLK_F13* = Keycode 0x40000068 142 | SDLK_F14* = Keycode 0x40000069 143 | SDLK_F15* = Keycode 0x4000006a 144 | SDLK_F16* = Keycode 0x4000006b 145 | SDLK_F17* = Keycode 0x4000006c 146 | SDLK_F18* = Keycode 0x4000006d 147 | SDLK_F19* = Keycode 0x4000006e 148 | SDLK_F20* = Keycode 0x4000006f 149 | SDLK_F21* = Keycode 0x40000070 150 | SDLK_F22* = Keycode 0x40000071 151 | SDLK_F23* = Keycode 0x40000072 152 | SDLK_F24* = Keycode 0x40000073 153 | SDLK_EXECUTE* = Keycode 0x40000074 154 | SDLK_HELP* = Keycode 0x40000075 155 | SDLK_MENU* = Keycode 0x40000076 156 | SDLK_SELECT* = Keycode 0x40000077 157 | SDLK_STOP* = Keycode 0x40000078 158 | SDLK_AGAIN* = Keycode 0x40000079 159 | SDLK_UNDO* = Keycode 0x4000007a 160 | SDLK_CUT* = Keycode 0x4000007b 161 | SDLK_COPY* = Keycode 0x4000007c 162 | SDLK_PASTE* = Keycode 0x4000007d 163 | SDLK_FIND* = Keycode 0x4000007e 164 | SDLK_MUTE* = Keycode 0x4000007f 165 | SDLK_VOLUMEUP* = Keycode 0x40000080 166 | SDLK_VOLUMEDOWN* = Keycode 0x40000081 167 | SDLK_KP_COMMA* = Keycode 0x40000085 168 | SDLK_KP_EQUALSAS400* = Keycode 0x40000086 169 | SDLK_ALTERASE* = Keycode 0x40000099 170 | SDLK_SYSREQ* = Keycode 0x4000009a 171 | SDLK_CANCEL* = Keycode 0x4000009b 172 | SDLK_CLEAR* = Keycode 0x4000009c 173 | SDLK_PRIOR* = Keycode 0x4000009d 174 | SDLK_RETURN2* = Keycode 0x4000009e 175 | SDLK_SEPARATOR* = Keycode 0x4000009f 176 | SDLK_OUT* = Keycode 0x400000a0 177 | SDLK_OPER* = Keycode 0x400000a1 178 | SDLK_CLEARAGAIN* = Keycode 0x400000a2 179 | SDLK_CRSEL* = Keycode 0x400000a3 180 | SDLK_EXSEL* = Keycode 0x400000a4 181 | SDLK_KP_00* = Keycode 0x400000b0 182 | SDLK_KP_000* = Keycode 0x400000b1 183 | SDLK_THOUSANDSSEPARATOR* = Keycode 0x400000b2 184 | SDLK_DECIMALSEPARATOR* = Keycode 0x400000b3 185 | SDLK_CURRENCYUNIT* = Keycode 0x400000b4 186 | SDLK_CURRENCYSUBUNIT* = Keycode 0x400000b5 187 | SDLK_KP_LEFTPAREN* = Keycode 0x400000b6 188 | SDLK_KP_RIGHTPAREN* = Keycode 0x400000b7 189 | SDLK_KP_LEFTBRACE* = Keycode 0x400000b8 190 | SDLK_KP_RIGHTBRACE* = Keycode 0x400000b9 191 | SDLK_KP_TAB* = Keycode 0x400000ba 192 | SDLK_KP_BACKSPACE* = Keycode 0x400000bb 193 | SDLK_KP_A* = Keycode 0x400000bc 194 | SDLK_KP_B* = Keycode 0x400000bd 195 | SDLK_KP_C* = Keycode 0x400000be 196 | SDLK_KP_D* = Keycode 0x400000bf 197 | SDLK_KP_E* = Keycode 0x400000c0 198 | SDLK_KP_F* = Keycode 0x400000c1 199 | SDLK_KP_XOR* = Keycode 0x400000c2 200 | SDLK_KP_POWER* = Keycode 0x400000c3 201 | SDLK_KP_PERCENT* = Keycode 0x400000c4 202 | SDLK_KP_LESS* = Keycode 0x400000c5 203 | SDLK_KP_GREATER* = Keycode 0x400000c6 204 | SDLK_KP_AMPERSAND* = Keycode 0x400000c7 205 | SDLK_KP_DBLAMPERSAND* = Keycode 0x400000c8 206 | SDLK_KP_VERTICALBAR* = Keycode 0x400000c9 207 | SDLK_KP_DBLVERTICALBAR* = Keycode 0x400000ca 208 | SDLK_KP_COLON* = Keycode 0x400000cb 209 | SDLK_KP_HASH* = Keycode 0x400000cc 210 | SDLK_KP_SPACE* = Keycode 0x400000cd 211 | SDLK_KP_AT* = Keycode 0x400000ce 212 | SDLK_KP_EXCLAM* = Keycode 0x400000cf 213 | SDLK_KP_MEMSTORE* = Keycode 0x400000d0 214 | SDLK_KP_MEMRECALL* = Keycode 0x400000d1 215 | SDLK_KP_MEMCLEAR* = Keycode 0x400000d2 216 | SDLK_KP_MEMADD* = Keycode 0x400000d3 217 | SDLK_KP_MEMSUBTRACT* = Keycode 0x400000d4 218 | SDLK_KP_MEMMULTIPLY* = Keycode 0x400000d5 219 | SDLK_KP_MEMDIVIDE* = Keycode 0x400000d6 220 | SDLK_KP_PLUSMINUS* = Keycode 0x400000d7 221 | SDLK_KP_CLEAR* = Keycode 0x400000d8 222 | SDLK_KP_CLEARENTRY* = Keycode 0x400000d9 223 | SDLK_KP_BINARY* = Keycode 0x400000da 224 | SDLK_KP_OCTAL* = Keycode 0x400000db 225 | SDLK_KP_DECIMAL* = Keycode 0x400000dc 226 | SDLK_KP_HEXADECIMAL* = Keycode 0x400000dd 227 | SDLK_LCTRL* = Keycode 0x400000e0 228 | SDLK_LSHIFT* = Keycode 0x400000e1 229 | SDLK_LALT* = Keycode 0x400000e2 230 | SDLK_LGUI* = Keycode 0x400000e3 231 | SDLK_RCTRL* = Keycode 0x400000e4 232 | SDLK_RSHIFT* = Keycode 0x400000e5 233 | SDLK_RALT* = Keycode 0x400000e6 234 | SDLK_RGUI* = Keycode 0x400000e7 235 | SDLK_MODE* = Keycode 0x40000101 236 | SDLK_SLEEP* = Keycode 0x40000102 237 | SDLK_WAKE* = Keycode 0x40000103 238 | SDLK_CHANNEL_INCREMENT* = Keycode 0x40000104 239 | SDLK_CHANNEL_DECREMENT* = Keycode 0x40000105 240 | SDLK_MEDIA_PLAY* = Keycode 0x40000106 241 | SDLK_MEDIA_PAUSE* = Keycode 0x40000107 242 | SDLK_MEDIA_RECORD* = Keycode 0x40000108 243 | SDLK_MEDIA_FAST_FORWARD* = Keycode 0x40000109 244 | SDLK_MEDIA_REWIND* = Keycode 0x4000010a 245 | SDLK_MEDIA_NEXT_TRACK* = Keycode 0x4000010b 246 | SDLK_MEDIA_PREVIOUS_TRACK* = Keycode 0x4000010c 247 | SDLK_MEDIA_STOP* = Keycode 0x4000010d 248 | SDLK_MEDIA_EJECT* = Keycode 0x4000010e 249 | SDLK_MEDIA_PLAY_PAUSE* = Keycode 0x4000010f 250 | SDLK_MEDIA_SELECT* = Keycode 0x40000110 251 | SDLK_AC_NEW* = Keycode 0x40000111 252 | SDLK_AC_OPEN* = Keycode 0x40000112 253 | SDLK_AC_CLOSE* = Keycode 0x40000113 254 | SDLK_AC_EXIT* = Keycode 0x40000114 255 | SDLK_AC_SAVE* = Keycode 0x40000115 256 | SDLK_AC_PRINT* = Keycode 0x40000116 257 | SDLK_AC_PROPERTIES* = Keycode 0x40000117 258 | SDLK_AC_SEARCH* = Keycode 0x40000118 259 | SDLK_AC_HOME* = Keycode 0x40000119 260 | SDLK_AC_BACK* = Keycode 0x4000011a 261 | SDLK_AC_FORWARD* = Keycode 0x4000011b 262 | SDLK_AC_STOP* = Keycode 0x4000011c 263 | SDLK_AC_REFRESH* = Keycode 0x4000011d 264 | SDLK_AC_BOOKMARKS* = Keycode 0x4000011e 265 | SDLK_SOFTLEFT* = Keycode 0x4000011f 266 | SDLK_SOFTRIGHT* = Keycode 0x40000120 267 | SDLK_CALL* = Keycode 0x40000121 268 | SDLK_ENDCALL* = Keycode 0x40000122 269 | 270 | type 271 | Keymod* = distinct uint16 272 | ## Valid key mods. 273 | 274 | func `==`*(x, y: Keymod): bool {.borrow.} 275 | func `and`*(a, b: Keymod): Keymod {.borrow.} 276 | func `or`(a, b: Keymod): Keymod {.borrow.} 277 | 278 | const 279 | KMOD_NONE* = Keymod 0x0000 280 | KMOD_LSHIFT* = Keymod 0x0001 281 | KMOD_RSHIFT* = Keymod 0x0002 282 | KMOD_LEVEL5* = Keymod 0x0004 283 | KMOD_LCTRL* = Keymod 0x0040 284 | KMOD_RCTRL* = Keymod 0x0080 285 | KMOD_LALT* = Keymod 0x0100 286 | KMOD_RALT* = Keymod 0x0200 287 | KMOD_LGUI* = Keymod 0x0400 288 | KMOD_RGUI* = Keymod 0x0800 289 | KMOD_NUM* = Keymod 0x1000 290 | KMOD_CAPS* = Keymod 0x2000 291 | KMOD_MODE* = Keymod 0x4000 292 | KMOD_SCROLL* = Keymod 0x8000 293 | KMOD_CTRL* = KMOD_LCTRL or KMOD_RCTRL 294 | KMOD_SHIFT* = KMOD_LSHIFT or KMOD_RSHIFT 295 | KMOD_ALT* = KMOD_LALT or KMOD_RALT 296 | KMOD_GUI* = KMOD_LGUI or KMOD_RGUI 297 | 298 | # vim: set sts=2 et sw=2: 299 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3log.nim: -------------------------------------------------------------------------------- 1 | ## Log definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | LogCategory* {.size: cint.sizeof.} = enum 11 | ## Log category. 12 | LOG_CATEGORY_APPLICATION 13 | LOG_CATEGORY_ERROR 14 | LOG_CATEGORY_ASSERT 15 | LOG_CATEGORY_SYSTEM 16 | LOG_CATEGORY_AUDIO 17 | LOG_CATEGORY_VIDEO 18 | LOG_CATEGORY_RENDER 19 | LOG_CATEGORY_INPUT 20 | LOG_CATEGORY_TEST 21 | LOG_CATEGORY_GPU 22 | 23 | LOG_CATEGORY_RESERVED1 24 | LOG_CATEGORY_RESERVED2 25 | LOG_CATEGORY_RESERVED3 26 | LOG_CATEGORY_RESERVED4 27 | LOG_CATEGORY_RESERVED5 28 | LOG_CATEGORY_RESERVED6 29 | LOG_CATEGORY_RESERVED7 30 | LOG_CATEGORY_RESERVED8 31 | LOG_CATEGORY_RESERVED9 32 | LOG_CATEGORY_RESERVED10 33 | 34 | LOG_CATEGORY_CUSTOM 35 | 36 | LogPriority* {.size: cint.sizeof.} = enum 37 | ## Log priority. 38 | LOG_PRIORITY_INVALID 39 | LOG_PRIORITY_TRACE 40 | LOG_PRIORITY_VERBOSE 41 | LOG_PRIORITY_DEBUG 42 | LOG_PRIORITY_INFO 43 | LOG_PRIORITY_WARN 44 | LOG_PRIORITY_ERROR 45 | LOG_PRIORITY_CRITICAL 46 | 47 | const 48 | LOG_PRIORITY_COUNT* = LogPriority.high.int + 1 49 | 50 | type 51 | LogOutputFunction* = proc (userdata: pointer, category: LogCategory, 52 | priority: LogPriority, 53 | message: cstring) {.cdecl, gcsafe, raises: [].} 54 | 55 | # vim: set sts=2 et sw=2: 56 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3main.nim: -------------------------------------------------------------------------------- 1 | ## Main definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | # vim: set sts=2 et sw=2: 10 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3messagebox.nim: -------------------------------------------------------------------------------- 1 | ## Message box definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3video import Window 10 | 11 | type 12 | MessageBoxFlags* = distinct uint32 13 | 14 | func `+`*(a, b: MessageBoxFlags): MessageBoxFlags {.borrow.} 15 | func `or`*(a, b: MessageBoxFlags): MessageBoxFlags {.borrow.} 16 | 17 | const 18 | MESSAGEBOX_ERROR* = MessageBoxFlags 0x00000010 ## Error dialog. 19 | MESSAGEBOX_WARNING* = MessageBoxFlags 0x00000020 ## Warning dialog. 20 | MESSAGEBOX_INFORMATION* = MessageBoxFlags 0x00000040 ## Informational dialog. 21 | MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT* = MessageBoxFlags 0x00000080 ## Buttons placed left to right. 22 | MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT* = MessageBoxFlags 0x00000100 ## Buttons placed right to left. 23 | 24 | type 25 | MessageBoxButtonFlags* = distinct uint32 26 | 27 | const 28 | MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT* = MessageBoxButtonFlags 0x00000001 ## Default button when return is hit. 29 | MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT* = MessageBoxButtonFlags 0x00000002 ## Default button when escape is hit. 30 | 31 | type 32 | MessageBoxButtonData* {.final, pure.} = object 33 | ## Individual button data. 34 | flags* : MessageBoxButtonFlags ## `MessageBoxButtonFlags`. 35 | buttonid* : cint ## User defined button ID (returned by `ShowMessageBox`). 36 | text* : cstring ## Button text (UTF-8). 37 | 38 | MessageBoxColor* {.final, pure.} = object 39 | ## Message box color. 40 | r*: byte 41 | g*: byte 42 | b*: byte 43 | 44 | MessageBoxColorType* {.size: cint.sizeof.} = enum 45 | MESSAGEBOX_COLOR_BACKGROUND 46 | MESSAGEBOX_COLOR_TEXT 47 | MESSAGEBOX_COLOR_BUTTON_BORDER 48 | MESSAGEBOX_COLOR_BUTTON_BACKGROUND 49 | MESSAGEBOX_COLOR_BUTTON_SELECTED 50 | 51 | const 52 | MESSAGEBOX_COLOR_COUNT* = MessageBoxColorType.high.int + 1 53 | 54 | type 55 | MessageBoxColorScheme* {.final, pure.} = object 56 | ## Colors for message box dialogs. 57 | colors* : array[MESSAGEBOX_COLOR_COUNT, MessageBoxColor] 58 | 59 | MessageBoxData* {.final, pure.} = object 60 | ## MessageBox data. 61 | flags* : MessageBoxFlags ## `MessageBoxFlags`. 62 | window* : Window ## Parent window or `nil`. 63 | title* : cstring ## Title (UTF-8). 64 | message* : cstring ## Message text (UTF-8). 65 | 66 | numbuttons* : cint 67 | buttons* : ptr MessageBoxButtonData ## Read only. 68 | 69 | color_scheme* : ptr MessageBoxColorScheme ## Read only. 70 | 71 | # vim: set sts=2 et sw=2: 72 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3mouse.nim: -------------------------------------------------------------------------------- 1 | ## Mouse event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | MouseID* = distinct uint32 11 | ## Mouse ID. 12 | 13 | Cursor* = ptr object 14 | ## Cursor. 15 | 16 | SystemCursor* {.size: cint.sizeof.} = enum 17 | ## Cursor types for `create_system_cursor()`. 18 | SYSTEM_CURSOR_DEFAULT 19 | SYSTEM_CURSOR_TEXT 20 | SYSTEM_CURSOR_WAIT 21 | SYSTEM_CURSOR_CROSSHAIR 22 | SYSTEM_CURSOR_PROGRESS 23 | SYSTEM_CURSOR_NWSE_RESIZE 24 | SYSTEM_CURSOR_NESW_RESIZE 25 | SYSTEM_CURSOR_EW_RESIZE 26 | SYSTEM_CURSOR_NS_RESIZE 27 | SYSTEM_CURSOR_MOVE 28 | SYSTEM_CURSOR_NOT_ALLOWED 29 | SYSTEM_CURSOR_POINTER 30 | SYSTEM_CURSOR_NW_RESIZE 31 | SYSTEM_CURSOR_N_RESIZE 32 | SYSTEM_CURSOR_NE_RESIZE 33 | SYSTEM_CURSOR_E_RESIZE 34 | SYSTEM_CURSOR_SE_RESIZE 35 | SYSTEM_CURSOR_S_RESIZE 36 | SYSTEM_CURSOR_SW_RESIZE 37 | SYSTEM_CURSOR_W_RESIZE 38 | 39 | const 40 | SDL_SYSTEM_CURSOR_COUNT* = SystemCursor.high.int + 1 41 | 42 | type 43 | MouseWheelDirection* {.size: cint.sizeof.} = enum 44 | ## Scroll event scroll direction types. 45 | MOUSEWHEEL_NORMAL 46 | MOUSEWHEEL_FLIPPED 47 | 48 | type 49 | MouseButtonFlags* = distinct uint32 50 | ## Bitmask of pressed mouse buttons. 51 | 52 | func button_mask(x: MouseButtonFlags): MouseButtonFlags {.compiletime.} = 53 | MouseButtonFlags 1'u32 shl (x.uint32 - 1) 54 | 55 | const 56 | BUTTON_LEFT* = MouseButtonFlags 1 57 | BUTTON_MIDDLE* = MouseButtonFlags 2 58 | BUTTON_RIGHT* = MouseButtonFlags 3 59 | BUTTON_X1* = MouseButtonFlags 4 60 | BUTTON_X2* = MouseButtonFlags 5 61 | BUTTON_LMASK* = button_mask BUTTON_LEFT 62 | BUTTON_MMASK* = button_mask BUTTON_MIDDLE 63 | BUTTON_RMASK* = button_mask BUTTON_RIGHT 64 | BUTTON_X1MASK* = button_mask BUTTON_X1 65 | BUTTON_X2MASK* = button_mask BUTTON_X2 66 | 67 | # vim: set sts=2 et sw=2: 68 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3pen.nim: -------------------------------------------------------------------------------- 1 | ## Pen event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3mouse import MouseID 10 | from sdl3touch import TouchID 11 | 12 | type 13 | PenID* = distinct uint32 14 | ## `PenIDs` identify pens uniquely within a session. 15 | 16 | const 17 | PEN_MOUSEID* = cast[MouseID](-2) 18 | ## `MouseID` for mouse events simulated with pen input. 19 | 20 | PEN_TOUCHID* = cast[TouchID](-2) 21 | ## `TouchID` for touch events simulated with pen input. 22 | 23 | type 24 | PenInputFlags* = distinct uint32 25 | ## Pen input flags. 26 | 27 | const 28 | PEN_INPUT_DOWN* = PenInputFlags 1u shl 0 29 | PEN_INPUT_BUTTON_1* = PenInputFlags 1u shl 1 30 | PEN_INPUT_BUTTON_2* = PenInputFlags 1u shl 2 31 | PEN_INPUT_BUTTON_3* = PenInputFlags 1u shl 3 32 | PEN_INPUT_BUTTON_4* = PenInputFlags 1u shl 4 33 | PEN_INPUT_BUTTON_5* = PenInputFlags 1u shl 5 34 | PEN_INPUT_ERASER_TIP* = PenInputFlags 1u shl 30 35 | 36 | type 37 | PenAxis* {.size: cint.sizeof.} = enum 38 | ## Pen axis indices. 39 | PEN_AXIS_PRESSURE 40 | PEN_AXIS_XTILT 41 | PEN_AXIS_YTILT 42 | PEN_AXIS_DISTANCE 43 | PEN_AXIS_ROTATION 44 | PEN_AXIS_SLIDER 45 | PEN_AXIS_TANGENTIAL_PRESSURE 46 | 47 | const 48 | PEN_AXIS_COUNT* = PenAxis.high.int + 1 49 | ## Last valid axis index. 50 | 51 | # vim: set sts=2 et sw=2: 52 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3pixels.nim: -------------------------------------------------------------------------------- 1 | ## Pixel format definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | # Transparency definitions. 10 | const 11 | ALPHA_OPAQUE* = byte 255 12 | ALPHA_OPAQUE_FLOAT* = cfloat 1.0 13 | 14 | const 15 | ALPHA_TRANSPARENT* = byte 0 16 | ALPHA_TRANSPARENT_FLOAT* = cfloat 0.0 17 | 18 | type 19 | PixelType {.size: cint.sizeof.} = enum 20 | ## Pixel type. 21 | PIXELTYPE_UNKNOWN 22 | PIXELTYPE_INDEX1 23 | PIXELTYPE_INDEX4 24 | PIXELTYPE_INDEX8 25 | PIXELTYPE_PACKED8 26 | PIXELTYPE_PACKED16 27 | PIXELTYPE_PACKED32 28 | PIXELTYPE_ARRAYU8 29 | PIXELTYPE_ARRAYU16 30 | PIXELTYPE_ARRAYU32 31 | PIXELTYPE_ARRAYF16 32 | PIXELTYPE_ARRAYF32 33 | PIXELTYPE_INDEX2 34 | 35 | BitmapOrder* {.size: cint.sizeof.} = enum 36 | ## Bitmap pixel order (high bit to low bit). 37 | BITMAPORDER_NONE 38 | BITMAPORDER_4321 39 | BITMAPORDER_1234 40 | 41 | PackedOrder {.size: cint.sizeof.} = enum 42 | ## Packed component order (high bit to low bit). 43 | PACKEDORDER_NONE 44 | PACKEDORDER_XRGB 45 | PACKEDORDER_RGBX 46 | PACKEDORDER_ARGB 47 | PACKEDORDER_RGBA 48 | PACKEDORDER_XBGR 49 | PACKEDORDER_BGRX 50 | PACKEDORDER_ABGR 51 | PACKEDORDER_BGRA 52 | 53 | ArrayOrder* {.size: cint.sizeof.} = enum 54 | ## Array component order, low byte to high byte. 55 | ARRAYORDER_NONE 56 | ARRAYORDER_RGB 57 | ARRAYORDER_RGBA 58 | ARRAYORDER_ARGB 59 | ARRAYORDER_BGR 60 | ARRAYORDER_BGRA 61 | ARRAYORDER_ABGR 62 | 63 | PackedLayout {.size: cint.sizeof.} = enum 64 | ## Packed component layout. 65 | PACKEDLAYOUT_NONE 66 | PACKEDLAYOUT_332 67 | PACKEDLAYOUT_4444 68 | PACKEDLAYOUT_1555 69 | PACKEDLAYOUT_5551 70 | PACKEDLAYOUT_565 71 | PACKEDLAYOUT_8888 72 | PACKEDLAYOUT_2101010 73 | PACKEDLAYOUT_1010102 74 | 75 | # Note: 76 | # SDL_ISPIXELFORMAT macros moved after PixelFormatEnum. 77 | 78 | type 79 | PixelFormatEnum* {.size: uint32.sizeof.} = enum 80 | ## Pixel format. 81 | PIXELFORMAT_UNKNOWN = 0 82 | PIXELFORMAT_INDEX1LSB = 0x11100100 83 | PIXELFORMAT_INDEX1MSB = 0x11200100 84 | PIXELFORMAT_INDEX4LSB = 0x12100400 85 | PIXELFORMAT_INDEX4MSB = 0x12200400 86 | PIXELFORMAT_INDEX8 = 0x13000801 87 | PIXELFORMAT_RGB332 = 0x14110801 88 | PIXELFORMAT_XRGB4444 = 0x15120c02 89 | PIXELFORMAT_XRGB1555 = 0x15130f02 90 | PIXELFORMAT_RGB565 = 0x15151002 91 | PIXELFORMAT_ARGB4444 = 0x15321002 92 | PIXELFORMAT_ARGB1555 = 0x15331002 93 | PIXELFORMAT_RGBA4444 = 0x15421002 94 | PIXELFORMAT_RGBA5551 = 0x15441002 95 | PIXELFORMAT_XBGR4444 = 0x15520c02 96 | PIXELFORMAT_XBGR1555 = 0x15530f02 97 | PIXELFORMAT_BGR565 = 0x15551002 98 | PIXELFORMAT_ABGR4444 = 0x15721002 99 | PIXELFORMAT_ABGR1555 = 0x15731002 100 | PIXELFORMAT_BGRA4444 = 0x15821002 101 | PIXELFORMAT_BGRA5551 = 0x15841002 102 | PIXELFORMAT_XRGB8888 = 0x16161804 103 | PIXELFORMAT_XRGB2101010 = 0x16172004 104 | PIXELFORMAT_RGBX8888 = 0x16261804 105 | PIXELFORMAT_ARGB8888 = 0x16362004 106 | PIXELFORMAT_ARGB2101010 = 0x16372004 107 | PIXELFORMAT_RGBA8888 = 0x16462004 108 | PIXELFORMAT_XBGR8888 = 0x16561804 109 | PIXELFORMAT_XBGR2101010 = 0x16572004 110 | PIXELFORMAT_BGRX8888 = 0x16661804 111 | PIXELFORMAT_ABGR8888 = 0x16762004 112 | PIXELFORMAT_ABGR2101010 = 0x16772004 113 | PIXELFORMAT_BGRA8888 = 0x16862004 114 | PIXELFORMAT_RGB24 = 0x17101803 115 | PIXELFORMAT_BGR24 = 0x17401803 116 | PIXELFORMAT_RGB48 = 0x18103006 117 | PIXELFORMAT_RGBA64 = 0x18204008 118 | PIXELFORMAT_ARGB64 = 0x18304008 119 | PIXELFORMAT_BGR48 = 0x18403006 120 | PIXELFORMAT_BGRA64 = 0x18504008 121 | PIXELFORMAT_ABGR64 = 0x18604008 122 | PIXELFORMAT_RGB48_FLOAT = 0x1a103006 123 | PIXELFORMAT_RGBA64_FLOAT = 0x1a204008 124 | PIXELFORMAT_ARGB64_FLOAT = 0x1a304008 125 | PIXELFORMAT_BGR48_FLOAT = 0x1a403006 126 | PIXELFORMAT_BGRA64_FLOAT = 0x1a504008 127 | PIXELFORMAT_ABGR64_FLOAT = 0x1a604008 128 | PIXELFORMAT_RGB96_FLOAT = 0x1b10600c 129 | PIXELFORMAT_RGBA128_FLOAT = 0x1b208010 130 | PIXELFORMAT_ARGB128_FLOAT = 0x1b308010 131 | PIXELFORMAT_BGR96_FLOAT = 0x1b40600c 132 | PIXELFORMAT_BGRA128_FLOAT = 0x1b508010 133 | PIXELFORMAT_ABGR128_FLOAT = 0x1b608010 134 | PIXELFORMAT_INDEX2LSB = 0x1c100200 135 | PIXELFORMAT_INDEX2MSB = 0x1c200200 136 | 137 | PIXELFORMAT_EXTERNAL_OES = 0x2053454f 138 | PIXELFORMAT_P010 = 0x30313050 139 | PIXELFORMAT_NV21 = 0x3132564e 140 | PIXELFORMAT_NV12 = 0x3231564e 141 | PIXELFORMAT_YV12 = 0x32315659 142 | PIXELFORMAT_YUY2 = 0x32595559 143 | PIXELFORMAT_MJPG = 0x47504a4d 144 | PIXELFORMAT_YVYU = 0x55595659 145 | PIXELFORMAT_IYUV = 0x56555949 146 | PIXELFORMAT_UYVY = 0x59565955 147 | 148 | when cpuEndian == bigEndian: 149 | const 150 | PIXELFORMAT_RGBA32* = PIXELFORMAT_RGBA8888 151 | PIXELFORMAT_ARGB32* = PIXELFORMAT_ARGB8888 152 | PIXELFORMAT_BGRA32* = PIXELFORMAT_BGRA8888 153 | PIXELFORMAT_ABGR32* = PIXELFORMAT_ABGR8888 154 | PIXELFORMAT_RGBX32* = PIXELFORMAT_RGBX8888 155 | PIXELFORMAT_XRGB32* = PIXELFORMAT_XRGB8888 156 | PIXELFORMAT_BGRX32* = PIXELFORMAT_BGRX8888 157 | PIXELFORMAT_XBGR32* = PIXELFORMAT_XBGR8888 158 | else: 159 | const 160 | PIXELFORMAT_RGBA32* = PIXELFORMAT_ABGR8888 161 | PIXELFORMAT_ARGB32* = PIXELFORMAT_BGRA8888 162 | PIXELFORMAT_BGRA32* = PIXELFORMAT_ARGB8888 163 | PIXELFORMAT_ABGR32* = PIXELFORMAT_RGBA8888 164 | PIXELFORMAT_RGBX32* = PIXELFORMAT_XBGR8888 165 | PIXELFORMAT_XRGB32* = PIXELFORMAT_BGRX8888 166 | PIXELFORMAT_BGRX32* = PIXELFORMAT_XRGB8888 167 | PIXELFORMAT_XBGR32* = PIXELFORMAT_RGBX8888 168 | 169 | func pixel_flag(format: PixelFormatEnum): uint32 {.inline.} = 170 | (format.uint32 shr 28) and 0x0f 171 | 172 | func pixel_type(format: PixelFormatEnum): uint32 {.inline.} = 173 | (format.uint32 shr 24) and 0x0f 174 | 175 | func pixel_order(format: PixelFormatEnum): uint32 {.inline.} = 176 | (format.uint32 shr 20) and 0x0f 177 | 178 | func pixel_layout(format: PixelFormatEnum): uint32 {.inline.} = 179 | (format.uint32 shr 16) and 0x0f 180 | 181 | func is_fourcc(format: PixelFormatEnum): bool {.inline.} = 182 | (format != PIXELFORMAT_UNKNOWN) and (format.pixel_flag != 1) 183 | 184 | func bits_per_pixel*(format: PixelFormatEnum): int {.inline.} = 185 | int (if format.is_fourcc: 0'u32 else: (format.uint32 shr 8) and 0xff) 186 | 187 | func bytes_per_pixel*(format: PixelFormatEnum): int {.inline.} = 188 | if format.is_fourcc: 189 | case format 190 | of PIXELFORMAT_YUY2, PIXELFORMAT_UYVY, PIXELFORMAT_YVYU, PIXELFORMAT_P010: 191 | 2 192 | else: 193 | 1 194 | else: 195 | int format.uint32 and 0xff 196 | 197 | func is_indexed*(format: PixelFormatEnum): bool {.inline.} = 198 | format.is_fourcc.not and ( 199 | (format.pixel_type == PIXELTYPE_INDEX1.uint32) or 200 | (format.pixel_type == PIXELTYPE_INDEX2.uint32) or 201 | (format.pixel_type == PIXELTYPE_INDEX4.uint32) or 202 | (format.pixel_type == PIXELTYPE_INDEX8.uint32) 203 | ) 204 | 205 | func is_packed*(format: PixelFormatEnum): bool {.inline.} = 206 | format.is_fourcc.not and ( 207 | (format.pixel_type == PIXELTYPE_PACKED8.uint32) or 208 | (format.pixel_type == PIXELTYPE_PACKED16.uint32) or 209 | (format.pixel_type == PIXELTYPE_PACKED32.uint32) 210 | ) 211 | 212 | func is_array*(format: PixelFormatEnum): bool {.inline.} = 213 | format.is_fourcc.not and ( 214 | (format.pixel_type == PIXELTYPE_ARRAYU8.uint32) or 215 | (format.pixel_type == PIXELTYPE_ARRAYU16.uint32) or 216 | (format.pixel_type == PIXELTYPE_ARRAYU32.uint32) or 217 | (format.pixel_type == PIXELTYPE_ARRAYF16.uint32) or 218 | (format.pixel_type == PIXELTYPE_ARRAYF32.uint32) 219 | ) 220 | 221 | func is_alpha*(format: PixelFormatEnum): bool {.inline.} = 222 | format.is_packed and ( 223 | (format.pixel_order == PACKEDORDER_ARGB.uint32) or 224 | (format.pixel_order == PACKEDORDER_RGBA.uint32) or 225 | (format.pixel_order == PACKEDORDER_ABGR.uint32) or 226 | (format.pixel_order == PACKEDORDER_BGRA.uint32) 227 | ) 228 | 229 | func is_10bit*(format: PixelFormatEnum): bool {.inline.} = 230 | format.is_fourcc.not and ( 231 | (format.pixel_type == PIXELTYPE_PACKED32.uint32) and 232 | (format.pixel_layout == PACKEDLAYOUT_2101010.uint32) 233 | ) 234 | 235 | func is_float*(format: PixelFormatEnum): bool {.inline.} = 236 | format.is_fourcc.not and ( 237 | (format.pixel_type == PIXELTYPE_ARRAYF16.uint32) or 238 | (format.pixel_type == PIXELTYPE_ARRAYF32.uint32) 239 | ) 240 | 241 | type 242 | ColorType* {.size: cint.sizeof.} = enum 243 | ## The color type. 244 | COLOR_TYPE_UNKNOWN = 0 245 | COLOR_TYPE_RGB = 1 246 | COLOR_TYPE_YCBCR = 2 247 | 248 | ColorRange* {.size: cint.sizeof.} = enum 249 | ## The color range, 250 | ## as described by https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en. 251 | COLOR_RANGE_UNKNOWN = 0 252 | COLOR_RANGE_LIMITED = 1 253 | COLOR_RANGE_FULL = 2 254 | 255 | ColorPrimaries* {.size: cint.sizeof.} = enum 256 | ## The color primaries, 257 | ## as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en. 258 | COLOR_PRIMARIES_UNKNOWN = 0 259 | COLOR_PRIMARIES_BT709 = 1 260 | COLOR_PRIMARIES_UNSPECIFIED = 2 261 | COLOR_PRIMARIES_BT470M = 4 262 | COLOR_PRIMARIES_BT470BG = 5 263 | COLOR_PRIMARIES_BT601 = 6 264 | COLOR_PRIMARIES_SMPTE240 = 7 265 | COLOR_PRIMARIES_GENERIC_FILM = 8 266 | COLOR_PRIMARIES_BT2020 = 9 267 | COLOR_PRIMARIES_XYZ = 10 268 | COLOR_PRIMARIES_SMPTE431 = 11 269 | COLOR_PRIMARIES_SMPTE432 = 12 ## DCI P3. 270 | COLOR_PRIMARIES_EBU3213 = 22 271 | COLOR_PRIMARIES_CUSTOM = 31 272 | 273 | TransferCharacteristics* {.size: cint.sizeof.} = enum 274 | ## The transfer characteristics, 275 | ## as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en. 276 | TRANSFER_CHARACTERISTICS_UNKNOWN = 0 277 | TRANSFER_CHARACTERISTICS_BT709 = 1 278 | TRANSFER_CHARACTERISTICS_UNSPECIFIED = 2 279 | TRANSFER_CHARACTERISTICS_GAMMA22 = 4 280 | TRANSFER_CHARACTERISTICS_GAMMA28 = 5 281 | TRANSFER_CHARACTERISTICS_BT601 = 6 282 | TRANSFER_CHARACTERISTICS_SMPTE240 = 7 283 | TRANSFER_CHARACTERISTICS_LINEAR = 8 284 | TRANSFER_CHARACTERISTICS_LOG100 = 9 285 | TRANSFER_CHARACTERISTICS_LOG100_SQRT10 = 10 286 | TRANSFER_CHARACTERISTICS_IEC61966 = 11 287 | TRANSFER_CHARACTERISTICS_BT1361 = 12 288 | TRANSFER_CHARACTERISTICS_SRGB = 13 289 | TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14 290 | TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15 291 | TRANSFER_CHARACTERISTICS_PQ = 16 292 | TRANSFER_CHARACTERISTICS_SMPTE428 = 17 293 | TRANSFER_CHARACTERISTICS_HLG = 18 294 | TRANSFER_CHARACTERISTICS_CUSTOM = 31 295 | 296 | MatrixCoefficients* {.size: cint.sizeof.} = enum 297 | ## The matrix coefficients, 298 | ## as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en. 299 | MATRIX_COEFFICIENTS_IDENTITY = 0 300 | MATRIX_COEFFICIENTS_BT709 = 1 301 | MATRIX_COEFFICIENTS_UNSPECIFIED = 2 302 | MATRIX_COEFFICIENTS_FCC = 4 303 | MATRIX_COEFFICIENTS_BT470BG = 5 304 | MATRIX_COEFFICIENTS_BT601 = 6 305 | MATRIX_COEFFICIENTS_SMPTE240 = 7 306 | MATRIX_COEFFICIENTS_YCGCO = 8 307 | MATRIX_COEFFICIENTS_BT2020_NCL = 9 308 | MATRIX_COEFFICIENTS_BT2020_CL = 10 309 | MATRIX_COEFFICIENTS_SMPTE2085 = 11 310 | MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12 311 | MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13 312 | MATRIX_COEFFICIENTS_ICTCP = 14 313 | MATRIX_COEFFICIENTS_CUSTOM = 31 314 | 315 | ChromaLocation* {.size: cint.sizeof.} = enum 316 | ## The chroma sample location. 317 | CHROMA_LOCATION_NONE = 0 318 | CHROMA_LOCATION_LEFT = 1 319 | CHROMA_LOCATION_CENTER = 2 320 | CHROMA_LOCATION_TOPLEFT = 3 321 | 322 | #[ 323 | func define_colorspace(typ: ColorType, range: ColorRange, 324 | primaries: ColorPrimaries, 325 | transfer: TransferCharacteristics, 326 | matrix: MatrixCoefficients, 327 | chroma: ChromaLocation): uint32 = 328 | ## Colorspace definition. 329 | (typ.uint32 shl 28) or (range.uint32 shl 24) or (chroma.uint32 shl 20) or 330 | (primaries.uint32 shl 10) or (transfer.uint32 shl 5) or (matrix.uint32 shl 0) 331 | ]# 332 | 333 | # XXX: 334 | #func COLORSPACETYPE(x) (SDL_ColorType)(((X) >> 28) & 0x0F) 335 | #func COLORSPACERANGE(x) (SDL_ColorRange)(((X) >> 24) & 0x0F) 336 | #func COLORSPACECHROMA(x) (SDL_ChromaLocation)(((X) >> 20) & 0x0F) 337 | #func COLORSPACEPRIMARIES(x) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F) 338 | #func COLORSPACETRANSFER(x) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F) 339 | #func COLORSPACEMATRIX(x) (SDL_MatrixCoefficients)((X) & 0x1F) 340 | 341 | # XXX: 342 | #define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG) 343 | #define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709) 344 | #define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL) 345 | #define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL) 346 | #define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL) 347 | 348 | type 349 | Colorspace* {.size: cint.sizeof.} = enum 350 | ## The color space. 351 | COLORSPACE_UNKNOWN = 0 352 | COLORSPACE_SRGB_LINEAR = 0x12000500 353 | COLORSPACE_SRGB = 0x120005a0 354 | COLORSPACE_HDR10 = 0x12002600 355 | COLORSPACE_BT709_LIMITED = 0x21100421 356 | COLORSPACE_BT601_LIMITED = 0x211018c6 357 | COLORSPACE_BT2020_LIMITED = 0x21102609 358 | COLORSPACE_JPEG = 0x220004c6 359 | COLORSPACE_BT709_FULL = 0x22100421 360 | COLORSPACE_BT601_FULL = 0x221018c6 361 | COLORSPACE_BT2020_FULL = 0x22102609 362 | 363 | const 364 | COLORSPACE_RGB_DEFAULT* = COLORSPACE_SRGB 365 | ## The default colorspace for RGB surfaces if no colorspace is specified. 366 | 367 | COLORSPACE_YUV_DEFAULT* = COLORSPACE_JPEG 368 | ## The default colorspace for YUV surfaces if no colorspace is specified. 369 | 370 | type 371 | Color* {.final, pure.} = object 372 | ## Color. 373 | r* : byte 374 | g* : byte 375 | b* : byte 376 | a* : byte 377 | 378 | func init*(T: typedesc[Color], r, g, b: byte, a: byte = 0xff): T {.inline.} = 379 | T(r: r, g: g, b: b, a: a) 380 | 381 | type 382 | FColor* {.final, pure.} = object 383 | ## The bits of this structure can be directly reinterpreted 384 | ## as a float-packed color which uses the `PIXELFORMAT_RGBA128_FLOAT` 385 | ## format. 386 | r* : cfloat 387 | g* : cfloat 388 | b* : cfloat 389 | a* : cfloat 390 | 391 | FColour* = FColor 392 | 393 | func init*(T: typedesc[FColor], r, g, b: SomeFloat, 394 | a: SomeFloat = 1.0): FColor {.inline.} = 395 | T(r: r.cfloat, g: g.cfloat, b: b.cfloat, a: a.cfloat) 396 | 397 | type 398 | Palette* {.final, pure.} = object 399 | ncolors* : cint 400 | colors* : ptr UncheckedArray[Color] 401 | version* : uint32 402 | refcount : cint 403 | 404 | type 405 | PixelFormatDetails* {.bycopy, final, pure.} = object 406 | ## Pixel format. All attributes are read-only. 407 | format* : PixelFormatEnum 408 | bits_per_pixel* : byte 409 | bytes_per_pixel* : byte 410 | padding : array[2, byte] 411 | rmask* : uint32 412 | gmask* : uint32 413 | bmask* : uint32 414 | amask* : uint32 415 | rbits* : byte 416 | gbits* : byte 417 | bbits* : byte 418 | abits* : byte 419 | rshift* : byte 420 | gshift* : byte 421 | bshift* : byte 422 | ashift* : byte 423 | 424 | PixelFormatDetailsPtr* = ptr PixelFormatDetails 425 | ## Pixel format pointer. 426 | 427 | # --------------------------------------------------------------------------- # 428 | # Sanity checks # 429 | # --------------------------------------------------------------------------- # 430 | 431 | when defined(gcc) and hostCPU == "amd64": 432 | when Palette.sizeof != 24: 433 | {.error: "invalid Palette size: " & $Palette.sizeof.} 434 | # when PixelFormatDetails.sizeof != 56: 435 | # {.error: "invalid PixelFormat size: " & $PixelFormatDetails.sizeof.} 436 | 437 | # vim: set sts=2 et sw=2: 438 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3power.nim: -------------------------------------------------------------------------------- 1 | ## Power management definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | PowerState* {.size: cint.sizeof.} = enum # XXX: TODO: check size. 11 | ## Power state. 12 | POWERSTATE_ERROR = -1 13 | POWERSTATE_UNKNOWN 14 | POWERSTATE_ON_BATTERY 15 | POWERSTATE_NO_BATTERY 16 | POWERSTATE_CHARGING 17 | POWERSTATE_CHARGED 18 | 19 | # vim: set sts=2 et sw=2: 20 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3properties.nim: -------------------------------------------------------------------------------- 1 | ## Properties. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | PropertiesID* = distinct uint32 11 | ## Properties ID. 12 | 13 | func `==`*(a, b: PropertiesID): bool {.borrow.} 14 | 15 | type 16 | PropertyType* {.size: cint.sizeof.} = enum 17 | ## Property type. 18 | PROPERTY_TYPE_INVALID 19 | PROPERTY_TYPE_POINTER 20 | PROPERTY_TYPE_STRING 21 | PROPERTY_TYPE_NUMBER 22 | PROPERTY_TYPE_FLOAT 23 | PROPERTY_TYPE_BOOLEAN 24 | 25 | # XXX: typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value); 26 | 27 | type 28 | EnumeratePropertiesCallback* = proc ( 29 | userdata : pointer, 30 | props : PropertiesID, 31 | name : cstring 32 | ) {.cdecl, raises: [].} 33 | 34 | # vim: set sts=2 et sw=2: 35 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3rect.nim: -------------------------------------------------------------------------------- 1 | ## Rect definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | const 10 | # SDL_stdinc.h. 11 | FLT_EPSILON = 1.1920928955078125e-07f 12 | 13 | type 14 | Point* {.bycopy, final, pure.} = object 15 | ## Point (integer). 16 | x* : cint 17 | y* : cint 18 | 19 | FPoint* {.bycopy, final, pure.} = object 20 | ## Point (floating point). 21 | x* : cfloat 22 | y* : cfloat 23 | 24 | func init*(T: typedesc[FPoint], x: float, y: float): T {.inline.} = 25 | T(x: x.cfloat, y: y.cfloat) 26 | 27 | func init*(T: typedesc[FPoint], x: int, y: int): T {.inline.} = 28 | T(x: x.cfloat, y: y.cfloat) 29 | 30 | type 31 | Rect* {.bycopy, final, pure.} = object 32 | ## Rectangle (integer). 33 | x* : cint 34 | y* : cint 35 | w* : cint 36 | h* : cint 37 | 38 | func init*(T: typedesc[Rect], x, y: int, w, h: int): T {.inline.} = 39 | T(x: x.cint, y: y.cint, w: w.cint, h: h.cint) 40 | 41 | type 42 | FRect* {.bycopy, final, pure.} = object 43 | ## Rectangle (floating point). 44 | x* : cfloat 45 | y* : cfloat 46 | w* : cfloat 47 | h* : cfloat 48 | 49 | func init*(T: typedesc[FRect], x, y, w, h: float): T {.inline.} = 50 | T(x: x.cfloat, y: y.cfloat, w: w.cfloat, h: h.cfloat) 51 | 52 | func init*(T: typedesc[FRect], x, y, w, h: int): T {.inline.} = 53 | T(x: x.cfloat, y: y.cfloat, w: w.cfloat, h: h.cfloat) 54 | 55 | func point_in_rect*(p: Point, r: Rect): bool {.inline.} = 56 | ## Return `true` if point resides inside a rectangle. 57 | (p.x >= r.x) and (p.x < (r.x + r.w)) and 58 | (p.y >= r.y) and (p.y < (r.y + r.h)) 59 | 60 | func rect_empty*(r: ptr Rect): bool {.inline.} = 61 | ## Return `true` if the rectangle has no area. 62 | (r == nil) or (r.w <= 0) or (r.h <= 0) 63 | 64 | func rect_empty*(r: Rect): bool {.inline.} = 65 | ## Return `true` if the rectangle has no area. 66 | (r.w <= 0) or (r.h <= 0) 67 | 68 | func rect_equals*(a, b: ptr Rect): bool {.inline.} = 69 | ## Return `true` if the two rectangles are equal. 70 | (a != nil) and (b != nil) and 71 | (a.x == b.x) and (a.y == b.y) and 72 | (a.w == b.w) and (a.h == b.h) 73 | 74 | func point_in_rect_float*(p: ptr FPoint, r: ptr FRect): bool {.inline.} = 75 | ## Return `true` if point resides inside a rectangle. 76 | (p.x >= r.x) and (p.x <= (r.x + r.w)) and (p.y >= r.y) and (p.y <= (r.y + r.h)) 77 | 78 | func rect_empty_float*(r: ptr FRect): bool {.inline.} = 79 | ## Return `true` if the rectangle has no area. 80 | (r == nil) or (r.w < 0.0f) or (r.h < 0.0f) 81 | 82 | func rects_equal_epsilon*(a, b: ptr FRect, epsilon: cfloat): bool {.inline.} = 83 | (a != nil) and (b != nil) and ((a == b) or 84 | ((abs(a.x - b.x) <= epsilon) and 85 | (abs(a.y - b.y) <= epsilon) and 86 | (abs(a.w - b.w) <= epsilon) and 87 | (abs(a.h - b.h) <= epsilon))) 88 | 89 | func rects_equal_float*(a, b: ptr FRect): bool {.inline.} = 90 | rects_equal_epsilon(a, b, FLT_EPSILON) 91 | 92 | # vim: set sts=2 et sw=2: 93 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3render.nim: -------------------------------------------------------------------------------- 1 | ## Renderer definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3pixels import FColor, PixelFormatEnum 10 | from sdl3rect import FPoint 11 | 12 | const 13 | SOFTWARE_RENDERER* = cstring"software" 14 | ## Software renderer name. 15 | 16 | type 17 | Vertex* {.final, pure.} = object 18 | ## Vertex. 19 | position* : FPoint ## Vertex position (`Renderer` coordinates). 20 | color* : FColor ## Vertex color. 21 | tex_coord* : FPoint ## Normalized texture coordinates (if needed). 22 | 23 | func init*(T: typedesc[Vertex], pos: FPoint, color: FColor): T {.inline.} = 24 | T(position: pos, color: color, tex_coord: FPoint(x: 0, y: 0)) 25 | 26 | type 27 | TextureAccess* {.size: cint.sizeof.} = enum 28 | ## Texture access pattern allowed. 29 | TEXTUREACCESS_STATIC ## Changes rarely, not lockable. 30 | TEXTUREACCESS_STREAMING ## Changes frequently, lockable. 31 | TEXTUREACCESS_TARGET ## Texture can be used as a render target. 32 | 33 | RendererLogicalPresentation* {.size: cint.sizeof.} = enum # XXX: size 34 | ## Logical size mapped to the output. 35 | LOGICAL_PRESENTATION_DISABLED 36 | LOGICAL_PRESENTATION_STRETCH 37 | LOGICAL_PRESENTATION_LETTERBOX 38 | LOGICAL_PRESENTATION_OVERSCAN 39 | LOGICAL_PRESENTATION_INTEGER_SCALE 40 | 41 | Renderer* = ptr object 42 | ## Rendering state. 43 | 44 | Texture* = ptr object 45 | ## Texture. 46 | 47 | RenderCreateProperty* = enum 48 | ## Render property. 49 | PROP_RENDERER_CREATE_NAME_STRING = cstring"SDL.renderer.create.name" 50 | PROP_RENDERER_CREATE_WINDOW_POINTER = cstring"SDL.renderer.create.window" 51 | PROP_RENDERER_CREATE_SURFACE_POINTER = cstring"SDL.renderer.create.surface" 52 | PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER = cstring"SDL.renderer.create.output_colorspace" 53 | PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER = cstring"SDL.renderer.create.present_vsync" 54 | PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER = cstring"SDL.renderer.create.vulkan.instance" 55 | PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER = cstring"SDL.renderer.create.vulkan.surface" 56 | PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER = cstring"SDL.renderer.create.vulkan.physical_device" 57 | PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER = cstring"SDL.renderer.create.vulkan.device" 58 | PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER = cstring"SDL.renderer.create.vulkan.graphics_queue_family_index" 59 | PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER = cstring"SDL.renderer.create.vulkan.present_queue_family_index" 60 | 61 | RenderDeviceProperty* = enum 62 | PROP_RENDERER_NAME_STRING = cstring"SDL.renderer.name" 63 | PROP_RENDERER_WINDOW_POINTER = cstring"SDL.renderer.window" 64 | PROP_RENDERER_SURFACE_POINTER = cstring"SDL.renderer.surface" 65 | PROP_RENDERER_VSYNC_NUMBER = cstring"SDL.renderer.vsync" 66 | PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER = cstring"SDL.renderer.max_texture_size" 67 | PROP_RENDERER_TEXTURE_FORMATS_POINTER = cstring"SDL.renderer.texture_formats" 68 | PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER = cstring"SDL.renderer.output_colorspace" 69 | PROP_RENDERER_HDR_ENABLED_BOOLEAN = cstring"SDL.renderer.HDR_enabled" 70 | PROP_RENDERER_SDR_WHITE_POINT_FLOAT = cstring"SDL.renderer.SDR_white_point" 71 | PROP_RENDERER_HDR_HEADROOM_FLOAT = cstring"SDL.renderer.HDR_headroom" 72 | PROP_RENDERER_D3D9_DEVICE_POINTER = cstring"SDL.renderer.d3d9.device" 73 | PROP_RENDERER_D3D11_DEVICE_POINTER = cstring"SDL.renderer.d3d11.device" 74 | PROP_RENDERER_D3D11_SWAPCHAIN_POINTER = cstring"SDL.renderer.d3d11.swap_chain" 75 | PROP_RENDERER_D3D12_DEVICE_POINTER = cstring"SDL.renderer.d3d12.device" 76 | PROP_RENDERER_D3D12_SWAPCHAIN_POINTER = cstring"SDL.renderer.d3d12.swap_chain" 77 | PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER = cstring"SDL.renderer.d3d12.command_queue" 78 | PROP_RENDERER_VULKAN_INSTANCE_POINTER = cstring"SDL.renderer.vulkan.instance" 79 | PROP_RENDERER_VULKAN_SURFACE_NUMBER = cstring"SDL.renderer.vulkan.surface" 80 | PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER = cstring"SDL.renderer.vulkan.physical_device" 81 | PROP_RENDERER_VULKAN_DEVICE_POINTER = cstring"SDL.renderer.vulkan.device" 82 | PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER = cstring"SDL.renderer.vulkan.graphics_queue_family_index" 83 | PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER = cstring"SDL.renderer.vulkan.present_queue_family_index" 84 | PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER = cstring"SDL.renderer.vulkan.swapchain_image_count" 85 | PROP_RENDERER_GPU_DEVICE_POINTER = cstring"SDL.renderer.gpu.device" 86 | 87 | TextureCreateProperty* = enum 88 | PROP_TEXTURE_CREATE_COLORSPACE_NUMBER = cstring"SDL.texture.colorspace" 89 | PROP_TEXTURE_CREATE_FORMAT_NUMBER = cstring"SDL.texture.format" 90 | PROP_TEXTURE_CREATE_ACCESS_NUMBER = cstring"SDL.texture.access" 91 | PROP_TEXTURE_CREATE_WIDTH_NUMBER = cstring"SDL.texture.width" 92 | PROP_TEXTURE_CREATE_HEIGHT_NUMBER = cstring"SDL.texture.height" 93 | PROP_TEXTURE_SDR_WHITE_POINT_FLOAT = cstring"SDL.texture.SDR_white_point" 94 | PROP_TEXTURE_HDR_HEADROOM_FLOAT = cstring"SDL.texture.HDR_headroom" 95 | PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER = cstring"SDL.texture.d3d11.texture" 96 | PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER = cstring"SDL.texture.d3d11.texture_u" 97 | PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER = cstring"SDL.texture.d3d11.texture_v" 98 | PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER = cstring"SDL.texture.d3d12.texture" 99 | PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER = cstring"SDL.texture.d3d12.texture_u" 100 | PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER = cstring"SDL.texture.d3d12.texture_v" 101 | PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER = cstring"SDL.texture.opengl.texture" 102 | PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER = cstring"SDL.texture.opengl.texture_uv" 103 | PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER = cstring"SDL.texture.opengl.texture_u" 104 | PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER = cstring"SDL.texture.opengl.texture_v" 105 | PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER = cstring"SDL.texture.opengl.target" 106 | PROP_TEXTURE_OPENGL_TEX_W_FLOAT = cstring"SDL.texture.opengl.tex_w" 107 | PROP_TEXTURE_OPENGL_TEX_H_FLOAT = cstring"SDL.texture.opengl.tex_h" 108 | PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER = cstring"SDL.texture.opengles2.texture" 109 | PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER = cstring"SDL.texture.opengles2.texture_uv" 110 | PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER = cstring"SDL.texture.opengles2.texture_u" 111 | PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER = cstring"SDL.texture.opengles2.texture_v" 112 | PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER = cstring"SDL.texture.vulkan.texture" 113 | 114 | TextureProperty* = enum 115 | PROP_TEXTURE_COLORSPACE_NUMBER = cstring"SDL.texture.colorspace" 116 | PROP_TEXTURE_D3D11_TEXTURE_POINTER = cstring"SDL.texture.d3d11.texture" 117 | PROP_TEXTURE_D3D11_TEXTURE_U_POINTER = cstring"SDL.texture.d3d11.texture_u" 118 | PROP_TEXTURE_D3D11_TEXTURE_V_POINTER = cstring"SDL.texture.d3d11.texture_v" 119 | PROP_TEXTURE_D3D12_TEXTURE_POINTER = cstring"SDL.texture.d3d12.texture" 120 | PROP_TEXTURE_D3D12_TEXTURE_U_POINTER = cstring"SDL.texture.d3d12.texture_u" 121 | PROP_TEXTURE_D3D12_TEXTURE_V_POINTER = cstring"SDL.texture.d3d12.texture_v" 122 | PROP_TEXTURE_OPENGL_TEXTURE_NUMBER = cstring"SDL.texture.opengl.texture" 123 | PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER = cstring"SDL.texture.opengl.texture_uv" 124 | PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER = cstring"SDL.texture.opengl.texture_u" 125 | PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER = cstring"SDL.texture.opengl.texture_v" 126 | PROP_TEXTURE_OPENGL_TEXTURE_TARGET = cstring"SDL.texture.opengl.target" 127 | PROP_TEXTURE_OPENGL_TEX_W_FLOAT = cstring"SDL.texture.opengl.tex_w" 128 | PROP_TEXTURE_OPENGL_TEX_H_FLOAT = cstring"SDL.texture.opengl.tex_h" 129 | PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER = cstring"SDL.texture.opengles2.texture" 130 | PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER = cstring"SDL.texture.opengles2.texture_uv" 131 | PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER = cstring"SDL.texture.opengles2.texture_u" 132 | PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER = cstring"SDL.texture.opengles2.texture_v" 133 | PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET = cstring"SDL.texture.opengles2.target" 134 | PROP_TEXTURE_VULKAN_TEXTURE_NUMBER = cstring"SDL.texture.vulkan.texture" 135 | 136 | # XXX: 137 | # define SDL_RENDERER_VSYNC_DISABLED 0 138 | #define SDL_RENDERER_VSYNC_ADAPTIVE (-1) 139 | 140 | const 141 | DEBUG_TEXT_FONT_CHARACTER_SIZE* = 8 142 | ## The size, in pixels, of a single `RenderDebugText` character. 143 | 144 | # --------------------------------------------------------------------------- # 145 | # Sanity checks # 146 | # --------------------------------------------------------------------------- # 147 | 148 | # when defined(gcc) and hostCPU == "amd64": 149 | # when RendererInfo.sizeof != 88: 150 | # {.fatal: "invalid RendererInfo size: " & $RendererInfo.sizeof.} 151 | 152 | # vim: set sts=2 et sw=2: 153 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3scancode.nim: -------------------------------------------------------------------------------- 1 | ## Keyboard scancodes definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | Scancode* = distinct cint 11 | ## Keyboard scancode. 12 | 13 | const 14 | SCANCODE_UNKNOWN* = Scancode 0 15 | 16 | SCANCODE_A* = Scancode 4 17 | SCANCODE_B* = Scancode 5 18 | SCANCODE_C* = Scancode 6 19 | SCANCODE_D* = Scancode 7 20 | SCANCODE_E* = Scancode 8 21 | SCANCODE_F* = Scancode 9 22 | SCANCODE_G* = Scancode 10 23 | SCANCODE_H* = Scancode 11 24 | SCANCODE_I* = Scancode 12 25 | SCANCODE_J* = Scancode 13 26 | SCANCODE_K* = Scancode 14 27 | SCANCODE_L* = Scancode 15 28 | SCANCODE_M* = Scancode 16 29 | SCANCODE_N* = Scancode 17 30 | SCANCODE_O* = Scancode 18 31 | SCANCODE_P* = Scancode 19 32 | SCANCODE_Q* = Scancode 20 33 | SCANCODE_R* = Scancode 21 34 | SCANCODE_S* = Scancode 22 35 | SCANCODE_T* = Scancode 23 36 | SCANCODE_U* = Scancode 24 37 | SCANCODE_V* = Scancode 25 38 | SCANCODE_W* = Scancode 26 39 | SCANCODE_X* = Scancode 27 40 | SCANCODE_Y* = Scancode 28 41 | SCANCODE_Z* = Scancode 29 42 | 43 | SCANCODE_1* = Scancode 30 44 | SCANCODE_2* = Scancode 31 45 | SCANCODE_3* = Scancode 32 46 | SCANCODE_4* = Scancode 33 47 | SCANCODE_5* = Scancode 34 48 | SCANCODE_6* = Scancode 35 49 | SCANCODE_7* = Scancode 36 50 | SCANCODE_8* = Scancode 37 51 | SCANCODE_9* = Scancode 38 52 | SCANCODE_0* = Scancode 39 53 | 54 | SCANCODE_RETURN* = Scancode 40 55 | SCANCODE_ESCAPE* = Scancode 41 56 | SCANCODE_BACKSPACE* = Scancode 42 57 | SCANCODE_TAB* = Scancode 43 58 | SCANCODE_SPACE* = Scancode 44 59 | 60 | SCANCODE_MINUS* = Scancode 45 61 | SCANCODE_EQUALS* = Scancode 46 62 | SCANCODE_LEFTBRACKET* = Scancode 47 63 | SCANCODE_RIGHTBRACKET* = Scancode 48 64 | SCANCODE_BACKSLASH* = Scancode 49 65 | SCANCODE_NONUSHASH* = Scancode 50 66 | SCANCODE_SEMICOLON* = Scancode 51 67 | SCANCODE_APOSTROPHE* = Scancode 52 68 | SCANCODE_GRAVE* = Scancode 53 69 | SCANCODE_COMMA* = Scancode 54 70 | SCANCODE_PERIOD* = Scancode 55 71 | SCANCODE_SLASH* = Scancode 56 72 | 73 | SCANCODE_CAPSLOCK* = Scancode 57 74 | 75 | SCANCODE_F1* = Scancode 58 76 | SCANCODE_F2* = Scancode 59 77 | SCANCODE_F3* = Scancode 60 78 | SCANCODE_F4* = Scancode 61 79 | SCANCODE_F5* = Scancode 62 80 | SCANCODE_F6* = Scancode 63 81 | SCANCODE_F7* = Scancode 64 82 | SCANCODE_F8* = Scancode 65 83 | SCANCODE_F9* = Scancode 66 84 | SCANCODE_F10* = Scancode 67 85 | SCANCODE_F11* = Scancode 68 86 | SCANCODE_F12* = Scancode 69 87 | 88 | SCANCODE_PRINTSCREEN* = Scancode 70 89 | SCANCODE_SCROLLLOCK* = Scancode 71 90 | SCANCODE_PAUSE* = Scancode 72 91 | SCANCODE_INSERT* = Scancode 73 92 | SCANCODE_HOME* = Scancode 74 93 | SCANCODE_PAGEUP* = Scancode 75 94 | SCANCODE_DELETE* = Scancode 76 95 | SCANCODE_END* = Scancode 77 96 | SCANCODE_PAGEDOWN* = Scancode 78 97 | SCANCODE_RIGHT* = Scancode 79 98 | SCANCODE_LEFT* = Scancode 80 99 | SCANCODE_DOWN* = Scancode 81 100 | SCANCODE_UP* = Scancode 82 101 | 102 | SCANCODE_NUMLOCKCLEAR* = Scancode 83 103 | 104 | SCANCODE_KP_DIVIDE* = Scancode 84 105 | SCANCODE_KP_MULTIPLY* = Scancode 85 106 | SCANCODE_KP_MINUS* = Scancode 86 107 | SCANCODE_KP_PLUS* = Scancode 87 108 | SCANCODE_KP_ENTER* = Scancode 88 109 | SCANCODE_KP_1* = Scancode 89 110 | SCANCODE_KP_2* = Scancode 90 111 | SCANCODE_KP_3* = Scancode 91 112 | SCANCODE_KP_4* = Scancode 92 113 | SCANCODE_KP_5* = Scancode 93 114 | SCANCODE_KP_6* = Scancode 94 115 | SCANCODE_KP_7* = Scancode 95 116 | SCANCODE_KP_8* = Scancode 96 117 | SCANCODE_KP_9* = Scancode 97 118 | SCANCODE_KP_0* = Scancode 98 119 | SCANCODE_KP_PERIOD* = Scancode 99 120 | 121 | SCANCODE_NONUSBACKSLASH* = Scancode 100 122 | SCANCODE_APPLICATION* = Scancode 101 123 | SCANCODE_POWER* = Scancode 102 124 | SCANCODE_KP_EQUALS* = Scancode 103 125 | SCANCODE_F13* = Scancode 104 126 | SCANCODE_F14* = Scancode 105 127 | SCANCODE_F15* = Scancode 106 128 | SCANCODE_F16* = Scancode 107 129 | SCANCODE_F17* = Scancode 108 130 | SCANCODE_F18* = Scancode 109 131 | SCANCODE_F19* = Scancode 110 132 | SCANCODE_F20* = Scancode 111 133 | SCANCODE_F21* = Scancode 112 134 | SCANCODE_F22* = Scancode 113 135 | SCANCODE_F23* = Scancode 114 136 | SCANCODE_F24* = Scancode 115 137 | SCANCODE_EXECUTE* = Scancode 116 138 | SCANCODE_HELP* = Scancode 117 139 | SCANCODE_MENU* = Scancode 118 140 | SCANCODE_SELECT* = Scancode 119 141 | SCANCODE_STOP* = Scancode 120 142 | SCANCODE_AGAIN* = Scancode 121 ## Redo. 143 | SCANCODE_UNDO* = Scancode 122 144 | SCANCODE_CUT* = Scancode 123 145 | SCANCODE_COPY* = Scancode 124 146 | SCANCODE_PASTE* = Scancode 125 147 | SCANCODE_FIND* = Scancode 126 148 | SCANCODE_MUTE* = Scancode 127 149 | SCANCODE_VOLUMEUP* = Scancode 128 150 | SCANCODE_VOLUMEDOWN* = Scancode 129 151 | 152 | SCANCODE_KP_COMMA* = Scancode 133 153 | SCANCODE_KP_EQUALSAS400* = Scancode 134 154 | 155 | SCANCODE_INTERNATIONAL1* = Scancode 135 156 | SCANCODE_INTERNATIONAL2* = Scancode 136 157 | SCANCODE_INTERNATIONAL3* = Scancode 137 ## Yen. 158 | SCANCODE_INTERNATIONAL4* = Scancode 138 159 | SCANCODE_INTERNATIONAL5* = Scancode 139 160 | SCANCODE_INTERNATIONAL6* = Scancode 140 161 | SCANCODE_INTERNATIONAL7* = Scancode 141 162 | SCANCODE_INTERNATIONAL8* = Scancode 142 163 | SCANCODE_INTERNATIONAL9* = Scancode 143 164 | SCANCODE_LANG1* = Scancode 144 ## Hangul/English toggle. 165 | SCANCODE_LANG2* = Scancode 145 ## Hanja conversion. 166 | SCANCODE_LANG3* = Scancode 146 ## Katakana. 167 | SCANCODE_LANG4* = Scancode 147 ## Hiragana. 168 | SCANCODE_LANG5* = Scancode 148 ## Zenkaku/Hankaku. 169 | SCANCODE_LANG6* = Scancode 149 ## Reserved. 170 | SCANCODE_LANG7* = Scancode 150 ## Reserved. 171 | SCANCODE_LANG8* = Scancode 151 ## Reserved. 172 | SCANCODE_LANG9* = Scancode 152 ## Reserved. 173 | 174 | SCANCODE_ALTERASE* = Scancode 153 ## Erase-Eaze. 175 | SCANCODE_SYSREQ* = Scancode 154 176 | SCANCODE_CANCEL* = Scancode 155 177 | SCANCODE_CLEAR* = Scancode 156 178 | SCANCODE_PRIOR* = Scancode 157 179 | SCANCODE_RETURN2* = Scancode 158 180 | SCANCODE_SEPARATOR* = Scancode 159 181 | SCANCODE_OUT* = Scancode 160 182 | SCANCODE_OPER* = Scancode 161 183 | SCANCODE_CLEARAGAIN* = Scancode 162 184 | SCANCODE_CRSEL* = Scancode 163 185 | SCANCODE_EXSEL* = Scancode 164 186 | 187 | SCANCODE_KP_00* = Scancode 176 188 | SCANCODE_KP_000* = Scancode 177 189 | SCANCODE_THOUSANDSSEPARATOR* = Scancode 178 190 | SCANCODE_DECIMALSEPARATOR* = Scancode 179 191 | SCANCODE_CURRENCYUNIT* = Scancode 180 192 | SCANCODE_CURRENCYSUBUNIT* = Scancode 181 193 | SCANCODE_KP_LEFTPAREN* = Scancode 182 194 | SCANCODE_KP_RIGHTPAREN* = Scancode 183 195 | SCANCODE_KP_LEFTBRACE* = Scancode 184 196 | SCANCODE_KP_RIGHTBRACE* = Scancode 185 197 | SCANCODE_KP_TAB* = Scancode 186 198 | SCANCODE_KP_BACKSPACE* = Scancode 187 199 | SCANCODE_KP_A* = Scancode 188 200 | SCANCODE_KP_B* = Scancode 189 201 | SCANCODE_KP_C* = Scancode 190 202 | SCANCODE_KP_D* = Scancode 191 203 | SCANCODE_KP_E* = Scancode 192 204 | SCANCODE_KP_F* = Scancode 193 205 | SCANCODE_KP_XOR* = Scancode 194 206 | SCANCODE_KP_POWER* = Scancode 195 207 | SCANCODE_KP_PERCENT* = Scancode 196 208 | SCANCODE_KP_LESS* = Scancode 197 209 | SCANCODE_KP_GREATER* = Scancode 198 210 | SCANCODE_KP_AMPERSAND* = Scancode 199 211 | SCANCODE_KP_DBLAMPERSAND* = Scancode 200 212 | SCANCODE_KP_VERTICALBAR* = Scancode 201 213 | SCANCODE_KP_DBLVERTICALBAR* = Scancode 202 214 | SCANCODE_KP_COLON* = Scancode 203 215 | SCANCODE_KP_HASH* = Scancode 204 216 | SCANCODE_KP_SPACE* = Scancode 205 217 | SCANCODE_KP_AT* = Scancode 206 218 | SCANCODE_KP_EXCLAM* = Scancode 207 219 | SCANCODE_KP_MEMSTORE* = Scancode 208 220 | SCANCODE_KP_MEMRECALL* = Scancode 209 221 | SCANCODE_KP_MEMCLEAR* = Scancode 210 222 | SCANCODE_KP_MEMADD* = Scancode 211 223 | SCANCODE_KP_MEMSUBTRACT* = Scancode 212 224 | SCANCODE_KP_MEMMULTIPLY* = Scancode 213 225 | SCANCODE_KP_MEMDIVIDE* = Scancode 214 226 | SCANCODE_KP_PLUSMINUS* = Scancode 215 227 | SCANCODE_KP_CLEAR* = Scancode 216 228 | SCANCODE_KP_CLEARENTRY* = Scancode 217 229 | SCANCODE_KP_BINARY* = Scancode 218 230 | SCANCODE_KP_OCTAL* = Scancode 219 231 | SCANCODE_KP_DECIMAL* = Scancode 220 232 | SCANCODE_KP_HEXADECIMAL* = Scancode 221 233 | 234 | SCANCODE_LCTRL* = Scancode 224 235 | SCANCODE_LSHIFT* = Scancode 225 236 | SCANCODE_LALT* = Scancode 226 ## Alt, option. 237 | SCANCODE_LGUI* = Scancode 227 ## Windows, ⌘ (apple), meta. 238 | SCANCODE_RCTRL* = Scancode 228 239 | SCANCODE_RSHIFT* = Scancode 229 240 | SCANCODE_RALT* = Scancode 230 ## Alt gr, option. 241 | SCANCODE_RGUI* = Scancode 231 ## Windows, ⌘ (apple), meta. 242 | 243 | SCANCODE_MODE* = Scancode 257 244 | 245 | # Values mapped from usage page 0x0c (USB consumer page). 246 | 247 | SCANCODE_SLEEP* = Scancode 258 248 | SCANCODE_WAKE* = Scancode 259 249 | 250 | SCANCODE_CHANNEL_INCREMENT* = Scancode 260 251 | SCANCODE_CHANNEL_DECREMENT* = Scancode 261 252 | 253 | SCANCODE_MEDIA_PLAY* = Scancode 262 254 | SCANCODE_MEDIA_PAUSE* = Scancode 263 255 | SCANCODE_MEDIA_RECORD* = Scancode 264 256 | SCANCODE_MEDIA_FAST_FORWARD* = Scancode 265 257 | SCANCODE_MEDIA_REWIND* = Scancode 266 258 | SCANCODE_MEDIA_NEXT_TRACK* = Scancode 267 259 | SCANCODE_MEDIA_PREVIOUS_TRACK* = Scancode 268 260 | SCANCODE_MEDIA_STOP* = Scancode 269 261 | SCANCODE_MEDIA_EJECT* = Scancode 270 262 | SCANCODE_MEDIA_PLAY_PAUSE* = Scancode 271 263 | SCANCODE_MEDIA_SELECT* = Scancode 272 264 | 265 | SCANCODE_AC_NEW* = Scancode 273 266 | SCANCODE_AC_OPEN* = Scancode 274 267 | SCANCODE_AC_CLOSE* = Scancode 275 268 | SCANCODE_AC_EXIT* = Scancode 276 269 | SCANCODE_AC_SAVE* = Scancode 277 270 | SCANCODE_AC_PRINT* = Scancode 278 271 | SCANCODE_AC_PROPERTIES* = Scancode 279 272 | 273 | SCANCODE_AC_SEARCH* = Scancode 280 274 | SCANCODE_AC_HOME* = Scancode 281 275 | SCANCODE_AC_BACK* = Scancode 282 276 | SCANCODE_AC_FORWARD* = Scancode 283 277 | SCANCODE_AC_STOP* = Scancode 284 278 | SCANCODE_AC_REFRESH* = Scancode 285 279 | SCANCODE_AC_BOOKMARKS* = Scancode 286 280 | 281 | # Mobile keys. 282 | SCANCODE_SOFTLEFT* = Scancode 287 283 | SCANCODE_SOFTRIGHT* = Scancode 288 284 | SCANCODE_CALL* = Scancode 289 285 | SCANCODE_ENDCALL* = Scancode 290 286 | 287 | SCANCODE_RESERVED* = Scancode 400 288 | 289 | const 290 | SCANCODE_COUNT* = 512 291 | 292 | # vim: set sts=2 et sw=2: 293 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3sensor.nim: -------------------------------------------------------------------------------- 1 | ## Sensor event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | type 10 | Sensor* = ptr object 11 | ## Sensor. 12 | 13 | SensorID* = distinct uint32 14 | ## Sensor unique ID. 15 | ## 16 | ## The ID starts at 1. Invalid ID has value 0. 17 | 18 | SensorType* {.size: cint.sizeof.} = enum 19 | ## Sensor types. 20 | SENSOR_INVALID = -1 ## Returned for an invalid sensor. 21 | SENSOR_UNKNOWN ## Unknown sensor type. 22 | SENSOR_ACCEL ## Accelerometer. 23 | SENSOR_GYRO ## Gyroscope. 24 | SENSOR_ACCEL_L ## Accelerometer for left Joy-Con controller 25 | ## and Wii nunchuk. 26 | SENSOR_GYRO_L ## Gyroscope for left Joy-Con controller. 27 | SENSOR_ACCEL_R ## Accelerometer for right Joy-Con controller. 28 | SENSOR_GYRO_R ## Gyroscope for right Joy-Con controller. 29 | 30 | const 31 | STANDARD_GRAVITY* = cfloat 9.80665 32 | 33 | # vim: set sts=2 et sw=2: 34 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3storage.nim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amnr/nsdl3/00a6b4ec067cfce9012fb9c1eea518c4a2537c8f/src/nsdl3/sdl3inc/sdl3storage.nim -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3surface.nim: -------------------------------------------------------------------------------- 1 | ## Surface definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3pixels import PixelFormatEnum 10 | 11 | type 12 | SurfaceFlags* = distinct uint32 13 | ## Surface flags. 14 | 15 | func `and`(a, b: SurfaceFlags): SurfaceFlags {.borrow.} 16 | func `or`*(a, b: SurfaceFlags): SurfaceFlags {.borrow.} 17 | 18 | func `==`*(a: SurfaceFlags, b: uint32): bool {.borrow.} 19 | 20 | const 21 | SURFACE_DEFAULT* = SurfaceFlags 0 22 | SURFACE_PREALLOCATED* = SurfaceFlags 0x00000001 23 | SURFACE_LOCK_NEEDED* = SurfaceFlags 0x00000002 24 | SURFACE_LOCKED* = SurfaceFlags 0x00000004 25 | SURFACE_SIMD_ALIGNED* = SurfaceFlags 0x00000008 26 | 27 | # Note: mustlock moved after Surface. 28 | 29 | type 30 | BlitMap* {.final, incompletestruct, pure.} = object 31 | ## Blit map. 32 | 33 | ScaleMode* {.size: cint.sizeof.} = enum 34 | ## Textture scaling mode. 35 | SCALEMODE_INVALID = -1 36 | SCALEMODE_NEAREST ## Nearest pixel sampling. 37 | SCALEMODE_LINEAR ## Linear filtering. 38 | 39 | FlipMode* {.size: cint.sizeof.} = enum 40 | ## The flip mode. 41 | FLIP_NONE ## Do not flip. 42 | FLIP_HORIZONTAL ## Flip horizontally. 43 | FLIP_VERTICAL ## Flip vertically. 44 | 45 | type 46 | Surface* {.bycopy, final, pure.} = object 47 | ## Surface. 48 | ## 49 | ## Note:: 50 | ## This structure should be treated as read-only, except for pixels, 51 | ## which, if not `nil` 52 | ## , contains the raw pixel data for the surface. 53 | flags* : SurfaceFlags ## Read-only. 54 | format* : PixelFormatEnum ## Read-only. 55 | w* : cint ## Read-only. 56 | h* : cint ## Read-only. 57 | pitch* : cint ## Read-only. 58 | pixels* : ptr UncheckedArray[byte] ## Read-write. 59 | refcount : cint 60 | internal : ptr SurfaceData 61 | 62 | SurfaceData {.final, incompletestruct, pure.} = object 63 | 64 | SurfacePtr* = ptr Surface 65 | ## Surface. 66 | 67 | func pixels16*(self: ptr Surface): ptr UncheckedArray[uint16] {.inline.} = 68 | ## `Surface` pixels as unchecked array of `uint16`. 69 | cast[ptr UncheckedArray[uint16]](self.pixels) 70 | 71 | func pixels32*(self: ptr Surface): ptr UncheckedArray[uint32] {.inline.} = 72 | ## `Surface` pixels as unchecked array of `uint32`. 73 | cast[ptr UncheckedArray[uint32]](self.pixels) 74 | 75 | func mustlock*(self: ptr Surface): bool {.inline.} = 76 | ## Evaluates to true if the surface needs to be locked before access. 77 | (self.flags and SURFACE_LOCK_NEEDED) != 0 78 | 79 | type 80 | PropSurface* = enum 81 | PROP_SURFACE_COLORSPACE_NUMBER = cstring"SDL.surface.colorspace" 82 | PROP_SURFACE_SDR_WHITE_POINT_FLOAT = cstring"SDL.surface.SDR_white_point" 83 | PROP_SURFACE_HDR_HEADROOM_FLOAT = cstring"SDL.surface.HDR_headroom" 84 | PROP_SURFACE_TONEMAP_OPERATOR_STRING = cstring"SDL.surface.tonemap" 85 | PROP_SURFACE_HOTSPOT_X_NUMBER = cstring"SDL.surface.hotspot.x" 86 | PROP_SURFACE_HOTSPOT_Y_NUMBER = cstring"SDL.surface.hotspot.y" 87 | 88 | # vim: set sts=2 et sw=2: 89 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3timer.nim: -------------------------------------------------------------------------------- 1 | ## Timer definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | # Time constants. 10 | const 11 | MS_PER_SECOND* = 1000 ## Number of milliseconds in a second. 12 | US_PER_SECOND* = 1000_000 ## Number of microseconds in a second. 13 | NS_PER_SECOND* = 1000_000_000 ## Number of nanoseconds in a second. 14 | NS_PER_MS* = 1000_000 ## Number of nanoseconds in a millisecond. 15 | NS_PER_US* = 1000 ## Number of nanoseconds in a microsecond. 16 | 17 | func seconds_to_ns*[T: SomeInteger](ms: T): uint64 {.inline.} = 18 | ## Convert seconds to nanoseconds. 19 | ms.uint64 * NS_PER_SECOND 20 | 21 | func ns_to_seconds*[T: SomeInteger](ns: T): T {.inline.} = 22 | ## Convert nanoseconds to seconds. 23 | ns div NS_PER_SECOND 24 | 25 | func ms_to_ns*[T: SomeInteger](ms: T): uint64 {.inline.} = 26 | ## Convert milliseconds to nanoseconds. 27 | ms.uint64 * NS_PER_MS 28 | 29 | func ns_to_ms*[T: SomeInteger](ns: T): T {.inline.} = 30 | ## Convert nanoseconds to milliseconds. 31 | ns div NS_PER_MS 32 | 33 | func us_to_ns*[T: SomeInteger](us: T): uint64 {.inline.} = 34 | ## Convert microseconds to nanoseconds. 35 | us.uint64 * NS_PER_US 36 | 37 | func ns_to_us*[T: SomeInteger](ns: T): T {.inline.} = 38 | ## Convert nanoseconds to microseconds. 39 | ns div NS_PER_US 40 | 41 | type 42 | TimerID* = distinct uint32 43 | ## Timer ID. 44 | 45 | type 46 | TimerCallback* = proc ( 47 | userdata : pointer, 48 | timer_id : TimerID, 49 | interval : uint32 50 | ): uint32 {.cdecl, gcsafe, raises: [].} 51 | 52 | NSTimerCallback* = proc ( 53 | userdata : pointer, 54 | timer_id : TimerID, 55 | interval : uint32 56 | ): uint64 {.cdecl, gcsafe, raises: [].} 57 | 58 | # vim: set sts=2 et sw=2: 59 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3touch.nim: -------------------------------------------------------------------------------- 1 | ## Touch event definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3mouse import MouseID 10 | 11 | type 12 | TouchID* = uint64 13 | ## A unique ID for a touch device. 14 | 15 | FingerID* = uint64 16 | ## A unique ID for a single finger on a touch device. 17 | 18 | TouchDeviceType* {.size: cint.sizeof.} = enum 19 | ## An enum that describes the type of a touch device. 20 | TOUCH_DEVICE_INVALID = -1 21 | TOUCH_DEVICE_DIRECT 22 | TOUCH_DEVICE_INDIRECT_ABSOLUTE 23 | TOUCH_DEVICE_INDIRECT_RELATIVE 24 | 25 | Finger* {.final, pure.} = object 26 | id*: FingerID 27 | x*: cfloat 28 | y*: cfloat 29 | pressure*: cfloat 30 | 31 | const 32 | TOUCH_MOUSEID* = cast[MouseID](-1'i32) 33 | ## Device ID for mouse events simulated with touch input. 34 | 35 | MOUSE_TOUCHID* = cast[TouchID](-1'i64) 36 | ## Touch ID for touch events simulated with mouse input. 37 | 38 | # vim: set sts=2 et sw=2: 39 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3video.nim: -------------------------------------------------------------------------------- 1 | ## Video definitions. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from sdl3pixels import PixelFormatEnum 10 | from sdl3rect import Point 11 | 12 | type 13 | DisplayID* = distinct uint32 14 | ## Unique display ID. 15 | 16 | func `==`*(a, b: DisplayID): bool {.borrow.} 17 | 18 | type 19 | WindowID* = distinct uint32 20 | ## Unique window ID. 21 | 22 | func `==`*(a, b: WindowID): bool {.borrow.} 23 | 24 | type 25 | PropGlobalVideo* = enum 26 | PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER = cstring"video.wayland.wl_display" 27 | 28 | type 29 | SystemTheme* {.size: cint.sizeof.} = enum # XXX size 30 | ## System theme. 31 | SYSTEM_THEME_UNKNOWN 32 | SYSTEM_THEME_LIGHT 33 | SYSTEM_THEME_DARK 34 | 35 | DisplayMode* {.bycopy, final, pure.} = object 36 | ## Display mode. 37 | display_id* : DisplayID ## Display mode. 38 | format* : PixelFormatEnum ## Pixel format. 39 | w* : cint ## Screen width. 40 | h* : cint ## Screen height. 41 | pixel_density* : cfloat ## Size to pixels scale. 42 | refresh_rate* : cfloat ## Refresh rate (0 - unspecified). 43 | refresh_rate_numerator* : cint ## Refresh rate numenator (0 - unspecified). 44 | refresh_rate_denominator* : cint ## Refresh rate denominator. 45 | internal : pointer ## Private. 46 | 47 | DisplayOrientation* {.size: cint.sizeof.} = enum # XXX size 48 | ## Display orientation. 49 | ORIENTATION_UNKNOWN 50 | ORIENTATION_LANDSCAPE 51 | ORIENTATION_LANDSCAPE_FLIPPED 52 | ORIENTATION_PORTRAIT 53 | ORIENTATION_PORTRAIT_FLIPPED 54 | 55 | Window* = ptr object 56 | ## Window. 57 | 58 | type 59 | WindowFlags* = distinct uint64 60 | ## Window flags. 61 | 62 | func `and`*(a, b: WindowFlags): WindowFlags {.borrow.} 63 | func `or`*(a, b: WindowFlags): WindowFlags {.borrow.} 64 | 65 | func `==`*(a, b: WindowFlags): bool {.borrow.} 66 | func `==`*(a: WindowFlags, b: uint32): bool {.borrow.} 67 | 68 | const 69 | WINDOW_FULLSCREEN* = WindowFlags 0x00000000_00000001 70 | WINDOW_OPENGL* = WindowFlags 0x00000000_00000002 71 | WINDOW_OCCLUDED* = WindowFlags 0x00000000_00000004 72 | WINDOW_HIDDEN* = WindowFlags 0x00000000_00000008 73 | WINDOW_BORDERLESS* = WindowFlags 0x00000000_00000010 74 | WINDOW_RESIZABLE* = WindowFlags 0x00000000_00000020 75 | WINDOW_MINIMIZED* = WindowFlags 0x00000000_00000040 76 | WINDOW_MAXIMIZED* = WindowFlags 0x00000000_00000080 77 | WINDOW_MOUSE_GRABBED* = WindowFlags 0x00000000_00000100 78 | WINDOW_INPUT_FOCUS* = WindowFlags 0x00000000_00000200 79 | WINDOW_MOUSE_FOCUS* = WindowFlags 0x00000000_00000400 80 | WINDOW_EXTERNAL* = WindowFlags 0x00000000_00000800 81 | WINDOW_MODAL* = WindowFlags 0x00000000_00001000 82 | WINDOW_HIGH_PIXEL_DENSITY* = WindowFlags 0x00000000_00002000 83 | WINDOW_MOUSE_CAPTURE* = WindowFlags 0x00000000_00004000 84 | WINDOW_MOUSE_RELATIVE_MODE* = WindowFlags 0x00000000_00008000 85 | WINDOW_ALWAYS_ON_TOP* = WindowFlags 0x00000000_00010000 86 | WINDOW_UTILITY* = WindowFlags 0x00000000_00020000 87 | WINDOW_TOOLTIP* = WindowFlags 0x00000000_00040000 88 | WINDOW_POPUP_MENU* = WindowFlags 0x00000000_00080000 89 | WINDOW_KEYBOARD_GRABBED* = WindowFlags 0x00000000_00100000 90 | WINDOW_VULKAN* = WindowFlags 0x00000000_10000000 91 | WINDOW_METAL* = WindowFlags 0x00000000_20000000 92 | WINDOW_TRANSPARENT* = WindowFlags 0x00000000_40000000 93 | WINDOW_NOT_FOCUSABLE* = WindowFlags 0x00000000_80000000 94 | 95 | # XXX 96 | # WINDOW_FULLSCREEN_DESKTOP* = WINDOW_FULLSCREEN or WindowFlags 0x00001000 97 | # WINDOW_INPUT_GRABBED* = WINDOW_MOUSE_GRABBED 98 | 99 | # Window positions. 100 | 101 | const WINDOWPOS_UNDEFINED_MASK = 0x1fff_0000'u32 102 | 103 | func WINDOWPOS_UNDEFINED_DISPLAY(x: uint32): uint32 {.inline.} = 104 | WINDOWPOS_UNDEFINED_MASK or x 105 | 106 | const WINDOWPOS_UNDEFINED* = int WINDOWPOS_UNDEFINED_DISPLAY 0 107 | 108 | template windowpos_isundefined*(x: uint32): bool = 109 | (x and 0xffff_0000'u32) == WINDOWPOS_UNDEFINED_MASK 110 | 111 | const WINDOWPOS_CENTERED_MASK = 0x2fff_0000'u32 112 | 113 | func windowpos_centered_display*(x: DisplayID): uint32 {.inline.} = 114 | WINDOWPOS_CENTERED_MASK or x.uint32 115 | 116 | func windowpos_centered_display*(x: uint32): uint32 {.inline.} = 117 | WINDOWPOS_CENTERED_MASK or x 118 | 119 | const WINDOWPOS_CENTERED* = int windowpos_centered_display 0 120 | 121 | template windowpos_iscentered*(x: uint32): bool = 122 | (x and 0xffff_0000'u32) == WINDOWPOS_CENTERED_MASK 123 | 124 | type 125 | FlashOperation* {.size: cint.sizeof.} = enum # XXX: size 126 | ## Window flash operation. 127 | FLASH_CANCEL 128 | FLASH_BRIEFLY 129 | FLASH_UNTIL_FOCUSED 130 | 131 | type 132 | GLContext* = ptr object 133 | ## OpenGL context. 134 | 135 | type 136 | EGLDisplay* = ptr object ## Opaque type for an EGL display. 137 | EGLConfig* = ptr object ## Opaque type for an EGL config. 138 | EGLSurface* = ptr object ## Opaque type for an EGL surface. 139 | EGLAttrib* = ptr cint # XXX: distinct 140 | ## An EGL attribute, used when creating an EGL context. 141 | EGLint* = distinct cint 142 | ## An EGL integer attribute, used when creating an EGL surface. 143 | 144 | type 145 | EGLAttribArrayCallback* = proc (): ptr EGLAttrib {.cdecl.} 146 | EGLIntArrayCallback* = proc (): ptr EGLint {.cdecl.} 147 | 148 | type 149 | GLattr* {.pure, size: cint.sizeof} = enum # XXX: size 150 | ## OpenGL configuration attributes. 151 | GL_RED_SIZE 152 | GL_GREEN_SIZE 153 | GL_BLUE_SIZE 154 | GL_ALPHA_SIZE 155 | GL_BUFFER_SIZE 156 | GL_DOUBLEBUFFER 157 | GL_DEPTH_SIZE 158 | GL_STENCIL_SIZE 159 | GL_ACCUM_RED_SIZE 160 | GL_ACCUM_GREEN_SIZE 161 | GL_ACCUM_BLUE_SIZE 162 | GL_ACCUM_ALPHA_SIZE 163 | GL_STEREO 164 | GL_MULTISAMPLEBUFFERS 165 | GL_MULTISAMPLESAMPLES 166 | GL_ACCELERATED_VISUAL 167 | GL_RETAINED_BACKING 168 | GL_CONTEXT_MAJOR_VERSION 169 | GL_CONTEXT_MINOR_VERSION 170 | GL_CONTEXT_FLAGS 171 | GL_CONTEXT_PROFILE_MASK 172 | GL_SHARE_WITH_CURRENT_CONTEXT 173 | GL_FRAMEBUFFER_SRGB_CAPABLE 174 | GL_CONTEXT_RELEASE_BEHAVIOR 175 | GL_CONTEXT_RESET_NOTIFICATION 176 | GL_CONTEXT_NO_ERROR 177 | GL_FLOATBUFFERS 178 | GL_EGL_PLATFORM 179 | 180 | GLprofile* {.size: cint.sizeof} = enum # XXX: size 181 | GL_CONTEXT_PROFILE_CORE = 0x0001 182 | GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002 183 | GL_CONTEXT_PROFILE_ES = 0x0004 184 | 185 | GLcontextFlag* {.size: cint.sizeof} = enum # XXX: size 186 | GL_CONTEXT_DEBUG_FLAG = 0x0001 187 | GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002 188 | GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004 189 | GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008 190 | 191 | GLcontextReleaseFlag* {.size: cint.sizeof} = enum # XXX: size 192 | GL_CONTEXT_RELEASE_BEHAVIOR_NONE = 0x0000 193 | GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x0001 194 | 195 | GLContextResetNotification* {.size: cint.sizeof} = enum # XXX: size 196 | GL_CONTEXT_RESET_NO_NOTIFICATION = 0x0000 197 | GL_CONTEXT_RESET_LOSE_CONTEXT = 0x0001 198 | 199 | # XXX: distinct type. 200 | const 201 | SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN* = cstring"SDL.display.HDR_enabled" 202 | SDL_PROP_DISPLAY_KMSDRM_PANEL_ORIENTATION_NUMBER* = cstring"SDL.display.SDR_white_level" 203 | 204 | type 205 | WindowBooleanProperty* = enum 206 | PROP_WINDOW_CREATE_ALWAYS_ON_TOP_BOOLEAN = cstring"SDL.window.create.always_on_top" 207 | PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN = cstring"SDL.window.create.borderless" 208 | PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN = cstring"SDL.window.create.focusable" 209 | PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN = cstring"SDL.window.create.external_graphics_context" 210 | PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN = cstring"SDL.window.create.fullscreen" 211 | PROP_WINDOW_CREATE_HEIGHT_NUMBER = cstring"SDL.window.create.height" 212 | PROP_WINDOW_CREATE_HIDDEN_BOOLEAN = cstring"SDL.window.create.hidden" 213 | PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN = cstring"SDL.window.create.high-pixel-density" 214 | PROP_WINDOW_CREATE_MAXIMIZED_BOOLEAN = cstring"SDL.window.create.maximized" 215 | PROP_WINDOW_CREATE_MENU_BOOLEAN = cstring"SDL.window.create.menu" 216 | PROP_WINDOW_CREATE_METAL_BOOLEAN = cstring"SDL.window.create.metal" 217 | PROP_WINDOW_CREATE_MINIMIZED_BOOLEAN = cstring"SDL.window.create.minimized" 218 | PROP_WINDOW_CREATE_MODAL_BOOLEAN = cstring"SDL.window.create.modal" 219 | PROP_WINDOW_CREATE_MOUSE_GRABBED_BOOLEAN = cstring"SDL.window.create.mouse_grabbed" 220 | PROP_WINDOW_CREATE_OPENGL_BOOLEAN = cstring"SDL.window.create.opengl" 221 | PROP_WINDOW_CREATE_PARENT_POINTER = cstring"SDL.window.create.parent" 222 | PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN = cstring"SDL.window.create.resizable" 223 | PROP_WINDOW_CREATE_TITLE_STRING = cstring"SDL.window.create.title" 224 | PROP_WINDOW_CREATE_TRANSPARENT_BOOLEAN = cstring"SDL.window.create.transparent" 225 | PROP_WINDOW_CREATE_TOOLTIP_BOOLEAN = cstring"SDL.window.create.tooltip" 226 | PROP_WINDOW_CREATE_UTILITY_BOOLEAN = cstring"SDL.window.create.utility" 227 | PROP_WINDOW_CREATE_VULKAN_BOOLEAN = cstring"SDL.window.create.vulkan" 228 | PROP_WINDOW_CREATE_WIDTH_NUMBER = cstring"SDL.window.create.width" 229 | PROP_WINDOW_CREATE_X_NUMBER = cstring"SDL.window.create.x" 230 | PROP_WINDOW_CREATE_Y_NUMBER = cstring"SDL.window.create.y" 231 | PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER = cstring"SDL.window.create.cocoa.window" 232 | PROP_WINDOW_CREATE_COCOA_VIEW_POINTER = cstring"SDL.window.create.cocoa.view" 233 | PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN = cstring"SDL.window.create.wayland.surface_role_custom" 234 | PROP_WINDOW_CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN = cstring"SDL.window.create.wayland.create_egl_window" 235 | PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER = cstring"SDL.window.create.wayland.wl_surface" 236 | PROP_WINDOW_CREATE_WIN32_HWND_POINTER = cstring"SDL.window.create.win32.hwnd" 237 | PROP_WINDOW_CREATE_WIN32_PIXEL_FORMAT_HWND_POINTER = cstring"SDL.window.create.win32.pixel_format_hwnd" 238 | PROP_WINDOW_CREATE_X11_WINDOW_NUMBER = cstring"SDL.window.create.x11.window" 239 | 240 | type 241 | WindowPointerProperty* = enum 242 | PROP_WINDOW_SHAPE_POINTER = cstring"SDL.window.shape" 243 | PROP_WINDOW_HDR_ENABLED_BOOLEAN = cstring"SDL.window.HDR_enabled" 244 | PROP_WINDOW_SDR_WHITE_LEVEL_FLOAT = cstring"SDL.window.SDR_white_level" 245 | PROP_WINDOW_HDR_HEADROOM_FLOAT = cstring"SDL.window.HDR_headroom" 246 | PROP_WINDOW_ANDROID_WINDOW_POINTER = cstring"SDL.window.android.window" 247 | PROP_WINDOW_ANDROID_SURFACE_POINTER = cstring"SDL.window.android.surface" 248 | PROP_WINDOW_UIKIT_WINDOW_POINTER = cstring"SDL.window.uikit.window" 249 | PROP_WINDOW_UIKIT_METAL_VIEW_TAG_NUMBER = cstring"SDL.window.uikit.metal_view_tag" 250 | PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER = cstring"SDL.window.uikit.opengl.framebuffer" 251 | PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER = cstring"SDL.window.uikit.opengl.renderbuffer" 252 | PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER = cstring"SDL.window.uikit.opengl.resolve_framebuffer" 253 | PROP_WINDOW_KMSDRM_DEVICE_INDEX_NUMBER = cstring"SDL.window.kmsdrm.dev_index" 254 | PROP_WINDOW_KMSDRM_DRM_FD_NUMBER = cstring"SDL.window.kmsdrm.drm_fd" 255 | PROP_WINDOW_KMSDRM_GBM_DEVICE_POINTER = cstring"SDL.window.kmsdrm.gbm_dev" 256 | PROP_WINDOW_COCOA_WINDOW_POINTER = cstring"SDL.window.cocoa.window" 257 | PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER = cstring"SDL.window.cocoa.metal_view_tag" 258 | PROP_WINDOW_OPENVR_OVERLAY_ID = cstring"SDL.window.openvr.overlay_id" 259 | PROP_WINDOW_VIVANTE_DISPLAY_POINTER = cstring"SDL.window.vivante.display" 260 | PROP_WINDOW_VIVANTE_WINDOW_POINTER = cstring"SDL.window.vivante.window" 261 | PROP_WINDOW_VIVANTE_SURFACE_POINTER = cstring"SDL.window.vivante.surface" 262 | PROP_WINDOW_WINRT_WINDOW_POINTER = cstring"SDL.window.winrt.window" 263 | PROP_WINDOW_WIN32_HWND_POINTER = cstring"SDL.window.win32.hwnd" 264 | PROP_WINDOW_WIN32_HDC_POINTER = cstring"SDL.window.win32.hdc" 265 | PROP_WINDOW_WIN32_INSTANCE_POINTER = cstring"SDL.window.win32.instance" 266 | PROP_WINDOW_WAYLAND_DISPLAY_POINTER = cstring"SDL.window.wayland.display" 267 | PROP_WINDOW_WAYLAND_SURFACE_POINTER = cstring"SDL.window.wayland.surface" 268 | PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER = cstring"SDL.window.wayland.egl_window" 269 | PROP_WINDOW_WAYLAND_XDG_SURFACE_POINTER = cstring"SDL.window.wayland.xdg_surface" 270 | PROP_WINDOW_WAYLAND_VIEWPORT_POINTER = cstring"SDL.window.wayland.viewport" 271 | PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_POINTER = cstring"SDL.window.wayland.xdg_toplevel" 272 | PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_EXPORT_HANDLE_POINTER = cstring"SDL.window.wayland.xdg_toplevel_export_handle" 273 | PROP_WINDOW_WAYLAND_XDG_POPUP_POINTER = cstring"SDL.window.wayland.xdg_popup" 274 | PROP_WINDOW_WAYLAND_XDG_POSITIONER_POINTER = cstring"SDL.window.wayland.xdg_positioner" 275 | PROP_WINDOW_X11_DISPLAY_POINTER = cstring"SDL.window.x11.display" 276 | PROP_WINDOW_X11_SCREEN_NUMBER = cstring"SDL.window.x11.screen" 277 | PROP_WINDOW_X11_WINDOW_NUMBER = cstring"SDL.window.x11.window" 278 | 279 | #define SDL_WINDOW_SURFACE_VSYNC_DISABLED 0 280 | #define SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE (-1 281 | 282 | type 283 | HitTestResult* {.size: cint.sizeof.} = enum # XXX: size 284 | HITTEST_NORMAL 285 | HITTEST_DRAGGABLE 286 | HITTEST_RESIZE_TOPLEFT 287 | HITTEST_RESIZE_TOP 288 | HITTEST_RESIZE_TOPRIGHT 289 | HITTEST_RESIZE_RIGHT 290 | HITTEST_RESIZE_BOTTOMRIGHT 291 | HITTEST_RESIZE_BOTTOM 292 | HITTEST_RESIZE_BOTTOMLEFT 293 | HITTEST_RESIZE_LEFT 294 | 295 | HitTest* = proc (win: ptr Window, area: ptr Point, 296 | data: pointer): HitTestResult {.cdecl.} 297 | ## Callback for hit testing. 298 | 299 | # --------------------------------------------------------------------------- # 300 | # Sanity checks # 301 | # --------------------------------------------------------------------------- # 302 | 303 | # when defined(gcc) and hostCPU == "amd64": 304 | # when DisplayMode.sizeof != 32: 305 | # {.error: "invalid DisplayMode size: " & $DisplayMode.sizeof.} 306 | 307 | # vim: set sts=2 et sw=2: 308 | -------------------------------------------------------------------------------- /src/nsdl3/sdl3inc/sdl3video_capture.nim: -------------------------------------------------------------------------------- 1 | ## Video capture. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | from pixels import PixelFormatEnum 10 | 11 | type 12 | VideoCaptureDeviceID* = distinct uint32 13 | ## Capture device ID. Starts at 1. Value 0 == invalid ID. 14 | 15 | VideoCaptureDevice* = ptr object 16 | 17 | const 18 | VIDEO_CAPTURE_ALLOW_ANY_CHANGE* = 1 19 | 20 | type 21 | VideoCaptureSpec* {.final, pure.} = object 22 | format* : PixelFormatEnum ## `PixelFormatEnum` format. 23 | width* : cint ## Frame width. 24 | height* : cint ## Frame height. 25 | 26 | VideoCaptureStatus {.size: cint.sizeof.} = enum 27 | ## Video Capture Status. 28 | VIDEO_CAPTURE_FAIL = -1 29 | VIDEO_CAPTURE_INIT = 0 30 | VIDEO_CAPTURE_STOPPED 31 | VIDEO_CAPTURE_PLAYING 32 | 33 | VideoCaptureFrame* {.final, pure.} = object 34 | timestamp_ns* : uint64 ## Frame timestamp (ns). 35 | num_planes* : cint ## Number of planes. 36 | data* : array[3, byte] ## Pointer to data of i-th plane. 37 | pitch* : array[3, cint] ## Pitch of i-th plane. 38 | internal : pointer ## Private. 39 | 40 | # vim: set sts=2 et sw=2: 41 | -------------------------------------------------------------------------------- /src/nsdl3/utils.nim: -------------------------------------------------------------------------------- 1 | ## SDL ABI utils. 2 | ## 3 | #[ 4 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 5 | ]# 6 | 7 | {.push raises: [].} 8 | 9 | when defined uselogging: 10 | import std/logging 11 | import std/macros 12 | 13 | const 14 | uselogging {.booldefine.} = false 15 | 16 | when uselogging: 17 | template log_error*(args: varargs[typed, `$`]) = 18 | try: 19 | unpackVarargs echo, "ERROR: SDL3: ", args 20 | except Exception: 21 | discard 22 | else: 23 | template log_error*(args: varargs[typed, `$`]) = 24 | unpackVarargs echo, "ERROR: SDL3: ", args 25 | 26 | macro available_since*(procvar: typed, minver: string) = 27 | ## Check whether unchecked function is available. 28 | ## 29 | ## If the function is not available, the default value of return type 30 | ## is returned. 31 | let procname = $procvar 32 | return quote do: 33 | if `procvar` == nil: 34 | log_error `procname`, " is available since SDL ", `minver` 35 | return result.type.default 36 | 37 | template ensure_not_nil*(procname: string, body: untyped) = 38 | when result.typeof isnot ptr: 39 | {.fatal: "ensure_not_nil requires function that returns pointer".} 40 | result = body 41 | if unlikely result == nil: 42 | log_error procname, " failed: ", $SDL_GetError() 43 | return nil 44 | 45 | template ensure_natural*(procname: string, body: untyped) = 46 | result = body 47 | if unlikely result < 0: 48 | log_error procname, " failed: ", $SDL_GetError() 49 | 50 | template ensure_positive*(procname: string, body: untyped) = 51 | result = body 52 | if unlikely result <= 0: 53 | log_error procname, " failed: ", $SDL_GetError() 54 | 55 | # XXX: 56 | #[ 57 | template ensure_true(procname: string, body: untyped) = 58 | when result.typeof isnot bool: 59 | {.fatal: "ensure_true requires function that returns bool".} 60 | result = body 61 | if unlikely result.not: 62 | log_error procname, " failed: ", $SDL_GetError() 63 | ]# 64 | 65 | template ensure_zero*(procname: string, body: untyped) = 66 | let res {.inject.} = body 67 | if unlikely res.uint == 0: 68 | log_error procname, " failed: ", $SDL_GetError() 69 | result = false 70 | else: 71 | result = true 72 | 73 | # vim: set sts=2 et sw=2: 74 | -------------------------------------------------------------------------------- /tests/config.nims: -------------------------------------------------------------------------------- 1 | switch("path", "$projectDir/../src") -------------------------------------------------------------------------------- /tests/test_libsdl3.nim: -------------------------------------------------------------------------------- 1 | ## SDL3 ABI functions. 2 | #[ 3 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import std/unittest 9 | 10 | import nsdl3/libsdl3 11 | 12 | test "open library": 13 | check open_sdl3_library() 14 | close_sdl3_library() 15 | 16 | # vim: set sts=2 et sw=2: 17 | -------------------------------------------------------------------------------- /tests/test_nsdl3.nim: -------------------------------------------------------------------------------- 1 | ## SDL3 library wrapper. 2 | #[ 3 | SPDX-License-Identifier: NCSA OR MIT OR Zlib 4 | ]# 5 | 6 | {.push raises: [].} 7 | 8 | import std/unittest 9 | 10 | include nsdl3 11 | 12 | test "open library": 13 | check open_sdl3_library() 14 | 15 | check Init() 16 | 17 | let ver = GetVersion() 18 | 19 | check ver.major == 3 20 | 21 | Quit() 22 | close_sdl3_library() 23 | 24 | # vim: set sts=2 et sw=2: 25 | --------------------------------------------------------------------------------