G : ShortReal from Standard;
B : ShortReal from Standard )
is deferred;
- ---Purpose: call_togl_set_text_attributes
+ ---Purpose: Set text attributes for under-/overlayer.
+ -- <Font> argument defines the name of the font to be used,
+ -- <Type> argument defines the display type of the text,
+ -- <R> <G> <B> values define the color of decal or subtitle background.
+ -- To set the color of the text you can use the SetColor method.
Text ( me : mutable;
AText : CString from Standard;
Standard_EXPORT void SetTransparency (const Standard_ShortReal ATransparency);
Standard_EXPORT void UnsetTransparency ();
Standard_EXPORT void SetLineAttributes (const Standard_Integer Type,const Standard_ShortReal Width);
+
+ //! Set text attributes for under-/overlayer. <br>
+ //! <Font> argument defines the name of the font to be used, <br>
+ //! <Type> argument defines the display type of the text, <br>
+ //! <R> <G> <B> values define the color of decal or subtitle background. <br>
+ //! To set the color of the text you can use the SetColor method. <br>
Standard_EXPORT void SetTextAttributes (const Standard_CString FontName,const Standard_Integer Type,const Standard_ShortReal R,const Standard_ShortReal G,const Standard_ShortReal B);
Standard_EXPORT void Text (const Standard_CString AText,const Standard_ShortReal X,const Standard_ShortReal Y,const Standard_ShortReal AHeight);
Standard_EXPORT void TextSize (const Standard_CString AText,const Standard_ShortReal AHeight,Standard_ShortReal& AWidth,Standard_ShortReal& AnAscent,Standard_ShortReal& ADescent) const;
{
if (!TheLayerProp.ListId || openglDisplay.IsNull()) return;
- if ( strcmp ( TheLayerProp.AspectText.Font(), Font ) != 0 ||
- (int)TheLayerProp.AspectText.DisplayType() != AType )
+ // get current subtitle text color
+ const TEL_COLOUR &aSubColor = TheLayerProp.AspectText.SubtitleColor ();
+
+ // update if there are any modifications
+ if (strcmp (TheLayerProp.AspectText.Font(), Font) != 0 ||
+ (int)TheLayerProp.AspectText.DisplayType() != AType ||
+ aSubColor.rgb[0] != (float)R ||
+ aSubColor.rgb[1] != (float)G ||
+ aSubColor.rgb[2] != (float)B)
{
CALL_DEF_CONTEXTTEXT aContextText = myDefaultContextText;
aContextText.Font = Font;
aContextText.DisplayType = AType;
- aContextText.Color.r = R;
- aContextText.Color.g = G;
- aContextText.Color.b = B;
+ aContextText.ColorSubTitle.r = R;
+ aContextText.ColorSubTitle.g = G;
+ aContextText.ColorSubTitle.b = B;
TheLayerProp.AspectText.SetContext(aContextText);
-
- TheLayerProp.FontCurrent = openglDisplay->FindFont(TheLayerProp.AspectText.Font(), TheLayerProp.AspectText.FontAspect(), TheLayerProp.TextParam.Height);
-
TheLayerProp.FontChanged = Standard_True;
}
}
{
TheLayerProp.TextParam.Height = (int )height;
TheLayerProp.FontCurrent = openglDisplay->FindFont(TheLayerProp.AspectText.Font(), TheLayerProp.AspectText.FontAspect(), (int )height);
- TheLayerProp.FontChanged = Standard_False;
+ TheLayerProp.FontChanged = Standard_False;
}
- TCollection_ExtendedString estr(AText);
- const Techar *s = (const Techar *)estr.ToExtString();
+ TCollection_ExtendedString aExtStr(AText);
+ const Techar *aTChStr = (const Techar *)aExtStr.ToExtString();
//szv: conversion of Techar to wchar_t
- wchar_t *s1 = (wchar_t*)s;
+ wchar_t *aWChStr = (wchar_t*)aTChStr;
if (sizeof(Techar) != sizeof(wchar_t))
{
- Tint i = 0; while (s[i++]);
- s1 = new wchar_t[i];
- i = 0; while (s1[i++] = (wchar_t)(*s++));
+ Tint i = 0; while (aTChStr[i++]);
+ aWChStr = new wchar_t[i];
+ i = 0; while (aWChStr[i++] = (wchar_t)(*aTChStr++));
+ }
+
+ const Aspect_TypeOfDisplayText aDispType =
+ TheLayerProp.AspectText.DisplayType();
+
+ // display type of text
+ if (aDispType != Aspect_TODT_NORMAL)
+ {
+ switch (aDispType)
+ {
+ // blend type
+ case Aspect_TODT_BLEND:
+ {
+ glEnable(GL_COLOR_LOGIC_OP);
+ glLogicOp(GL_XOR);
+ }
+ break;
+
+ // subtitle type
+ case Aspect_TODT_SUBTITLE:
+ {
+ GLint aViewport[4];
+ GLdouble aModelMatrix[16], aProjMatrix[16];
+ glGetIntegerv (GL_VIEWPORT, aViewport);
+ glGetDoublev (GL_MODELVIEW_MATRIX, aModelMatrix);
+ glGetDoublev (GL_PROJECTION_MATRIX, aProjMatrix);
+
+ int aWidth, anAscent, aDescent;
+ openglDisplay->StringSize(aWChStr, aWidth, anAscent, aDescent);
+
+ GLdouble aWinX, aWinY, aWinZ;
+ gluProject ((GLdouble)X, (GLdouble)Y, 0.0, aModelMatrix,
+ aProjMatrix, aViewport, &aWinX, &aWinY, &aWinZ);
+
+ // project coordinates
+ GLdouble aCoordX[4];
+ GLdouble aCoordY[4];
+ GLdouble aCoordZ[4];
+
+ // left bottom corner
+ gluUnProject (aWinX, aWinY + aDescent, aWinZ, aModelMatrix,
+ aProjMatrix, aViewport, &aCoordX[0], &aCoordY[0], &aCoordZ[0]);
+
+ // right bottom corner
+ gluUnProject (aWinX + aWidth, aWinY + aDescent, aWinZ, aModelMatrix,
+ aProjMatrix, aViewport, &aCoordX[1], &aCoordY[1], &aCoordZ[1]);
+
+ // right top corner
+ gluUnProject (aWinX + aWidth, aWinY + anAscent, aWinZ, aModelMatrix,
+ aProjMatrix, aViewport, &aCoordX[2], &aCoordY[2], &aCoordZ[2]);
+
+ // left top corner
+ gluUnProject (aWinX, aWinY + anAscent, aWinZ, aModelMatrix,
+ aProjMatrix, aViewport, &aCoordX[3], &aCoordY[3], &aCoordZ[3]);
+
+ // draw colored plane and reset the color
+ glColor3fv (TheLayerProp.AspectText.SubtitleColor ().rgb);
+ glBegin(GL_POLYGON);
+ glVertex3d(aCoordX[0], aCoordY[0], aCoordZ[0]);
+ glVertex3d(aCoordX[1], aCoordY[1], aCoordZ[1]);
+ glVertex3d(aCoordX[2], aCoordY[2], aCoordZ[2]);
+ glVertex3d(aCoordX[3], aCoordY[3], aCoordZ[3]);
+ glEnd();
+ glColor3fv (TheLayerProp.Color.rgb);
+ }
+ break;
+
+ case Aspect_TODT_DEKALE:
+ {
+ GLint aViewport[4];
+ GLdouble aModelMatrix[16], aProjMatrix[16];
+ glGetIntegerv (GL_VIEWPORT, aViewport);
+ glGetDoublev (GL_MODELVIEW_MATRIX, aModelMatrix);
+ glGetDoublev (GL_PROJECTION_MATRIX, aProjMatrix);
+
+ GLdouble aWinX, aWinY, aWinZ;
+ gluProject ((GLdouble)X, (GLdouble)Y, 0.0, aModelMatrix,
+ aProjMatrix, aViewport, &aWinX, &aWinY, &aWinZ);
+
+ GLdouble aProjX, aProjY, aProjZ;
+
+ gluUnProject (aWinX + 1, aWinY + 1, aWinZ, aModelMatrix,
+ aProjMatrix, aViewport, &aProjX, &aProjY, &aProjZ);
+
+ // draw a decal
+ glColor3fv (TheLayerProp.AspectText.SubtitleColor ().rgb);
+ openglDisplay->RenderText (aWChStr, 1, (float)aProjX, (float)aProjY,
+ (float)aProjZ, &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+
+ gluUnProject (aWinX, aWinY, aWinZ, aModelMatrix, aProjMatrix,
+ aViewport, &aProjX, &aProjY, &aProjZ);
+
+ gluUnProject (aWinX - 1, aWinY - 1, aWinZ, aModelMatrix, aProjMatrix,
+ aViewport, &aProjX, &aProjY, &aProjZ);
+
+ openglDisplay->RenderText(aWChStr, 1, (float)aProjX, (float)aProjY,
+ (float)aProjZ, &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+
+ gluUnProject (aWinX - 1, aWinY + 1, aWinZ, aModelMatrix, aProjMatrix,
+ aViewport, &aProjX, &aProjY, &aProjZ);
+
+ openglDisplay->RenderText(aWChStr, 1, (float)aProjX, (float)aProjY,
+ (float)aProjZ, &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+
+ gluUnProject (aWinX + 1, aWinY - 1, aWinZ, aModelMatrix, aProjMatrix,
+ aViewport, &aProjX, &aProjY, &aProjZ);
+
+ openglDisplay->RenderText(aWChStr, 1, (float)aProjX, (float)aProjY,
+ (float)aProjZ, &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+ glColor3fv (TheLayerProp.Color.rgb);
+ }
+ break;
+ }
}
- openglDisplay->RenderText(s1, 1, (float)X, (float)Y, 0.F, &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+ openglDisplay->RenderText(aWChStr, 1, (float)X, (float)Y, 0.F,
+ &TheLayerProp.AspectText, &TheLayerProp.TextParam);
+
+ if (aDispType == Aspect_TODT_BLEND)
+ glDisable(GL_COLOR_LOGIC_OP);
//szv: delete temporary wide string
if (sizeof(Techar) != sizeof(wchar_t))
- delete[] s1;
+ delete[] aWChStr;
}
void OpenGl_GraphicDriver::TextSize (const Standard_CString AText, const Standard_ShortReal AHeight, Standard_ShortReal& AWidth, Standard_ShortReal& AnAscent, Standard_ShortReal& ADescent) const
{
TheLayerProp.TextParam.Height = (int )height;
TheLayerProp.FontCurrent = openglDisplay->FindFont(TheLayerProp.AspectText.Font(), TheLayerProp.AspectText.FontAspect(), (int )height);
- TheLayerProp.FontChanged = Standard_False;
+ TheLayerProp.FontChanged = Standard_False;
}
TCollection_ExtendedString estr(AText);
AWorkspace->SetTextParam(&myParam);
- GLboolean blend_state = GL_FALSE;
GLdouble modelMatrix[16], projMatrix[16];
GLint viewport[4];
GLdouble objrefX, objrefY, objrefZ;
switch (aspect_text->DisplayType())
{
case Aspect_TODT_BLEND:
- blend_state = glIsEnabled(GL_BLEND);
- if (!blend_state) glEnable(GL_BLEND);
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
break;
if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
if (aspect_text->DisplayType() == Aspect_TODT_BLEND)
{
- if (!blend_state) glDisable(GL_BLEND);
glDisable(GL_COLOR_LOGIC_OP);
}
}
return;
theLayer->SetColor( aColor );
- theLayer->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_SUBTITLE, aColor );
+ theLayer->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, aColor );
TCollection_AsciiString theText( aText.ToExtString(), '?' );
Standard_Integer aTextH = GetTextHeight();
Standard_Integer aWidth, anAscent, aDescent;
myOverlay->Clear();
myOverlay->SetViewport( aW, aH ); //szv:!!!
myOverlay->Begin();
- myOverlay->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_SUBTITLE, Quantity_Color() );
+ myOverlay->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, Quantity_Color() );
myOverlay->SetOrtho( 0, Max( aW, aH ), Max( aW, aH ), 0, Aspect_TOC_TOP_LEFT );
return Standard_True;
#include <ViewerTest.hxx>
#include <ViewerTest_EventManager.hxx>
#include <Visual3d_View.hxx>
+#include <Visual3d_ViewManager.hxx>
+#include <V3d_LayerMgr.hxx>
#include <NIS_View.hxx>
#include <NIS_Triangulated.hxx>
#include <NIS_InteractiveContext.hxx>
#include <Image_PixMap.hxx>
#include <TColStd_SequenceOfInteger.hxx>
+#ifdef WNT
+#undef DrawText
+#endif
+
+#include <Visual3d_Layer.hxx>
+
#ifndef WNT
#include <Graphic3d_GraphicDevice.hxx>
#include <Xw_GraphicDevice.hxx>
return 0;
}
+DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
+
+// this class provides a presentation of text item in v3d view under-/overlayer
+class V3d_TextItem : public Visual3d_LayerItem
+{
+public:
+
+ // CASCADE RTTI
+ DEFINE_STANDARD_RTTI(V3d_TextItem)
+
+ // constructor
+ Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
+ const Standard_Real theX1,
+ const Standard_Real theY1,
+ const Standard_Real theHeight,
+ const TCollection_AsciiString& theFontName,
+ const Quantity_Color& theColor,
+ const Quantity_Color& theSubtitleColor,
+ const Aspect_TypeOfDisplayText& theTypeOfDisplay,
+ const Handle(Visual3d_Layer)& theLayer);
+
+ // redraw method
+ Standard_EXPORT void RedrawLayerPrs();
+
+private:
+
+ Standard_Real myX1;
+ Standard_Real myY1;
+ Standard_Real myHeight;
+ TCollection_AsciiString myText;
+ TCollection_AsciiString myFontName;
+ Quantity_Color myColor;
+ Quantity_Color mySubtitleColor;
+ Aspect_TypeOfDisplayText myType;
+ Handle(Visual3d_Layer) myLayer;
+
+};
+
+IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
+IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
+
+// create and add to display the text item
+V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
+ const Standard_Real theX1,
+ const Standard_Real theY1,
+ const Standard_Real theHeight,
+ const TCollection_AsciiString& theFontName,
+ const Quantity_Color& theColor,
+ const Quantity_Color& theSubtitleColor,
+ const Aspect_TypeOfDisplayText& theTypeOfDisplay,
+ const Handle(Visual3d_Layer)& theLayer)
+ : myX1 (theX1), myY1 (theY1),
+ myText (theText),
+ myHeight (theHeight),
+ myLayer (theLayer),
+ myColor (theColor),
+ mySubtitleColor (theSubtitleColor),
+ myType (theTypeOfDisplay),
+ myFontName (theFontName)
+{
+ if (!myLayer.IsNull ())
+ myLayer->AddLayerItem (this);
+}
+
+// render item
+void V3d_TextItem::RedrawLayerPrs ()
+{
+ if (myLayer.IsNull ())
+ return;
+
+ myLayer->SetColor (myColor);
+ myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
+ myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
+}
+
+//=======================================================================
+//function : VOverlayText
+//purpose : Test text displaying in view overlay
+//=======================================================================
+static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
+{
+ // get the active view
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ di << "No active view. Please call vinit.\n";
+ return 1;
+ }
+ else if (argc < 4 || argc > 13)
+ {
+ di << "Use: " << argv[0];
+ di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
+ di << "[background_color: R G B]\n";
+ di << " height - pixel height of the text (default=10.0)\n";
+ di << " font_name - name of font (default=courier)\n";
+ di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
+ di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
+ di << " background_color- R G B values used for subtitle and decal text\n";
+ di << "(default=255.0 255.0 255.0)\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aText (argv[1]);
+ Standard_Real aPosX = atof(argv[2]);
+ Standard_Real aPosY = atof(argv[3]);
+ Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
+
+ // font name
+ TCollection_AsciiString aFontName = "Courier";
+ if (argc >= 6)
+ aFontName = TCollection_AsciiString (argv[5]);
+
+ // text colors
+ Quantity_Parameter aColorRed = 1.0;
+ Quantity_Parameter aColorGreen = 1.0;
+ Quantity_Parameter aColorBlue = 1.0;
+ if (argc >= 9)
+ {
+ aColorRed = atof (argv[6])/255.;
+ aColorGreen = atof (argv[7])/255.;
+ aColorBlue = atof (argv[8])/255.;
+ }
+
+ // display type
+ TCollection_AsciiString aDispStr;
+ if (argc >= 10)
+ aDispStr = TCollection_AsciiString (argv[9]);
+
+ Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
+ if (aDispStr.IsEqual ("subtitle"))
+ aTextType = Aspect_TODT_SUBTITLE;
+ else if (aDispStr.IsEqual ("decal"))
+ aTextType = Aspect_TODT_DEKALE;
+ else if (aDispStr.IsEqual ("blend"))
+ aTextType = Aspect_TODT_BLEND;
+
+ // subtitle color
+ Quantity_Parameter aSubRed = 1.0;
+ Quantity_Parameter aSubGreen = 1.0;
+ Quantity_Parameter aSubBlue = 1.0;
+ if (argc == 13)
+ {
+ aSubRed = atof (argv[10])/255.;
+ aSubGreen = atof (argv[11])/255.;
+ aSubBlue = atof (argv[12])/255.;
+ }
+
+ // check fo current overlay
+ Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
+ if (anOverlay.IsNull ())
+ {
+ Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
+ anOverlay = aMgr->Overlay ();
+ aView->SetLayerMgr (aMgr);
+ }
+
+ Quantity_Color aTextColor (aColorRed, aColorGreen,
+ aColorBlue, Quantity_TOC_RGB);
+ Quantity_Color aSubtColor (aSubRed, aSubGreen,
+ aSubBlue, Quantity_TOC_RGB);
+
+ // add text item
+ Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
+ aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
+
+ // update view
+ aView->MustBeResized();
+ aView->Redraw();
+
+ return 0;
+}
+
//=======================================================================
//function : ViewerCommands
//purpose :
theCommands.Add("vzlayer",
"vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
__FILE__,VZLayer,group);
+ theCommands.Add("voverlaytext",
+ "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
+ " : height - pixel height of the text (default=10.0)"
+ " : font_name - name of font (default=courier)"
+ " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
+ " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
+ " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
+ __FILE__,VOverlayText,group);
}
AColor : Color from Quantity)
---Level: Public
---Purpose: Modifies the current texts attributes.
- -- Warning: No default attributes
+ -- <AFont> defines the name of the font to be used.
+ -- <AType> defines the display type of the text.
+ -- <AColor> defines the color of decal or subtitle background.
+ -- To set the color of the text you can use the SetColor method.
+ -- Warning: No default attributes
raises LayerDefinitionError from Visual3d;
-- if Layer is not open.