I think it would be better to include the tool and/or have instructions to paste/add the "reference" for layer selecting to the tools. I plan to add this to all of my VECTOR editing tools because that is when I would use it the most. The benefit of this is that the code only lives in ONE PLACE. The same code is not repeated in a bunch of tools.
I rarely use the select shape tool because Fazek's translate point tool picks shapes as well. I really need to hop around layers when I'm editing vectors. Currently I have several "extra" bits in my own custom keydown utility script. I can just add this code to my utility script and I won't even need to edit the tools themselves.
-----------------
Simple Option
-----------------
For simple installation using the "reference" technique all the user needs to do is add that OnMouseDown function to any tool they want this functionality;
Code: Select all
function LM_SelectPoints:OnMouseDown(moho, mouseEvent)
Syn_SelectLayer:OnMouseDown(moho, mouseEvent, view)
end
Just add that code to any tool and it will use your new tool. I am pretty sure all the tools have an OnMouseDown function so really all you need to do is stick in this part inside the existing function:
Code: Select all
Syn_SelectLayer:OnMouseDown(moho, mouseEvent, view)
--------------------
Advanced Option
--------------------
Or you can add the code from your tool to the lm_utilities.lua script or to your own custom utilities script (better for portability) in a mousedown function.
Add this code to the lm_utilities.lua file:
Code: Select all
function MOHO.OnMouseDown(moho, mouseEvent, view)
-------
local mesh = moho:Mesh()
if (moho.layer:Parent() == nil) or (mesh == nil)then
return
end
local prevMousePt = LM.Point:new_local()
local prevSelID = -1
local layer = moho.layer
local prevLayer = moho.layer
local parlayer = layer:Parent()
local layernum = parlayer:CountLayers()-1
local shapefound = false
for i = layernum, 0, -1 do
local layerobj = parlayer:Layer(i)
--print(tostring(layerobj))-----------------------------
if (layerobj:LayerType() == MOHO.LT_VECTOR) then
moho:SetSelLayer(layerobj)
prevMousePt:Set(mouseEvent.pt)
prevSelID = mouseEvent.view:PickShape(mouseEvent.pt)
--shapenum = mesh:CountShapes()
--shapeiter = shapenum -1
for i = 0, mesh:CountShapes() -1 do
mesh:Shape(i).fSelected = false
--print(tostring(mesh:Shape(i)))--------------------
if (prevSelID >= 0) then
mesh = moho:Mesh()
mesh:Shape(prevSelID).fSelected = true
--print(tostring(mesh:Shape(prevSelID)))-------
shapefound = true
break
end
end
if (shapefound == true) then
break
else
moho:SetSelLayer(prevLayer)
end
end
moho:UpdateSelectedChannels()
end
mouseEvent.view:DrawMe()
moho:UpdateUI()
end
Then look for a "OnMouseDown" function in any of the tools you want this fucnctionality and add this line inside that function:
Code: Select all
MOHO.OnMouseDown(moho, mouseEvent)
I am pretty sure that almost all the tools have an OnMouseDown function otherwise they wouldn't be able to do anything. There might be issues with conflicting key commands (CTRL + SHIFT).
I just did the above enhancement with my FA point tools and it works good so far.
The benefit of putting the code in a utilities script is that it doesn't require the tool to be in the tool palette. You are adding the functionality very simply directly to the tools themselves. If you want to update the script later no need to edit the tools, just edit the utility script.
-----
p.s.
The beauty of custom utility scripts is that once they are referenced in all the tool scripts you can add new things without needing to install a new tool or edit the tools. If you have a reference to a custom utility script OnMouseDown function and later decide to add a NEW function or cool trick that does something else just add it to the utility script.
-vern