Last active
August 29, 2015 14:20
-
-
Save shakesoda/54e37cbd3ff7bf928b1a to your computer and use it in GitHub Desktop.
Love 0.10 setTextInput polyfill for 0.9.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local ffi = require "ffi" | |
| ffi.cdef [[ | |
| typedef struct SDL_Rect | |
| { | |
| int x, y; | |
| int w, h; | |
| } SDL_Rect; | |
| void SDL_SetTextInputRect(SDL_Rect *rect); | |
| ]] | |
| local sdl | |
| if love.system.getOS() == "Windows" then | |
| -- you probably won't need this section, I just run love out of my working dirs. | |
| if love and love.system.getOS() == "Windows" and love.filesystem.isDirectory("bin") then | |
| sdl = ffi.load("bin/SDL2") | |
| else | |
| sdl = ffi.load("SDL2") | |
| end | |
| else | |
| sdl = ffi.C | |
| end | |
| local setTextInput = love.keyboard.setTextInput | |
| love.keyboard.setTextInput = function(enable, x, y, w, h) | |
| if x and y and w and h then | |
| local r = ffi.new("SDL_Rect[1]") | |
| r[0].x = x | |
| r[0].y = y | |
| r[0].w = w | |
| r[0].h = h | |
| sdl.SDL_SetTextInputRect(r) | |
| end | |
| setTextInput(enable) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment