Add ttf and net modules. Fix nimterop generation. Add separate modules for importing
This commit is contained in:
parent
5b4be1012c
commit
7a3d6c4f15
11 changed files with 262 additions and 90 deletions
2
nim.cfg
2
nim.cfg
|
|
@ -1 +1 @@
|
|||
-d:SDL_DL -d:SDL_Static -d:SDL_image_DL -d:SDL_mixer_DL
|
||||
-d:SDL_DL -d:SDL_Static -d:SDL_image_Static -d:SDL_mixer_Static -d:SDL_net_Static -d:SDL_ttf_Static -d:SDL_image_DL -d:SDL_mixer_DL -d:SDL_net_DL -d:SDL_ttf_DL
|
||||
|
|
@ -12,14 +12,9 @@ getHeader(
|
|||
)
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
# # let contents = readFile(srcDir/"include/SDL_gpu.h")
|
||||
# # let newContents = contents.replace(re"""#include "SDL.h"""", "#include <SDL2/SDL.h>", limit=1).
|
||||
# # replace(re"""#include "begin_code.h"""", "", limit=1).
|
||||
# # replace(re"""#include "close_code.h"""", "", limit=1)
|
||||
|
||||
# # writeFile(srcDir/"include/SDL_gpu.h", newContents)
|
||||
cSkipSymbol @["bool"]
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
|
||||
cOverride:
|
||||
const KEYCODE_UNDERSCORE* = ('_').KeyCodeEnum
|
||||
|
|
@ -149,28 +144,8 @@ cPlugin:
|
|||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
# if sym.name == "Uint64":
|
||||
# sym.name = "uint64"
|
||||
# if sym.name == "Uint32":
|
||||
# sym.name = "uint32"
|
||||
# if sym.name == "Uint16":
|
||||
# sym.name = "uint16"
|
||||
# if sym.name == "Uint8":
|
||||
# sym.name = "uint8"
|
||||
|
||||
# if sym.name == "Sint64":
|
||||
# sym.name = "int64"
|
||||
# if sym.name == "Sint32":
|
||||
# sym.name = "int32"
|
||||
# if sym.name == "Sint16":
|
||||
# sym.name = "int16"
|
||||
# if sym.name == "Sint8":
|
||||
# sym.name = "int8"
|
||||
# if sym.name == "Bool":
|
||||
# sym.name = "bool"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath")
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_Path, recurse = true)
|
||||
else:
|
||||
cImport(SDL_Path, recurse = true)
|
||||
cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath")
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
import os, strutils
|
||||
import os, strutils, strformat
|
||||
import ../nim_sdl2/wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir / "build" / "sdl2_image"
|
||||
buildDir = baseDir / "build"
|
||||
sdlIncludeDir = buildDir / "sdl2" / "include"
|
||||
srcDir = buildDir / "sdl2_image"
|
||||
|
||||
getHeader(
|
||||
"SDL_image.h",
|
||||
|
|
@ -13,23 +15,9 @@ getHeader(
|
|||
altNames = "SDL2_image"
|
||||
)
|
||||
|
||||
static:
|
||||
# static:
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
let contents = readFile(srcDir/"SDL_image.h")
|
||||
let newContents = contents.replace("""#include "SDL.h"
|
||||
#include "SDL_version.h"
|
||||
#include "begin_code.h"""", """
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_version.h>
|
||||
#include <SDL2/begin_code.h>
|
||||
""").
|
||||
replace("""#include "close_code.h"""", "#include <SDL2/close_code.h>")
|
||||
|
||||
writeFile(srcDir/"SDL_image.h", newContents)
|
||||
|
||||
# cOverride:
|
||||
# type
|
||||
|
||||
|
||||
cPlugin:
|
||||
|
|
@ -118,7 +106,7 @@ cPlugin:
|
|||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath")
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_image_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
else:
|
||||
cImport(SDL_image_Path, recurse = false)
|
||||
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import os, strutils
|
||||
import os, strutils, strformat
|
||||
import ../nim_sdl2/wrapper as sdl2_wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir / "build" / "sdl2_mixer"
|
||||
buildDir = baseDir / "build"
|
||||
sdlIncludeDir = buildDir / "sdl2" / "include"
|
||||
srcDir = buildDir / "sdl2_mixer"
|
||||
|
||||
getHeader(
|
||||
"SDL_mixer.h",
|
||||
|
|
@ -13,31 +15,9 @@ getHeader(
|
|||
altNames = "SDL2_mixer"
|
||||
)
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
let contents = readFile(srcDir/"SDL_mixer.h")
|
||||
let newContents = contents.replace("""#include "SDL_stdinc.h"
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_version.h"
|
||||
#include "begin_code.h"
|
||||
""", """
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_rwops.h>
|
||||
#include <SDL2/SDL_audio.h>
|
||||
#include <SDL2/SDL_endian.h>
|
||||
#include <SDL2/SDL_version.h>
|
||||
#include <SDL2/begin_code.h>
|
||||
""").
|
||||
replace("""#include "close_code.h"""", "#include <SDL2/close_code.h>")
|
||||
|
||||
writeFile(srcDir/"SDL_mixer.h", newContents)
|
||||
|
||||
# cOverride:
|
||||
# type
|
||||
|
||||
# static:
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
|
|
@ -124,8 +104,7 @@ cPlugin:
|
|||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath")
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_mixer_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
else:
|
||||
cImport(SDL_mixer_Path, recurse = false)
|
||||
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
|
|
|
|||
114
src/nim_sdl2_net/wrapper.nim
Normal file
114
src/nim_sdl2_net/wrapper.nim
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
import os, strutils, strformat
|
||||
import ../nim_sdl2/wrapper as sdl2_wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
buildDir = baseDir / "build"
|
||||
sdlIncludeDir = buildDir / "sdl2" / "include"
|
||||
srcDir = buildDir / "sdl2_net"
|
||||
|
||||
getHeader(
|
||||
"SDL_net.h",
|
||||
dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_net"
|
||||
)
|
||||
|
||||
# static:
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
# sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
if sym.name == "__MACOSX__":
|
||||
sym.name = "MACOSX"
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.replace(re"^_+", "")
|
||||
sym.name = sym.name.replace(re"_+$", "")
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_net_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
else:
|
||||
cImport(SDL_net_Path, recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
113
src/nim_sdl2_ttf/wrapper.nim
Normal file
113
src/nim_sdl2_ttf/wrapper.nim
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
import os, strutils, strformat
|
||||
import ../nim_sdl2/wrapper as sdl2_wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
buildDir = baseDir / "build"
|
||||
sdlDir = buildDir / "sdl2"
|
||||
sdlIncludeDir = sdlDir / "include"
|
||||
cmakeModPath = baseDir / "cmake" / "sdl2"
|
||||
srcDir = buildDir / "sdl2_ttf"
|
||||
|
||||
getHeader(
|
||||
"SDL_ttf.h",
|
||||
dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_ttf",
|
||||
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY=2.0.12 -DSDL2_PATH={sdlDir}"
|
||||
)
|
||||
|
||||
# static:
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
# sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
if sym.name == "__MACOSX__":
|
||||
sym.name = "MACOSX"
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.replace(re"^_+", "")
|
||||
sym.name = sym.name.replace(re"_+$", "")
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
when defined(SDL_Static):
|
||||
cImport(SDL_ttf_Path, recurse = false, flags = &"-I={sdlIncludeDir}")
|
||||
else:
|
||||
cImport(SDL_ttf_Path, recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={sdlIncludeDir}")
|
||||
|
|
@ -1,7 +1,2 @@
|
|||
import nim_sdl2 / wrapper as sdl2_wrapper
|
||||
import nim_sdl2_image / wrapper as sdl2_image_wrapper
|
||||
import nim_sdl2_mixer / wrapper as sdl2_mixer_wrapper
|
||||
|
||||
export sdl2_wrapper
|
||||
export sdl2_image_wrapper
|
||||
export sdl2_mixer_wrapper
|
||||
import nim_sdl2 / wrapper
|
||||
export wrapper
|
||||
2
src/sdl2_image.nim
Normal file
2
src/sdl2_image.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import nim_sdl2_image / wrapper
|
||||
export wrapper
|
||||
2
src/sdl2_mixer.nim
Normal file
2
src/sdl2_mixer.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import nim_sdl2_mixer / wrapper
|
||||
export wrapper
|
||||
2
src/sdl2_net.nim
Normal file
2
src/sdl2_net.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import nim_sdl2_net / wrapper
|
||||
export wrapper
|
||||
2
src/sdl2_ttf.nim
Normal file
2
src/sdl2_ttf.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import nim_sdl2_ttf / wrapper
|
||||
export wrapper
|
||||
Loading…
Add table
Add a link
Reference in a new issue