0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / OpenGl / OpenGl_AspectText.hxx
1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef OpenGl_AspectText_Header
17 #define OpenGl_AspectText_Header
18
19 #include <InterfaceGraphic_Graphic3d.hxx>
20 #include <Font_FontAspect.hxx>
21 #include <Aspect_TypeOfStyleText.hxx>
22 #include <Aspect_TypeOfDisplayText.hxx>
23 #include <Graphic3d_CAspectText.hxx>
24
25 #include <TCollection_AsciiString.hxx>
26
27 #include <OpenGl_Element.hxx>
28
29 class OpenGl_ShaderProgram;
30
31 //! Text representation parameters
32 class OpenGl_AspectText : public OpenGl_Element
33 {
34
35 public:
36
37   Standard_EXPORT OpenGl_AspectText();
38   Standard_EXPORT virtual ~OpenGl_AspectText();
39
40   //! Copy parameters
41   Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect);
42
43   //! @return font family name
44   const TCollection_AsciiString& FontName() const
45   {
46     return myFont;
47   }
48
49   //! @return font family name
50   TCollection_AsciiString& ChangeFontName()
51   {
52     return myFont;
53   }
54
55   //! @return is zoomable flag
56   bool IsZoomable() const
57   {
58     return myZoomable;
59   }
60
61   //! @return rotation angle
62   float Angle() const
63   {
64     return myAngle;
65   }
66
67   //! @return font aspect (regular/bold/italic)
68   Font_FontAspect FontAspect() const
69   {
70     return myFontAspect;
71   }
72
73   //! @param theValue font aspect (regular/bold/italic)
74   void SetFontAspect (const Font_FontAspect theValue)
75   {
76     myFontAspect = theValue;
77   }
78
79   //! @return text color
80   const TEL_COLOUR& Color() const
81   {
82     return myColor;
83   }
84
85   //! @return text color
86   TEL_COLOUR& ChangeColor()
87   {
88     return myColor;
89   }
90
91   //! @return annotation style
92   Aspect_TypeOfStyleText StyleType() const
93   {
94     return myStyleType;
95   }
96
97   //! @return subtitle style (none/blend/decale/subtitle)
98   Aspect_TypeOfDisplayText DisplayType() const
99   {
100     return myDisplayType;
101   }
102
103   void SetDisplayType (const Aspect_TypeOfDisplayText theType)
104   {
105     myDisplayType = theType;
106   }
107
108   //! @return subtitle color
109   const TEL_COLOUR& SubtitleColor() const
110   {
111     return mySubtitleColor;
112   }
113
114   //! @return subtitle color
115   TEL_COLOUR& ChangeSubtitleColor()
116   {
117     return mySubtitleColor;
118   }
119
120   //! Init and return OpenGl shader program resource.
121   //! @return shader program resource.
122   const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
123   {
124     if (!myResources.IsShaderReady())
125     {
126       myResources.BuildShader (theCtx, myShaderProgram);
127       myResources.SetShaderReady();
128     }
129
130     return myResources.ShaderProgram;
131   }
132
133   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
134   Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
135
136 protected:
137
138   TCollection_AsciiString         myFont;
139   TEL_COLOUR                      myColor;
140   TEL_COLOUR                      mySubtitleColor;
141   float                           myAngle;
142   Aspect_TypeOfStyleText          myStyleType;
143   Aspect_TypeOfDisplayText        myDisplayType;
144   Font_FontAspect                 myFontAspect;
145   bool                            myZoomable;
146   Handle(Graphic3d_ShaderProgram) myShaderProgram;
147
148 protected:
149
150   //! OpenGl resources
151   mutable struct Resources
152   {
153   public:
154     Resources() : myIsShaderReady (Standard_False) {}
155
156     Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
157     void SetShaderReady()       { myIsShaderReady = Standard_True; }
158     void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
159
160     Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)&          theCtx,
161                                       const Handle(Graphic3d_ShaderProgram)& theShader);
162
163     Handle(OpenGl_ShaderProgram) ShaderProgram;
164     TCollection_AsciiString      ShaderProgramId;
165
166   private:
167
168     Standard_Boolean myIsShaderReady;
169
170   } myResources;
171
172 public:
173
174   DEFINE_STANDARD_ALLOC
175
176 };
177
178 #endif // OpenGl_AspectText_Header