MeVisLab Toolbox Reference
View2DFont Class Referenceabstract

Abstract GL font drawing using FTGL. More...

#include <View2DFont.h>

Inheritance diagram for View2DFont:
View2DFontFTGL View2DFontQt

Public Types

enum  AlignXMode { ALIGN_LEFT , ALIGN_RIGHT , ALIGN_CENTER }
 align mode of multi-line text More...
 

Public Member Functions

 View2DFont ()
 
virtual ~View2DFont ()
 
virtual bool init (const char *fontname=nullptr)=0
 init with given font (either just a font name without .ttf or an absolute path) requires a valid GL context! More...
 
virtual int getFontHeight (float fontSize) const =0
 get height of font (ascender + descender) More...
 
virtual int getFontAscender (float fontSize) const =0
 get ascender of font More...
 
virtual int getFontDescender (float fontSize) const =0
 get descender of font More...
 
virtual int getStringWidth (float fontSize, const char *string, int len) const =0
 get width of simple string More...
 
virtual void drawString (float dx, float dy, float fontSize, const float *color, const char *string, int length, bool shadow=true, const float *shadowColor=nullptr, bool flipped=false)=0
 draws a simple string with no linefeeds, the drawing starts at the top-left corner color needs to point to a float[4] array (RGBA) shadowColor is optional and needs to point to a float[3] array (RGB), alpha is taken from color. More...
 
void drawStringFlipped (float dx, float dy, float fontSize, const float *color, const char *string, int length, bool shadow=true, const float *shadowColor=nullptr)
 as above for drawing a string up-side down where you don't need to specify all parameters More...
 
virtual void getTextSize (float fontSize, const char *text, int &width, int &height, float lineSpacing=0.0f) const
 returns size of the box spanned by text box More...
 
virtual void drawText (float dx, float dy, float fontSize, const float *color, const char *text, AlignXMode mode, bool shadow=true, float lineSpacing=0.0f, const float *shadowColor=nullptr)
 draws a multi-line text, lines are separated by
, the drawing starts at the top-left corner. More...
 

Static Public Member Functions

static View2DFontglobalFont ()
 get the global font used for annotations etc. (only call this within a valid GL context!) More...
 
static View2DFontcreateFont (const char *fontname=nullptr)
 create a new font object with the given font name (/see init). More...
 

Detailed Description

Abstract GL font drawing using FTGL.

This is the extended version of mlGL2DFont (from MLOpenGL). Most calls are bridged towards mlGL2DFont, but it additionally features rendering of larger text blocks including line feeds. All strings are expected to be in UTF8 encoding.

Font rendering of all draw methods starts at top-left (x,y).

The above figure illustrates how the fonts are rendered. The rendering starts at the top-left (x,y). The height of the font is given by the sum of ascender and descender.

Definition at line 29 of file View2DFont.h.

Member Enumeration Documentation

◆ AlignXMode

align mode of multi-line text

Enumerator
ALIGN_LEFT 
ALIGN_RIGHT 
ALIGN_CENTER 

Definition at line 36 of file View2DFont.h.

Constructor & Destructor Documentation

◆ View2DFont()

View2DFont::View2DFont ( )

◆ ~View2DFont()

virtual View2DFont::~View2DFont ( )
virtual

Member Function Documentation

◆ createFont()

static View2DFont* View2DFont::createFont ( const char *  fontname = nullptr)
static

create a new font object with the given font name (/see init).

If no fontname is given, this uses the same font as globalFont(). The caller becomes the owner of the object.

Only call this within a valid GL context!

◆ drawString()

virtual void View2DFont::drawString ( float  dx,
float  dy,
float  fontSize,
const float *  color,
const char *  string,
int  length,
bool  shadow = true,
const float *  shadowColor = nullptr,
bool  flipped = false 
)
pure virtual

draws a simple string with no linefeeds, the drawing starts at the top-left corner color needs to point to a float[4] array (RGBA) shadowColor is optional and needs to point to a float[3] array (RGB), alpha is taken from color.

flipped if set draws the string up-side down (for those cases where the coordinate system is not flipped from the OpenGL default)

Implemented in View2DFontQt, and View2DFontFTGL.

◆ drawStringFlipped()

void View2DFont::drawStringFlipped ( float  dx,
float  dy,
float  fontSize,
const float *  color,
const char *  string,
int  length,
bool  shadow = true,
const float *  shadowColor = nullptr 
)
inline

as above for drawing a string up-side down where you don't need to specify all parameters

Definition at line 65 of file View2DFont.h.

◆ drawText()

virtual void View2DFont::drawText ( float  dx,
float  dy,
float  fontSize,
const float *  color,
const char *  text,
AlignXMode  mode,
bool  shadow = true,
float  lineSpacing = 0.0f,
const float *  shadowColor = nullptr 
)
virtual

draws a multi-line text, lines are separated by
, the drawing starts at the top-left corner.

color needs to point to a float[4] array (RGBA) shadowColor is optional and needs to point to a float[3] array (RGB), alpha is taken from color.

◆ getFontAscender()

virtual int View2DFont::getFontAscender ( float  fontSize) const
pure virtual

get ascender of font

Implemented in View2DFontQt, and View2DFontFTGL.

◆ getFontDescender()

virtual int View2DFont::getFontDescender ( float  fontSize) const
pure virtual

get descender of font

Implemented in View2DFontQt, and View2DFontFTGL.

◆ getFontHeight()

virtual int View2DFont::getFontHeight ( float  fontSize) const
pure virtual

get height of font (ascender + descender)

Implemented in View2DFontQt, and View2DFontFTGL.

◆ getStringWidth()

virtual int View2DFont::getStringWidth ( float  fontSize,
const char *  string,
int  len 
) const
pure virtual

get width of simple string

Implemented in View2DFontQt, and View2DFontFTGL.

◆ getTextSize()

virtual void View2DFont::getTextSize ( float  fontSize,
const char *  text,
int &  width,
int &  height,
float  lineSpacing = 0.0f 
) const
virtual

returns size of the box spanned by text box

◆ globalFont()

static View2DFont* View2DFont::globalFont ( )
static

get the global font used for annotations etc. (only call this within a valid GL context!)

◆ init()

virtual bool View2DFont::init ( const char *  fontname = nullptr)
pure virtual

init with given font (either just a font name without .ttf or an absolute path) requires a valid GL context!

Implemented in View2DFontQt, and View2DFontFTGL.


The documentation for this class was generated from the following file: