[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  WindowAddHotspot()
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?


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

Posted by Baatti   USA  (7 posts)  [Biography] bio
Date Fri 20 Nov 2009 02:16 PM (UTC)

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

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
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 20 Nov 2009 07:22 PM (UTC)
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
[Go to top] 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.


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

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]