1 // 2 // Written by David Megginson, started January 2000. 3 // Adopted for standalone fgpanel application by Torsten Dreyer, August 2009 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License as 7 // published by the Free Software Foundation; either version 2 of the 8 // License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, but 11 // WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 // 19 20 #ifndef FGTEXTLAYER_HXX 21 #define FGTEXTLAYER_HXX 22 23 #include <string> 24 #include <simgear/timing/timestamp.hxx> 25 26 #include "FGFontCache.hxx" 27 #include "FGInstrumentLayer.hxx" 28 29 using namespace std; 30 31 /** 32 * A text layer of an instrument. 33 * 34 * This is a layer holding a string of static and/or generated text. 35 * It is useful for instruments that have text displays, such as 36 * a chronometer, GPS, or NavCom radio. 37 */ 38 39 class FGTextLayer : public FGInstrumentLayer { 40 public: 41 enum ChunkType { 42 TEXT, 43 TEXT_VALUE, 44 DOUBLE_VALUE 45 }; 46 47 class Chunk : public SGConditional { 48 public: 49 Chunk (const string &text, 50 const string &fmt = "%s"); 51 Chunk (const ChunkType type, 52 const SGPropertyNode *node, 53 const string &fmt = "", 54 const float mult = 1.0, 55 const float offs = 0.0, 56 const bool truncation = false); 57 58 const char *getValue () const; 59 private: 60 ChunkType m_type; 61 string m_text; 62 SGConstPropertyNode_ptr m_node; 63 string m_fmt; 64 float m_mult; 65 float m_offs; 66 bool m_trunc; 67 mutable char m_buf[1024]; 68 69 }; 70 71 static bool Init (); 72 73 FGTextLayer (const int w = -1, const int h = -1); 74 virtual ~FGTextLayer (); 75 76 virtual void draw (); 77 78 // Transfer pointer!! 79 virtual void addChunk (Chunk * const chunk); 80 virtual void setColor (const float r, 81 const float g, 82 const float b); 83 virtual void setPointSize (const float size); 84 virtual void setFontName (const string &name); 85 86 private: 87 88 void recalc_value () const; 89 90 typedef vector<Chunk *> chunk_list; 91 chunk_list m_chunks; 92 float m_color[4]; 93 94 float m_pointSize; 95 static SGPath The_Font_Path; 96 mutable string m_font_name; 97 mutable string m_value; 98 mutable SGTimeStamp m_then; 99 mutable SGTimeStamp m_now; 100 101 static FGFontCache The_Font_Cache; 102 103 static GLuint Text_Layer_Program_Object; 104 static GLint Text_Layer_Position_Loc; 105 static GLint Text_Layer_Tex_Coord_Loc; 106 static GLint Text_Layer_MVP_Loc; 107 static GLint Text_Layer_Sampler_Loc; 108 static GLint Text_Layer_Color_Loc; 109 }; 110 111 #endif 112