Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| Well you have got me going on this one now ...
I am still not sure which plugin you used, the page I mentioned had two on it, but I'll assume you used the lower one, which lets you have horizontal and vertical icons, and be dragged around.
The code below lets you grey out the whole icon, by reloading the image, and decreasing its contrast if the target plugin is not enabled:
-- button 1
{
icon = "search_32.png",
tooltip = "Underdark Mapper",
target_plugin = "aba6daf3fb30699071cb5d05",
script = function (n)
local id = buttons [n].target_plugin
local f = frames [n] -- where is image?
local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
-- redraw the image
WindowDrawImage(win, n,
x1 + 1, y1 + 1, -- left, top
x2 - 1, y2 - 1, -- right, bottom
2) -- mode - stretch or shrink
-- toggle enable flag for target plugin
EnablePlugin(id, not GetPluginInfo (id, 17))
-- grey out if disabled now
if not GetPluginInfo (id, 17) then
WindowFilter (win, x1, y1, x2, y2, 8, .4)
end -- if
end, -- function
}, -- end of button 3
I've fiddled around a bit to make it more readable. For one thing, you don't need to test if something elseif not something. For example:
if GetPluginInfo (id, 17) then
-- do something
elseif not GetPluginInfo (id, 17) then
-- do something else
end -- if
A simple else will do that, you don't need to test again, ie.
if GetPluginInfo (id, 17) then
-- do something
else
-- do something else
end -- if
Also it seems more logical to me to test if the plugin is enabled *after* you have toggled its enable flag.
My code above simply reloads the image (I wasn't sure if changing its contrast would be symmetrical, the image might have eventually degraded). Fortunately all the images are still in memory. Also the current plugin's window is stored in the variable "win" already.
The only problem I then found was if you reloaded the plugin (after testing) and the target plugin (the mapper) was already disabled, the icon would be drawn the wrong way around. So I added a couple more lines further down where the image is originally loaded. That is, after:
-- where to draw the icon
if horizontal then
x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET
x2, y2 = n * (ICON_SIZE + OFFSET), ICON_SIZE + OFFSET
else
x1, y1 = OFFSET, (n - 1) * (ICON_SIZE + OFFSET) + OFFSET
x2, y2 = ICON_SIZE + OFFSET, n * (ICON_SIZE + OFFSET)
end -- if
-- draw the image
WindowDrawImage(win, n,
x1, y1, -- left, top
x2, y2, -- right, bottom
2) -- mode - stretch or shrink
Add:
if v.target_plugin then
-- grey out if disabled now
if not GetPluginInfo (v.target_plugin, 17) then
WindowFilter (win, x1, y1, x2, y2, 8, .4)
end -- if
end -- if
This is why the variable which contained the target plugin's ID had to be moved from a local variable to be inside the table. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|