Nick's Hyperlink code that was made for another user on this forum

Posted by Wuggly on Tue 08 Mar 2016 04:56 AM — 7 posts, 28,699 views.

USA #0
I'm referring to the one in this link.
http://www.gammon.com.au/forum/?id=12868&reply=7#reply7
I'll post the code in next post to save ya bit of time.

After you mouseover, the colour becomes richer.

I've tried writing black text over it before it returns and redraws the text, tried drawing a black rectangle, among a few other things trying to keep it from doing that, but with no success.

It's almost as if it is turning the text bold, but not quite.

Yellow seems to be the only colour where it's not quite as noticeable, but I'm wanting to use a different colour.

If you make the text white, keeping the mouseover blue, after you mouseover the white text has a blue haze to it and if you make the mouseover colour red, after you mouseover it has a red haze to it.

Any idea's on how to fix this little issue?

EDIT: I'm using v4.94 and although that plugin says it requires v4.97, I updated to that version and the issue still exists.
Amended on Tue 08 Mar 2016 05:16 AM by Wuggly
USA #1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="KillArea"
   author="Quit"
   id="1257642da6518030a25c93c4"
   language="Lua"
   purpose="List Area to level in"
   date_written="2015-05-03 20:32:36"
   requires="4.97"
   version="1.0"
   save_state="y"
   >

</plugin>

<aliases>
  <alias
   match="killlist"
   enabled="y"
   send_to="12"
   sequence="100"
  >

<send>
 
  WindowShow (win, true)

</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[

require "movewindow"  -- load the movewindow.lua module

win = GetPluginID () .. "_KillArea"
font = "f"

-----------------------------------------
-- one entry for each hyperlink you want drawn
-----------------------------------------
links = {
 { text = "Jungles of Verume", tip = "Goto Jungle of Verume", send = "mapper goto 30599" },
 { text = "Seven Wonders",     tip = "Goto Seven Wonders",    send = "mapper goto 32981" },

-- more here ...

 } -- end of links table

-----------------------------------------
-- draw hyperlink text in required colour
-----------------------------------------
function drawText (which, colour)
  Redraw ()
  return WindowText (win, font, which.text, which.x, which.y, 0, 0, ColourNameToRGB  (colour))
end -- drawText
 
-----------------------------------------
-- mouse up
-----------------------------------------
function mouseup_hyperlink (flags, hotspotid)
  Send (links [tonumber (hotspotid)].send)  
end -- mouseup_hyperlink

-----------------------------------------
-- mouse over
-----------------------------------------
function mouseover_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "blue")
end -- mouseover_hyperlink

-----------------------------------------
-- cancel mouse over
-----------------------------------------
function cancel_mouseover_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "yellow")
end -- cancel_mouseover_hyperlink

-----------------------------------------
-- mouse down
-----------------------------------------
function mousedown_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "white")
end -- mousedown_hyperlink

-----------------------------------------
-- cancel mouse down
-----------------------------------------
function cancel_mousedown_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "yellow")
end -- cancel_mousedown_hyperlink

-----------------------------------------
-- make one hyperlink at current x,y location
-----------------------------------------
function MakeHyperlink (item, which)
 
  -- remember current x and y in the links table
  which.x = x
  which.y = y
 
  width = drawText (which, "yellow")
 
  WindowAddHotspot (win, item, which.x, which.y, which.x + width, which.y + font_height, 
                    "mouseover_hyperlink", -- MouseOver 
                    "cancel_mouseover_hyperlink", -- CancelMouseOver 
                    "mousedown_hyperlink", -- MouseDown 
                    "cancel_mousedown_hyperlink", -- CancelMouseDown 
                    "mouseup_hyperlink", -- MouseUp 
                    which.tip, 
                    miniwin.cursor_hand,
                    0) --  Flag

  y = y + font_height

end -- MakeHyperlink

function OnPluginInstall ()
  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, miniwin.pos_top_right)  -- default to top right
  
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, miniwin.pos_top_right, 0, 0)
  
  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  
  
  -- find its height
  font_height = WindowFontInfo (win, font, 1)  -- height

  -- position for first hyperlink  
  x = 10    -- all text indented this far in
  y = 25    -- first hyperlink this far down
                 
  maxTextWidth = 0
  
  -- find maximum width 
  for k, v in ipairs (links) do
    maxTextWidth = math.max (maxTextWidth, WindowTextWidth(win, font, v.text))
  end -- for
  
  -- make the proper window
  WindowCreate (win, 
               windowinfo.window_left, 
               windowinfo.window_top, 
               maxTextWidth + (x * 2), 
               y + (#links * font_height) + 5,
               windowinfo.window_mode,   
               windowinfo.window_flags,
               ColourNameToRGB "black")

  -- title background
  WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, font_height + 5, ColourNameToRGB "gray", 0)
  
                 
  -- draw a border
  WindowRectOp (win, miniwin.rect_draw_edge, 0, 0, 0, 0, 
                miniwin.rect_edge_raised, 
                miniwin.rect_edge_at_all + miniwin.rect_option_softer_buttons) -- draw border
  
  movewindow.add_drag_handler (win, 0, 0, 0, font_height) -- add the drag handler

  -- first line
  WindowText (win, font, "Kill Areas", x, 5, 0, 0, ColourNameToRGB  "gainsboro")

  -- add all hyperlinks  
  for k, v in ipairs (links) do
    MakeHyperlink (k, v)
  end -- for
       
end -- OnPluginInstall

function OnPluginSaveState ()
  -- save window current location for next time  
  movewindow.save_state (win)
end -- function OnPluginSaveState

]]>
</script>

</muclient>
USA Global Moderator #2
I don't see what you're describing. Can you show a picture or something of what you see?

Also you need to change this

function mouseup_hyperlink (flags, hotspotid)
  Send (links [tonumber (hotspotid)].send)  
end -- mouseup_hyperlink

into this

function mouseup_hyperlink (flags, hotspotid)
  Execute (links [tonumber (hotspotid)].send)  
end -- mouseup_hyperlink

Because mapper goto is an alias. You don't want to send it to the server.



Also, you should add callbacks to delete the miniwindow if the plugin is disabled or uninstalled.
Amended on Tue 08 Mar 2016 12:51 PM by Fiendish
USA Global Moderator #3
Fiendish said:

I don't see what you're describing. Can you show a picture or something of what you see?


Oh I see it now. I had to install the Lucida Console font.
That looks like it's because of truetype anti-aliasing.

In any case, you could use a different font like Courier New.
Amended on Tue 08 Mar 2016 07:46 PM by Fiendish
USA #4
Thanks. Never thought of changing the font.

And I was just using that code as an example of the problem. In my version of it I don't use send/execute at all. I just use it to change variables.


map_selected = (links [tonumber (hotspotid)].map_selected)


EDIT: Looks like Courier New does it too. I found MS Sans Serif works, but can't get it small enough. Will keep looking around trying out different fonts.
Amended on Tue 08 Mar 2016 06:38 PM by Wuggly
USA Global Moderator #5
Well it's definitely a problem with what you're doing and how that interacts with ClearText. ( https://blogs.msdn.microsoft.com/oldnewthing/20060614-00/?p=30873#sthash.DeyKIWeW.dpuf )

The answer (because disabling cleartext for this is kinda silly) is that if you're going to print antialiased text on top of other antialiased text then first you need to redo the background.
Amended on Tue 08 Mar 2016 08:05 PM by Fiendish
Australia Forum Administrator #6
Yes, perhaps work out the rough size of the text rectangle (using WindowTextWidth and working out the vertical height from the font info), and then clearing that rectangle first.