Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions | Variables
rendertext.cpp File Reference
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include "SDL_opengl.h"
#include "inexor/engine/glemu.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/rendertext.hpp"
#include "inexor/io/Error.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_hash.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/texture.hpp"
#include "inexor/util/legacy_time.hpp"

Macros

#define FONTTAB   (4*FONTW)
 
#define TEXTTAB(x)   ((int((x)/FONTTAB)+1.0f)*FONTTAB)
 
#define TEXTSKELETON
 
#define TEXTWORDSKELETON
 
#define TEXTEND(cursor)   if(cursor >= i) { do { TEXTINDEX(cursor); } while(0); }
 
#define TEXTINDEX(idx)
 
#define TEXTWHITE(idx)   if(y+FONTH > hity && x >= hitx) return idx;
 
#define TEXTLINE(idx)   if(y+FONTH > hity) return idx;
 
#define TEXTCOLOR(idx)
 
#define TEXTCHAR(idx)   x += cw; TEXTWHITE(idx)
 
#define TEXTWORD   TEXTWORDSKELETON
 
#define TEXTINDEX(idx)   if(idx == cursor) { cx = x; cy = y; break; }
 
#define TEXTWHITE(idx)
 
#define TEXTLINE(idx)
 
#define TEXTCOLOR(idx)
 
#define TEXTCHAR(idx)   x += cw;
 
#define TEXTWORD   TEXTWORDSKELETON if(i >= cursor) break;
 
#define TEXTINDEX(idx)
 
#define TEXTWHITE(idx)
 
#define TEXTLINE(idx)   if(x > width) width = x;
 
#define TEXTCOLOR(idx)
 
#define TEXTCHAR(idx)   x += cw;
 
#define TEXTWORD   x += w;
 
#define TEXTINDEX(idx)   if(idx == cursor) { cx = x; cy = y; }
 
#define TEXTWHITE(idx)
 
#define TEXTLINE(idx)
 
#define TEXTCOLOR(idx)   if(usecolor) { int nextpos = 0; text_color(&str[idx], a, nextpos); idx += nextpos;}
 
#define TEXTCHAR(idx)   draw_char(tex, c, left+x, top+y, scale); x += cw;
 
#define TEXTWORD   TEXTWORDSKELETON
 

Functions

void newfont (char *name, char *tex, int *defaultw, int *defaulth)
 
void fontoffset (char *c)
 
void fontscale (int *scale)
 
void fonttex (char *s)
 
void fontchar (int *x, int *y, int *w, int *h, int *offsetx, int *offsety, int *advance)
 
void fontskip (int *n)
 
 COMMANDN (font, newfont,"ssii")
 
 COMMAND (fontoffset,"s")
 
 COMMAND (fontscale,"i")
 
 COMMAND (fonttex,"s")
 
 COMMAND (fontchar,"iiiiiii")
 
 COMMAND (fontskip,"i")
 
void fontalias (const char *dst, const char *src)
 
 COMMAND (fontalias,"ss")
 
bool setfont (const char *name)
 
void pushfont ()
 
bool popfont ()
 
void gettextres (int &w, int &h)
 
float text_widthf (const char *str)
 
void tabify (const char *str, int *numtabs)
 
 COMMAND (tabify,"si")
 
void draw_textf (const char *fstr, int left, int top,...)
 
static float draw_char (Texture *&tex, int c, float x, float y, float scale)
 
static void text_color (const char *curstring, int a, int &skipamount)
 
int text_visible (const char *str, float hitx, float hity, int maxwidth)
 
void text_posf (const char *str, int cursor, float &cx, float &cy, int maxwidth)
 
void text_boundsf (const char *str, float &width, float &height, int maxwidth)
 
void draw_text (const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth)
 
void reloadfonts ()
 

Variables

static hashnameset< fontfonts
 
static fontfontdef = nullptr
 
static int fontdeftex = 0
 
fontcurfont = nullptr
 
int curfonttex = 0
 
static vector< font * > fontstack
 
const matrix4x3textmatrix = nullptr
 

Macro Definition Documentation

#define FONTTAB   (4*FONTW)

Referenced by tabify().

#define TEXTCHAR (   idx)    x += cw; TEXTWHITE(idx)
#define TEXTCHAR (   idx)    x += cw;
#define TEXTCHAR (   idx)    x += cw;
#define TEXTCHAR (   idx)    draw_char(tex, c, left+x, top+y, scale); x += cw;
#define TEXTCOLOR (   idx)
#define TEXTCOLOR (   idx)
#define TEXTCOLOR (   idx)
#define TEXTCOLOR (   idx)    if(usecolor) { int nextpos = 0; text_color(&str[idx], a, nextpos); idx += nextpos;}
#define TEXTEND (   cursor)    if(cursor >= i) { do { TEXTINDEX(cursor); } while(0); }

