SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

Sketchup::Tool#activate() with mouse position #642

Open voqhai opened 3 years ago

voqhai commented 3 years ago

When Tool activates, I want to know the current mouse position to draw something at the cursor or display a dialog nearby. I don't want the user to have to click or move mouse to get the position.

https://ruby.sketchup.com/Sketchup/Tool.html#activate-instance_method

def activate(flags, x, y, view)
    show_menu_at([x, y])
end

``

thomthom commented 3 years ago

With the other events we get the mouse coordinates from the underlying OS mouse events.

In this case, activate is not a mouse event, so it poses additional challenges. It would be possible to compute the X, Y, but then you have the case of the mouse might not even be within the viewport - which isn't unlikely if the tool was activated via a menu or toolbar button.

Can you elaborate on how you'd deal with that in your extension? Can you explain more about your higher level goals here?

voqhai commented 3 years ago

If the mouse outside the viewport when activate, I think the value of x, y should be nil, so I will choose to draw(view) or dialog.show at the center or edge of the viewport

DanRathbun commented 3 years ago

@voqhai : If the mouse outside the viewport when activate, I think the value of x, y should be nil, ...

I would think it better to follow precedent set by the View#screen_coords method, ... ie:

If the referenced point is not in the current viewport, the x and/or y value may be negative.

DanRathbun commented 3 years ago

... and speaking of the View#screen_coords method, ...

@thomthom, perhaps the easiest solution might be to create an override for the absence of an argument which would return the screen coordinates of the current mouse position when the method is called.

In this way the tool activate callback wouldn't be compromised with "out of band" behavior.