View Full Version : down & adjust events (metool)

11-29-2007, 12:51 PM
How can I determine if a handle was pressed in the "down" event?
I'm trying to do one thing (new handle) if there was a click anywhere but on a handle and another thing (move it) if a handle was clicked.

11-29-2007, 02:25 PM
I don't know for sure since I work more in Layout, but according to the SDK:

hnum = start( instance, eventinfo )
Take an initial mouse-down position and return the index of the handle that should be dragged.

domouse = down( instance, eventinfo )
Process a mouse-down event. If this function returns 0, handle processing will be done instead of raw mouse event processing.

So you would check first for _domouse, and if _domouse is >0 then its a mouse-down event. If _domouse ==0, then processing is handed to the handle, which then you would check _hnum for the handle index number.

11-29-2007, 02:43 PM
My problem is that down seems to be always called before hadle processing. During "down" I cannot (or I do not know how to) determine if a handle was pressed. If I delegate the processing to handle (by returning 0), it is called only if actual handle was pressed. Otherwise my click is not being registered because I skipped processing it in the down event by returning 0.

Apparently it is doable because LW's native bezier tool does just that (there probably are other examples too)

11-29-2007, 02:49 PM
Upon further inspection i see that it is adjust that is not being called, not handle. I think I'm onto something. Thanks for pointing me into the right direction :)

11-30-2007, 12:33 PM
Well, I'm still stuck. Any other ideas? Anyone?

11-30-2007, 05:37 PM
I have written my independent processing to do it in the down event.
Convert modeler world position of a handle into event local position that defined "event->axis" as z-axis, and check if a handle was clicked.

But, there is a problem a little ...
I want the viewing position in modeler ...
Give me it ...

11-30-2007, 09:58 PM
Have you looked at /lwsdk/html/articles/box4.html? Ernie gives a good explanation of how the MeshEditTools work there. And if you compile the lwsdk/sample/Modeler/CommandSequence/boxes/Box4 example plugin using wdtool.c and wdbui.c, you can get a runtime Trace of all the callbacks which is very useful for learning how Tool system works.


12-05-2007, 01:45 PM
Yes, the tutorial in the SDK does layout how to do what you asked above, like hurley pointed out. I have read it a couple times, soon going to try it.

12-05-2007, 02:08 PM
I've looked at it before (and compiled it) when I took interest in building my own tools. It does not seem to discuss the "down" function but I'll have another look in case I missed something.

12-05-2007, 06:52 PM
The "Down callback" cannot obtain Handle information.
It can know Handle information by the "Adjust callback".
However, when Handle is not clicked, the "Adjust callback" will not be called.
I have the possibility of misunderstanding it possibly.:)

12-05-2007, 08:40 PM
Hello master pictrix! This is EXACTLY how I understand it too and this is my problem (or I am not seeing clearly). If an empty space is clicked (not a handle) I want to create a new handle there and if a handle is clicked I want to adjust it. I cannot perform the "new handle" action in the adjust function because it is not called at all if empty space is clicked. I could do it in down function, but in down function I cannot tell if a handle was clicked or not. I could probably test proximity to existing handles, but maybe there is some more direct way of doing it.
As I said before, the built in bezier tool seems to do it. For the time being I add new handles with the right mouse click, but I'd be still happy to hear how to do it properly.

12-05-2007, 11:02 PM
Hi art ,

It is the order of calling the callback.
Adjust : if Handle click
Build : if update == LWT_TEST_UPDATE

Coordinates of the down of the mouse are recorded by the "Down callback".
It sets it in newHandleFlag (your private variable)= turning ON.
To call the "Build callback", update=LWT_TEST_UPDATE is set.

If the "Adjust callback" is called, Handle is processed.
And, it sets it in newHandleFlag=OFF.

When the "Build callback" is called, newHandleFlag is examined.
If it is ON, new Handle is made in the recorded coordinate value.

12-06-2007, 07:30 AM
I knew it would be simple. Thank you for explanation pictrix. Now I have a lightbulb flashing over my head (again) :)

12-06-2007, 09:43 PM
I've always used Art's method of adding new handles with the right mouse and I was hoping that Pictrix's method would work. But I can only get that method to create 1 handle. Once there's handles in the system, Modeler only seems to call Dirty and Test if Adjust is called first. So the next Down event will not call Build to create another handle.

I made a little bare bones C++ plugin to for testing here (http://www.hurleyworks.com/code/basicModTool.zip) if anyone is interested.


12-06-2007, 11:49 PM
Once there's handles in the system, Modeler only seems to call Dirty and Test if Adjust is called first. So the next Down event will not call Build to create another handle.


I'm sorry. It is my mistake. :thumbsdow

I am writing the program without using "Count, Handle, Start, and Adjust" callback.

The function that replaces it is made and executed.

Function to know click and drug of user handles.
This is used from the Down callback.
Function equal with Adjust callback.
It uses it from Move callback and the Up callback.

Flexibility is very obtained. :)

12-07-2007, 09:35 AM
Thanks for posting, Steve!
I actually have been using plain C so far so this is a nice piece of code to look at if I wanted to see how to write plugins in C++. I've read about wrappers but never really tried using one.

12-13-2007, 09:17 AM
Please correct me if I am wrong, guys. The way I understand your posts, given the functions provided by the SDK it is not easy/possible to keep adding NEW handles with left mouse click, while retaining the ability to adjust existing handles also with a left mouse click.

If I create my own function for that purpose, I must somehow detect proximity of the click to an existing handle location. Simple enough, but how do I take the viewport zoom into account? I could not find anything on that in the docs.

Do you think that the LW tools such as bezier or spline use custom functions for that purpose? Forgive me my fixation on those tools, but the way they adds new handles with left mouse click is exactly what I want for my.. ehm.. bezier :) ... tool.

12-13-2007, 09:24 AM
Also, Steve, the wrapper that you used, is it the same that Mike has come up with or is it your own/modified version? I have downloaded Mike's wrapper some time ago, but never had time to dive too deep into it. I am not all that proficient with this stuff, but I think I'll use the wrapper from now on.

12-13-2007, 11:26 PM
I haven't seen Mike's wrapper classes. He was kind enough to share a technique for wrapping static LW callbacks to class functions on the yahoo forum.


Here's (http://www.hurleyworks.com/code/handleTool.zip)a little plugin that shows how you might get things working the way you'd like. The picking code is pretty crude but maybe it will help you get some ideas.


12-14-2007, 08:43 AM
It might be crude, but it seems to do the job. Now let me digest that code.
Thank you VERY much for your help and the sample code.