-
Notifications
You must be signed in to change notification settings - Fork 1
/
native.lua
55 lines (45 loc) · 1.11 KB
/
native.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local ffiStatus, ffi = pcall(require, "ffi")
if not ffiStatus then
return false
end
local sdl
local sys = ffi.C
if ffi.os == "Windows" then
sdl = ffi.load("SDL2")
else
sdl = sys
end
pcall(function()
ffi.cdef[[
typedef struct SDL_Window SDL_Window;
SDL_Window* SDL_GL_GetCurrentWindow();
void SDL_GetWindowPosition(SDL_Window* window, int* x, int* y);
int SDL_CaptureMouse(bool enabled);
int SDL_GetGlobalMouseState(int* x, int* y);
]]
end)
local uin = {}
uin.ffi = ffi
uin.sdl = sdl
uin.sys = sys
uin.os = ffi.os
function uin.getCurrentWindow()
return sdl.SDL_GL_GetCurrentWindow()
end
function uin.getWindowPosition()
local window = uin.getCurrentWindow()
local x = ffi.new("int[1]")
local y = ffi.new("int[1]")
sdl.SDL_GetWindowPosition(window, x, y)
return x[0], y[0]
end
function uin.captureMouse(value)
return sdl.SDL_CaptureMouse(value)
end
function uin.getGlobalMouseState()
local x = ffi.new("int[1]")
local y = ffi.new("int[1]")
local state = sdl.SDL_GetGlobalMouseState(x, y)
return x[0], y[0], state
end
return uin