Referenced by draw_text(), and text_posf().

#define TEXTINDEX (   idx)
#define TEXTINDEX (   idx)    if(idx == cursor) { cx = x; cy = y; break; }
#define TEXTINDEX (   idx)
#define TEXTINDEX (   idx)    if(idx == cursor) { cx = x; cy = y; }
#define TEXTLINE (   idx)    if(y+FONTH > hity) return idx;

Referenced by text_boundsf().

#define TEXTLINE (   idx)
#define TEXTLINE (   idx)    if(x > width) width = x;
#define TEXTLINE (   idx)
#define TEXTSKELETON
#define TEXTTAB (   x)    ((int((x)/FONTTAB)+1.0f)*FONTTAB)

Referenced by tabify().

#define TEXTWHITE (   idx)    if(y+FONTH > hity && x >= hitx) return idx;
#define TEXTWHITE (   idx)
#define TEXTWHITE (   idx)
#define TEXTWHITE (   idx)
#define TEXTWORD   TEXTWORDSKELETON
#define TEXTWORD   TEXTWORDSKELETON if(i >= cursor) break;
#define TEXTWORD   x += w;
#define TEXTWORD   TEXTWORDSKELETON
#define TEXTWORDSKELETON
Value:
for(; j <= i; j++)\
{\
int c = uchar(str[j]);\
if(c=='\x1b') { if(str[j+1]) { j++; TEXTCOLOR(j) }}\
else { float cw = scale*curfont->chars[c-curfont->charoffset].advance; TEXTCHAR(j) }\
}
int charoffset
Definition: rendertext.hpp:23
#define TEXTINDEX(idx)
#define TEXTCHAR(idx)
vector< charinfo > chars
Definition: rendertext.hpp:22
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
#define TEXTCOLOR(idx)
unsigned char uchar
Basic type definitions.
Definition: cube_types.hpp:7
font * curfont
Definition: rendertext.cpp:26

Function Documentation

COMMAND ( fontoffset  ,
"s"   
)
COMMAND ( fontscale  ,
"i"   
)
COMMAND ( fonttex  ,
"s"   
)
COMMAND ( fontchar  ,
"iiiiiii"   
)
COMMAND ( fontskip  ,
"i"   
)
COMMAND ( fontalias  ,
"ss"   
)
COMMAND ( tabify  ,
"si"   
)
COMMANDN ( font  ,
newfont  ,
"ssii"   
)
static float draw_char ( Texture *&  tex,
int  c,
float  x,
float  y,
float  scale 
)
static
void draw_text ( const char *  str,
int  left,
int  top,
int  r,
int  g,
int  b,
int  a,
int  cursor,
int  maxwidth 
)
void draw_textf ( const char *  fstr,
int  left,
int  top,
  ... 
)
void fontalias ( const char *  dst,
const char *  src 
)
void fontchar ( int *  x,
int *  y,
int *  w,
int *  h,
int *  offsetx,
int *  offsety,
int *  advance 
)
void fontoffset ( char *  c)

References font::charoffset.

void fontscale ( int *  scale)

References font::defaulth, and font::scale.

void fontskip ( int *  n)
void fonttex ( char *  s)
void gettextres ( int &  w,
int &  h 
)
void newfont ( char *  name,
char *  tex,
int *  defaultw,
int *  defaulth 
)
bool popfont ( )
void pushfont ( )
void reloadfonts ( )

References enumerate, f(), fatal(), loopv, and reloadtexture().

Referenced by resetgl().

bool setfont ( const char *  name)
void tabify ( const char *  str,
int *  numtabs 
)
void text_boundsf ( const char *  str,
float &  width,
float &  height,
int  maxwidth 
)

References FONTH, TEXTLINE, and TEXTSKELETON.

Referenced by text_bounds(), and text_widthf().

static void text_color ( const char *  curstring,
int  a,
int &  skipamount 
)
static

References gle::color(), gle::end(), and xtraverts.

void text_posf ( const char *  str,
int  cursor,
float &  cx,
float &  cy,
int  maxwidth 
)

References TEXTEND, and TEXTSKELETON.

Referenced by text_pos().

int text_visible ( const char *  str,
float  hitx,
float  hity,
int  maxwidth 
)

References TEXTSKELETON.

Referenced by editor::hit(), and editor::key().

float text_widthf ( const char *  str)

References text_boundsf().

Referenced by tabify(), and text_width().

Variable Documentation

font* curfont = nullptr
int curfonttex = 0
font* fontdef = nullptr
static
int fontdeftex = 0
static

Referenced by fontalias(), fontchar(), fonttex(), and newfont().

hashnameset<font> fonts
static
vector<font *> fontstack
static
const matrix4x3* textmatrix = nullptr