Cursor snapping to a nearby point...
-
Hi folks,
Sketchup 7.1.4871
Vista SP1, 32-bitI'm experimenting with capturing mouse coordinate input via tool class event handling. I'm using the "simple_tool.rb" script as a guide. Here's my little test script...
class Clicktest
Initialize the input point upon start
def activate
@pt1 = Sketchup::InputPoint.new
endRespond to left-clicks in the design window
def onLButtonDown flags, x, y, view
@pt1.pick view, x, y
@pos1 = @pt1.position
str = "%.2f, %.2f, %.2f" % [@pos1.x, @pos1.y, @pos1.z]
puts "pt1: " + str
end
endCreate the Command object
simple_cmd = UI::Command.new("ClickTest") {
Sketchup.active_model.select_tool Clicktest.new
}Add the Command to the Tools menu
tool_menu = UI.menu "Tools"
tool_menu.add_separator
tool_menu.add_item simple_cmdWhen I select this tool and move the cursor towards a vertex, it appears to be selecting the vertex once the cursor gets sufficiently close to it, but it's not visually indicating that it's doing so. It doesn't behave the way Sketchup does when Sketchup is used manually - e.g. Sketchup uses tooltips and coloring to cue the user that a point close-to-but-not-immediately-underneath the cursor is about to be selected if the mouse is clicked. I think maybe this is called "snapping"?
Is there a way that I can make this behavior more visually apparent to the user of the tool?
Thanks!
-
In the
draw
event of your tool you must call@pt.draw
.(You can wrap you code in [code] tags to preserve formatting and readability when posting.)
-
ThomThom,
Thank you for your quick reply!
In the draw event of your tool you must call @pt.draw. <<
OK. But do you know of any reference materials that I could study to shed a little more light on this subject? I've looked around at the example files, and "linetool.rb" has a draw method - but it raises more questions than it answers.
I'll do my homework, but it would be nice if there was some sort of documentation for this. I must be missing something somewhere.
Thanks again!
-
You have the API docs: http://code.google.com/apis/sketchup/docs/ourdoc/tool.html
Another point I forgot to mention was that you also need to invalidate the view to make it draw.
The concept is:
Whatever you want your tool to display in the viewport is added to the draw method of your tool. Here you useview.draw*
methods for instance.
But in order to trigger the draw method the view needs to be invalidated. (view.invalidate
) That will refresh the SU viewport and call your draw method.So in your mouse click event where you pick things, when you have new data to display you call view.invalidate which then leads to the draw method to be called and from there you draw whatever you want, in your case you want to draw @pt if it has anything to display (
@pt.draw if @pt.display?
) -
ThomThom,
Again, thanks for your speedy and gracious response.
You've provided some good information. Time permitting, I'll work on this this weekend and hopefully come to a better understanding.
Take care!
Advertisement