Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ WindowAddHotspot()

WindowAddHotspot()

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Baatti   USA  (7 posts)  Bio
Date Fri 20 Nov 2009 02:16 PM (UTC)

Amended on Fri 20 Nov 2009 05:40 PM (UTC) by Baatti

Message
Hey Nick and everyone.

I would like to STRONGLY request that WindowAddHotspot() have a make-over. The parameters regarding Mouse actions can only be strings representing function names and can not take parameters. Although there are ways to work around that, it is a serious draw back.

Thank you for taking the time to read this and I hope that this issue will be fixed.


[edit]: to be more clear, I wish that there was a way to pass FUNCTIONS instead of STRINGS, I understand that passing parameters is not necessary, but to have the ability to pass a FUNCTION instead of a STRING representing a function would be nice. Although Twisol explained to me why this isn't likely to be possible as there are multiple scripting languages at question and they all handle things differently. Still, if its do-able, that'd be nice
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 20 Nov 2009 07:22 PM (UTC)
Message
There would be no language-neutral way of passing functions as a call to other functions.

However it can be achieved to pass other arguments to hotspot functions, particularly if you are using Lua, as recommended.

In the file movewindow.lua which ships with MUSHclient there are examples of this. Here is one:


-- make a mouse-down handler with the movement information as an upvalue

local function make_mousedown_handler (mwi)

  return function (flags, hotspot_id)

    local win = mwi.win
    
    -- find where mouse is so we can adjust window relative to mouse
    mwi.startx = WindowInfo (win, 14)
    mwi.starty = WindowInfo (win, 15)
    
    -- find where window is in case we drag it offscreen
    mwi.origx = WindowInfo (win, 10) 
    mwi.origy = WindowInfo (win, 11)
    
  end -- mousedown

end -- make_mousedown_handler


What this does is make a hotspot handler (which normally only takes flags and hotspot ID), and adds another parameter, the mwi field (which is actually a table of other parameters such as where the window is).

By using a function-making function this extra parameter is stored as an upvalue to the function, making it available when the function is called, as you can see above.

Now all you have to do is give the returned function (the one with the upvalue) a name which doesn't clash with other functions, and each miniwindow can have its own hotspot handler with extra arguments. eg


   -- mouse handlers
    movewindow_info.mousedown   = make_mousedown_handler   (movewindow_info)  
    movewindow_info.dragmove    = make_dragmove_handler    (movewindow_info)
    movewindow_info.dragrelease = make_dragrelease_handler (movewindow_info)
 
  -- save table in global namespace
  _G ["mw_" .. win .. "_movewindow_info"] = movewindow_info
    

-- and later ...

 -- make a hotspot
  WindowAddHotspot(win, hotspot_id,  
                   left or 0, top or 0, right or 0, bottom or 0,   -- rectangle
                   "",   -- MouseOver
                   "",   -- CancelMouseOver
                   "mw_" .. win .. "_movewindow_info.mousedown",  -- MouseDown
                   "",   -- CancelMouseDown
                   "",   -- MouseUp
                   "Drag to move window",  -- tooltip text
                   cursor or 1, -- cursor
                   0)  -- flags


You will note that function names can have dots in them, so the function you pass can actually be an element in a table.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,393 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.