Get mouse position/Get mouse control

Get mouse position/Get mouse control

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Get mouse position/Get mouse control

Post by gajop »

What I want: Be able to read current mouse position in one of my drawing functions (called from DrawWorld).
Now, I'm only supposed to be drawing that if my widget is in a certain state, but that state is triggered by pressing on a chili button, therefor I cannot do a "return true" in MousePress to get mouse control, because it never gets called.

So I'm looking for a way to either get current mouse positions in an arbitrary function (that isn't a Mouse* call-in) or for a way to gain mouse control from an arbitrary function so my MouseDraw would be called.

Sample of what I want to do:

Code: Select all

function widget:DrawWorld()
  if internalState == "drawUnit" then
    -- not even sure if this is a way to draw a unit, but whatevs
    gl.PushMatrix()
    -- these unitDraw_* variables should be either set in a MouseDraw or fetched by some unsynced read...
    gl.Translate(unitDraw_x, unitDraw_y, unitDraw_z)
    gl.UnitShape(selUnitDef, teamId)
    gl.PopMatrix()
  end
end

-- and somewhere I have a chili button
function widget:initialize()
  window = Chili.Window:New {
     parent = screen0,
     children = { 
        Chili.Button:New {
           caption = "clicky",
           OnClick = {
             function()
               internalState = "drawUnit"
             end
           }
        }
     }
  }
end
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Get mouse position/Get mouse control

Post by gajop »

:oops:
Post Reply

Return to “Lua Scripts”