I am using a custom display conduit to overlay some on-screen text, or HUD, as user feedback (for some python scripts I’m developing) overriding the DrawOverlay() function in the custom display conduit.
For purposes of legibility, it would be great to either:
Mask the text.
Create a semi transparent background for the whole HUD
The purpose is to still be able to read the text when there are objects below it when the user pans / zooms / etc.
I see that the key is the .NET method DrawString using a brush (which, if i understood correctly is the actual mask).
More useful, perhaps, is the MeasureString (the equivalent of which does not exist in python / rhinopython / rhinoscriptsyntax) method which returns the string’s height and width in pixels.
Now, the problem in translating it to python:
Once I have the pixel height and width of a given string, how do I then draw a rectangle in the custom display conduit’s DrawOverlay function at the correct screen coordinates and pixel size without too much messing around with converting from world to screen units??
I was also going to ask a similar question, so I post it here.
I would like to draw the framerate in the Holomark view.
I know you answered this back on the old NG, but I can’t find the script example you made.
Updated to the latest build and voila’ there’s Measure2dText method Great!
I’ve implemented it to mask overlay text drawn in a custom display conduit. However, I’ve noticed that the resulting rectangle is only centered horizontally around the text string whereas, vertically, the rectangle and text string are bottom aligned resulting in a greater ‘padding’ along the top of the text string (see attached image).
I am using the same worldCoordinate parameter for both Draw2dText and Measure2dText.
Any ideas as to why this would be?
I know it will center the rectangle if both Draw2DText and Measure2dText are set to be middle justified. But If I have a list of strings which should all be left justified, then I have to tweak the position of the rectangle before passing it to Draw2dRectangle?
I’m sure next time the help is auto-generated the comments will appear. For now, here are the xml comments.
/// <summary>
/// Determines screen rectangle that would be drawn to using the Draw2dText(..) function
/// with the same parameters.
/// </summary>
/// <param name="text">text to measure.</param>
/// <param name="definitionPoint">either lower-left or middle of text.</param>
/// <param name="middleJustified">true=middle justified. false=lower-left justified.</param>
/// <param name="rotationRadians">text rotation in radians</param>
/// <param name="height">height in pixels (good default is 12)</param>
/// <param name="fontFace">font name (good default is "Arial")</param>
/// <returns>rectangle in the viewport's screen coordinates on success.</returns>