[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]  Lua
. . -> [Subject]  Strange behavior with MouseOver function
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Strange behavior with MouseOver function

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


Posted by Zim   (22 posts)  [Biography] bio
Date Sun 07 Feb 2016 12:46 PM (UTC)
Message
I'm writing a plugin right now that has hotspots located on top of different words. I'm trying to make it so when you mouseover one of the hotspots it will add brackets to the word under the hotspot (just to indicate mouseover.) Currently it does do this, however it also duplicates the words lower on the miniwindow.

When iterating over the table that creates the hotspots I use: "m=1" before the ipairs loop and "m=m+1" to keep track of the cycles. If I just use "i" from "for i, v in ipairs(some_table)" then it will work as expected. But I can't do this because in my plugin (this one is just an example) I am using a custom iterator so the order it iterates and the cycle number are different.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, January 28, 2016, 7:40 PM -->
<!-- MuClient version 5.00 -->

<!-- Plugin "test" generated by Plugin Wizard -->

<muclient
<plugin
   name="test"
   author="Zim"
   id="6741be368ebea9880ba5faac">
   language="Lua"
   purpose="testing stuff"
   save_state="y"
   date_written="2016-01-28 19:38:51"
   requires="5.00"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>
<timers>
  <timer name="tic" enabled="y" minute="0" second="1.00" offset_second="0.00"    send_to="12"
>
  <send>  
	update_window()
  </send>

  </timer>
</timers>
<!--  Script  -->


<script>
<![CDATA[
--------------------------------------------------------------------------------
--   ENABLE/DISABLE
--------------------------------------------------------------------------------
function OnPluginEnable ()
	WindowShow (win,  true)
end

function OnPluginDisable()
	WindowShow (win,  false)
end

function OnPluginClose ()
	WindowShow (win,  false)
end
--------------------------------------------------------------------------------
--   MINIWINDOW
--------------------------------------------------------------------------------
function update_window()
	WindowCircleOp (win, 3, 1, 1, window_width - 1, window_height - 1,
        ColourNameToRGB("gray"), 0, 2, ColourNameToRGB("white"), 0, 1, 1) -- frame
	m = 1
	for i, v in ipairs(some_table) do
		WindowText (win, "f", display_with_brackets(i),
            5, 5+m*(5+font_height)-font_height, window_width, 5+m*(5+font_height), ColourNameToRGB("black"), 
            false) -- not Unicode
		WindowAddHotspot(win, "h"..tostring(i),  
               5, 5+m*(5+font_height)-font_height, window_width, 5+m*(5+font_height),   -- rectangle
                 "mouseover",   -- MouseOver
                 "canclemouseover",   -- CancelMouseOver
                 "",
                 "", 
                 "", 
                 "",  -- tooltip text
                 1, 0)  -- hand cursor
	m = m +1
	 end
	WindowShow(win, true)
end
--------------------------------------------------------------------------------
--   ADD BRACKETS TO MOUSEOVER TEXT
--------------------------------------------------------------------------------
function display_with_brackets(index)
	if index == mouseover_spot then
		return "["..some_table[index].."]"
	else
		return some_table[index]
	end
end
--------------------------------------------------------------------------------
--   HOTSPOT HANDLERS
--------------------------------------------------------------------------------
function mouseover(flags, hotspot_id)
	for p = 1, #some_table, 1 do
		if hotspot_id == "h"..tostring(p) then
			mouseover_spot = p
			update_window()
			break
		end
	end
end
function canclemouseover(flags, hotspot_id)
	for p = 1, #some_table, 1 do
		if hotspot_id == "h"..tostring(p) then
			mouseover_spot = false
			update_window()
			break
		end
	end
end
--------------------------------------------------------------------------------
--   START EXECUTION HERE
--------------------------------------------------------------------------------

some_table = {"I", "really", "don't", "know", "why", "this", "does", "this!"}

win = "test" .. GetPluginID ()
WindowCreate (win, 0, 0, 0, 0, miniwin.pos_center_all, 0, ColourNameToRGB("black")) -- load dummy window so we can load fonts

WindowFont (win, "f", "FixedSys", 10, false, false, false, false)
font_height = WindowFontInfo (win, "f", 1)

window_height = 300
window_width = 100

WindowCreate (win, 0, 0, window_width, window_height, miniwin.pos_center_all, 0, ColourNameToRGB("black"))
update_window()

]]>
</script>


</muclient>
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 07 Feb 2016 08:49 PM (UTC)
Message
I don't like the idea of recreating hotspots during a mouse-over. It is likely to remove things from internal tables used by the mouse-over routine (like the current hotspot). I suggest reworking so you don't do that.

- Nick Gammon

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

Posted by Zim   (22 posts)  [Biography] bio
Date Reply #2 on Mon 08 Feb 2016 03:09 AM (UTC)
Message
Nick Gammon said:

I don't like the idea of recreating hotspots during a mouse-over. It is likely to remove things from internal tables used by the mouse-over routine (like the current hotspot). I suggest reworking so you don't do that.


Okay, so I shouldn't be treating hotspots like other drawn entities in the win such as WindowCircleOp? I'm assuming this means that they don't disappear when the window is re-drawn? This would also explain why you have functions to move and delete hotspots.
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 08 Feb 2016 04:05 AM (UTC)
Message
That's right. Hot spots aren't "drawn" so much as a conceptual rectangle inside which interactions occur. The rectangle itself has no visible form.

- Nick Gammon

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

Posted by Zim   (22 posts)  [Biography] bio
Date Reply #4 on Mon 08 Feb 2016 04:53 AM (UTC)
Message
So I created a function called at the beginning of execution before update_widow() named create_hotspots() to create the hotspots. Then whenever I would have recreated hotspots in update_widow() I now just use WindowMoveHotspot(). Works like a charm. Is this the proper way of doing it?
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Mon 08 Feb 2016 06:28 AM (UTC)
Message
Without working my way through the code that handles that, this sounds like a better solution. Moving an existing hotspot is just changing some data in the hotspot definition, which is a different thing from deleting it (possibly while it is active) and then re-making it.

So yes, I think that is much better.

- 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.


2,664 views.

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.

[Home]


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]