Page 26 of 41

Re: Löve Frames - A GUI Library

Posted: Mon Dec 01, 2014 6:00 am
by Rishavs
The buttons are getting rendered but the click event is not firing.

Re: Löve Frames - A GUI Library

Posted: Tue Dec 02, 2014 4:40 pm
by LaggyNewbie
I have a game that does some deserializing of data using a serialize.lua library found on the forums.

With a os.clock() taken before and after running 1 deserialize() operation, the time is about .001 seconds.

Just by adding:

require("libs.loveframes")

and not even adding the update or draw events required by loveframes, the same deserialize() function process jumps to taking .7 seconds to complete.

Any idea why just including a require to loveframes makes my deserialize() operation increase by a couple orders of magnitude?

Re: Löve Frames - A GUI Library

Posted: Tue Dec 02, 2014 11:27 pm
by Nikolai Resokav
Rishavs wrote:The buttons are getting rendered but the click event is not firing.
Can you post a .love of your project?
LaggyNewbie wrote:I have a game that does some deserializing of data using a serialize.lua library found on the forums.

With a os.clock() taken before and after running 1 deserialize() operation, the time is about .001 seconds.

Just by adding:

require("libs.loveframes")

and not even adding the update or draw events required by loveframes, the same deserialize() function process jumps to taking .7 seconds to complete.

Any idea why just including a require to loveframes makes my deserialize() operation increase by a couple orders of magnitude?
Love Frames performs several tasks when you require it, and I haven't really taken the time to optimize any of them.

Re: Löve Frames - A GUI Library

Posted: Wed Dec 03, 2014 8:21 pm
by LaggyNewbie
I think I figured out the problem. There were global variable names being shared by both libraries (specifically the utf8.lua file) but not throwing any errors. I ended up changing the serialize library to Tserial.lua which doesn't appear to have any naming conflicts with the love frame library

Re: Löve Frames - A GUI Library

Posted: Sat Dec 06, 2014 9:32 pm
by Ford_Prefect
I have the same problem as Rishavs - the .OnClick callback for buttons does not work.

Here's my code (relevant parts on top):

Code: Select all

function love.load()
	require("lib.Frames")
	
	button_circles = loveframes.Create("button")
	button_circles:SetWidth(200)
	button_circles:SetText("Toggle Lines")
	button_circles.x = 20
	button_circles.y = 20
	
	circles = false
		
	button_circles.OnClick = function ()
		circles = not circles
		button_circles:SetText("test")
	end

	love.window.setMode(1280, 800)
	math.randomseed(os.time())
	math.random(); math.random(); math.random()
	
	planet = {}
	t = 0
	
	--planets
	planet.number = math.random(10)
	sun = {}
	sun.radius = math.random(30, 50)
	sun.x = 1280/2
	sun.y = 800/2
	
	for i = 1, planet.number do
		planet[i] = {}
		planet[i].radius = math.random(5, sun.radius * 0.5)
		if i == 1 then
			planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100)
		else
			planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75)
		end
		
		planet[i].T = math.pow(planet[i].distance, 3/2) * 10
		planet[i].t = t + math.random(100000)
		
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T)
	end
	
	
	
end

function love.update()	
	for i = 1, planet.number do
		planet[i].t = planet[i].t + 1
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T)
	end
	
	loveframes.update()
end

function love.draw()
	love.graphics.circle("fill", sun.x, sun.y, sun.radius)
	for i = 1, planet.number do
		love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius)
		if circles then
			love.graphics.circle("line", sun.x, sun.y, planet[i].distance)
		end
	end
	loveframes.draw()
end
It works flawlessly if I use .OnMouseEnter instead. It also works flawlessly in another older project, where I have _exactly_ the same syntax (and the libs were copied over from there).

I'll attach the .love

Re: Löve Frames - A GUI Library

Posted: Sat Dec 06, 2014 10:12 pm
by Nikolai Resokav
Ford_Prefect wrote:I have the same problem as Rishavs - the .OnClick callback for buttons does not work.

Here's my code (relevant parts on top):

Code: Select all

function love.load()
	require("lib.Frames")
	
	button_circles = loveframes.Create("button")
	button_circles:SetWidth(200)
	button_circles:SetText("Toggle Lines")
	button_circles.x = 20
	button_circles.y = 20
	
	circles = false
		
	button_circles.OnClick = function ()
		circles = not circles
		button_circles:SetText("test")
	end

	love.window.setMode(1280, 800)
	math.randomseed(os.time())
	math.random(); math.random(); math.random()
	
	planet = {}
	t = 0
	
	--planets
	planet.number = math.random(10)
	sun = {}
	sun.radius = math.random(30, 50)
	sun.x = 1280/2
	sun.y = 800/2
	
	for i = 1, planet.number do
		planet[i] = {}
		planet[i].radius = math.random(5, sun.radius * 0.5)
		if i == 1 then
			planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100)
		else
			planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75)
		end
		
		planet[i].T = math.pow(planet[i].distance, 3/2) * 10
		planet[i].t = t + math.random(100000)
		
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T)
	end
	
	
	
