-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Interoperate with Ulydev/push (mouse position override) #20
Comments
Hello. Glad you like the library. I tried using Slab with one of the examples provided with the Push library and noticed the issue you were describing. Slab is designed to be able to work with other libraries with minimal interference. However, instances like these have not been caught yet and as more people use external libraries and bring up these issues, I can work on making sure Slab will still work seamlessly with them. I will look at resolving this in the next update. |
Sorry I didn't confirm this earlier. I'm not sure how 11e76e1 fixes the issue. On that commit I need to use my workaround of patching love.mouse.getPosition directly to allow the mouse to click buttons. However, even worse 8af1168 broke that workaround. Now I can find no way to get slab to work with push without modifying slab. I git bisected with this main.lua code (along with push.lua and slab checked out to ./slab) to find that commit: local Slab = require 'slab'
local SlabTest = require 'slab.SlabTest'
local push = require 'push'
local last_mouse = {
x = 0,
y = 0,
}
function love.load(args)
-- After 8af116802f2eadbab6399965db6157816affb5f7, this workaround doesn't
-- work anymore. Before that commit, buttons aren't clickable without this
-- workaround. On v0.7.2, buttons aren't clickable with or without it.
local vanilla_mouse_position_fn = love.mouse.getPosition
love.mouse.getPosition = function()
local x,y = push:toGame(vanilla_mouse_position_fn())
-- Track last position within game screen to mimic behaviour of love
-- window.
x = x or last_mouse.x
y = y or last_mouse.y
last_mouse.x = x
last_mouse.y = y
return x,y
end
love.graphics.setBackgroundColor(0.07, 0.07, 0.07)
local game_width, game_height, window_width, window_height, push_cfg = 800, 600, 1920, 1080, nil
push:setupScreen(game_width, game_height, window_width, window_height, push_cfg)
Slab.Initialize(args)
end
function love.update(dt)
Slab.Update(dt)
SlabTest.Begin()
Slab.BeginWindow('Git Bisect')
do
if Slab.Button("Good") then
love.event.quit( 0 )
end
if Slab.Button("Bad") then
love.event.quit( 1 )
end
end
Slab.EndWindow()
end
function love.keypressed(k)
local exitstatus
if k == 'g' then
exitstatus = 0
elseif k == 'b' then
exitstatus = 1
end
if exitstatus then
love.event.quit( exitstatus )
end
end
function love.draw()
push:start()
Slab.Draw()
push:finish()
end
function love.resize(...)
push:resize(...)
end |
Fix flamendless#20. Add function arg to customize screen to slab coordinates. Improve interoperability with screen resizing libraries by allowing users to specify a function to transform screen coordinates into game coordinates. For example, with Ulydev/push you could do: local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 800, 600, 1920, 1080 push:setupScreen(game_width, game_height, window_width, window_height) Slab.Initialize(get_push_mouse, args)
Fix flamendless#20. Add function arg to customize screen to slab coordinates. Improve interoperability with screen resizing libraries by allowing users to specify a function to transform screen coordinates into game coordinates. For example, with Ulydev/push you could do: local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 800, 600, 1920, 1080 push:setupScreen(game_width, game_height, window_width, window_height) Slab.Initialize(get_push_mouse, args)
Fix flamendless#20. Add function arg to customize screen to slab coordinates. Improve interoperability with screen resizing libraries by allowing users to specify a function to transform screen coordinates into game coordinates. For example, with Ulydev/push you could do: local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 800, 600, 1920, 1080 push:setupScreen(game_width, game_height, window_width, window_height) Slab.Initialize(get_push_mouse, args)
Fix #20. Add function arg to customize screen to slab coordinates. Improve interoperability with screen resizing libraries by allowing users to specify a function to transform screen coordinates into game coordinates. For example, with Ulydev/push you could do: local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 800, 600, 1920, 1080 push:setupScreen(game_width, game_height, window_width, window_height) Slab.Initialize(get_push_mouse, args) close #80
Fix flamendless#20. Related to flamendless#80. The function arg to customize screen to slab coordinates isn't passed from Slab.Initialize -- it only passes the input table. Usage with push.lua: function love.load(args) local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 320, 240, 1280, 720 push:setupScreen(game_width, game_height, window_width, window_height) args.TransformPointToSlab = get_push_mouse Slab.Initialize(args) end function love.draw() push:start() Slab.Draw() push:finish() end
Fix flamendless#20. Related to flamendless#80. 5fb76d3 changed the order of arguments from flamendless#80, so nothing was ever passed as TransformPointToSlab. Instead, pass it inside the args table that probably jives better with how things are done in slab. The function arg to customize screen to slab coordinates isn't passed from Slab.Initialize -- it only passes the input table. Usage with push.lua: function love.load(args) local function get_push_mouse(x,y) local new_x,new_y = push:toGame(x,y) if new_x and new_y then return new_x,new_y end return x,y end local game_width, game_height, window_width, window_height = 320, 240, 1280, 720 push:setupScreen(game_width, game_height, window_width, window_height) args.TransformPointToSlab = get_push_mouse Slab.Initialize(args) end function love.draw() push:start() Slab.Draw() push:finish() end
Slab looks really great!
Would be nice to work with Ulydev/push or other libraries that mess with resolution. Push lets you assume one resolution and it scales the game to fit the window. It provides a conversion method from screen pixel coordinates to game coordinates (so if your game is 320x240, you'll never get y outside [0,240]).
I can hack it to work by changing this line:
https://github.com/coding-jackalope/Slab/blob/48e027193b43d730933447b6e6b7e97f2d2c47ce/Internal/Input/Mouse.lua#L58
to:
Or I can clobber
love.mouse.getPosition
:But that makes it more difficult to take advantage of push's "outside game screen but inside love window" detection when your game is letterboxed/pillarboxed.
I'm not sure how you'd communicate the latter either since it's not an API call. A wiki page?
How would you prefer to handle interop with libraries?
The text was updated successfully, but these errors were encountered: