initial imgui integration

This commit is contained in:
Jeremy Penner 2020-10-16 09:17:10 -04:00
parent 750fffe015
commit a761ed8d5a
2 changed files with 46 additions and 32 deletions

46
editor/imview.lua Normal file
View file

@ -0,0 +1,46 @@
local imgui = require("imgui")
local enqueue_love_event = system.enqueue_love_event
function system.enqueue_love_event(ev, a, b, c, d, e, f)
local keyevents = {
textinput = function() imgui.TextInput(a) end,
keypressed = function() imgui.KeyPressed(a) end,
keyreleased = function() imgui.KeyReleased(a) end,
}
local mouseevents = {
mousemoved = function() imgui.MouseMoved(a, b) end,
mousepressed = function() imgui.MousePressed(c) end,
mousereleased = function() imgui.MouseReleased(c) end,
wheelmoved = function() imgui.WheelMoved(b) end
}
local pass_event_to_lite = true
if keyevents[ev] then
keyevents[ev]()
pass_event_to_lite = not imgui.GetWantCaptureKeyboard()
elseif mouseevents[ev] then
mouseevents[ev]()
pass_event_to_lite = not imgui.GetWantCaptureMouse()
elseif ev == 'quit' then
imgui.ShutDown()
end
if pass_event_to_lite then enqueue_love_event(ev, a, b, c, d, e, f) end
end
local View = require("core.view")
local ImView = View:extend()
function ImView.gui(self)
end
function ImView.draw(self)
imgui.NewFrame()
imgui.SetNextWindowPos(self.position.x, self.position.y, "Always")
imgui.SetNextWindowSize(self.size.x, self.size.y, "Always")
imgui.Begin(self:get_name(), nil, { "NoTitleBar", "NoResize", "NoMove", "NoCollapse" })
self:gui()
imgui.End()
imgui.EndFrame()
imgui.Render()
end
return ImView

View file

@ -70,36 +70,4 @@
"alt+l" "honeylisp:reload"
})
(fn love.load [])
(fn love.update [dt]
(imgui.NewFrame))
(fn love.draw []
(imgui.Render))
(fn love.quit []
(imgui.ShutDown))
(fn love.textinput [t]
(imgui.TextInput t))
(fn love.keypressed [key]
(imgui.KeyPressed key))
(fn love.keyreleased [key]
(imgui.KeyReleased key))
(fn love.mousemoved [x y]
(imgui.MouseMoved x y))
(fn love.mousepressed [x y button]
(imgui.MousePressed button))
(fn love.mousereleased [x y button]
(imgui.MouseReleased button))
(fn love.wheelmoved [x y]
(imgui.WheelMoved y))
{}