From db57432d41d4a83be1abdd601f72d6ad36a3abd5 Mon Sep 17 00:00:00 2001 From: Layla Date: Sun, 13 Nov 2022 10:34:59 -0500 Subject: [PATCH] Upgrade sdl version, implement embed rendering, and more! --- .gitignore | 4 + Makefile | 95 +++++++ ReadMe.md | 10 +- core/version.go | 4 + game/game.go | 9 +- gopher.bmp => game/gopher.bmp | Bin go.mod | 2 +- go.sum | 2 + importer/assests.go | 11 + input/input_handler.go | 6 +- sdl/input_handler.go | 6 +- sdl/render2d.go | 4 +- sdl/scancode.go | 488 +++++++++++++++++----------------- sdl/texture2d.go | 45 ++++ 14 files changed, 429 insertions(+), 257 deletions(-) create mode 100644 Makefile create mode 100644 core/version.go rename gopher.bmp => game/gopher.bmp (100%) create mode 100644 importer/assests.go diff --git a/.gitignore b/.gitignore index 3b735ec..cc33690 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.dll *.so *.dylib +*.x86_64 # Test binary, built with `go test -c` *.test @@ -19,3 +20,6 @@ # Go workspace file go.work + +# Builds +build/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c68bc77 --- /dev/null +++ b/Makefile @@ -0,0 +1,95 @@ +PROJECTNAME="Golang Game Framework" +PROJECT_BIN="golang-game-framework" +VERSION="DEV" +BUILD_NUMBER:=$(shell git rev-parse --short HEAD) + +# Go related variables. +GOBASE=$(shell pwd) +GOBIN=$(GOBASE)/build +GOFILES=$(wildcard *.go) + +# Make is verbose in Linux. Make it silent. +MAKEFLAGS += --silent + +go-full-build: go-clean go-get go-build-static + +go-build: + @echo " > Building binary..." + @mkdir -p $(GOBIN) + @GOOS=linux go build -ldflags "-X github.com/yeslayla/$(PROJECT_BIN)/core.Version=$(VERSION) -X github.com/yeslayla/$(PROJECT_BIN)/core.Build=$(BUILD_NUMBER)" -o $(GOBIN)/$(PROJECT_BIN) $(GOFILES) + @chmod 755 $(GOBIN)/$(PROJECT_BIN) + +go-build-static: + @echo " > Building static binary..." + @mkdir -p $(GOBIN) + @CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=amd64 go build -tags static -ldflags "-s -w -X github.com/yeslayla/$(PROJECT_BIN)/core.Version=$(VERSION) -X github.com/yeslayla/$(PROJECT_BIN)/core.Build=$(BUILD_NUMBER)" -o $(GOBIN)/$(PROJECT_BIN) $(GOFILES) + @chmod 755 $(GOBIN)/$(PROJECT_BIN) + +go-build-windows: + @echo " > Building static binary..." + @mkdir -p $(GOBIN) + @CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -tags static -ldflags "-s -w -X github.com/yeslayla/$(PROJECT_BIN)/core.Version=$(VERSION) -X github.com/yeslayla/$(PROJECT_BIN)/core.Build=$(BUILD_NUMBER) -H windowsgui" -o $(GOBIN)/$(PROJECT_BIN).exe $(GOFILES) + @chmod 755 $(GOBIN)/$(PROJECT_BIN) + +go-generate: + @echo " > Generating dependency files..." + @go generate $(generate) + +go-get: + @echo " > Checking if there is any missing dependencies..." + @go get $(get) + +go-install: + @echo " > Running go install..." + @go install $(GOFILES) + +go-clean: + @echo " > Cleaning build cache" + @go clean + +go-test: clean + @echo " > Running tests..." + @go test -coverprofile=coverage.out ./*/ + +go-run: + @echo " > Running ${PROJECTNAME}" + @-(cd $(GOBIN); ./$(PROJECT_BIN)) + +## install: Download and install dependencies +install: go-get + @sudo mv ./build/$(PROJECT_BIN) /usr/bin/$(PROJECT_BIN) + @sudo chmod +x /usr/bin/$(PROJECT_BIN) + +# clean: Runs go clean +clean: go-clean + +## full-build: cleans project, installs dependencies, and builds project +full-build: go-full-build + +## build-windows: Builds project staticly for Windows +build-windows: go-build-windows + +## build: Runs go build +build: go-build + +## package: Builds lambda zip +package: go-full-build + @echo " > Zipping package..." + @cd $(GOBIN) && zip $(PROJECTNAME).zip $(PROJECTNAME) + +## clean: Runs go clean +clean: + @rm -rf build + +## run: full-builds and executes project binary +run: go-build go-run + +## test: Run unit tests +test: go-test + +## help: Displays help text for make commands +.DEFAULT_GOAL := help +all: help +help: Makefile + @echo " Choose a command run in "$(PROJECTNAME)":" + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index 7047473..0db0be8 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -10,13 +10,19 @@ I have a strong desire to make this into a more flexible and feature complete sy ## Requirements -Fedora: +### Fedora ```bash sudo dnf install -y golang SDL2{,_image,_mixer,_ttf,_gfx}-devel ``` -Ubuntu: +For static compilation: + +```bash +sudo dnf install -y alsa-lib-devel libXext-devel libXcursor-devel libXi-devel libXrandr-devel libXxf86vm-devel libXScrnSaver-devel +``` + +#### Ubuntu: ```bash sudo apt install -y golang-go libsdl2{,-image,-mixer,-ttf,-gfx}-dev diff --git a/core/version.go b/core/version.go new file mode 100644 index 0000000..67027d2 --- /dev/null +++ b/core/version.go @@ -0,0 +1,4 @@ +package core + +var Version string +var Build string \ No newline at end of file diff --git a/game/game.go b/game/game.go index 0fbd955..1567820 100644 --- a/game/game.go +++ b/game/game.go @@ -1,16 +1,23 @@ package game import ( + "embed" "log" + "github.com/manleydev/golang-game-framework/importer" "github.com/manleydev/golang-game-framework/input" "github.com/manleydev/golang-game-framework/node" "github.com/manleydev/golang-game-framework/rendering" "github.com/manleydev/golang-game-framework/sdl" ) +//go:embed *.bmp +var assets embed.FS + func Run(root *node.Node, renderer rendering.Renderer2D, inputHandler input.InputHandler) { - texture := sdl.NewSdlTexture2D(renderer, "gopher.bmp") + + importer.SetAssets(&assets) + texture := sdl.NewEmbededSdlTexture2D(renderer, "gopher.bmp") g := node.NewSprite2D(texture) g.Name = "Gopher" diff --git a/gopher.bmp b/game/gopher.bmp similarity index 100% rename from gopher.bmp rename to game/gopher.bmp diff --git a/go.mod b/go.mod index 5fab34f..da25906 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/manleydev/golang-game-framework go 1.18 -require github.com/veandco/go-sdl2 v0.4.25 +require github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20221018092508-1cc5f3cf3545 diff --git a/go.sum b/go.sum index 78fd645..4c41490 100644 --- a/go.sum +++ b/go.sum @@ -4,3 +4,5 @@ github.com/veandco/go-sdl2 v0.4.24 h1:J+OCnPp0yfas4DAG13e3kIgC84mNxWGa3gpWYxrQQf github.com/veandco/go-sdl2 v0.4.24/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= github.com/veandco/go-sdl2 v0.4.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI= github.com/veandco/go-sdl2 v0.4.25/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20221018092508-1cc5f3cf3545 h1:TDLjgyfO/siYy4d1hek4Vom/ioQ+XT+H9xtHqo9B1Lo= +github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20221018092508-1cc5f3cf3545/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= diff --git a/importer/assests.go b/importer/assests.go new file mode 100644 index 0000000..db98774 --- /dev/null +++ b/importer/assests.go @@ -0,0 +1,11 @@ +package importer + +import ( + "embed" +) + +var EmbededAssets *embed.FS = nil + +func SetAssets(assets *embed.FS) { + EmbededAssets = assets +} diff --git a/input/input_handler.go b/input/input_handler.go index 704b1be..e54d9e1 100644 --- a/input/input_handler.go +++ b/input/input_handler.go @@ -1,8 +1,8 @@ package input type InputHandler interface { - IsKeyDown(uint) bool - IsKeyJustPressed(uint) bool - IsKeyJustReleased(uint) bool + IsKeyDown(uint32) bool + IsKeyJustPressed(uint32) bool + IsKeyJustReleased(uint32) bool Update(delta float64) error } diff --git a/sdl/input_handler.go b/sdl/input_handler.go index 7313190..31423a7 100644 --- a/sdl/input_handler.go +++ b/sdl/input_handler.go @@ -11,7 +11,7 @@ type SdlInputHandler struct { lastKeyState []uint8 } -func (input *SdlInputHandler) IsKeyDown(key uint) bool { +func (input *SdlInputHandler) IsKeyDown(key uint32) bool { keys := sdl.GetKeyboardState() if keys[key] == 1 { @@ -21,7 +21,7 @@ func (input *SdlInputHandler) IsKeyDown(key uint) bool { return false } -func (input *SdlInputHandler) IsKeyJustPressed(key uint) bool { +func (input *SdlInputHandler) IsKeyJustPressed(key uint32) bool { if input.keyState[key] == 1 && input.lastKeyState[key] == 0 { return true } @@ -29,7 +29,7 @@ func (input *SdlInputHandler) IsKeyJustPressed(key uint) bool { return false } -func (input *SdlInputHandler) IsKeyJustReleased(key uint) bool { +func (input *SdlInputHandler) IsKeyJustReleased(key uint32) bool { if input.keyState[key] == 0 && input.lastKeyState[key] == 1 { return true } diff --git a/sdl/render2d.go b/sdl/render2d.go index 6028ff0..1c7f527 100644 --- a/sdl/render2d.go +++ b/sdl/render2d.go @@ -37,7 +37,7 @@ func NewSdlRenderer2D(input SdlRenderer2DInput) *SdlRenderer2D { } if input.Fullscreen { - if err := w.window.SetFullscreen(sdl.WINDOW_FULLSCREEN_DESKTOP); err != nil { + if err := w.window.SetFullscreen(uint32(sdl.WINDOW_FULLSCREEN_DESKTOP)); err != nil { log.Print("Failed to set fullscreen: ", err) return nil } @@ -72,7 +72,7 @@ func (w *SdlRenderer2D) SetCamera(camera *rendering.Camera2D) error { func (w *SdlRenderer2D) Update(delta float64) error { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: return errors.New("Quit system not yet implemented!") default: if w.inputHandler != nil { diff --git a/sdl/scancode.go b/sdl/scancode.go index bb7724a..e0ccf77 100644 --- a/sdl/scancode.go +++ b/sdl/scancode.go @@ -1,260 +1,258 @@ package sdl -import ( - "github.com/veandco/go-sdl2/sdl" -) +import "github.com/veandco/go-sdl2/sdl" const ( - SCANCODE_UNKNOWN = sdl.SCANCODE_UNKNOWN + SCANCODE_UNKNOWN = uint32(sdl.SCANCODE_UNKNOWN) - SCANCODE_A = sdl.SCANCODE_A - SCANCODE_B = sdl.SCANCODE_B - SCANCODE_C = sdl.SCANCODE_C - SCANCODE_D = sdl.SCANCODE_D - SCANCODE_E = sdl.SCANCODE_E - SCANCODE_F = sdl.SCANCODE_F - SCANCODE_G = sdl.SCANCODE_G - SCANCODE_H = sdl.SCANCODE_H - SCANCODE_I = sdl.SCANCODE_I - SCANCODE_J = sdl.SCANCODE_J - SCANCODE_K = sdl.SCANCODE_K - SCANCODE_L = sdl.SCANCODE_L - SCANCODE_M = sdl.SCANCODE_M - SCANCODE_N = sdl.SCANCODE_N - SCANCODE_O = sdl.SCANCODE_O - SCANCODE_P = sdl.SCANCODE_P - SCANCODE_Q = sdl.SCANCODE_Q - SCANCODE_R = sdl.SCANCODE_R - SCANCODE_S = sdl.SCANCODE_S - SCANCODE_T = sdl.SCANCODE_T - SCANCODE_U = sdl.SCANCODE_U - SCANCODE_V = sdl.SCANCODE_V - SCANCODE_W = sdl.SCANCODE_W - SCANCODE_X = sdl.SCANCODE_X - SCANCODE_Y = sdl.SCANCODE_Y - SCANCODE_Z = sdl.SCANCODE_Z + SCANCODE_A = uint32(sdl.SCANCODE_A) + SCANCODE_B = uint32(sdl.SCANCODE_B) + SCANCODE_C = uint32(sdl.SCANCODE_C) + SCANCODE_D = uint32(sdl.SCANCODE_D) + SCANCODE_E = uint32(sdl.SCANCODE_E) + SCANCODE_F = uint32(sdl.SCANCODE_F) + SCANCODE_G = uint32(sdl.SCANCODE_G) + SCANCODE_H = uint32(sdl.SCANCODE_H) + SCANCODE_I = uint32(sdl.SCANCODE_I) + SCANCODE_J = uint32(sdl.SCANCODE_J) + SCANCODE_K = uint32(sdl.SCANCODE_K) + SCANCODE_L = uint32(sdl.SCANCODE_L) + SCANCODE_M = uint32(sdl.SCANCODE_M) + SCANCODE_N = uint32(sdl.SCANCODE_N) + SCANCODE_O = uint32(sdl.SCANCODE_O) + SCANCODE_P = uint32(sdl.SCANCODE_P) + SCANCODE_Q = uint32(sdl.SCANCODE_Q) + SCANCODE_R = uint32(sdl.SCANCODE_R) + SCANCODE_S = uint32(sdl.SCANCODE_S) + SCANCODE_T = uint32(sdl.SCANCODE_T) + SCANCODE_U = uint32(sdl.SCANCODE_U) + SCANCODE_V = uint32(sdl.SCANCODE_V) + SCANCODE_W = uint32(sdl.SCANCODE_W) + SCANCODE_X = uint32(sdl.SCANCODE_X) + SCANCODE_Y = uint32(sdl.SCANCODE_Y) + SCANCODE_Z = uint32(sdl.SCANCODE_Z) - SCANCODE_1 = sdl.SCANCODE_1 - SCANCODE_2 = sdl.SCANCODE_2 - SCANCODE_3 = sdl.SCANCODE_3 - SCANCODE_4 = sdl.SCANCODE_4 - SCANCODE_5 = sdl.SCANCODE_5 - SCANCODE_6 = sdl.SCANCODE_6 - SCANCODE_7 = sdl.SCANCODE_7 - SCANCODE_8 = sdl.SCANCODE_8 - SCANCODE_9 = sdl.SCANCODE_9 - SCANCODE_0 = sdl.SCANCODE_0 + SCANCODE_1 = uint32(sdl.SCANCODE_1) + SCANCODE_2 = uint32(sdl.SCANCODE_2) + SCANCODE_3 = uint32(sdl.SCANCODE_3) + SCANCODE_4 = uint32(sdl.SCANCODE_4) + SCANCODE_5 = uint32(sdl.SCANCODE_5) + SCANCODE_6 = uint32(sdl.SCANCODE_6) + SCANCODE_7 = uint32(sdl.SCANCODE_7) + SCANCODE_8 = uint32(sdl.SCANCODE_8) + SCANCODE_9 = uint32(sdl.SCANCODE_9) + SCANCODE_0 = uint32(sdl.SCANCODE_0) - SCANCODE_RETURN = sdl.SCANCODE_RETURN - SCANCODE_ESCAPE = sdl.SCANCODE_ESCAPE - SCANCODE_BACKSPACE = sdl.SCANCODE_BACKSPACE - SCANCODE_TAB = sdl.SCANCODE_TAB - SCANCODE_SPACE = sdl.SCANCODE_SPACE + SCANCODE_RETURN = uint32(sdl.SCANCODE_RETURN) + SCANCODE_ESCAPE = uint32(sdl.SCANCODE_ESCAPE) + SCANCODE_BACKSPACE = uint32(sdl.SCANCODE_BACKSPACE) + SCANCODE_TAB = uint32(sdl.SCANCODE_TAB) + SCANCODE_SPACE = uint32(sdl.SCANCODE_SPACE) - SCANCODE_MINUS = sdl.SCANCODE_MINUS - SCANCODE_EQUALS = sdl.SCANCODE_EQUALS - SCANCODE_LEFTBRACKET = sdl.SCANCODE_LEFTBRACKET - SCANCODE_RIGHTBRACKET = sdl.SCANCODE_RIGHTBRACKET - SCANCODE_BACKSLASH = sdl.SCANCODE_BACKSLASH - SCANCODE_NONUSHASH = sdl.SCANCODE_NONUSHASH - SCANCODE_SEMICOLON = sdl.SCANCODE_SEMICOLON - SCANCODE_APOSTROPHE = sdl.SCANCODE_APOSTROPHE - SCANCODE_GRAVE = sdl.SCANCODE_GRAVE - SCANCODE_COMMA = sdl.SCANCODE_COMMA - SCANCODE_PERIOD = sdl.SCANCODE_PERIOD - SCANCODE_SLASH = sdl.SCANCODE_SLASH - SCANCODE_CAPSLOCK = sdl.SCANCODE_CAPSLOCK - SCANCODE_F1 = sdl.SCANCODE_F1 - SCANCODE_F2 = sdl.SCANCODE_F2 - SCANCODE_F3 = sdl.SCANCODE_F3 - SCANCODE_F4 = sdl.SCANCODE_F4 - SCANCODE_F5 = sdl.SCANCODE_F5 - SCANCODE_F6 = sdl.SCANCODE_F6 - SCANCODE_F7 = sdl.SCANCODE_F7 - SCANCODE_F8 = sdl.SCANCODE_F8 - SCANCODE_F9 = sdl.SCANCODE_F9 - SCANCODE_F10 = sdl.SCANCODE_F10 - SCANCODE_F11 = sdl.SCANCODE_F11 - SCANCODE_F12 = sdl.SCANCODE_F12 - SCANCODE_PRINTSCREEN = sdl.SCANCODE_PRINTSCREEN - SCANCODE_SCROLLLOCK = sdl.SCANCODE_SCROLLLOCK - SCANCODE_PAUSE = sdl.SCANCODE_PAUSE - SCANCODE_INSERT = sdl.SCANCODE_INSERT - SCANCODE_HOME = sdl.SCANCODE_HOME - SCANCODE_PAGEUP = sdl.SCANCODE_PAGEUP - SCANCODE_DELETE = sdl.SCANCODE_DELETE - SCANCODE_END = sdl.SCANCODE_END - SCANCODE_PAGEDOWN = sdl.SCANCODE_PAGEDOWN - SCANCODE_RIGHT = sdl.SCANCODE_RIGHT - SCANCODE_LEFT = sdl.SCANCODE_LEFT - SCANCODE_DOWN = sdl.SCANCODE_DOWN - SCANCODE_UP = sdl.SCANCODE_UP + SCANCODE_MINUS = uint32(sdl.SCANCODE_MINUS) + SCANCODE_EQUALS = uint32(sdl.SCANCODE_EQUALS) + SCANCODE_LEFTBRACKET = uint32(sdl.SCANCODE_LEFTBRACKET) + SCANCODE_RIGHTBRACKET = uint32(sdl.SCANCODE_RIGHTBRACKET) + SCANCODE_BACKSLASH = uint32(sdl.SCANCODE_BACKSLASH) + SCANCODE_NONUSHASH = uint32(sdl.SCANCODE_NONUSHASH) + SCANCODE_SEMICOLON = uint32(sdl.SCANCODE_SEMICOLON) + SCANCODE_APOSTROPHE = uint32(sdl.SCANCODE_APOSTROPHE) + SCANCODE_GRAVE = uint32(sdl.SCANCODE_GRAVE) + SCANCODE_COMMA = uint32(sdl.SCANCODE_COMMA) + SCANCODE_PERIOD = uint32(sdl.SCANCODE_PERIOD) + SCANCODE_SLASH = uint32(sdl.SCANCODE_SLASH) + SCANCODE_CAPSLOCK = uint32(sdl.SCANCODE_CAPSLOCK) + SCANCODE_F1 = uint32(sdl.SCANCODE_F1) + SCANCODE_F2 = uint32(sdl.SCANCODE_F2) + SCANCODE_F3 = uint32(sdl.SCANCODE_F3) + SCANCODE_F4 = uint32(sdl.SCANCODE_F4) + SCANCODE_F5 = uint32(sdl.SCANCODE_F5) + SCANCODE_F6 = uint32(sdl.SCANCODE_F6) + SCANCODE_F7 = uint32(sdl.SCANCODE_F7) + SCANCODE_F8 = uint32(sdl.SCANCODE_F8) + SCANCODE_F9 = uint32(sdl.SCANCODE_F9) + SCANCODE_F10 = uint32(sdl.SCANCODE_F10) + SCANCODE_F11 = uint32(sdl.SCANCODE_F11) + SCANCODE_F12 = uint32(sdl.SCANCODE_F12) + SCANCODE_PRINTSCREEN = uint32(sdl.SCANCODE_PRINTSCREEN) + SCANCODE_SCROLLLOCK = uint32(sdl.SCANCODE_SCROLLLOCK) + SCANCODE_PAUSE = uint32(sdl.SCANCODE_PAUSE) + SCANCODE_INSERT = uint32(sdl.SCANCODE_INSERT) + SCANCODE_HOME = uint32(sdl.SCANCODE_HOME) + SCANCODE_PAGEUP = uint32(sdl.SCANCODE_PAGEUP) + SCANCODE_DELETE = uint32(sdl.SCANCODE_DELETE) + SCANCODE_END = uint32(sdl.SCANCODE_END) + SCANCODE_PAGEDOWN = uint32(sdl.SCANCODE_PAGEDOWN) + SCANCODE_RIGHT = uint32(sdl.SCANCODE_RIGHT) + SCANCODE_LEFT = uint32(sdl.SCANCODE_LEFT) + SCANCODE_DOWN = uint32(sdl.SCANCODE_DOWN) + SCANCODE_UP = uint32(sdl.SCANCODE_UP) - SCANCODE_NUMLOCKCLEAR = sdl.SCANCODE_NUMLOCKCLEAR - SCANCODE_KP_DIVIDE = sdl.SCANCODE_KP_DIVIDE - SCANCODE_KP_MULTIPLY = sdl.SCANCODE_KP_MULTIPLY - SCANCODE_KP_MINUS = sdl.SCANCODE_KP_MINUS - SCANCODE_KP_PLUS = sdl.SCANCODE_KP_PLUS - SCANCODE_KP_ENTER = sdl.SCANCODE_KP_ENTER - SCANCODE_KP_1 = sdl.SCANCODE_KP_1 - SCANCODE_KP_2 = sdl.SCANCODE_KP_2 - SCANCODE_KP_3 = sdl.SCANCODE_KP_3 - SCANCODE_KP_4 = sdl.SCANCODE_KP_4 - SCANCODE_KP_5 = sdl.SCANCODE_KP_5 - SCANCODE_KP_6 = sdl.SCANCODE_KP_6 - SCANCODE_KP_7 = sdl.SCANCODE_KP_7 - SCANCODE_KP_8 = sdl.SCANCODE_KP_8 - SCANCODE_KP_9 = sdl.SCANCODE_KP_9 - SCANCODE_KP_0 = sdl.SCANCODE_KP_0 - SCANCODE_KP_PERIOD = sdl.SCANCODE_KP_PERIOD + SCANCODE_NUMLOCKCLEAR = uint32(sdl.SCANCODE_NUMLOCKCLEAR) + SCANCODE_KP_DIVIDE = uint32(sdl.SCANCODE_KP_DIVIDE) + SCANCODE_KP_MULTIPLY = uint32(sdl.SCANCODE_KP_MULTIPLY) + SCANCODE_KP_MINUS = uint32(sdl.SCANCODE_KP_MINUS) + SCANCODE_KP_PLUS = uint32(sdl.SCANCODE_KP_PLUS) + SCANCODE_KP_ENTER = uint32(sdl.SCANCODE_KP_ENTER) + SCANCODE_KP_1 = uint32(sdl.SCANCODE_KP_1) + SCANCODE_KP_2 = uint32(sdl.SCANCODE_KP_2) + SCANCODE_KP_3 = uint32(sdl.SCANCODE_KP_3) + SCANCODE_KP_4 = uint32(sdl.SCANCODE_KP_4) + SCANCODE_KP_5 = uint32(sdl.SCANCODE_KP_5) + SCANCODE_KP_6 = uint32(sdl.SCANCODE_KP_6) + SCANCODE_KP_7 = uint32(sdl.SCANCODE_KP_7) + SCANCODE_KP_8 = uint32(sdl.SCANCODE_KP_8) + SCANCODE_KP_9 = uint32(sdl.SCANCODE_KP_9) + SCANCODE_KP_0 = uint32(sdl.SCANCODE_KP_0) + SCANCODE_KP_PERIOD = uint32(sdl.SCANCODE_KP_PERIOD) - SCANCODE_NONUSBACKSLASH = sdl.SCANCODE_NONUSBACKSLASH - SCANCODE_APPLICATION = sdl.SCANCODE_APPLICATION - SCANCODE_POWER = sdl.SCANCODE_POWER - SCANCODE_KP_EQUALS = sdl.SCANCODE_KP_EQUALS - SCANCODE_F13 = sdl.SCANCODE_F13 - SCANCODE_F14 = sdl.SCANCODE_F14 - SCANCODE_F15 = sdl.SCANCODE_F15 - SCANCODE_F16 = sdl.SCANCODE_F16 - SCANCODE_F17 = sdl.SCANCODE_F17 - SCANCODE_F18 = sdl.SCANCODE_F18 - SCANCODE_F19 = sdl.SCANCODE_F19 - SCANCODE_F20 = sdl.SCANCODE_F20 - SCANCODE_F21 = sdl.SCANCODE_F21 - SCANCODE_F22 = sdl.SCANCODE_F22 - SCANCODE_F23 = sdl.SCANCODE_F23 - SCANCODE_F24 = sdl.SCANCODE_F24 - SCANCODE_EXECUTE = sdl.SCANCODE_EXECUTE - SCANCODE_HELP = sdl.SCANCODE_HELP - SCANCODE_MENU = sdl.SCANCODE_MENU - SCANCODE_SELECT = sdl.SCANCODE_SELECT - SCANCODE_STOP = sdl.SCANCODE_STOP - SCANCODE_AGAIN = sdl.SCANCODE_AGAIN - SCANCODE_UNDO = sdl.SCANCODE_UNDO - SCANCODE_CUT = sdl.SCANCODE_CUT - SCANCODE_COPY = sdl.SCANCODE_COPY - SCANCODE_PASTE = sdl.SCANCODE_PASTE - SCANCODE_FIND = sdl.SCANCODE_FIND - SCANCODE_MUTE = sdl.SCANCODE_MUTE - SCANCODE_VOLUMEUP = sdl.SCANCODE_VOLUMEUP - SCANCODE_VOLUMEDOWN = sdl.SCANCODE_VOLUMEDOWN - SCANCODE_KP_COMMA = sdl.SCANCODE_KP_COMMA - SCANCODE_KP_EQUALSAS400 = sdl.SCANCODE_KP_EQUALSAS400 + SCANCODE_NONUSBACKSLASH = uint32(sdl.SCANCODE_NONUSBACKSLASH) + SCANCODE_APPLICATION = uint32(sdl.SCANCODE_APPLICATION) + SCANCODE_POWER = uint32(sdl.SCANCODE_POWER) + SCANCODE_KP_EQUALS = uint32(sdl.SCANCODE_KP_EQUALS) + SCANCODE_F13 = uint32(sdl.SCANCODE_F13) + SCANCODE_F14 = uint32(sdl.SCANCODE_F14) + SCANCODE_F15 = uint32(sdl.SCANCODE_F15) + SCANCODE_F16 = uint32(sdl.SCANCODE_F16) + SCANCODE_F17 = uint32(sdl.SCANCODE_F17) + SCANCODE_F18 = uint32(sdl.SCANCODE_F18) + SCANCODE_F19 = uint32(sdl.SCANCODE_F19) + SCANCODE_F20 = uint32(sdl.SCANCODE_F20) + SCANCODE_F21 = uint32(sdl.SCANCODE_F21) + SCANCODE_F22 = uint32(sdl.SCANCODE_F22) + SCANCODE_F23 = uint32(sdl.SCANCODE_F23) + SCANCODE_F24 = uint32(sdl.SCANCODE_F24) + SCANCODE_EXECUTE = uint32(sdl.SCANCODE_EXECUTE) + SCANCODE_HELP = uint32(sdl.SCANCODE_HELP) + SCANCODE_MENU = uint32(sdl.SCANCODE_MENU) + SCANCODE_SELECT = uint32(sdl.SCANCODE_SELECT) + SCANCODE_STOP = uint32(sdl.SCANCODE_STOP) + SCANCODE_AGAIN = uint32(sdl.SCANCODE_AGAIN) + SCANCODE_UNDO = uint32(sdl.SCANCODE_UNDO) + SCANCODE_CUT = uint32(sdl.SCANCODE_CUT) + SCANCODE_COPY = uint32(sdl.SCANCODE_COPY) + SCANCODE_PASTE = uint32(sdl.SCANCODE_PASTE) + SCANCODE_FIND = uint32(sdl.SCANCODE_FIND) + SCANCODE_MUTE = uint32(sdl.SCANCODE_MUTE) + SCANCODE_VOLUMEUP = uint32(sdl.SCANCODE_VOLUMEUP) + SCANCODE_VOLUMEDOWN = uint32(sdl.SCANCODE_VOLUMEDOWN) + SCANCODE_KP_COMMA = uint32(sdl.SCANCODE_KP_COMMA) + SCANCODE_KP_EQUALSAS400 = uint32(sdl.SCANCODE_KP_EQUALSAS400) - SCANCODE_INTERNATIONAL1 = sdl.SCANCODE_INTERNATIONAL1 - SCANCODE_INTERNATIONAL2 = sdl.SCANCODE_INTERNATIONAL2 - SCANCODE_INTERNATIONAL3 = sdl.SCANCODE_INTERNATIONAL3 - SCANCODE_INTERNATIONAL4 = sdl.SCANCODE_INTERNATIONAL4 - SCANCODE_INTERNATIONAL5 = sdl.SCANCODE_INTERNATIONAL5 - SCANCODE_INTERNATIONAL6 = sdl.SCANCODE_INTERNATIONAL6 - SCANCODE_INTERNATIONAL7 = sdl.SCANCODE_INTERNATIONAL7 - SCANCODE_INTERNATIONAL8 = sdl.SCANCODE_INTERNATIONAL8 - SCANCODE_INTERNATIONAL9 = sdl.SCANCODE_INTERNATIONAL9 - SCANCODE_LANG1 = sdl.SCANCODE_LANG1 - SCANCODE_LANG2 = sdl.SCANCODE_LANG2 - SCANCODE_LANG3 = sdl.SCANCODE_LANG3 - SCANCODE_LANG4 = sdl.SCANCODE_LANG4 - SCANCODE_LANG5 = sdl.SCANCODE_LANG5 - SCANCODE_LANG6 = sdl.SCANCODE_LANG6 - SCANCODE_LANG7 = sdl.SCANCODE_LANG7 - SCANCODE_LANG8 = sdl.SCANCODE_LANG8 - SCANCODE_LANG9 = sdl.SCANCODE_LANG9 + SCANCODE_INTERNATIONAL1 = uint32(sdl.SCANCODE_INTERNATIONAL1) + SCANCODE_INTERNATIONAL2 = uint32(sdl.SCANCODE_INTERNATIONAL2) + SCANCODE_INTERNATIONAL3 = uint32(sdl.SCANCODE_INTERNATIONAL3) + SCANCODE_INTERNATIONAL4 = uint32(sdl.SCANCODE_INTERNATIONAL4) + SCANCODE_INTERNATIONAL5 = uint32(sdl.SCANCODE_INTERNATIONAL5) + SCANCODE_INTERNATIONAL6 = uint32(sdl.SCANCODE_INTERNATIONAL6) + SCANCODE_INTERNATIONAL7 = uint32(sdl.SCANCODE_INTERNATIONAL7) + SCANCODE_INTERNATIONAL8 = uint32(sdl.SCANCODE_INTERNATIONAL8) + SCANCODE_INTERNATIONAL9 = uint32(sdl.SCANCODE_INTERNATIONAL9) + SCANCODE_LANG1 = uint32(sdl.SCANCODE_LANG1) + SCANCODE_LANG2 = uint32(sdl.SCANCODE_LANG2) + SCANCODE_LANG3 = uint32(sdl.SCANCODE_LANG3) + SCANCODE_LANG4 = uint32(sdl.SCANCODE_LANG4) + SCANCODE_LANG5 = uint32(sdl.SCANCODE_LANG5) + SCANCODE_LANG6 = uint32(sdl.SCANCODE_LANG6) + SCANCODE_LANG7 = uint32(sdl.SCANCODE_LANG7) + SCANCODE_LANG8 = uint32(sdl.SCANCODE_LANG8) + SCANCODE_LANG9 = uint32(sdl.SCANCODE_LANG9) - SCANCODE_ALTERASE = sdl.SCANCODE_ALTERASE - SCANCODE_SYSREQ = sdl.SCANCODE_SYSREQ - SCANCODE_CANCEL = sdl.SCANCODE_CANCEL - SCANCODE_CLEAR = sdl.SCANCODE_CLEAR - SCANCODE_PRIOR = sdl.SCANCODE_PRIOR - SCANCODE_RETURN2 = sdl.SCANCODE_RETURN2 - SCANCODE_SEPARATOR = sdl.SCANCODE_SEPARATOR - SCANCODE_OUT = sdl.SCANCODE_OUT - SCANCODE_OPER = sdl.SCANCODE_OPER - SCANCODE_CLEARAGAIN = sdl.SCANCODE_CLEARAGAIN - SCANCODE_CRSEL = sdl.SCANCODE_CRSEL - SCANCODE_EXSEL = sdl.SCANCODE_EXSEL + SCANCODE_ALTERASE = uint32(sdl.SCANCODE_ALTERASE) + SCANCODE_SYSREQ = uint32(sdl.SCANCODE_SYSREQ) + SCANCODE_CANCEL = uint32(sdl.SCANCODE_CANCEL) + SCANCODE_CLEAR = uint32(sdl.SCANCODE_CLEAR) + SCANCODE_PRIOR = uint32(sdl.SCANCODE_PRIOR) + SCANCODE_RETURN2 = uint32(sdl.SCANCODE_RETURN2) + SCANCODE_SEPARATOR = uint32(sdl.SCANCODE_SEPARATOR) + SCANCODE_OUT = uint32(sdl.SCANCODE_OUT) + SCANCODE_OPER = uint32(sdl.SCANCODE_OPER) + SCANCODE_CLEARAGAIN = uint32(sdl.SCANCODE_CLEARAGAIN) + SCANCODE_CRSEL = uint32(sdl.SCANCODE_CRSEL) + SCANCODE_EXSEL = uint32(sdl.SCANCODE_EXSEL) - SCANCODE_KP_00 = sdl.SCANCODE_KP_00 - SCANCODE_KP_000 = sdl.SCANCODE_KP_000 - SCANCODE_THOUSANDSSEPARATOR = sdl.SCANCODE_THOUSANDSSEPARATOR - SCANCODE_DECIMALSEPARATOR = sdl.SCANCODE_DECIMALSEPARATOR - SCANCODE_CURRENCYUNIT = sdl.SCANCODE_CURRENCYUNIT - SCANCODE_CURRENCYSUBUNIT = sdl.SCANCODE_CURRENCYSUBUNIT - SCANCODE_KP_LEFTPAREN = sdl.SCANCODE_KP_LEFTPAREN - SCANCODE_KP_RIGHTPAREN = sdl.SCANCODE_KP_RIGHTPAREN - SCANCODE_KP_LEFTBRACE = sdl.SCANCODE_KP_LEFTBRACE - SCANCODE_KP_RIGHTBRACE = sdl.SCANCODE_KP_RIGHTBRACE - SCANCODE_KP_TAB = sdl.SCANCODE_KP_TAB - SCANCODE_KP_BACKSPACE = sdl.SCANCODE_KP_BACKSPACE - SCANCODE_KP_A = sdl.SCANCODE_KP_A - SCANCODE_KP_B = sdl.SCANCODE_KP_B - SCANCODE_KP_C = sdl.SCANCODE_KP_C - SCANCODE_KP_D = sdl.SCANCODE_KP_D - SCANCODE_KP_E = sdl.SCANCODE_KP_E - SCANCODE_KP_F = sdl.SCANCODE_KP_F - SCANCODE_KP_XOR = sdl.SCANCODE_KP_XOR - SCANCODE_KP_POWER = sdl.SCANCODE_KP_POWER - SCANCODE_KP_PERCENT = sdl.SCANCODE_KP_PERCENT - SCANCODE_KP_LESS = sdl.SCANCODE_KP_LESS - SCANCODE_KP_GREATER = sdl.SCANCODE_KP_GREATER - SCANCODE_KP_AMPERSAND = sdl.SCANCODE_KP_AMPERSAND - SCANCODE_KP_DBLAMPERSAND = sdl.SCANCODE_KP_DBLAMPERSAND - SCANCODE_KP_VERTICALBAR = sdl.SCANCODE_KP_VERTICALBAR - SCANCODE_KP_DBLVERTICALBAR = sdl.SCANCODE_KP_DBLVERTICALBAR - SCANCODE_KP_COLON = sdl.SCANCODE_KP_COLON - SCANCODE_KP_HASH = sdl.SCANCODE_KP_HASH - SCANCODE_KP_SPACE = sdl.SCANCODE_KP_SPACE - SCANCODE_KP_AT = sdl.SCANCODE_KP_AT - SCANCODE_KP_EXCLAM = sdl.SCANCODE_KP_EXCLAM - SCANCODE_KP_MEMSTORE = sdl.SCANCODE_KP_MEMSTORE - SCANCODE_KP_MEMRECALL = sdl.SCANCODE_KP_MEMRECALL - SCANCODE_KP_MEMCLEAR = sdl.SCANCODE_KP_MEMCLEAR - SCANCODE_KP_MEMADD = sdl.SCANCODE_KP_MEMADD - SCANCODE_KP_MEMSUBTRACT = sdl.SCANCODE_KP_MEMSUBTRACT - SCANCODE_KP_MEMMULTIPLY = sdl.SCANCODE_KP_MEMMULTIPLY - SCANCODE_KP_MEMDIVIDE = sdl.SCANCODE_KP_MEMDIVIDE - SCANCODE_KP_PLUSMINUS = sdl.SCANCODE_KP_PLUSMINUS - SCANCODE_KP_CLEAR = sdl.SCANCODE_KP_CLEAR - SCANCODE_KP_CLEARENTRY = sdl.SCANCODE_KP_CLEARENTRY - SCANCODE_KP_BINARY = sdl.SCANCODE_KP_BINARY - SCANCODE_KP_OCTAL = sdl.SCANCODE_KP_OCTAL - SCANCODE_KP_DECIMAL = sdl.SCANCODE_KP_DECIMAL - SCANCODE_KP_HEXADECIMAL = sdl.SCANCODE_KP_HEXADECIMAL + SCANCODE_KP_00 = uint32(sdl.SCANCODE_KP_00) + SCANCODE_KP_000 = uint32(sdl.SCANCODE_KP_000) + SCANCODE_THOUSANDSSEPARATOR = uint32(sdl.SCANCODE_THOUSANDSSEPARATOR) + SCANCODE_DECIMALSEPARATOR = uint32(sdl.SCANCODE_DECIMALSEPARATOR) + SCANCODE_CURRENCYUNIT = uint32(sdl.SCANCODE_CURRENCYUNIT) + SCANCODE_CURRENCYSUBUNIT = uint32(sdl.SCANCODE_CURRENCYSUBUNIT) + SCANCODE_KP_LEFTPAREN = uint32(sdl.SCANCODE_KP_LEFTPAREN) + SCANCODE_KP_RIGHTPAREN = uint32(sdl.SCANCODE_KP_RIGHTPAREN) + SCANCODE_KP_LEFTBRACE = uint32(sdl.SCANCODE_KP_LEFTBRACE) + SCANCODE_KP_RIGHTBRACE = uint32(sdl.SCANCODE_KP_RIGHTBRACE) + SCANCODE_KP_TAB = uint32(sdl.SCANCODE_KP_TAB) + SCANCODE_KP_BACKSPACE = uint32(sdl.SCANCODE_KP_BACKSPACE) + SCANCODE_KP_A = uint32(sdl.SCANCODE_KP_A) + SCANCODE_KP_B = uint32(sdl.SCANCODE_KP_B) + SCANCODE_KP_C = uint32(sdl.SCANCODE_KP_C) + SCANCODE_KP_D = uint32(sdl.SCANCODE_KP_D) + SCANCODE_KP_E = uint32(sdl.SCANCODE_KP_E) + SCANCODE_KP_F = uint32(sdl.SCANCODE_KP_F) + SCANCODE_KP_XOR = uint32(sdl.SCANCODE_KP_XOR) + SCANCODE_KP_POWER = uint32(sdl.SCANCODE_KP_POWER) + SCANCODE_KP_PERCENT = uint32(sdl.SCANCODE_KP_PERCENT) + SCANCODE_KP_LESS = uint32(sdl.SCANCODE_KP_LESS) + SCANCODE_KP_GREATER = uint32(sdl.SCANCODE_KP_GREATER) + SCANCODE_KP_AMPERSAND = uint32(sdl.SCANCODE_KP_AMPERSAND) + SCANCODE_KP_DBLAMPERSAND = uint32(sdl.SCANCODE_KP_DBLAMPERSAND) + SCANCODE_KP_VERTICALBAR = uint32(sdl.SCANCODE_KP_VERTICALBAR) + SCANCODE_KP_DBLVERTICALBAR = uint32(sdl.SCANCODE_KP_DBLVERTICALBAR) + SCANCODE_KP_COLON = uint32(sdl.SCANCODE_KP_COLON) + SCANCODE_KP_HASH = uint32(sdl.SCANCODE_KP_HASH) + SCANCODE_KP_SPACE = uint32(sdl.SCANCODE_KP_SPACE) + SCANCODE_KP_AT = uint32(sdl.SCANCODE_KP_AT) + SCANCODE_KP_EXCLAM = uint32(sdl.SCANCODE_KP_EXCLAM) + SCANCODE_KP_MEMSTORE = uint32(sdl.SCANCODE_KP_MEMSTORE) + SCANCODE_KP_MEMRECALL = uint32(sdl.SCANCODE_KP_MEMRECALL) + SCANCODE_KP_MEMCLEAR = uint32(sdl.SCANCODE_KP_MEMCLEAR) + SCANCODE_KP_MEMADD = uint32(sdl.SCANCODE_KP_MEMADD) + SCANCODE_KP_MEMSUBTRACT = uint32(sdl.SCANCODE_KP_MEMSUBTRACT) + SCANCODE_KP_MEMMULTIPLY = uint32(sdl.SCANCODE_KP_MEMMULTIPLY) + SCANCODE_KP_MEMDIVIDE = uint32(sdl.SCANCODE_KP_MEMDIVIDE) + SCANCODE_KP_PLUSMINUS = uint32(sdl.SCANCODE_KP_PLUSMINUS) + SCANCODE_KP_CLEAR = uint32(sdl.SCANCODE_KP_CLEAR) + SCANCODE_KP_CLEARENTRY = uint32(sdl.SCANCODE_KP_CLEARENTRY) + SCANCODE_KP_BINARY = uint32(sdl.SCANCODE_KP_BINARY) + SCANCODE_KP_OCTAL = uint32(sdl.SCANCODE_KP_OCTAL) + SCANCODE_KP_DECIMAL = uint32(sdl.SCANCODE_KP_DECIMAL) + SCANCODE_KP_HEXADECIMAL = uint32(sdl.SCANCODE_KP_HEXADECIMAL) - SCANCODE_LCTRL = sdl.SCANCODE_LCTRL - SCANCODE_LSHIFT = sdl.SCANCODE_LSHIFT - SCANCODE_LALT = sdl.SCANCODE_LALT - SCANCODE_LGUI = sdl.SCANCODE_LGUI - SCANCODE_RCTRL = sdl.SCANCODE_RCTRL - SCANCODE_RSHIFT = sdl.SCANCODE_RSHIFT - SCANCODE_RALT = sdl.SCANCODE_RALT - SCANCODE_RGUI = sdl.SCANCODE_RGUI - SCANCODE_MODE = sdl.SCANCODE_MODE - SCANCODE_AUDIONEXT = sdl.SCANCODE_AUDIONEXT - SCANCODE_AUDIOPREV = sdl.SCANCODE_AUDIOPREV - SCANCODE_AUDIOSTOP = sdl.SCANCODE_AUDIOSTOP - SCANCODE_AUDIOPLAY = sdl.SCANCODE_AUDIOPLAY - SCANCODE_AUDIOMUTE = sdl.SCANCODE_AUDIOMUTE - SCANCODE_MEDIASELECT = sdl.SCANCODE_MEDIASELECT - SCANCODE_WWW = sdl.SCANCODE_WWW - SCANCODE_MAIL = sdl.SCANCODE_MAIL - SCANCODE_CALCULATOR = sdl.SCANCODE_CALCULATOR - SCANCODE_COMPUTER = sdl.SCANCODE_COMPUTER - SCANCODE_AC_SEARCH = sdl.SCANCODE_AC_SEARCH - SCANCODE_AC_HOME = sdl.SCANCODE_AC_HOME - SCANCODE_AC_BACK = sdl.SCANCODE_AC_BACK - SCANCODE_AC_FORWARD = sdl.SCANCODE_AC_FORWARD - SCANCODE_AC_STOP = sdl.SCANCODE_AC_STOP - SCANCODE_AC_REFRESH = sdl.SCANCODE_AC_REFRESH - SCANCODE_AC_BOOKMARKS = sdl.SCANCODE_AC_BOOKMARKS - SCANCODE_BRIGHTNESSDOWN = sdl.SCANCODE_BRIGHTNESSDOWN - SCANCODE_BRIGHTNESSUP = sdl.SCANCODE_BRIGHTNESSUP - SCANCODE_DISPLAYSWITCH = sdl.SCANCODE_DISPLAYSWITCH - SCANCODE_KBDILLUMTOGGLE = sdl.SCANCODE_KBDILLUMTOGGLE - SCANCODE_KBDILLUMDOWN = sdl.SCANCODE_KBDILLUMDOWN - SCANCODE_KBDILLUMUP = sdl.SCANCODE_KBDILLUMUP - SCANCODE_EJECT = sdl.SCANCODE_EJECT - SCANCODE_SLEEP = sdl.SCANCODE_SLEEP - SCANCODE_APP1 = sdl.SCANCODE_APP1 - SCANCODE_APP2 = sdl.SCANCODE_APP2 - NUM_SCANCODES = sdl.NUM_SCANCODES + SCANCODE_LCTRL = uint32(sdl.SCANCODE_LCTRL) + SCANCODE_LSHIFT = uint32(sdl.SCANCODE_LSHIFT) + SCANCODE_LALT = uint32(sdl.SCANCODE_LALT) + SCANCODE_LGUI = uint32(sdl.SCANCODE_LGUI) + SCANCODE_RCTRL = uint32(sdl.SCANCODE_RCTRL) + SCANCODE_RSHIFT = uint32(sdl.SCANCODE_RSHIFT) + SCANCODE_RALT = uint32(sdl.SCANCODE_RALT) + SCANCODE_RGUI = uint32(sdl.SCANCODE_RGUI) + SCANCODE_MODE = uint32(sdl.SCANCODE_MODE) + SCANCODE_AUDIONEXT = uint32(sdl.SCANCODE_AUDIONEXT) + SCANCODE_AUDIOPREV = uint32(sdl.SCANCODE_AUDIOPREV) + SCANCODE_AUDIOSTOP = uint32(sdl.SCANCODE_AUDIOSTOP) + SCANCODE_AUDIOPLAY = uint32(sdl.SCANCODE_AUDIOPLAY) + SCANCODE_AUDIOMUTE = uint32(sdl.SCANCODE_AUDIOMUTE) + SCANCODE_MEDIASELECT = uint32(sdl.SCANCODE_MEDIASELECT) + SCANCODE_WWW = uint32(sdl.SCANCODE_WWW) + SCANCODE_MAIL = uint32(sdl.SCANCODE_MAIL) + SCANCODE_CALCULATOR = uint32(sdl.SCANCODE_CALCULATOR) + SCANCODE_COMPUTER = uint32(sdl.SCANCODE_COMPUTER) + SCANCODE_AC_SEARCH = uint32(sdl.SCANCODE_AC_SEARCH) + SCANCODE_AC_HOME = uint32(sdl.SCANCODE_AC_HOME) + SCANCODE_AC_BACK = uint32(sdl.SCANCODE_AC_BACK) + SCANCODE_AC_FORWARD = uint32(sdl.SCANCODE_AC_FORWARD) + SCANCODE_AC_STOP = uint32(sdl.SCANCODE_AC_STOP) + SCANCODE_AC_REFRESH = uint32(sdl.SCANCODE_AC_REFRESH) + SCANCODE_AC_BOOKMARKS = uint32(sdl.SCANCODE_AC_BOOKMARKS) + SCANCODE_BRIGHTNESSDOWN = uint32(sdl.SCANCODE_BRIGHTNESSDOWN) + SCANCODE_BRIGHTNESSUP = uint32(sdl.SCANCODE_BRIGHTNESSUP) + SCANCODE_DISPLAYSWITCH = uint32(sdl.SCANCODE_DISPLAYSWITCH) + SCANCODE_KBDILLUMTOGGLE = uint32(sdl.SCANCODE_KBDILLUMTOGGLE) + SCANCODE_KBDILLUMDOWN = uint32(sdl.SCANCODE_KBDILLUMDOWN) + SCANCODE_KBDILLUMUP = uint32(sdl.SCANCODE_KBDILLUMUP) + SCANCODE_EJECT = uint32(sdl.SCANCODE_EJECT) + SCANCODE_SLEEP = uint32(sdl.SCANCODE_SLEEP) + SCANCODE_APP1 = uint32(sdl.SCANCODE_APP1) + SCANCODE_APP2 = uint32(sdl.SCANCODE_APP2) + NUM_SCANCODES = uint32(sdl.NUM_SCANCODES) ) diff --git a/sdl/texture2d.go b/sdl/texture2d.go index c3f7874..e98e1c8 100644 --- a/sdl/texture2d.go +++ b/sdl/texture2d.go @@ -1,10 +1,13 @@ package sdl import ( + "io/ioutil" "log" "github.com/manleydev/golang-game-framework/core" + "github.com/manleydev/golang-game-framework/importer" "github.com/manleydev/golang-game-framework/rendering" + "github.com/veandco/go-sdl2/sdl" ) @@ -36,6 +39,48 @@ func NewSdlTexture2D(renderer rendering.Renderer2D, bmpPath string) *SdlTexture2 return &tex } +func NewEmbededSdlTexture2D(renderer rendering.Renderer2D, bmpPath string) *SdlTexture2D { + sdlRenderer, ok := renderer.(*SdlRenderer2D) + if !ok { + log.Print("Renderer is not an SDL renderer") + return nil + } + + f, err := importer.EmbededAssets.Open(bmpPath) + if err != nil { + log.Printf("Failed to load '%s' from embeded assets: %s", bmpPath, err) + return nil + } + defer f.Close() + + raw, err := ioutil.ReadAll(f) + if err != nil { + log.Printf("Failed to read '%s' from embeded assets: %s", bmpPath, err) + return nil + } + + buffer, err := sdl.RWFromMem(raw) + if err != nil { + log.Printf("Failed to create buffer for embeded asset '%s': %s", bmpPath, err) + } + + tex := SdlTexture2D{} + surface, err := sdl.LoadBMPRW(buffer, true) + if err != nil { + log.Print("Failed to load bmp: ", err) + return nil + } + defer surface.Free() + + tex.texture, err = sdlRenderer.renderer.CreateTextureFromSurface(surface) + if err != nil { + log.Print("Failed to create SDL texture: ", err) + return nil + } + + return &tex +} + func (tex SdlTexture2D) GetCenter() core.Vector2 { _, _, width, height, err := tex.texture.Query() if err != nil {