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;
public MyText(Plane sketchPlane, Point2D insPoint, string textString, double height, Color maskColor) : base(sketchPlane, insPoint, textString, height)
{
MaskColor = maskColor;
}
protected override void Draw(DrawParams data)
{
DrawBackground(data);
data.RenderContext.PushRasterizerState();
data.RenderContext.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_PolygonOffset_Minus3Minus2);
base.Draw(data);
data.RenderContext.PopRasterizerState();
}
private void DrawBackground(DrawParams data)
{
if (Vertices != null && Vertices.Length > 0)
{
Color prevColorWireframe = data.RenderContext.CurrentWireColor;
data.RenderContext.SetColorWireframe(MaskColor);
data.RenderContext.PushRasterizerState();
data.RenderContext.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_NoPolygonOffset);
data.RenderContext.DrawQuads(Vertices, new Vector3D[] { Plane.AxisZ });
data.RenderContext.PopRasterizerState();
data.RenderContext.SetColorWireframe(prevColorWireframe);
}
}
protected override void DrawForSelection(GfxDrawForSelectionParams data)
{
DrawText(data);
}
protected override void DrawSelected(DrawParams data)
{
Draw(data);
}
}
Then use it like below.
MyText mt = new MyText(Plane.XY, new Point2D(10, 10), "this is a text with background", 10, Color.Aqua);
model1.Entities.Add(mt,Color.Orange);
Notes: The text entity derived in this way can be selected only by clicking on the text (and not on the mask).
Comments
Please sign in to leave a comment.