On this page | |
Inheritance |
|
Overview ¶
A text drawable is designed for custom Python states and is used for drawing text elements in the viewport in viewport coordinates. For instance, you can use a text drawable to display directives for guiding the user or for displaying technical information.
hou.TextDrawable
lets you translate, rotate and scale the text in 2D space with viewport coordinates.
The lower left corner of the viewport is the base point coordinate (0,0).
Here’s an example for displaying text in the upper left corner of the viewport.
import hou class State(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer # Create an empty text drawable self.text_drawable = hou.TextDrawable(self.scene_viewer, 'text_drawable_name') # Display the text on the next viewport redraw self.text_drawable.show(True) def onDraw( self, kwargs ): # draw the text in the viewport upper left handle = kwargs['draw_handle'] (x,y,width,height) = self.scene_viewer.curViewport().size() margin = 10 params = { 'text': 'First line<br>Second line<br>Third line', 'multi_line' : True, 'color1' : hou.Color(1.0,0.0,0.0), 'translate' : hou.Vector3(0, height, 0), 'origin' : hou.drawableTextOrigin.UpperLeft, 'margins': hou.Vector2(margin, -margin) } self.text_drawable.draw( handle, params )
An example to display text at the cursor position.
import hou class State(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer # Create the text drawable self.text_cursor = hou.TextDrawable(self.scene_viewer, 'text_cursor') # Display the text on the next viewport redraw self.text_cursor.show(True) def onMouseEvent(self, kwargs): # Compute the mouse position in screen coordinates ui_event = kwargs["ui_event"] (origin, dir) = ui_event.ray() self.mouse_screen = self.scene_viewer.curViewport().mapToScreen(origin) def onDraw( self, kwargs ): # draw the text in the viewport upper left handle = kwargs['draw_handle'] params = { 'text': '<font color="yellow">x=%.2f, y=%.2f</font>' % (self.mouse_screen[0], self.mouse_screen[1]), 'translate' : hou.Vector3(self.mouse_screen[0],self.mouse_screen[1], 0.0) } self.text_cursor.draw( handle, params )
Methods ¶
__init__(scene_viewer, name, label=None, params=None)
Creates a text drawable object. The new drawable is hidden by default.
scene_viewer
A hou.SceneViewer reference to the viewer the text will appear in.
name
A string to identify this drawable object.
label
An optional string for the drawable label. Defaults to empty.
params
An optional parameter dictionary for setting the drawable parameters. These parameters are also be used with hou.AdvancedDrawable.draw or hou.AdvancedDrawable.setParams.
Other drawable common parameters are documented here.
Parameter |
Type |
Description |
---|---|---|
|
Default foreground color for drawing the text. This value can be overridden with the text |
|
|
Bool |
Draws the text on multiple lines if formatted with line breaks |
|
Origin point for placing the text within its bounding box. Defaults to hou.drawableTextOrigin.BottomLeft. |
|
|
String |
The text to draw. A small subset of HTML 4.0 tokens is available for formatting the text:
|
|
hou.Vector2 or sequence of 2 double values |
Specifies the x and y margins of the text 2D bounding box, in viewport coordinates. Defaults to 0.0. |
size(text)
→ tuple of
double
Computes the width and height of a text
string for the drawable font and returns the values in a tuple:
-
Width
(dimension in pixels). -
Height
(dimension in pixels).
Methods from hou.Drawable ¶
name()
The name of this drawable.
label()
The label of this drawable.
setLabel(label)
Set the label for this drawable.
show(value)
Displays or hides the element attached to this drawable in the viewport. The element will appear the next time the viewer redraws.
value
True
to show the element or False
to hide it.
visible()
→ bool
Returns True if the drawable is visible or not.
setTransform(xform)
Sets the transform matrix of the element attached to this drawable. The changes will appear the next time the viewer redraws.
xform
A hou.Matrix4 transformation matrix to set the element’s translation, rotation, and scale.
transform()
: → hou.Matrix4
Returns the transform matrix of the element attached to the drawable.
Methods from hou.AdvancedDrawable ¶
setParams(params)
Sets the parameters of the drawable. The settings will take effect in the viewport the next time hou.AdvancedDrawable.draw is called.
params
A dictionary of parameters for setting the drawable options. Each drawable type uses a specific set of parameters, detailed information can be found in the drawable derived class params documentation such as GeometryDrawable and TextDrawable.
The following are parameters common to all hou.AdvancedDrawable
types:
|
Vector representing an For hou.TextDrawable, |
|
|
Vector representing an For instance, |
|
|
double |
Value used as the occlusion factor of the overlay in areas occluded by the existing geometry as determined by the depth buffer. A fade factor of 1.0 means no distinction must be made and a value of 0.0 completely hides occluded parts. Defaults to 0. |
|
int |
Sets the glow width value. For instance, this changes the glow width of line segments or text. Defaults to 0. |
|
Sets the mode for highlighting the generated matte of the drawable. Defaults to hou.drawableHighlightMode.Matte. |
|
|
hou.Vector3 or sequence of 3 doubles |
Position of the geometry in 3D space. For hou.TextDrawable, it’s the position of the text to display in viewport coordinates. Defaults to hou.Vector3(0, 0, 0). |
|
hou.Vector3 or sequence of 3 doubles |
Rotation vector in degrees. Defaults to hou.Vector3(0, 0, 0). |
|
hou.Vector3 or sequence of 3 doubles |
Scaling vector. Defaults to hou.Vector3(1, 1, 1). |
|
Sequence of doubles or ints |
Assigns a 2D window to the viewport, in viewport coordinates, for drawing a geometry. The sequence defines the location and size of the window, and must contain the following values:
|
|
Bool |
Specifies if the drawable should use the |
|
Bool |
Specifies if the drawable should use the |
draw(handle, params=None)
Method implemented by leaf classes to support the drawing of elements in a viewport. This method should normally be called from the python state onDraw or onDrawInterrupt event to render the drawable in the current viewport.
handle
This is an opaque value created by Houdini to render the drawable. This handle
value is passed
to the python state onDraw
callback by Houdini and should be passed directly to the drawable object’s draw
method.
params
An optional dictionary of parameters for setting the drawable parameters. These are the same parameters hou.AdvancedDrawable.setParams is using.
See also |