Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Message
| This seems like a reasonable request, although I am having trouble visualizing exactly how it would be used in practice.
However I can see that being able to update miniwindows in response to the current scroll position in the output window could be handy.
I've added a new callback in version 4.96, called just when the output window is being drawn. This lets you update a miniwindow which you have positioned appropriately. Example output:

I have an example plugin:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="OnPluginDrawOutputWindow_test"
author="Nick Gammon"
id="53fa0d56e81938a116e851e7"
language="Lua"
purpose="Testing OnPluginDrawOutputWindow"
date_written="2014-11-10 06:45:43"
requires="4.96"
version="1.0"
>
<description trim="y">
<![CDATA[
Draws extra stuff, per line, over the output window
]]>
</description>
</plugin>
<!-- Script -->
<script>
<![CDATA[
function OnPluginWorldOutputResized ()
main_height = GetInfo (263)
main_width = GetInfo (264)
win = "Overlay_" .. GetPluginID () -- get a unique name, ensure not empty if outside plugin
WindowCreate (win, main_width - panel_width, 0, panel_width, main_height, 0, miniwin.create_absolute_location, background_colour) -- create window
WindowShow (win, true) -- show it
WindowFont (win, "f", "Courier New", 9) -- define font
-- find height of font for future calculations
font_height = WindowFontInfo (win, font, 1) -- height
end -- OnPluginWorldOutputResized
function OnPluginDrawOutputWindow (firstline, offset)
local font_height = GetInfo (212)
local text_colour = ColourNameToRGB ("green")
-- clear window
WindowRectOp (win, miniwin.rect_fill, 0, 0, -1, -1, background_colour)
-- allow for scrolling position
local top = (((firstline - 1) * font_height) - offset) - 2
local lastline = firstline + (main_height / font_height)
for line = firstline, lastline do
if line >= 1 and GetLineInfo (line, 1) then
WindowText (win, font, line .. ": " .. GetLineInfo (line, 1), 0, top, 0, 0, text_colour)
top = top + font_height
end -- if line exists
end -- for each line
end -- OnPluginDrawOutputWindow
function OnPluginInstall ()
panel_width = 200
background_colour = ColourNameToRGB("lightgray")
font = "f"
OnPluginWorldOutputResized ()
end -- OnPluginInstall
]]>
</script>
</muclient>
Be warned, it appears that if you attempt to do a WindowCreate inside OnPluginDrawOutputWindow it causes the client to behave strangely. This is probably because it is creating a device context during window updating. I have worked around this by creating the window initially (OnPluginInstall) and then recreating it if the window is resized (OnPluginWorldOutputResized).
You are passed the first line number which is being drawn (which I use to call GetLineInfo). You can work out the last line by calculating how many lines must be visible. The mucking around with the top pixel here:
local top = ((firstline * GetInfo (212)) - offset) - GetInfo (212) - 1
... is necessary because moving the scroll thumb can make the line scroll in sub-line intervals.
You could conceivably use this same concept to add things like floating balloons or information windows, which draw (and scroll) relative to lines in the output window. The plugin isn't bulletproof, for example change:
WindowFont (win, "f", "Courier New", 9) -- define font
... to get the actual output font and font size, to match that used in the output window (if desired). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|