I am trying to develop a linking interface between different elements using buttons (click on a button, then click on another button to link them together).
In order to give visual feedback to the user, I would like to draw a line between linked buttons, ideally from center to center.
I had two ideas :
1 - Use the DrawScreen function of the widget and draw a line using coordinates. Two problems : First Chili needs to be defined before my widget (lower layer) and thus the lines appear under my chili window ; second, I do not know how to get the global coordinates of my buttons (they are actually in a window which is in a scroll panel which is in a window, and adding all the coords does not seem to give me the right value).
2 - Create a custom Control as child of my scroll panel and use a custom DrawControl to draw lines between linked buttons. I tried to do as stated hereviewtopic.php?t=26858 but did not manage to get the desired results (nothing seems to appear on my screen).
Here is the piece of code I tried to write :
Code: Select all
local function drawLinks()
for k, out in pairs(Links) do
if k == "begin" and out then
local x1, x2, y1, y2 = 0, 0, 0, 0
-- UI.Scenario.Output.Begin is the button
-- UI.Scenario.Begin is the parent window of the button
x1 = UI.Scenario.Output.Begin.x + UI.Scenario.Begin.x
y1 = UI.Scenario.Output.Begin.y + UI.Scenario.Begin.y
-- same
x2 = UI.Scenario.Input[out].x + UI.Scenario.Levels[out].x
y2 = UI.Scenario.Input[out].y + UI.Scenario.Levels[out].y
gl.Vertex(x1, y1)
gl.Vertex(x2, y2)
else
for kk, linked in pairs(out) do
-- TODO
end
end
end
end
UI.Scenario.Links = Chili.Control:New{
parent = UI.Scenario.ScenarioScrollPanel,
x = '0%',
y = '0%',
width = '100%',
height = '100%',
DrawControl = function(obj)
local x = obj.x
local y = obj.y
local w = obj.width
local h = obj.height
gl.Color(1, 1, 1, 1)
gl.PushMatrix()
gl.Translate(x, y, 0)
gl.Scale(w, h, 1)
gl.BeginEnd(GL.LINES, drawLinks)
gl.PopMatrix()
end
}
Thank you in advance !