1e40006f06
using-declarations are okay in headers (i.e. aliasing)
107 lines
2.9 KiB
C++
107 lines
2.9 KiB
C++
//
|
|
// Written by David Megginson, started January 2000.
|
|
// Adopted for standalone fgpanel application by Torsten Dreyer, August 2009
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <simgear/timing/timestamp.hxx>
|
|
|
|
#include "FGFontCache.hxx"
|
|
#include "FGInstrumentLayer.hxx"
|
|
|
|
|
|
/**
|
|
* A text layer of an instrument.
|
|
*
|
|
* This is a layer holding a string of static and/or generated text.
|
|
* It is useful for instruments that have text displays, such as
|
|
* a chronometer, GPS, or NavCom radio.
|
|
*/
|
|
|
|
class FGTextLayer : public FGInstrumentLayer {
|
|
public:
|
|
enum ChunkType {
|
|
TEXT,
|
|
TEXT_VALUE,
|
|
DOUBLE_VALUE
|
|
};
|
|
|
|
class Chunk : public SGConditional {
|
|
public:
|
|
Chunk (const std::string &text,
|
|
const std::string &fmt = "%s");
|
|
Chunk (const ChunkType type,
|
|
const SGPropertyNode *node,
|
|
const std::string &fmt = "",
|
|
const float mult = 1.0,
|
|
const float offs = 0.0,
|
|
const bool truncation = false);
|
|
|
|
const char *getValue () const;
|
|
private:
|
|
ChunkType m_type;
|
|
std::string m_text;
|
|
SGConstPropertyNode_ptr m_node;
|
|
std::string m_fmt;
|
|
float m_mult;
|
|
float m_offs;
|
|
bool m_trunc;
|
|
mutable char m_buf[1024];
|
|
|
|
};
|
|
|
|
static bool Init ();
|
|
|
|
FGTextLayer (const int w = -1, const int h = -1);
|
|
virtual ~FGTextLayer ();
|
|
|
|
virtual void draw ();
|
|
|
|
// Transfer pointer!!
|
|
virtual void addChunk (Chunk * const chunk);
|
|
virtual void setColor (const float r,
|
|
const float g,
|
|
const float b);
|
|
virtual void setPointSize (const float size);
|
|
virtual void setFontName (const std::string &name);
|
|
|
|
private:
|
|
|
|
void recalc_value () const;
|
|
|
|
typedef std::vector<Chunk *> chunk_list;
|
|
chunk_list m_chunks;
|
|
float m_color[4];
|
|
|
|
float m_pointSize;
|
|
static SGPath The_Font_Path;
|
|
mutable std::string m_font_name;
|
|
mutable std::string m_value;
|
|
mutable SGTimeStamp m_then;
|
|
mutable SGTimeStamp m_now;
|
|
|
|
static FGFontCache The_Font_Cache;
|
|
|
|
static GLuint Text_Layer_Program_Object;
|
|
static GLint Text_Layer_Position_Loc;
|
|
static GLint Text_Layer_Tex_Coord_Loc;
|
|
static GLint Text_Layer_MVP_Loc;
|
|
static GLint Text_Layer_Sampler_Loc;
|
|
static GLint Text_Layer_Color_Loc;
|
|
};
|