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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  New module to simplify moving miniwindows around by dragging them

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: New module to simplify moving miniwindows around by dragging them
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 04 May 2010 06:13 AM (UTC)  quote  ]
Message
See http://www.gammon.com.au/forum/?id=9965&page=2 in which I added the dragging code to the inventory alias (it got turned into a plugin so that the dragging would work properly).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tiredchris   (17 posts)  [Biography] bio
Date Mon 03 May 2010 11:11 PM (UTC)  quote  ]
Message
I'm at a complete loss as to how to use this to move a miniwindow. Well where to put any of the code really. I'm just getting into mini-windows and some of this just looks...well hard. Could someone do youtoube video on how to set this up beginning to end with the inventory mini-window thread? I just got that one down, so a demonstration would go a long way for helping me :)
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 03:33 AM (UTC)  quote  ]
Message
Added to next release, commit e3bebba.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 03:02 AM (UTC)  quote  ]
Message

@@ -104,10 +104,17 @@
     
     -- 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
 
 -- make a mouse drag-move handler with the movement information as an upvalue
@@ -123,10 +130,17 @@
                        WindowInfo (win, 18) - mwi.starty
   
     -- move the window to the new location - offset by how far mouse was into window
     WindowPosition(win, posx, posy, 0, 2);
     
+    -- move the friends if they still exist
+    for i,v in ipairs(mwi.window_friends) do
+        if (v ~= nil) then
+            WindowPosition(v, posx+mwi.window_friend_deltas[i][1], posy+mwi.window_friend_deltas[i][2], 0, WindowInfo(v, 8))
+        end -- if
+    end -- for
+
     -- change the mouse cursor shape appropriately
     if posx < mwi.margin - WindowInfo (win, 3) or 
        posx > GetInfo (281) - mwi.margin or
        posy < 0 or   -- don't drag title out of view
        posy > GetInfo (280) - mwi.margin then
@@ -212,29 +226,33 @@
 end -- make_check_map_position_handler
 
 -- call movewindow.install in OnPluginInstall to find the position of the window, before creating it
 --  - it also creates the handler functions ready for use later
 
-function movewindow.install (win, default_position, default_flags, nocheck)
+function movewindow.install (win, default_position, default_flags, nocheck, default_friends)
 
   win = win or GetPluginID ()  -- default to current plugin ID
   
   assert (not string.match (win, "[^A-Za-z0-9_]"), "Invalid window name in movewindow.install: " .. win)
   
   default_position = default_position or 7 -- on right, center top/bottom
   default_flags = default_flags or 0
+  if (default_friends == nil) then
+    default_friends = {}
+  end
   
   -- set up handlers and where window should be shown (from saved state, if any)
   local movewindow_info = {
      win = win,   -- save window ID
      
      -- save current position in table (obtained from state file)
      window_left  = tonumber (GetVariable ("mw_" .. win .. "_windowx")) or 0,
      window_top   = tonumber (GetVariable ("mw_" .. win .. "_windowy")) or 0,
      window_mode  = tonumber (GetVariable ("mw_" .. win .. "_windowmode")) or default_position,
      window_flags = tonumber (GetVariable ("mw_" .. win .. "_windowflags")) or default_flags,
-     
+     window_friends = default_friends,
+     window_friend_deltas = {},
      margin = 20  -- how close we can put to the edge of the window
     }
 
     -- handler to reposition window
     movewindow_info.check_map_position = make_check_map_position_handler (movewindow_info)  -- for startup

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 02:56 AM (UTC)  quote  ]

Amended on Wed 07 Apr 2010 02:57 AM (UTC) by Nick Gammon

Message
My diffs aren't working properly.

Can you post the diffs, but before putting them into the code tags, just go to MUSHclient's Edit menu -> Convert Clipboard Forum Codes. That will fix up the clipboard to be correct to paste here.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 02:43 AM (UTC)  quote  ]
Message
Here, how about this. :)

http://ilikepants.pastebin.com/deyK9YXn

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 02:39 AM (UTC)  quote  ]
Message
The whole module or just the diff?

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 02:37 AM (UTC)  quote  ]
Message
OK can you repost with the square brackets escaped as I described (use MUSHclient to do that) and I'll merge it in.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 02:36 AM (UTC)  quote  ]
Message
It seems to work. Except I changed.


WindowPosition(v, posx+mwi.window_friend_deltas[j][1], posy+mwi.window_friend_deltas[j][2], 0, 2)


to


