Writing tooltip text to the screen


#1

The Sketchup Scale tool, for example, displays this text at the cursor on Lbuttondown if cursor is not near a scale handle: “Select a grip and move it to scale”.
I’m trying to do this but not getting it.
I think I need:
view.tooltip = string AND/OR
view.draw_text point3d string #3D?
and maybe
view.invalidate
view.inputpoint x,y #2D?

all within the tool defs:
def onLButtonDown(flags, x, y, view) #2D?
def draw(view)

But I’m not understanding how to put it together.


#2

It’s near the cursor. Since the position of a 2d cursor in the viewport has no unambigious 3d position, we always need to use the inference engine via an InputPoint. Because of this, you find the tooltip at the cursor in Sketchup::Inputpoint.


#3

I think Barry wants to set his own tooltip rather than read the one provided by the inference engine.


#4

That’s correct. I would appreciate guidance on how to do it.


#5

Yes it should be

view.tooltip = "tipstring"

Look at “linetool.rb” in the Examples extension by the SketchUp Team.


#6

OK, but where do I define it, and where do I draw it?
The linetool only has tooltips for actual input points, not for just clicking on the screen where I’m not trying to pick anything.

Backgroud: The tool I’m writing exists ONLY to allow optional VCB input to an other wise non"tool" command. No mouse interaction required. I’m now just trying to give user some feedback if they uselessly click on the screen.


#7

Well you SET it to your desired text, anywhere / anywhen the text needs to change. You think that such a time is just after the user clicks on something. So that would be within the onLButtonDown() or onLButtonUp() callbacks.

You might not draw it. SketchUp may decide when to draw it. OR it may only be drawn for a sec whilst the mouse does not move. Once the mouse moves, the tip might get reset. So try it within the onMouseMove() callback.

The problem is that I do not think you can disable SketchUp’s built-in inferencing, so if the user moves near a vertex or midpoint, etc., SketchUp might display it own tooltips.

Perhaps it would be better, instead of struggling with tooltips (like walking against a windstorm,) that you use a cursor with a “Dont” symbol (red barred circle.) Like the SolidTools NoSelect cursor.

Then if they DO click, you display a messagebox that tells them to just enter text for the VCB.


#8

I added:

 def onMouseMove(flags, x, y, view)
       view.tooltip = "Type revised angle, or click on a tool."
 end

Which works. From the API I didn’t understand that it could be this simple.
The text appears every time the mouse stops moving which is OK.
No other tooltips appear, even if mouse is hovering over objects or vertices.
I assume that’s because I’m not requesting any input points.

Thanks Again.


#9

Yea, it makes sense right? It is a mouse text tip after all. So it follows that it would be the mouse routines that decide when to show the tips.

But remember that other places in your code is where you decide what the text will be, or if it will be nil. meaning in the onMouseMove it would normally be looking at a @var which is set to appropriate text or nil (for no tooltip) in other methods of the tool.