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
➜ Suggestions
➜ WindowAddHotSpot suggestion
|
WindowAddHotSpot suggestion
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Bast
(78 posts) Bio
|
| Date
| Thu 15 Jul 2010 03:33 AM (UTC) |
| Message
| Instead of passing function names in WindowAddHotSpot, can we actually pass a true function? The whole keeping up with ids in a table and then having generic mouse functions that check this table seems complicated. Doubly complicated when you start trying to keep up with hotspots from multiple miniwindows in the same plugin.
In lua
function somefunction (flags, hotspotid)
print("help")
end
-- New way
WindowAddHotspot(winid, winid .. ':' .. 'test',
left, top, right, bottom,
nil, -- mouseover
nil, -- cancelmouseover
nil, -- mousedown
nil, -- cancelmousedown
somefunction, -- mouseup
hint,
cursor, 0)
I don't know how hard this would be, but somewhere MUSHclient has to look up the function from the string anyway, so can we cut out the middle man?
Thanks,
Bast |
Bast
Scripts: http://github.com/endavis | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 15 Jul 2010 04:11 AM (UTC) |
| Message
| It's all very well in Lua, but the miniwindows functions are supposed to be language-neutral. I'm not sure, for example, how I might store a Python function internally in the C++ data structures.
However what you can do is use a function-generating function (with upvalues) to pass a single function and have the upvalue remember who it belongs to.
For example, in movewindow.lua there is a function make_mousedown_handler that makes a function for such a purpose. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Thu 15 Jul 2010 05:25 AM (UTC) Amended on Thu 15 Jul 2010 05:26 AM (UTC) by Nick Gammon
|
| Message
| Here's the whole function, you note that once it generates the mouse-down function, that function knows its miniwindow (you could save other stuff as well):
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)
-- find where the friends are relative to the window
for i,v in ipairs(mwi.window_friends) do
if (v ~= nil) then
mwi.window_friend_deltas[i] = {WindowInfo(v, 10) - mwi.origx, WindowInfo(v, 11) - mwi.origy}
end -- if
end -- for
end -- mousedown
end -- make_mousedown_handler
And here is how you add the hotspot:
-- mouse handlers
movewindow_info.mousedown = make_mousedown_handler (movewindow_info)
...
-- 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
Since handler functions can have dots in their names, you can store them all in some intermediate table, rather than polluting global namespace with them.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Bast
(78 posts) Bio
|
| Date
| Reply #3 on Thu 15 Jul 2010 02:15 PM (UTC) |
| Message
| Yeah, I figured it wouldn't be as easy as I wanted it to be and I already do something similar to your example in my miniwindows. I was curious if it was a limitation of the scripting languages.
Thanks again,
Bast |
Bast
Scripts: http://github.com/endavis | | 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.
15,624 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top