0024428: Implementation of LGPL license
[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
8 // under the terms of the GNU Lesser General Public 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
24 #include <TCollection_AsciiString.hxx>
25
26 #include <OpenGl_Element.hxx>
27 #include <Handle_OpenGl_ShaderProgram.hxx>
28
29 //! Text representation parameters
30 class OpenGl_AspectText : public OpenGl_Element
31 {
32
33 public:
34
35   OpenGl_AspectText();
36   virtual ~OpenGl_AspectText();
37
38   //! Copy parameters
39   void SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect);
40
41   //! @return font family name
42   const TCollection_AsciiString& FontName() const
43   {
44     return myFont;
45   }
46
47   //! @return font family name
48   TCollection_AsciiString& ChangeFontName()
49   {
50     return myFont;
51   }
52
53   //! @return is zoomable flag
54   bool IsZoomable() const
55   {
56     return myZoomable;
57   }
58
59   //! @return rotation angle
60   float Angle() const
61   {
62     return myAngle;
63   }
64
65   //! @return font aspect (regular/bold/italic)
66   Font_FontAspect FontAspect() const
67   {
68     return myFontAspect;
69   }
70
71   //! @param theValue font aspect (regular/bold/italic)
72   void SetFontAspect (const Font_FontAspect theValue)
73   {
74     myFontAspect = theValue;
75   }
76
77   //! @return text color
78   const TEL_COLOUR& Color() const
79   {
80     return myColor;
81   }
82
83   //! @return text color
84   TEL_COLOUR& ChangeColor()
85   {
86     return myColor;
87   }
88
89   //! @return annotation style
90   Aspect_TypeOfStyleText StyleType() const
91   {
92     return myStyleType;
93   }
94
95   //! @return subtitle style (none/blend/decale/subtitle)
96   Aspect_TypeOfDisplayText DisplayType() const
97   {
98     return myDisplayType;
99   }
100
101   void SetDisplayType (const Aspect_TypeOfDisplayText theType)
102   {
103     myDisplayType = theType;
104   }
105
106   //! @return subtitle color
107   const TEL_COLOUR& SubtitleColor() const
108   {
109     return mySubtitleColor;
110   }
111
112   //! @return subtitle color
113   TEL_COLOUR& ChangeSubtitleColor()
114   {
115     return mySubtitleColor;
116   }
117
118   //! Init and return OpenGl shader program resource.
119   //! @return shader program resource.
120   const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
121   {
122     if (!myResources.IsShaderReady())
123     {
124       myResources.BuildShader (theWorkspace, myShaderProgram);
125       myResources.SetShaderReady();
126     }
127
128     return myResources.ShaderProgram;
129   }
130
131   virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
132   virtual void Release (const Handle(OpenGl_Context)&   theContext);
133
134 protected:
135
136   TCollection_AsciiString         myFont;
137   TEL_COLOUR                      myColor;
138   TEL_COLOUR                      mySubtitleColor;
139   float                           myAngle;
140   Aspect_TypeOfStyleText          myStyleType;
141   Aspect_TypeOfDisplayText        myDisplayType;
142   Font_FontAspect                 myFontAspect;
143   bool                            myZoomable;
144   Handle(Graphic3d_ShaderProgram) myShaderProgram;
145
146 protected:
147
148   //! OpenGl resources
149   mutable struct Resources
150   {
151   public:
152     Resources() : myIsShaderReady (Standard_False) {}
153
154     Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
155     void SetShaderReady()       { myIsShaderReady = Standard_True; }
156     void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
157
158     void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
159
160     Handle(OpenGl_ShaderProgram) ShaderProgram;
161     TCollection_AsciiString      ShaderProgramId;
162
163   private:
164
165     Standard_Boolean myIsShaderReady;
166
167   } myResources;
168
169 public:
170
171   DEFINE_STANDARD_ALLOC
172
173 };
174
175 #endif // OpenGl_AspectText_Header