end

function love.update()	
	for i = 1, planet.number do
		planet[i].t = planet[i].t + 1
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T)
	end
	
	loveframes.update()
end

function love.draw()
	love.graphics.circle("fill", sun.x, sun.y, sun.radius)
	for i = 1, planet.number do
		love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius)
		if circles then
			love.graphics.circle("line", sun.x, sun.y, planet[i].distance)
		end
	end
	loveframes.draw()
end
It works flawlessly if I use .OnMouseEnter instead. It also works flawlessly in another older project, where I have _exactly_ the same syntax (and the libs were copied over from there).

I'll attach the .love
You need to add the mousepressed and mousereleased callbacks:

Code: Select all

function love.mousepressed(x, y, button)

	loveframes.mousepressed(x, y, button)
	
end

function love.mousereleased(x, y, button)

	loveframes.mousereleased(x, y, button)
	
end

Re: Löve Frames - A GUI Library

Posted: Sat Dec 06, 2014 10:20 pm
by Ford_Prefect
Nikolai Resokav wrote:
Ford_Prefect wrote:I have the same problem as Rishavs - the .OnClick callback for buttons does not work.

Here's my code (relevant parts on top):

Code: Select all

function love.load()
	require("lib.Frames")
	
	button_circles = loveframes.Create("button")
	button_circles:SetWidth(200)
	button_circles:SetText("Toggle Lines")
	button_circles.x = 20
	button_circles.y = 20
	
	circles = false
		
	button_circles.OnClick = function ()
		circles = not circles
		button_circles:SetText("test")
	end

	love.window.setMode(1280, 800)
	math.randomseed(os.time())
	math.random(); math.random(); math.random()
	
	planet = {}
	t = 0
	
	--planets
	planet.number = math.random(10)
	sun = {}
	sun.radius = math.random(30, 50)
	sun.x = 1280/2
	sun.y = 800/2
	
	for i = 1, planet.number do
		planet[i] = {}
		planet[i].radius = math.random(5, sun.radius * 0.5)
		if i == 1 then
			planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100)
		else
			planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75)
		end
		
		planet[i].T = math.pow(planet[i].distance, 3/2) * 10
		planet[i].t = t + math.random(100000)
		
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T)
	end
	
	
	
end

function love.update()	
	for i = 1, planet.number do
		planet[i].t = planet[i].t + 1
		planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T)
		planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T)
	end
	
	loveframes.update()
end

function love.draw()
	love.graphics.circle("fill", sun.x, sun.y, sun.radius)
	for i = 1, planet.number do
		love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius)
		if circles then
			love.graphics.circle("line", sun.x, sun.y, planet[i].distance)
		end
	end
	loveframes.draw()
end
It works flawlessly if I use .OnMouseEnter instead. It also works flawlessly in another older project, where I have _exactly_ the same syntax (and the libs were copied over from there).

I'll attach the .love
You need to add the mousepressed and mousereleased callbacks:

Code: Select all

function love.mousepressed(x, y, button)

	loveframes.mousepressed(x, y, button)
	
end

function love.mousereleased(x, y, button)

	loveframes.mousereleased(x, y, button)
	
end
Many thanks. Much appreciated. Me fail.

edit: While I'm at it, I have another question.
If I create slider and set it's default value, how do I get the slider to actually be at the corresponding point for that value? It's always stuck to the very left (horizontal slider) for me.

Re: Löve Frames - A GUI Library

Posted: Wed Dec 10, 2014 6:03 pm
by Doctory
is it possible to rename love frames when requiring it?

Re: Löve Frames - A GUI Library

Posted: Wed Dec 10, 2014 10:56 pm
by Nikolai Resokav
Doctory wrote:is it possible to rename love frames when requiring it?
Love Frames is returned when you require it, so something like this should work:

Code: Select all

gui = require("path.to.loveframes")

Re: Löve Frames - A GUI Library

Posted: Fri Dec 12, 2014 7:55 pm
by fmra
I'm trying to retrieve the name of an object using GetHoverObject, but having iterated through the table it returns, the names I gave the objects do not exist. Closest I get is "instance of class loveframes_object_imagebutton" or similar. I'm trying to retrieve the name to match it against a table value (the objects name). See "obj[x]"

Code: Select all

if loveframes.util.GetHoverObject() then
  obj = loveframes.util.GetHoverObject()
  for k, v in ipairs(tbl) do
    if obj[x] == v then
      ...
    end
  end
end