WindowPosition(v, posx+mwi.window_friend_deltas[j][1], posy+mwi.window_friend_deltas[j][2], 0, WindowInfo(v, 8))

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 02:33 AM (UTC)  quote  ]
Message
And does the code seem to work?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 02:33 AM (UTC)  quote  ]
Message
Looks OK. Personally I prefer:


 if v then


to:


 if (v ~= nil) then


Can you repost with forum codes escaped?

Template:post=9691 Please see the forum thread: http://gammon.com.au/forum/?id=9691.


If you don't there is a chance backslashes or things like [i] won't come out as you expect.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 02:13 AM (UTC)  quote  ]
Message
Oh for crying out loud...4th try at posting this. :)

Nick, I'd like your opinion on...

@@ -104,10 +104,17 @@
     
     -- 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 j,v in ipairs(mwi.window_friends) do
+        if (v ~= nil) then
+            mwi.window_friend_deltas[j] = {WindowInfo(v, 10) - mwi.origx, WindowInfo(v, 11) - mwi.origy}
+        end -- if
+    end -- for
+        
   end -- mousedown
 
 end -- make_mousedown_handler
 
 -- make a mouse drag-move handler with the movement information as an upvalue
@@ -123,10 +130,17 @@
                        WindowInfo (win, 18) - mwi.starty
   
     -- move the window to the new location - offset by how far mouse was into window
     WindowPosition(win, posx, posy, 0, 2);
     
+    -- move the friends if they still exist
+    for j,v in ipairs(mwi.window_friends) do
+        if (v ~= nil) then
+            WindowPosition(v, posx+mwi.window_friend_deltas[j][1], posy+mwi.window_friend_deltas[j][2], 0, 2)
+        end -- if
+    end -- for
+
     -- change the mouse cursor shape appropriately
     if posx < mwi.margin - WindowInfo (win, 3) or 
        posx > GetInfo (281) - mwi.margin or
        posy < 0 or   -- don't drag title out of view
        posy > GetInfo (280) - mwi.margin then
@@ -212,29 +226,33 @@
 end -- make_check_map_position_handler
 
 -- call movewindow.install in OnPluginInstall to find the position of the window, before creating it
 --  - it also creates the handler functions ready for use later
 
-function movewindow.install (win, default_position, default_flags, nocheck)
+function movewindow.install (win, default_position, default_flags, nocheck, default_friends)
 
   win = win or GetPluginID ()  -- default to current plugin ID
   
   assert (not string.match (win, "[^A-Za-z0-9_]"), "Invalid window name in movewindow.install: " .. win)
   
   default_position = default_position or 7 -- on right, center top/bottom
   default_flags = default_flags or 0
+  if (default_friends == nil) then
+    default_friends = {}
+  end
   
   -- set up handlers and where window should be shown (from saved state, if any)
   local movewindow_info = {
      win = win,   -- save window ID
      
      -- save current position in table (obtained from state file)
      window_left  = tonumber (GetVariable ("mw_" .. win .. "_windowx")) or 0,
      window_top   = tonumber (GetVariable ("mw_" .. win .. "_windowy")) or 0,
      window_mode  = tonumber (GetVariable ("mw_" .. win .. "_windowmode")) or default_position,
      window_flags = tonumber (GetVariable ("mw_" .. win .. "_windowflags")) or default_flags,
-     
+     window_friends = default_friends,
+     window_friend_deltas = {},
      margin = 20  -- how close we can put to the edge of the window
     }
 
     -- handler to reposition window
     movewindow_info.check_map_position = make_check_map_position_handler (movewindow_info)  -- for startup

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 07 Apr 2010 01:06 AM (UTC)  quote  ]
Message
Fiendish said:

I'd like to lobby for an amendment to .install that takes another parameter to optionally disable the call to
DoAfterSpecial (5, "mw_" .. win .. "_movewindow_info.check_map_position ()" , sendto.script)


I like the simplicity of the drag module, but that line seems to do more harm than good for me.


Added a parameter to do that. New commit 9e32881.

http://github.com/nickgammon/mushclient/blob/master/lua/movewindow.lua

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 12:25 AM (UTC)  quote  ]
Message
Also, the ability to pass in a list of other miniwindows to be synchronously moved by the same amount would be awesome.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 07 Apr 2010 12:05 AM (UTC)  quote  ]
Message
I'd like to lobby for an amendment to .install that takes another parameter to optionally disable the call to
DoAfterSpecial (5, "mw_" .. win .. "_movewindow_info.check_map_position ()" , sendto.script)


I like the simplicity of the drag module, but that line seems to do more harm than good for me.

http://aardwolfclientpackage.googlecode.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.


5,165 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]