Non-maintained solution
The proposed solution is not natively supported and may not work in all scenarios and versions.
Here's an example on how to derive the Text class in order to draw a colored background mask behind the text.
Here is the code:
class MyText : devDept.Eyeshot.Entities.Text
{
public Color MaskColor = System.Drawing.Color.Red;
// Enables the halo effect for selection,
// comment this line to disable the effect.
protected override haloType HaloMode => haloType.Thick;
public MyText(Plane sketchPlane, Point2D insPoint, string textString, double height, Color maskColor) : base(sketchPlane, insPoint, textString, height)
{
MaskColor = maskColor;
}
protected override void DrawText(DrawParams data)
{
DrawBackground(data.RenderContext);
base.DrawText(data);
}
protected override void DrawSimplified(RenderContextBase context)
{
DrawBackground(context);
base.DrawSimplified(context);
}
private void DrawBackground(RenderContextBase context)
{
if (Vertices != null && Vertices.Length > 0)
{
Color prevColorWireframe = context.CurrentWireColor;
if(!_suspendBgColor) context.SetColorWireframe(MaskColor);
context.PushRasterizerState();
context.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_PolygonOffset_Plus2Plus2);
context.DrawQuads(Vertices, new Vector3D[] { Plane.AxisZ });
context.PopRasterizerState();
if(!_suspendBgColor) context.SetColorWireframe(prevColorWireframe);
}
}
protected override void DrawForSelection(GfxDrawForSelectionParams data)
{
data.RenderContext.DrawQuads(Vertices, new Vector3D[] { Plane.AxisZ });
}
private bool _suspendBgColor = false;
protected override void DrawSelected(DrawParams data)
{
_suspendBgColor = data.IsDrawingForHalo;
Draw(data);
_suspendBgColor = false;
}
}
Then use it like below.
MyText mt = new MyText(Plane.XY, new Point2D(10, 10), "this is a text with background", 10, Color.Aqua);
design1.Entities.Add(mt,Color.Orange);
Comments
This method is not working properly when set the Billboard property to true. How can I fix this issue?
Hi Riley,
Please, override the DrawText method instead of the Draw method:
I will modify the article.
Wonderful!!!
As you said in the article "The text entity derived in this way can be selected only by clicking on the text (and not on the mask)". How can I fix this issue?
I found if I click the mask, the application throw an exception which says "the given key is not in the dictionary". Especially, when I set the ActionMode to SelectVisibleByPickDynamic, every time my cursor hover on the mask, this exception will occur.
Can you help me please?
Thanks and Regards,
Please sign in to leave a comment.