Lua and Gui's
Gui's at the moment seem to be all the rage on the Leadwerks forum. We have the recent release of the noesisGUI, Patrik's showing of his gui's progress, and tjheldna's release of tjui and probaly many others. I also decided to try my hand at gui creation.
Coming from a BASIC background (started with qb 1.0), I don't have the proper skills to use a third party gui without malloc errors or segfaulting everything. That, and my game is a lua game. Taking inspiration from Tjhldna's gui I started off making something similar in pure lua.
After 2 days I managed to create a window manager and the windows themselves.
It's a good start but a lot of things still need to be worked out.
!!ANIMATED, CLICK TO VIEW!!
Frontfacing code to make the demo:
function Script:Start()
-- Load Module
lwgui = require "/scripts/lwgui"
--Create Window Manger
self.windowmanager = lwgui.WindowManager()
--Create Windows
self.window1 = lwgui.Window(200,200,300,300,windowcallback) -- window1 callback
self.window2 = lwgui.Window(280,200,300,300)
self.window3 = lwgui.Window(480,180,300,300)
-- make the window see through
--self.window.SetTransparancy(100)
self.window2.SetTransparancy(100)
--self.window3.SetTransparancy(100)
--self.window.SetCallback(windowcallback) -- you can manually set a callback
self.window1.SetTitle("Einlanders' Leadwerks Gui Window")
self.window2.SetTitle("Einlanders' Leadwerks Gui WIndow 2")
self.window3.SetTitle("Einlanders' Leadwerks Gui WIndow 2")
-- set window color
self.window2.SetWindowBodyColor({0,0,255})
self.window3.SetWindowBodyColor({0,30,0})
--Add Window To Window Manager
self.windowmanager:AddWindow(self.window2)-- type checked
self.windowmanager:AddWindow(self.window1)-- type checked
self.windowmanager:AddWindow(self.window3)-- type checked
--self.window.testwm()
end
function Script:UpdateWorld()
-- update title
self.window1.SetTitle(self.window1.GetX()..":"..self.window1.GetY().." Einlanders' Leadwerks Gui Window:"..self.window1.GetDepth())
self.window2.SetTitle(self.window2.GetX()..":"..self.window2.GetY().." Einlanders' Leadwerks Gui WIndow 2:"..self.window2.GetDepth())
self.window3.SetTitle(self.window3.GetX()..":"..self.window3.GetY().." Einlanders' Leadwerks Gui WIndow 2:"..self.window3.GetDepth())
local window = Window:GetCurrent()
-- remove a window
if window:KeyHit(Key.Q) then
self.windowmanager:RemoveWindow(self.window1)-- type checked
self.window1 = nil
collectgarbage()
end
end
--This function will be called after the world is rendered, before the screen is refreshed.
--Use this to perform any 2D drawing you want the entity to display.
function Script:PostRender(context)
--process all logic inside the windows and window manager
self.windowmanager.Process()
-- Render all windows
self.windowmanager.Render()
end
function windowcallback(e) -- window 1 callback
System:Print(e[1])
end
-
7
5 Comments
Recommended Comments